Skip to content

Commit fda07fb

Browse files
committed
test(desktop-proof): handle missing Hyper-V module
Keep the no-mutation AST proof portable while retaining dynamic installed-family completeness on Windows. An absent Hyper-V module now produces explicit empty inventories instead of a misleading null command entry.
1 parent aaefdf7 commit fda07fb

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎.github/scripts/test_codex_desktop_boundary.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,19 @@ def test_broker_has_no_hyper_v_switch_mutation_commands(self):
845845
"$names=@($ast.FindAll({param($node)"
846846
"$node -is [System.Management.Automation.Language.CommandAst]},$true)|"
847847
"ForEach-Object{$_.GetCommandName()}|Where-Object{$_});"
848-
"$family=@((Get-Command -Module Hyper-V -Name '*VMSwitch*').Name);"
849-
"$used=@($names|ForEach-Object{$_.Split([char]92)[-1]}|"
848+
"$normalized=@($names|ForEach-Object{$_.Split([char]92)[-1]});"
849+
"$astVmSwitchCommands=@($normalized|Where-Object{"
850+
"$_ -match '^(?:Add|Disable|Enable|Get|New|Remove|Rename|Set)-VMSwitch'});"
851+
"$moduleAvailable=(@(Get-Module -ListAvailable -Name Hyper-V).Count -gt 0);"
852+
"$family=@();"
853+
"if($moduleAvailable){"
854+
"$family=@(Get-Command -Module Hyper-V -Name '*VMSwitch*' "
855+
"-ErrorAction Stop|ForEach-Object{$_.Name}|Where-Object{$_})};"
856+
"$used=@($normalized|"
850857
"Where-Object{$family -ccontains $_});"
851-
"[ordered]@{family=$family;used=$used}|ConvertTo-Json -Compress",
858+
"[ordered]@{module_available=$moduleAvailable;family=$family;"
859+
"ast_vmswitch_commands=$astVmSwitchCommands;used=$used}|"
860+
"ConvertTo-Json -Compress",
852861
],
853862
cwd=REPO_ROOT,
854863
text=True,
@@ -859,8 +868,14 @@ def test_broker_has_no_hyper_v_switch_mutation_commands(self):
859868
)
860869
self.assertEqual(inspected.returncode, 0, inspected.stdout + inspected.stderr)
861870
command_inventory = json.loads(inspected.stdout)
862-
self.assertIn("Set-VMSwitch", command_inventory["family"])
863-
self.assertEqual(command_inventory["used"], ["Get-VMSwitch"])
871+
self.assertNotIn(None, command_inventory["family"])
872+
self.assertEqual(command_inventory["ast_vmswitch_commands"], ["Get-VMSwitch"])
873+
if command_inventory["module_available"]:
874+
self.assertIn("Set-VMSwitch", command_inventory["family"])
875+
self.assertEqual(command_inventory["used"], ["Get-VMSwitch"])
876+
else:
877+
self.assertEqual(command_inventory["family"], [])
878+
self.assertEqual(command_inventory["used"], [])
864879

865880
def test_boundary_requires_direct_iso_application_not_a_template_vhd(self):
866881
self.assertEqual(self.contract["image"]["provisioning_mode"], "iso-apply-fresh-vhdx")

0 commit comments

Comments
 (0)