Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fail closed platform saves on unavailable usage
rcourtman441e45e74a7f
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex bee5e91d28..f1b02794dd 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -223,6 +223,14 @@ management, and fleet control surfaces.ownership cleanup only, not as install inventory proof or fleet enrollmentstate.+ The same lifecycle-adjacent platform-connections boundary also assumes+ direct TrueNAS and VMware connection writes fail closed when canonical+ monitored-system usage is unavailable. Shared `internal/api/` admission+ helpers must return `monitored_system_usage_unavailable` before save, and+ VMware must not collect external vCenter inventory before that canonical+ capacity view is safe, so fleet/setup surfaces cannot bypass the+ monitored-system accounting boundary through direct API writes.+## Forbidden Paths1. New install or update continuity behavior hidden only inside broad monitoring ownership.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 62ecc21be3..fdba8c1437 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -169,6 +169,7 @@ Own canonical runtime payload shapes between backend and frontend.and the same shared correlation card's ordering and truncation rule, so callers pass raw correlations instead of encoding their own top-N sort behaviorand the shared `frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx` and `frontend-modern/src/components/Infrastructure/ResourceCorrelationSummary.tsx` cards' infrastructure resource-link default, so the Patrol page, resource drawer, and problem-resource dashboard panels inherit the canonical resource-filter path construction instead of rebuilding infrastructure URLs inline8. Route frontend API-client parsed error propagation, API-error-status fallback handling, allowed-status handling, custom status-specific error handling, command-trigger success envelope handling, shared response parsing pipelines, missing-resource lookup handling, metadata CRUD routing, stream event consumption, response status, collection normalization, scalar payload coercion, and structured error normalization through canonical shared helpers under `frontend-modern/src/api/`+9. Keep direct platform-connection write admission on this shared API contract as well: `internal/api/truenas_handlers.go`, `internal/api/vmware_handlers.go`, `internal/api/monitored_system_limit_enforcement.go`, and `internal/api/contract_test.go` must keep TrueNAS and VMware creates/updates fail-closed with `monitored_system_usage_unavailable` whenever the canonical monitored-system usage view is unsettled or rebuilding, and VMware write admission must check that canonical usage state before collecting external vCenter inventory so direct API callers cannot persist connections behind an unsafe capacity view.9. Add or change API token scope, assignment, and revocation presentation through `frontend-modern/src/components/Settings/APITokenManager.tsx`, `frontend-modern/src/components/Settings/apiTokenManagerModel.ts`, and `frontend-modern/src/components/Settings/useAPITokenManagerState.ts`10. Add or change infrastructure operations token generation, lookup, assignment, the pure unified-agent inventory/install model, the split infrastructure install/reporting state owners, the split direct-node/discovery infrastructure settings owners, the shared infrastructure-operations state provider/context shell, and reporting/install presentation through `frontend-modern/src/components/Settings/InfrastructureOperationsController.tsx`, `frontend-modern/src/components/Settings/infrastructureOperationsModel.tsx`, `frontend-modern/src/components/Settings/useInfrastructureConfiguredNodesState.ts`, `frontend-modern/src/components/Settings/useInfrastructureDiscoveryRuntimeState.ts`, `frontend-modern/src/components/Settings/useInfrastructureInstallState.tsx`, `frontend-modern/src/components/Settings/useInfrastructureOperationsState.tsx`, and `frontend-modern/src/components/Settings/useInfrastructureReportingState.tsx`11. Keep `internal/api/session_store.go` on a fail-closed auth-persistence boundary: persisted OIDC refresh tokens may only round-trip through encrypted-at-rest session payloads, and any missing-crypto or invalid-ciphertext path must drop the token instead of preserving plaintext-at-rest session state.diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 2bf43a976b..ae75c7fbbf 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -70,6 +70,7 @@ querying, and the operator-facing storage health presentation layer.provider-backed recovery: storage and recovery must treat `truenas_disabled`as an explicit platform opt-out, not as the baseline onboarding state for asupported platform.+ That same adjacent API boundary also owns direct provider write admission when canonical monitored-system usage is unavailable. `internal/api/truenas_handlers.go`, `internal/api/vmware_handlers.go`, and the shared monitored-system admission helpers must fail those connection saves closed before provider state persists, and VMware must not collect external vCenter inventory before the canonical capacity view is safe.That same adjacent API boundary now also owns SSO outbound discovery and metadata fetch trust: storage- and recovery-adjacent surfaces may share `internal/api/sso_outbound.go`, `internal/api/saml_service.go`, and `internal/api/oidc_service.go`, but they must not fork separate metadata/discovery HTTP clients, redirect policies, or credential-file read rules when they depend on shared backend auth helpers.5. Route canonical storage/recovery resource selection through `frontend-modern/src/hooks/useUnifiedResources.ts` and the owning `unified-resources` contractThat shared hook now also projects resource `clusterId` through the shared cluster-name helper, so storage and recovery links keep the same cluster-context label as other unified-resource consumers instead of rebuilding a local fallback chain.diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 36484aa1b3..84102bdfd8 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -5432,6 +5432,80 @@ func TestContract_MonitoredSystemUsageUnavailableIncludesReason(t *testing.T) {}}+func TestContract_PlatformConnectionWritesFailClosedWhenUsageUnavailable(t *testing.T) {+ t.Run("truenas add", func(t *testing.T) {+ setTrueNASFeatureForTest(t, true)+ setMockModeForTrueNASTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, _, monitor := newTrueNASHandlersForTest(t, nil)+ bindUnavailableSupplementalUsageProviderForTest(+ t,+ monitor,+ unifiedresources.SourceTrueNAS,+ monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ )++ body := marshalTrueNASRequest(t, map[string]any{+ "name": "tower",+ "host": "tower.local",+ "apiKey": "super-secret",+ })+ req := httptest.NewRequest(http.MethodPost, "/api/truenas/connections", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleAdd(rec, req)++ assertMonitoredSystemUsageUnavailableReason(+ t,+ rec,+ monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ )+ })++ t.Run("vmware add", func(t *testing.T) {+ setVMwareFeatureForTest(t, true)+ setMockModeForVMwareTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, _ := newVMwareHandlersForTest(t)+ monitor, _, _ := newTestMonitor(t)+ handler.getMonitor = func(context.Context) *monitoring.Monitor { return monitor }+ bindUnavailableSupplementalUsageProviderForTest(+ t,+ monitor,+ unifiedresources.SourceVMware,+ monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ )++ previewRecordsCalled := false+ handler.previewRecords = func(context.Context, config.VMwareVCenterInstance) ([]unifiedresources.IngestRecord, error) {+ previewRecordsCalled = true+ return nil, nil+ }++ body := marshalVMwareRequest(t, map[string]any{+ "name": "lab-vcenter",+ "host": "vcsa.lab.local",+ "port": 443,+ "username": "[email protected]",+ "password": "super-secret",+ "enabled": true,+ })+ req := httptest.NewRequest(http.MethodPost, "/api/vmware/connections", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleAdd(rec, req)++ assertMonitoredSystemUsageUnavailableReason(+ t,+ rec,+ monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ )+ if previewRecordsCalled {+ t.Fatal("expected VMware write admission to fail before external inventory preview")+ }+ })+}+func TestContract_ConfiguredNodeReplacementsUseCanonicalSelectors(t *testing.T) {testCases := []struct {name stringdiff --git a/internal/api/monitored_system_limit_enforcement.go b/internal/api/monitored_system_limit_enforcement.goindex 6abccdef2f..24be4ea639 100644--- a/internal/api/monitored_system_limit_enforcement.go+++ b/internal/api/monitored_system_limit_enforcement.go@@ -286,12 +286,12 @@ func monitoredSystemLimitDecisionForCandidateReplacement(return monitoredSystemLimitDecisionFromPreview(ctx, limit, true, projection)}-func monitoredSystemLimitDecisionForRecords(+func monitoredSystemLimitDecisionForRecordsFromUsage(ctx context.Context,- monitor *monitoring.Monitor,+ limit int,+ usage monitoredSystemUsageSnapshot,recordsBySource map[unifiedresources.DataSource][]unifiedresources.IngestRecord,) monitoredSystemLimitDecision {- limit := maxMonitoredSystemsLimitForContext(ctx)if limit <= 0 {return monitoredSystemLimitDecision{limit: limit,@@ -299,7 +299,6 @@ func monitoredSystemLimitDecisionForRecords(}}- usage := monitoredSystemUsage(monitor)if !usage.available {return monitoredSystemLimitDecision{limit: limit,@@ -311,13 +310,13 @@ func monitoredSystemLimitDecisionForRecords(return monitoredSystemLimitDecisionFromPreview(ctx, limit, false, projection)}-func monitoredSystemLimitDecisionForRecordsReplacement(+func monitoredSystemLimitDecisionForRecordsReplacementFromUsage(ctx context.Context,- monitor *monitoring.Monitor,+ limit int,+ usage monitoredSystemUsageSnapshot,replacement unifiedresources.MonitoredSystemReplacement,recordsBySource map[unifiedresources.DataSource][]unifiedresources.IngestRecord,) monitoredSystemLimitDecision {- limit := maxMonitoredSystemsLimitForContext(ctx)if limit <= 0 {return monitoredSystemLimitDecision{limit: limit,@@ -325,7 +324,6 @@ func monitoredSystemLimitDecisionForRecordsReplacement(}}- usage := monitoredSystemUsage(monitor)if !usage.available {return monitoredSystemLimitDecision{limit: limit,diff --git a/internal/api/monitored_system_limit_enforcement_test.go b/internal/api/monitored_system_limit_enforcement_test.goindex 8e4b4f31c8..bc5467433e 100644--- a/internal/api/monitored_system_limit_enforcement_test.go+++ b/internal/api/monitored_system_limit_enforcement_test.go@@ -82,6 +82,21 @@ func requireSnippetBefore(t *testing.T, source string, earlier string, later str}}+func requireSourceSegment(t *testing.T, source string, start string, end string) string {+ t.Helper()++ startIndex := strings.Index(source, start)+ if startIndex < 0 {+ t.Fatalf("missing segment start %q", start)+ }+ remainder := source[startIndex:]+ endIndex := strings.Index(remainder[len(start):], end)+ if endIndex < 0 {+ t.Fatalf("missing segment end %q after %q", end, start)+ }+ return remainder[:len(start)+endIndex]+}+func TestMonitoredSystemLimitDecisionOnlyBlocksNetNewSystems(t *testing.T) {ctx := context.Background()@@ -301,8 +316,8 @@ func TestMonitoredSystemAdmissionSurfacesStayBehindSharedLimitGate(t *testing.T)sources: []sourceContract{{file: "vmware_handlers.go",requiredSnippets: []string{- "monitoredSystemLimitDecisionForRecords(",- "monitoredSystemLimitDecisionForRecordsReplacement(",+ "monitoredSystemLimitDecisionForRecordsFromUsage(",+ "monitoredSystemLimitDecisionForRecordsReplacementFromUsage(","SaveVMwareConfig(",},requiredOrderings: [][2]string{@@ -382,6 +397,48 @@ func TestMonitoredSystemAdmissionSurfacesStayBehindSharedLimitGate(t *testing.T)}}+func TestVMwareAdmissionEnforcementChecksUsageBeforeExternalInventory(t *testing.T) {+ source := readAPIPackageFile(t, "vmware_handlers.go")++ addEnforcement := requireSourceSegment(+ t,+ source,+ "func (h *VMwareHandlers) enforceMonitoredSystemLimit(",+ "func (h *VMwareHandlers) enforceMonitoredSystemLimitReplacement(",+ )+ requireSnippetBefore(+ t,+ addEnforcement,+ "usage := monitoredSystemUsage(monitor)",+ "records, invalidConfig, err := h.previewMonitoredSystemRecords(r.Context(), instance)",+ )+ requireSnippetBefore(+ t,+ addEnforcement,+ "if !usage.available",+ "records, invalidConfig, err := h.previewMonitoredSystemRecords(r.Context(), instance)",+ )++ replacementEnforcement := requireSourceSegment(+ t,+ source,+ "func (h *VMwareHandlers) enforceMonitoredSystemLimitReplacement(",+ "func (h *VMwareHandlers) previewMonitoredSystemRecords(",+ )+ requireSnippetBefore(+ t,+ replacementEnforcement,+ "usage := monitoredSystemUsage(monitor)",+ "records, invalidConfig, err := h.previewMonitoredSystemRecords(r.Context(), next)",+ )+ requireSnippetBefore(+ t,+ replacementEnforcement,+ "if !usage.available",+ "records, invalidConfig, err := h.previewMonitoredSystemRecords(r.Context(), next)",+ )+}+func TestMonitoredSystemCountNilMonitor(t *testing.T) {got := monitoredSystemCount(nil)if got != 0 {diff --git a/internal/api/monitored_system_usage_test_helpers_test.go b/internal/api/monitored_system_usage_test_helpers_test.goindex f214354476..9f05f24d2a 100644--- a/internal/api/monitored_system_usage_test_helpers_test.go+++ b/internal/api/monitored_system_usage_test_helpers_test.go@@ -67,6 +67,27 @@ func bindTestSupplementalUsageProvider(monitor.SetSupplementalRecordsProvider(source, provider)}+func bindUnavailableSupplementalUsageProviderForTest(+ t *testing.T,+ monitor *monitoring.Monitor,+ source unifiedresources.DataSource,+ reason string,+) {+ t.Helper()++ provider := newTestSupplementalUsageProvider(source)+ bindTestSupplementalUsageProvider(monitor, source, provider)++ switch reason {+ case monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled:+ return+ case monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryRebuildPending:+ provider.settleAtWithRecords(time.Now().UTC().Add(time.Minute), nil)+ default:+ t.Fatalf("unsupported monitored-system usage unavailable reason %q", reason)+ }+}+func assertMonitoredSystemUsageUnavailableReason(t *testing.T,rec *httptest.ResponseRecorder,diff --git a/internal/api/truenas_handlers_test.go b/internal/api/truenas_handlers_test.goindex ad174b763c..cf6c679773 100644--- a/internal/api/truenas_handlers_test.go+++ b/internal/api/truenas_handlers_test.go@@ -191,6 +191,50 @@ func TestTrueNASHandlers_HandleAdd_BlocksNewCountedSystemAtLimit(t *testing.T) {}}+func TestTrueNASHandlers_HandleAdd_ReturnsUnavailableWhenSupplementalInventoryNotSafe(t *testing.T) {+ for _, tc := range []struct {+ name string+ reason string+ }{+ {+ name: "unsettled",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ },+ {+ name: "rebuild pending",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryRebuildPending,+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ setTrueNASFeatureForTest(t, true)+ setMockModeForTrueNASTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, persistence, monitor := newTrueNASHandlersForTest(t, nil)+ bindUnavailableSupplementalUsageProviderForTest(t, monitor, unifiedresources.SourceTrueNAS, tc.reason)++ body := marshalTrueNASRequest(t, map[string]any{+ "name": "tower",+ "host": "tower.local",+ "apiKey": "super-secret",+ })+ req := httptest.NewRequest(http.MethodPost, "/api/truenas/connections", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleAdd(rec, req)++ assertMonitoredSystemUsageUnavailableReason(t, rec, tc.reason)++ stored, err := persistence.LoadTrueNASConfig()+ if err != nil {+ t.Fatalf("load truenas config: %v", err)+ }+ if len(stored) != 0 {+ t.Fatalf("expected unavailable monitored-system usage not to persist add, got %d connections", len(stored))+ }+ })+ }+}+func TestTrueNASHandlers_HandleAdd_AllowsCanonicalOverlapAtLimit(t *testing.T) {setTrueNASFeatureForTest(t, true)setMockModeForTrueNASTest(t, false)@@ -610,6 +654,64 @@ func TestTrueNASHandlers_HandleUpdate_BlocksProjectedNetNewSystemAtLimit(t *test}}+func TestTrueNASHandlers_HandleUpdate_ReturnsUnavailableWhenSupplementalInventoryNotSafe(t *testing.T) {+ for _, tc := range []struct {+ name string+ reason string+ }{+ {+ name: "unsettled",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ },+ {+ name: "rebuild pending",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryRebuildPending,+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ setTrueNASFeatureForTest(t, true)+ setMockModeForTrueNASTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, persistence, monitor := newTrueNASHandlersForTest(t, nil)+ bindUnavailableSupplementalUsageProviderForTest(t, monitor, unifiedresources.SourceTrueNAS, tc.reason)+ if err := persistence.SaveTrueNASConfig([]config.TrueNASInstance{+ {+ ID: "alpha",+ Name: "archive",+ Host: "archive.local",+ APIKey: "super-secret",+ UseHTTPS: true,+ Enabled: true,+ },+ }); err != nil {+ t.Fatalf("seed truenas config: %v", err)+ }++ body := marshalTrueNASRequest(t, map[string]any{+ "name": "archive",+ "host": "backup.local",+ "apiKey": "********",+ "useHttps": true,+ "enabled": true,+ })+ req := httptest.NewRequest(http.MethodPut, "/api/truenas/connections/alpha", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleUpdate(rec, req)++ assertMonitoredSystemUsageUnavailableReason(t, rec, tc.reason)++ stored, err := persistence.LoadTrueNASConfig()+ if err != nil {+ t.Fatalf("load truenas config: %v", err)+ }+ if len(stored) != 1 || stored[0].Host != "archive.local" {+ t.Fatalf("expected unavailable monitored-system usage to preserve stored connection, got %+v", stored)+ }+ })+ }+}+func TestTrueNASHandlers_HandleUpdate_UnknownID(t *testing.T) {setTrueNASFeatureForTest(t, true)setMockModeForTrueNASTest(t, false)diff --git a/internal/api/vmware_handlers.go b/internal/api/vmware_handlers.goindex 8823986370..4fa0255e31 100644--- a/internal/api/vmware_handlers.go+++ b/internal/api/vmware_handlers.go@@ -653,13 +653,15 @@ func (h *VMwareHandlers) enforceMonitoredSystemLimit(r *http.Request,instance config.VMwareVCenterInstance,) bool {- if maxMonitoredSystemsLimitForContext(r.Context()) <= 0 {+ limit := maxMonitoredSystemsLimitForContext(r.Context())+ if limit <= 0 {return false}monitor := h.monitorForRequest(r.Context())- if monitor == nil {- writeMonitoredSystemUsageUnavailable(w, monitoring.MonitoredSystemUsageUnavailableMonitorState)+ usage := monitoredSystemUsage(monitor)+ if !usage.available {+ writeMonitoredSystemUsageUnavailable(w, usage.unavailableReason)return true}@@ -669,7 +671,7 @@ func (h *VMwareHandlers) enforceMonitoredSystemLimit(return true}- decision := monitoredSystemLimitDecisionForRecords(r.Context(), monitor, map[unifiedresources.DataSource][]unifiedresources.IngestRecord{+ decision := monitoredSystemLimitDecisionForRecordsFromUsage(r.Context(), limit, usage, map[unifiedresources.DataSource][]unifiedresources.IngestRecord{unifiedresources.SourceVMware: records,})if !decision.usageAvailable {@@ -697,8 +699,9 @@ func (h *VMwareHandlers) enforceMonitoredSystemLimitReplacement(}monitor := h.monitorForRequest(r.Context())- if monitor == nil {- writeMonitoredSystemUsageUnavailable(w, monitoring.MonitoredSystemUsageUnavailableMonitorState)+ usage := monitoredSystemUsage(monitor)+ if !usage.available {+ writeMonitoredSystemUsageUnavailable(w, usage.unavailableReason)return true}@@ -709,7 +712,7 @@ func (h *VMwareHandlers) enforceMonitoredSystemLimitReplacement(}replacementID := strings.TrimSpace(current.ID)- decision := monitoredSystemLimitDecisionForRecordsReplacement(r.Context(), monitor, unifiedresources.MonitoredSystemReplacement{+ decision := monitoredSystemLimitDecisionForRecordsReplacementFromUsage(r.Context(), limit, usage, unifiedresources.MonitoredSystemReplacement{Source: unifiedresources.SourceVMware,Selector: unifiedresources.MonitoredSystemReplacementSelector{ResourceID: replacementID,diff --git a/internal/api/vmware_handlers_test.go b/internal/api/vmware_handlers_test.goindex 248454f9ad..ce43bf26d3 100644--- a/internal/api/vmware_handlers_test.go+++ b/internal/api/vmware_handlers_test.go@@ -218,6 +218,64 @@ func TestVMwareHandlers_HandleAdd_BlocksProjectedNetNewSystemsAtLimit(t *testing}}+func TestVMwareHandlers_HandleAdd_ReturnsUnavailableBeforePreviewingInventory(t *testing.T) {+ for _, tc := range []struct {+ name string+ reason string+ }{+ {+ name: "unsettled",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ },+ {+ name: "rebuild pending",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryRebuildPending,+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ setVMwareFeatureForTest(t, true)+ setMockModeForVMwareTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, persistence := newVMwareHandlersForTest(t)+ monitor, _, _ := newTestMonitor(t)+ handler.getMonitor = func(context.Context) *monitoring.Monitor { return monitor }+ bindUnavailableSupplementalUsageProviderForTest(t, monitor, unifiedresources.SourceVMware, tc.reason)++ previewRecordsCalled := false+ handler.previewRecords = func(context.Context, config.VMwareVCenterInstance) ([]unifiedresources.IngestRecord, error) {+ previewRecordsCalled = true+ return nil, errors.New("preview records should not run while monitored-system usage is unavailable")+ }++ body := marshalVMwareRequest(t, map[string]any{+ "name": "lab-vcenter",+ "host": "vcsa.lab.local",+ "port": 443,+ "username": "[email protected]",+ "password": "super-secret",+ "enabled": true,+ })+ req := httptest.NewRequest(http.MethodPost, "/api/vmware/connections", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleAdd(rec, req)++ assertMonitoredSystemUsageUnavailableReason(t, rec, tc.reason)+ if previewRecordsCalled {+ t.Fatal("expected VMware add not to preview external inventory while monitored-system usage is unavailable")+ }++ stored, err := persistence.LoadVMwareConfig()+ if err != nil {+ t.Fatalf("load vmware config: %v", err)+ }+ if len(stored) != 0 {+ t.Fatalf("expected unavailable monitored-system usage not to persist add, got %d connections", len(stored))+ }+ })+ }+}+func TestVMwareHandlers_HandleAdd_AllowsCanonicalOverlapAtLimit(t *testing.T) {setVMwareFeatureForTest(t, true)setMockModeForVMwareTest(t, false)@@ -693,6 +751,77 @@ func TestVMwareHandlers_HandleUpdate_BlocksProjectedNetNewSystemsAtLimit(t *test}}+func TestVMwareHandlers_HandleUpdate_ReturnsUnavailableBeforePreviewingInventory(t *testing.T) {+ for _, tc := range []struct {+ name string+ reason string+ }{+ {+ name: "unsettled",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryUnsettled,+ },+ {+ name: "rebuild pending",+ reason: monitoring.MonitoredSystemUsageUnavailableSupplementalInventoryRebuildPending,+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ setVMwareFeatureForTest(t, true)+ setMockModeForVMwareTest(t, false)+ setMaxMonitoredSystemsLicenseForTests(t, 1)++ handler, persistence := newVMwareHandlersForTest(t)+ monitor, _, _ := newTestMonitor(t)+ handler.getMonitor = func(context.Context) *monitoring.Monitor { return monitor }+ bindUnavailableSupplementalUsageProviderForTest(t, monitor, unifiedresources.SourceVMware, tc.reason)+ if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{{+ ID: "alpha",+ Name: "vc-a",+ Host: "vc-a.lab.local",+ Port: 443,+ Username: "[email protected]",+ Password: "super-secret",+ InsecureSkipVerify: true,+ Enabled: true,+ }}); err != nil {+ t.Fatalf("seed vmware config: %v", err)+ }++ previewRecordsCalled := false+ handler.previewRecords = func(context.Context, config.VMwareVCenterInstance) ([]unifiedresources.IngestRecord, error) {+ previewRecordsCalled = true+ return nil, errors.New("preview records should not run while monitored-system usage is unavailable")+ }++ body := marshalVMwareRequest(t, map[string]any{+ "name": "vc-b",+ "host": "vc-b.lab.local",+ "port": 443,+ "username": "[email protected]",+ "password": "********",+ "insecureSkipVerify": true,+ "enabled": true,+ })+ req := httptest.NewRequest(http.MethodPut, "/api/vmware/connections/alpha", bytes.NewReader(body))+ rec := httptest.NewRecorder()+ handler.HandleUpdate(rec, req)++ assertMonitoredSystemUsageUnavailableReason(t, rec, tc.reason)+ if previewRecordsCalled {+ t.Fatal("expected VMware update not to preview external inventory while monitored-system usage is unavailable")+ }++ stored, err := persistence.LoadVMwareConfig()+ if err != nil {+ t.Fatalf("load vmware config: %v", err)+ }+ if len(stored) != 1 || stored[0].Host != "vc-a.lab.local" {+ t.Fatalf("expected unavailable monitored-system usage to preserve stored connection, got %+v", stored)+ }+ })+ }+}+func TestVMwareHandlers_HandleTestConnection_SuccessAndFailure(t *testing.T) {setVMwareFeatureForTest(t, true)