Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Clamp Patrol monitor-only autonomy saves

rcourtmand0940db33b7d
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 5201acc03d..ae014a5ddf 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -250,6 +250,9 @@ profile and assignment columns, but embedded table framing must route through
`internal/api/` route wiring: monitor-mode configuration and remediation
entitlement payloads remain AI runtime/API-contract owned and must not create
agent lifecycle authority, install-token scope, or fleet command semantics.
+ Clearing stale Patrol full-mode unlock state during monitor-only saves is
+ also an AI runtime entitlement clamp, not a lifecycle enrollment or command
+ authority signal.
Patrol readiness and settings-save payload changes on those shared handlers
are also adjacent only: structured provider/model/tool causes may be exposed
to Patrol and Assistant, but they do not grant agent install, enrollment,
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 98aa84029d..a13793458b 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -129,6 +129,11 @@ runtime cost control, and shared AI transport surfaces.
metadata, while manual run requests, scheduled ticks, and scoped
alert/anomaly runs must fail or skip before LLM execution when the selected
Patrol model/provider is known not-ready.
+ Monitor-only Patrol autonomy saves are part of the same runtime gate:
+ when the safe-remediation extension or entitlement is unavailable, both the
+ browser state owner and `internal/api/ai_handlers.go` must clear stale
+ full-mode unlock state while clamping autonomy back to `monitor`, so paid
+ remediation permission cannot survive through a free runtime save.
4. Keep discovery scheduling authoritative through `internal/config/ai.go`: `discovery_enabled` and `discovery_interval_hours` must govern both lightweight infrastructure discovery and deep service-discovery background loops
5. Preserve auditability for outbound model-bound context exports and keep the export record aligned with the prompt boundary that actually reaches the provider
External provider-bound unified-resource context must enforce the same
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 07b8d9b330..1e31a97740 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -915,8 +915,11 @@ the canonical monitored-system blocked payload.
`/api/ai/patrol/autonomy`, while `approval`, `assisted`, and `full` return
the canonical license-required response instead of a generic save failure,
and Patrol frontend state owners must clamp stale paid autonomy to `monitor`
- before submitting that endpoint when the safe-remediation entitlement is not
- effective
+ and send `full_mode_unlocked:false` before submitting that endpoint when the
+ safe-remediation entitlement is not effective. The monitor-only backend path
+ must likewise clear stale full-mode unlock state in its response and
+ persistence layer instead of preserving paid remediation state through a free
+ configuration save
and the Patrol settings-save readiness contract, so
`/api/settings/ai/update` may save a selected Patrol provider/model even
when that model is not ready for tool-backed Patrol execution, but it must
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 0fdbf787b5..b99d2c9886 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -760,7 +760,11 @@ prompt explain the same operator-facing priority.
copy. When the failure includes Patrol readiness context, the inline state
must expose the provider, model, and readiness summary next to a direct
provider-settings action instead of hiding that diagnosis behind Assistant
- alone. If that inline state opens Assistant, the Patrol feature must hand off
+ alone. When safe remediation is locked, the same popover state owner must
+ clear stale full-mode unlock state before Apply Configuration submits the
+ monitor-only autonomy payload, so disabled paid controls cannot leak stale
+ permission into a save. If that inline state opens Assistant, the Patrol
+ feature must hand off
a source-named, model-only briefing and close the popover so the shared
Assistant drawer is not visually hidden behind feature chrome. When a Patrol
assessment handoff is attached, the shared Assistant drawer empty state must
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 0a4e07a2fc..a271d5a602 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -402,10 +402,11 @@ return the structured readiness reason if a stale UI still submits, and
scheduled or scoped alert/anomaly runs must skip before calling the model while
preserving the blocked reason and cause in Patrol status. The Patrol
configuration state owner must also clamp stale investigation/remediation
-autonomy back to findings-only `monitor` before submitting Apply Configuration
-when the safe-remediation entitlement is not effective, so an expired or
-downgraded plan cannot turn a recoverable configuration review into a Pro-only
-save failure. The same inline error surface must render any Patrol readiness
+autonomy back to findings-only `monitor` and clear stale full-mode unlock state
+before submitting Apply Configuration when the safe-remediation entitlement is
+not effective, so an expired or downgraded plan cannot turn a recoverable
+configuration review into a Pro-only save failure. The same inline error
+surface must render any Patrol readiness
provider, model, and summary carried by the failure object, and keep the
provider-settings action immediately available before the operator chooses to
open the Assistant handoff.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index e4e0ed5add..10a9417bbe 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -229,6 +229,9 @@ bypass the API fail-closed execution gate.
but monitor-mode AI configuration and remediation entitlement responses stay
AI runtime/API-contract owned and must not become recovery-local policy,
storage remediation authority, or storage-specific license semantics.
+ Clearing stale full-mode unlock state through that monitor-only save path is
+ likewise an AI runtime entitlement clamp, not recovery approval state or
+ storage remediation permission.
Adjacent Docker / Podman management routes may also share `internal/api/`
transport with storage/recovery. Storage and recovery consumers must
preserve the API-owned Docker / Podman agent or host wording for management
diff --git a/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts b/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
index 8c8754a204..8965cb3c80 100644
--- a/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
+++ b/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it } from 'vitest';
-import { resolvePatrolAutonomyLevelForSave } from '../usePatrolIntelligenceState';
+import {
+ resolvePatrolAutonomyLevelForSave,
+ resolvePatrolAutonomySettingsForSave,
+} from '../usePatrolIntelligenceState';
describe('usePatrolIntelligenceState', () => {
describe('resolvePatrolAutonomyLevelForSave', () => {
@@ -16,4 +19,52 @@ describe('usePatrolIntelligenceState', () => {
expect(resolvePatrolAutonomyLevelForSave('approval', false, false)).toBe('approval');
});
});
+
+ describe('resolvePatrolAutonomySettingsForSave', () => {
+ it('clears stale full-mode state when safe remediation is locked', () => {
+ expect(
+ resolvePatrolAutonomySettingsForSave({
+ level: 'full',
+ fullModeUnlocked: true,
+ autoFixLocked: true,
+ }),
+ ).toEqual({ autonomyLevel: 'monitor', fullModeUnlocked: false });
+ });
+
+ it('does not carry full-mode state into non-remediation modes', () => {
+ expect(
+ resolvePatrolAutonomySettingsForSave({
+ level: 'monitor',
+ fullModeUnlocked: true,
+ autoFixLocked: false,
+ }),
+ ).toEqual({ autonomyLevel: 'monitor', fullModeUnlocked: false });
+
+ expect(
+ resolvePatrolAutonomySettingsForSave({
+ level: 'approval',
+ fullModeUnlocked: true,
+ autoFixLocked: false,
+ }),
+ ).toEqual({ autonomyLevel: 'approval', fullModeUnlocked: false });
+ });
+
+ it('promotes remediation mode to full only when full mode is explicitly unlocked', () => {
+ expect(
+ resolvePatrolAutonomySettingsForSave({
+ level: 'assisted',
+ fullModeUnlocked: true,
+ autoFixLocked: false,
+ }),
+ ).toEqual({ autonomyLevel: 'full', fullModeUnlocked: true });
+
+ expect(
+ resolvePatrolAutonomySettingsForSave({
+ level: 'full',
+ fullModeUnlocked: false,
+ autoFixLocked: false,
+ }),
+ ).toEqual({ autonomyLevel: 'assisted', fullModeUnlocked: false });
+ });
+ });
});
diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
index c57c75945b..5047e5cb92 100644
--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
@@ -57,6 +57,24 @@ export function resolvePatrolAutonomyLevelForSave(
return level;
}
+export function resolvePatrolAutonomySettingsForSave({
+ level,
+ fullModeUnlocked,
+ autoFixLocked,
+}: {
+ level: PatrolAutonomyLevel;
+ fullModeUnlocked: boolean;
+ autoFixLocked: boolean;
+}): { autonomyLevel: PatrolAutonomyLevel; fullModeUnlocked: boolean } {
+ const canUseFullMode =
+ !autoFixLocked && (level === 'assisted' || level === 'full') && fullModeUnlocked;
+
+ return {
+ autonomyLevel: resolvePatrolAutonomyLevelForSave(level, canUseFullMode, autoFixLocked),
+ fullModeUnlocked: canUseFullMode,
+ };
+}
+
export function usePatrolIntelligenceState() {
const [initialSurfaceReady, setInitialSurfaceReady] = createSignal(false);
const [activeTab, setActiveTab] = createSignal<PatrolTab>('findings');
@@ -493,12 +511,13 @@ export function usePatrolIntelligenceState() {
try {
const settings = await getPatrolAutonomySettings();
if (!settings) return;
- const effectiveLevel =
- autoFixLocked() && settings.autonomy_level !== 'monitor'
- ? 'monitor'
- : settings.autonomy_level;
- setAutonomyLevel(effectiveLevel);
- setFullModeUnlocked(settings.full_mode_unlocked);
+ const effectiveSettings = resolvePatrolAutonomySettingsForSave({
+ level: settings.autonomy_level,
+ fullModeUnlocked: settings.full_mode_unlocked,
+ autoFixLocked: autoFixLocked(),
+ });
+ setAutonomyLevel(effectiveSettings.autonomyLevel);
+ setFullModeUnlocked(effectiveSettings.fullModeUnlocked);
setInvestigationBudget(settings.investigation_budget);
setInvestigationTimeout(settings.investigation_timeout_sec);
} catch (err) {
@@ -511,24 +530,27 @@ export function usePatrolIntelligenceState() {
if (autoFixLocked() && level !== 'monitor') return;
const previousLevel = autonomyLevel();
- const effectiveLevel = resolvePatrolAutonomyLevelForSave(
+ const previousFullModeUnlocked = fullModeUnlocked();
+ const effectiveSettings = resolvePatrolAutonomySettingsForSave({
level,
- fullModeUnlocked(),
- autoFixLocked(),
- );
- setAutonomyLevel(effectiveLevel);
+ fullModeUnlocked: fullModeUnlocked(),
+ autoFixLocked: autoFixLocked(),
+ });
+ setAutonomyLevel(effectiveSettings.autonomyLevel);
+ setFullModeUnlocked(effectiveSettings.fullModeUnlocked);
setIsUpdatingAutonomy(true);
try {
await updatePatrolAutonomySettings({
- autonomy_level: effectiveLevel,
- full_mode_unlocked: fullModeUnlocked(),
+ autonomy_level: effectiveSettings.autonomyLevel,
+ full_mode_unlocked: effectiveSettings.fullModeUnlocked,
investigation_budget: investigationBudget(),
investigation_timeout_sec: investigationTimeout(),
});
} catch (err) {
console.error('Failed to update autonomy:', err);
setAutonomyLevel(previousLevel);
+ setFullModeUnlocked(previousFullModeUnlocked);
notificationStore.error((err as Error).message || 'Failed to update autonomy level');
} finally {
setIsUpdatingAutonomy(false);
@@ -582,15 +604,17 @@ export function usePatrolIntelligenceState() {
setIsSavingAdvanced(true);
setAdvancedSettingsError(null);
try {
- const effectiveLevel = resolvePatrolAutonomyLevelForSave(
- autonomyLevel(),
- fullModeUnlocked(),
- autoFixLocked(),
- );
+ const effectiveSettings = resolvePatrolAutonomySettingsForSave({
+ level: autonomyLevel(),
+ fullModeUnlocked: fullModeUnlocked(),
+ autoFixLocked: autoFixLocked(),
+ });
+ setAutonomyLevel(effectiveSettings.autonomyLevel);
+ setFullModeUnlocked(effectiveSettings.fullModeUnlocked);
const result = await updatePatrolAutonomySettings({
- autonomy_level: effectiveLevel,
- full_mode_unlocked: fullModeUnlocked(),
+ autonomy_level: effectiveSettings.autonomyLevel,
+ full_mode_unlocked: effectiveSettings.fullModeUnlocked,
investigation_budget: investigationBudget(),
investigation_timeout_sec: investigationTimeout(),
});
diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go
index e750c987a6..2f5284edc5 100644
--- a/internal/api/ai_handlers.go
+++ b/internal/api/ai_handlers.go
@@ -6983,6 +6983,7 @@ func (h *AISettingsHandler) HandleGetPatrolAutonomy(w http.ResponseWriter, r *ht
}
autonomyLevel := cfg.GetPatrolAutonomyLevel()
+ fullModeUnlocked := cfg.PatrolFullModeUnlocked
// Community tier lock: without ai_autofix, patrol autonomy is findings-only ("monitor").
// If config contains a higher level from a previous Pro/trial period, clamp the effective
// value at read time so the UI reflects runtime enforcement.
@@ -6990,10 +6991,13 @@ func (h *AISettingsHandler) HandleGetPatrolAutonomy(w http.ResponseWriter, r *ht
if !hasAutoFix && autonomyLevel != config.PatrolAutonomyMonitor {
autonomyLevel = config.PatrolAutonomyMonitor
}
+ if !hasAutoFix {
+ fullModeUnlocked = false
+ }
settings := PatrolAutonomyResponse{
AutonomyLevel: autonomyLevel,
- FullModeUnlocked: cfg.PatrolFullModeUnlocked,
+ FullModeUnlocked: fullModeUnlocked,
InvestigationBudget: cfg.GetPatrolInvestigationBudget(),
InvestigationTimeoutSec: int(cfg.GetPatrolInvestigationTimeout().Seconds()),
}
@@ -7049,10 +7053,10 @@ func (h *AISettingsHandler) HandleUpdatePatrolAutonomyMonitorOnly(w http.Respons
req.InvestigationTimeoutSec = 1800
}
- effectiveUnlocked := cfg.PatrolFullModeUnlocked
- if req.FullModeUnlocked != nil {
- effectiveUnlocked = *req.FullModeUnlocked
- }
+ // This handler is only used when the safe-remediation extension is not active.
+ // Do not preserve stale full-mode acknowledgement or permission state through a
+ // monitor-only save.
+ effectiveUnlocked := false
cfg.PatrolAutonomyLevel = config.PatrolAutonomyMonitor
cfg.PatrolFullModeUnlocked = effectiveUnlocked
@@ -7065,7 +7069,7 @@ func (h *AISettingsHandler) HandleUpdatePatrolAutonomyMonitorOnly(w http.Respons
return
}
if err := persistence.SaveAIConfig(*cfg); err != nil {
- writeErrorResponse(w, http.StatusInternalServerError, "save_failed", "Failed to save Pulse Assistant config", nil)
+ writeErrorResponse(w, http.StatusInternalServerError, "save_failed", "Failed to save Pulse Patrol autonomy settings", nil)
return
}
if err := aiService.LoadConfig(); err != nil {
diff --git a/internal/api/ai_handlers_test.go b/internal/api/ai_handlers_test.go
index 3c20f48cdf..6f5577a331 100644
--- a/internal/api/ai_handlers_test.go
+++ b/internal/api/ai_handlers_test.go
@@ -70,7 +70,7 @@ func TestAISettingsHandler_PatrolAutonomyMonitorOnlyAllowsMonitor(t *testing.T)
persistence := config.NewConfigPersistence(tmp)
handler := newTestAISettingsHandler(cfg, persistence, nil)
- body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
+ body := `{"autonomy_level":"monitor","full_mode_unlocked":true,"investigation_budget":2,"investigation_timeout_sec":30}`
req := newLoopbackRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
rec := httptest.NewRecorder()
handler.HandleUpdatePatrolAutonomyMonitorOnly(rec, req)
@@ -83,12 +83,14 @@ func TestAISettingsHandler_PatrolAutonomyMonitorOnlyAllowsMonitor(t *testing.T)
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
require.True(t, resp.Success)
require.Equal(t, config.PatrolAutonomyMonitor, resp.Settings.AutonomyLevel)
+ require.False(t, resp.Settings.FullModeUnlocked)
require.Equal(t, 5, resp.Settings.InvestigationBudget)
require.Equal(t, 60, resp.Settings.InvestigationTimeoutSec)
saved, err := persistence.LoadAIConfig()
require.NoError(t, err)
require.Equal(t, config.PatrolAutonomyMonitor, saved.PatrolAutonomyLevel)
+ require.False(t, saved.PatrolFullModeUnlocked)
require.Equal(t, 5, saved.PatrolInvestigationBudget)
require.Equal(t, 60, saved.PatrolInvestigationTimeoutSec)
diff --git a/internal/api/ai_patrol_community_limits_test.go b/internal/api/ai_patrol_community_limits_test.go
index fa6876f06e..1be55c8cc7 100644
--- a/internal/api/ai_patrol_community_limits_test.go
+++ b/internal/api/ai_patrol_community_limits_test.go
@@ -55,6 +55,7 @@ func TestPatrolCommunityAutonomyLockedToMonitor(t *testing.T) {
// Persist a higher autonomy level to ensure read-time clamping works.
aiCfg := config.NewDefaultAIConfig()
aiCfg.PatrolAutonomyLevel = config.PatrolAutonomyApproval
+ aiCfg.PatrolFullModeUnlocked = true
if err := persistence.SaveAIConfig(*aiCfg); err != nil {
t.Fatalf("SaveAIConfig: %v", err)
}
@@ -76,11 +77,14 @@ func TestPatrolCommunityAutonomyLockedToMonitor(t *testing.T) {
if getResp.AutonomyLevel != config.PatrolAutonomyMonitor {
t.Fatalf("expected autonomy %q for Community, got %q", config.PatrolAutonomyMonitor, getResp.AutonomyLevel)
}
+ if getResp.FullModeUnlocked {
+ t.Fatalf("expected full mode to be locked for Community, got %+v", getResp)
+ }
// PUT via free adapter should allow findings-only monitor settings and
// persist the same clamped runtime limits used by the enterprise handler.
freeAdapter := aiAutoFixFreeAdapter{handler: handler}
- body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
+ body := `{"autonomy_level":"monitor","full_mode_unlocked":true,"investigation_budget":2,"investigation_timeout_sec":30}`
putReq := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
putRec := httptest.NewRecorder()
freeAdapter.HandleUpdatePatrolAutonomy(putRec, putReq)
@@ -100,6 +104,9 @@ func TestPatrolCommunityAutonomyLockedToMonitor(t *testing.T) {
if putResp.Settings.AutonomyLevel != config.PatrolAutonomyMonitor {
t.Fatalf("expected saved autonomy %q, got %q", config.PatrolAutonomyMonitor, putResp.Settings.AutonomyLevel)
}
+ if putResp.Settings.FullModeUnlocked {
+ t.Fatalf("expected monitor-only update to clear full mode, got %+v", putResp.Settings)
+ }
if putResp.Settings.InvestigationBudget != 5 || putResp.Settings.InvestigationTimeoutSec != 60 {
t.Fatalf("expected clamped budget/timeout 5/60, got %d/%d",
putResp.Settings.InvestigationBudget, putResp.Settings.InvestigationTimeoutSec)
@@ -111,6 +118,9 @@ func TestPatrolCommunityAutonomyLockedToMonitor(t *testing.T) {
if saved.PatrolAutonomyLevel != config.PatrolAutonomyMonitor {
t.Fatalf("expected persisted autonomy %q, got %q", config.PatrolAutonomyMonitor, saved.PatrolAutonomyLevel)
}
+ if saved.PatrolFullModeUnlocked {
+ t.Fatalf("expected persisted full mode unlock to be cleared for Community")
+ }
if saved.PatrolInvestigationBudget != 5 || saved.PatrolInvestigationTimeoutSec != 60 {
t.Fatalf("expected persisted budget/timeout 5/60, got %d/%d",
saved.PatrolInvestigationBudget, saved.PatrolInvestigationTimeoutSec)
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 17e0f9c750..df63a9e2ca 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -122,7 +122,7 @@ func TestContract_PatrolAutonomyCommunityMonitorUpdatePayload(t *testing.T) {
cfg := newTestConfigWithTokens(t, record)
router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
- body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
+ body := `{"autonomy_level":"monitor","full_mode_unlocked":true,"investigation_budget":2,"investigation_timeout_sec":30}`
req := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
req.Header.Set("X-API-Token", rawToken)
rec := httptest.NewRecorder()
@@ -142,6 +142,7 @@ func TestContract_PatrolAutonomyCommunityMonitorUpdatePayload(t *testing.T) {
t.Fatalf("expected success response, got %+v", resp)
}
if resp.Settings.AutonomyLevel != config.PatrolAutonomyMonitor ||
+ resp.Settings.FullModeUnlocked ||
resp.Settings.InvestigationBudget != 5 ||
resp.Settings.InvestigationTimeoutSec != 60 {
t.Fatalf("unexpected monitor update settings: %+v", resp.Settings)
diff --git a/tests/integration/tests/18-patrol-runtime-state.spec.ts b/tests/integration/tests/18-patrol-runtime-state.spec.ts
index 740aaec4c9..52ad9f74b5 100644
--- a/tests/integration/tests/18-patrol-runtime-state.spec.ts
+++ b/tests/integration/tests/18-patrol-runtime-state.spec.ts
@@ -691,6 +691,84 @@ test.describe("Patrol runtime-state browser contract", () => {
).toHaveCount(0);
});
+ test("clamps stale full-mode state before monitor-only Patrol configuration save", async ({
+ page,
+ }, testInfo) => {
+ test.skip(
+ testInfo.project.name.startsWith("mobile-"),
+ "Desktop-only Patrol configuration coverage",
+ );
+
+ let updatePayload: Record<string, unknown> | null = null;
+
+ await mockRuntimeCapabilities(page, ["ai_patrol", "ai_alerts"]);
+ await ensureAuthenticated(page);
+ await mockBlockedPatrolRuntimeState(page, {
+ autonomyRoute: async (route) => {
+ if (route.request().method() !== "PUT") {
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ autonomy_level: "full",
+ full_mode_unlocked: true,
+ investigation_budget: 15,
+ investigation_timeout_sec: 300,
+ }),
+ });
+ return;
+ }
+
+ updatePayload = route.request().postDataJSON() as Record<
+ string,
+ unknown
+ >;
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ success: true,
+ settings: {
+ autonomy_level: "monitor",
+ full_mode_unlocked: false,
+ investigation_budget: updatePayload.investigation_budget ?? 15,
+ investigation_timeout_sec:
+ updatePayload.investigation_timeout_sec ?? 300,
+ },
+ }),
+ });
+ },
+ });
+
+ await page.goto("/patrol", { waitUntil: "domcontentloaded" });
+ await page.getByRole("button", { name: "Configure Patrol" }).click();
+ const configPanel = page.getByRole("dialog", {
+ name: "Patrol Configuration",
+ });
+
+ await expect(
+ configPanel.getByRole("button", { name: "Remediate" }),
+ ).toBeDisabled();
+ await configPanel.evaluate((element) => {
+ element.scrollTop = element.scrollHeight;
+ });
+ await configPanel
+ .getByRole("button", { name: "Apply Configuration" })
+ .click();
+
+ await expect
+ .poll(() => updatePayload)
+ .toMatchObject({
+ autonomy_level: "monitor",
+ full_mode_unlocked: false,
+ });
+ await expect(configPanel).toBeHidden();
+ await expect(
+ page.getByText("Failed to save advanced settings"),
+ ).toHaveCount(0);
+ await expect(page.getByTestId("patrol-configuration-error")).toHaveCount(0);
+ });
+
test("shows the server reason when a stale manual Patrol run is rejected", async ({
page,
}, testInfo) => {