From 732b5bce4e40e0901e8bb36b88b0d4caa94898cd Mon Sep 17 00:00:00 2001 From: codex Date: Mon, 19 Oct 2026 15:03:12 +0800 Subject: [PATCH] fix(agent): align capability readiness contract --- agent/hypervisor/types_test.go | 25 ++++++++++++++++ .../Cloud/CloudAgentSettingsService.php | 2 +- web/tests/CloudAgentReadinessContractTest.php | 30 +++++++++++++++---- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/agent/hypervisor/types_test.go b/agent/hypervisor/types_test.go index 379cb507..9e9e39cc 100644 --- a/agent/hypervisor/types_test.go +++ b/agent/hypervisor/types_test.go @@ -5,6 +5,31 @@ import ( "testing" ) +func TestFeatureSetWireContract(t *testing.T) { + encoded, err := json.Marshal(FeatureSet{}) + if err != nil { + t.Fatalf("marshal FeatureSet: %v", err) + } + + var wire map[string]bool + if err := json.Unmarshal(encoded, &wire); err != nil { + t.Fatalf("decode FeatureSet wire payload: %v", err) + } + expected := []string{ + "create_vm", "delete_vm", "power", "settings", "network", + "reinstall", "snapshots", "firewall", "rescue", "metrics", + "console", "templates", "user_iso", "uefi", "secure_boot", + } + if len(wire) != len(expected) { + t.Fatalf("FeatureSet wire keys = %v, want exactly %v", wire, expected) + } + for _, key := range expected { + if _, exists := wire[key]; !exists { + t.Fatalf("FeatureSet wire payload is missing %q: %v", key, wire) + } + } +} + func TestVMMetadataWireContractExcludesPanelTemplateFields(t *testing.T) { encoded, err := json.Marshal(VMMetadata{ UUID: "11111111-1111-4111-8111-111111111111", diff --git a/web/app/Services/Cloud/CloudAgentSettingsService.php b/web/app/Services/Cloud/CloudAgentSettingsService.php index 01091488..b4235160 100644 --- a/web/app/Services/Cloud/CloudAgentSettingsService.php +++ b/web/app/Services/Cloud/CloudAgentSettingsService.php @@ -13,7 +13,7 @@ final class CloudAgentSettingsService private const REQUIRED_FEATURES = [ 'create_vm', 'delete_vm', 'power', 'settings', 'network', 'reinstall', 'snapshots', 'firewall', 'rescue', 'metrics', - 'console', 'templates', 'user_iso', 'reconciliation', + 'console', 'templates', 'user_iso', ]; /** Hosts that may receive catalog replicas or VM operations. */ diff --git a/web/tests/CloudAgentReadinessContractTest.php b/web/tests/CloudAgentReadinessContractTest.php index 0f24d3fe..567e65f2 100644 --- a/web/tests/CloudAgentReadinessContractTest.php +++ b/web/tests/CloudAgentReadinessContractTest.php @@ -23,7 +23,8 @@ $assert(is_string($settings) && str_contains($settings, "'GET', '/v1/capabilities', \$actor") && str_contains($settings, "private const REQUIRED_FEATURES = [") && str_contains($settings, "'create_vm', 'delete_vm', 'power', 'settings', 'network'") - && str_contains($settings, "'console', 'templates', 'user_iso', 'reconciliation'") + && str_contains($settings, "'console', 'templates', 'user_iso',") + && !str_contains($settings, "'reconciliation'") && str_contains($settings, "(\$capabilities['backend'] ?? null) !== 'libvirt'") && str_contains($settings, "\$features['uefi'] !== true") && str_contains($settings, "\$features['secure_boot'] !== false") @@ -47,10 +48,29 @@ $capabilitySummary = new ReflectionMethod( $required = [ 'create_vm', 'delete_vm', 'power', 'settings', 'network', 'reinstall', 'snapshots', 'firewall', 'rescue', 'metrics', - 'console', 'templates', 'user_iso', 'reconciliation', + 'console', 'templates', 'user_iso', ]; -$features = array_fill_keys($required, true); -$features['uefi'] = true; +$agentTypes = file_get_contents( + dirname($root) . '/agent/hypervisor/types.go' +); +$featureStruct = []; +$featureTags = []; +$assert(is_string($agentTypes) + && preg_match('/type FeatureSet struct \\{(?.*?)^\\}/ms', + $agentTypes, $featureStruct) === 1 + && preg_match_all('/json:"([a-z][a-z0-9_]*)"/', + $featureStruct['body'], $featureTags) !== false, + 'Go Agent capability feature contract could not be read.'); +$agentFeatureKeys = $featureTags[1]; +$agentRequired = array_values(array_diff( + $agentFeatureKeys, ['uefi', 'secure_boot'] +)); +$assert($agentRequired === $required + && $agentFeatureKeys === array_merge( + $required, ['uefi', 'secure_boot'] + ), + 'PHP required capabilities diverged from the Go Agent feature contract.'); +$features = array_fill_keys($agentFeatureKeys, true); $features['secure_boot'] = false; $summary = $capabilitySummary->invoke(null, [ 'backend' => 'libvirt', 'features' => $features, @@ -64,7 +84,7 @@ $assert($summary === [ 'storage_configuration' => true, 'network_selectors' => ['bridge:br0', 'network:default'], 'required_network_selector' => 'bridge:br0', - 'required_feature_count' => 14, + 'required_feature_count' => 13, 'available_features' => $required, 'unavailable_features' => [], ], 'Valid libvirt/UEFI/no-Secure-Boot capability response changed.');