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.

Record Patrol fix approvals in action audit

rcourtmancf8931031d52
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 986f299781..3128c153a6 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -283,6 +283,10 @@ profile and assignment columns, but embedded table framing must route through
lifecycle state. Patrol finding handoffs that force approval-required mode
from a non-empty `finding_id` are likewise AI/runtime governance, not an
agent command grant or lifecycle authorization primitive.
+ Patrol queued-fix approvals may now seed the shared action-audit store with
+ planned and pending lifecycle evidence, but lifecycle surfaces must treat
+ those records as action-governance context only; they do not create install,
+ enrollment, assignment, or fleet-command authority.
Lifecycle flows must not reintroduce anonymous bootstrap identity,
tenant-local commercial-owner surrogates, or fake activation records when
they traverse those shared handlers. They also must not infer tenant
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 765e97db60..2f2d57f1f5 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -654,6 +654,11 @@ approval policy, dry-run availability, safety checks, verification steps, and
timestamps are normalized before persistence by the unified-resource store, so
runtime callers cannot publish an execution audit that skipped the canonical
planning contract.
+Patrol investigation-fix approvals must use that same action-audit boundary:
+when the orchestrator queues a fix approval, `internal/api/ai_handlers.go` must
+attach a governed action plan, seed the shared action-audit store as planned
+and pending, and leave later execution or approval decisions to the governed
+action/approval paths instead of creating Patrol-only execution context.
The same ownership includes the Pulse query tool schema under
`internal/ai/tools/`: topology-query input names must stay canonical inside
the AI runtime itself, so new tool arguments such as `max_proxmox_nodes`
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 17433de65b..85d93992e9 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -430,6 +430,14 @@ the canonical monitored-system blocked payload.
atomically. It must not invoke the capability driver, create an
`executing`/`completed` event, or attach an execution result; execution
requires a later explicit execution contract.
+ Patrol investigation-fix approvals produced through
+ `internal/api/ai_handlers.go` must enter that same API-owned model at queue
+ time: the approval adapter must attach a governed `ActionPlan`, persist the
+ initial action audit as `planned` then `pending_approval`, and keep the
+ approval ID, action ID, dry-run/preflight posture, and lifecycle trail
+ available for Assistant handoff and resource action-history hydration.
+ Queuing the approval must not execute the fix or create a Patrol-local audit
+ record that bypasses `/api/actions` and the shared action-audit store.
Action execution is API-owned as the next explicit contract:
`POST /api/actions/{id}/execute` may only start execution for an approved
action or an approval-free executable plan, must atomically persist the
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 89922e82a4..c550019c5d 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -848,6 +848,10 @@ Patrol fix approvals also inherit the unified action-governance preflight
contract: queued fixes must keep their plan-level dry-run availability, safety
checks, verification steps, approval policy, and action id in the shared
approval/action-audit model instead of storing Patrol-only execution context.
+The investigation approval adapter must seed the unified action-audit store
+with planned and pending lifecycle evidence when it creates the approval, so
+Assistant handoffs and resource timelines can hydrate the same canonical
+action record before any operator decision or execution occurs.
That same store now owns the Patrol dashboard load bundle as well, so the
page refresh path stays aligned on a single orchestrated AI bundle instead of
repeating the individual summary, findings, approval, and correlation fetches
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 47a613ae91..98fbf5124b 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -1115,6 +1115,11 @@ recovery may treat the resulting Assistant session as incident context, but
must not reinterpret the finding ID or approval-required chat mode as backup
freshness, restore authorization, storage remediation permission, or recovery
transport state.
+Patrol queued-fix approvals that seed shared action-audit records follow the
+same rule: storage and recovery may display the resulting action history as
+incident-adjacent context, but they must not treat the pending action state,
+approval policy, or preflight posture as recovery proof or storage-local
+execution permission.
That same storage ownership also includes the shared storage-source presentation
contract in `frontend-modern/src/utils/storageSources.ts`: storage pages and
cross-surface storage links must reuse one canonical ordering, label, tone, and
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 8328348087..9dff9440bd 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1570,6 +1570,10 @@ action-audit state from this same store when an approval reference resolves to
a governed action, so chat follow-ups describe the canonical lifecycle record
rather than a stale approval snapshot. That read remains model-only review
context and must not expose raw command text or raw execution output.
+Patrol queued-fix approvals are producers of the same unified action-audit
+records: the approval adapter may seed planned and pending lifecycle events for
+the governed action, but the durable identity, state transitions, and history
+remain owned by this store rather than by a Patrol-specific audit ledger.
That same ownership boundary applies to incident-adjacent runtime history:
durable backend facts about what changed on a resource belong in
`ResourceChange` and the shared unified-resource store, while
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index 45b230f008..4ec539df77 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -2179,6 +2179,16 @@ func (s *Service) GetModelHandoffMetadata(ctx context.Context, sessionID string)
return sessions.GetModelHandoffMetadata(sessionID)
}
+// GetActionAuditStore returns the durable action-audit store used by the chat runtime.
+func (s *Service) GetActionAuditStore() unifiedresources.ResourceStore {
+ if s == nil {
+ return nil
+ }
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+ return s.actionAuditStore
+}
+
// ClearModelHandoffContext invalidates product-originated model-only handoff
// state after its source record can no longer be resolved. Unpinned resolved
// resources are cleared with it so stale Patrol handoffs cannot remain action
diff --git a/internal/ai/tools/action_audit.go b/internal/ai/tools/action_audit.go
index 97d417946b..d079900d8e 100644
--- a/internal/ai/tools/action_audit.go
+++ b/internal/ai/tools/action_audit.go
@@ -509,13 +509,95 @@ func (e *PulseToolExecutor) recordApprovalDecisionAtomically(approvalID string,
}
func (e *PulseToolExecutor) recordPendingApprovalAction(req *approval.ApprovalRequest) {
- if e == nil || req == nil || req.Plan == nil {
+ if e == nil {
+ return
+ }
+ RecordPendingApprovalAction(e.actionAuditStore, req)
+}
+
+// AttachApprovalActionPlan normalizes an approval request onto the shared
+// action-governance model before it is persisted by the approval store.
+func AttachApprovalActionPlan(req *approval.ApprovalRequest, now time.Time) {
+ if req == nil {
+ return
+ }
+ if now.IsZero() {
+ now = time.Now().UTC()
+ } else {
+ now = now.UTC()
+ }
+ req.ID = strings.TrimSpace(req.ID)
+ if req.ID == "" {
+ req.ID = uuid.NewString()
+ }
+ capabilityName := approvalCapabilityForTargetType(req.TargetType)
+ resourceID := approvalAuditResourceID(req.TargetType, req.TargetID, req.TargetName)
+ if req.Plan == nil {
+ actionID := uuid.NewString()
+ req.Plan = &unifiedresources.ActionPlan{
+ ActionID: actionID,
+ RequestID: req.ID,
+ Allowed: true,
+ RequiresApproval: true,
+ ApprovalPolicy: unifiedresources.ApprovalAdmin,
+ PredictedBlastRadius: approvalBlastRadius(req.TargetType, req.Command),
+ RollbackAvailable: approvalRollbackAvailable(req.TargetType, req.Command),
+ Message: strings.TrimSpace(req.Context),
+ PlannedAt: now,
+ PlanHash: approvalPlanHash(actionID, req.ID, capabilityName, resourceID, req.Command, req.TargetType, req.TargetID, req.Context),
+ }
+ }
+ if strings.TrimSpace(req.Plan.ActionID) == "" {
+ req.Plan.ActionID = uuid.NewString()
+ }
+ if strings.TrimSpace(req.Plan.RequestID) == "" {
+ req.Plan.RequestID = req.ID
+ }
+ if req.Plan.PlannedAt.IsZero() {
+ req.Plan.PlannedAt = now
+ }
+ if strings.TrimSpace(req.Plan.Message) == "" {
+ req.Plan.Message = strings.TrimSpace(req.Context)
+ }
+ req.Plan.Allowed = true
+ req.Plan.RequiresApproval = true
+ if req.Plan.ApprovalPolicy == "" {
+ req.Plan.ApprovalPolicy = unifiedresources.ApprovalAdmin
+ }
+ if strings.TrimSpace(req.Plan.PlanHash) == "" {
+ req.Plan.PlanHash = approvalPlanHash(req.Plan.ActionID, req.Plan.RequestID, capabilityName, resourceID, req.Command, req.TargetType, req.TargetID, req.Context)
+ }
+ req.ContextConfidence = approvalContextConfidence(req)
+ req.Preflight = approvalPreflight(req)
+ req.Plan.Preflight = req.Preflight
+}
+
+// RecordPendingApprovalAction persists the planned and pending audit state for
+// a newly-created governed approval request.
+func RecordPendingApprovalAction(store unifiedresources.ResourceStore, req *approval.ApprovalRequest) {
+ if store == nil || req == nil || req.Plan == nil {
return
}
record := actionAuditRecordFromApproval(req, unifiedresources.ActionStatePending, approvalAuditActor)
- e.recordActionAudit(record)
- e.recordActionLifecycle(req.Plan.ActionID, unifiedresources.ActionStatePlanned, approvalAuditActor, strings.TrimSpace(req.Context))
- e.recordActionLifecycle(req.Plan.ActionID, unifiedresources.ActionStatePending, approvalAuditActor, "waiting for approval")
+ if err := store.RecordActionAudit(record); err != nil {
+ log.Warn().Err(err).Str("action_id", record.ID).Msg("failed to persist pending approval action")
+ return
+ }
+ recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePlanned, strings.TrimSpace(req.Context))
+ recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePending, "waiting for approval")
+}
+
+func recordApprovalLifecycle(store unifiedresources.ResourceStore, actionID string, state unifiedresources.ActionState, message string) {
+ event := unifiedresources.ActionLifecycleEvent{
+ ActionID: strings.TrimSpace(actionID),
+ State: state,
+ Timestamp: time.Now().UTC(),
+ Actor: approvalAuditActor,
+ Message: strings.TrimSpace(message),
+ }
+ if err := store.RecordActionLifecycleEvent(event); err != nil {
+ log.Warn().Err(err).Str("action_id", actionID).Str("state", string(state)).Msg("failed to persist pending approval lifecycle event")
+ }
}
func mergeApprovedActionPlan(approved unifiedresources.ActionPlan, fallback unifiedresources.ActionPlan) unifiedresources.ActionPlan {
diff --git a/internal/ai/tools/action_audit_execution_test.go b/internal/ai/tools/action_audit_execution_test.go
index 95caf7bffd..f74866366e 100644
--- a/internal/ai/tools/action_audit_execution_test.go
+++ b/internal/ai/tools/action_audit_execution_test.go
@@ -84,6 +84,80 @@ func TestExecuteCommandWithAuditUsesExecutionStateMachine(t *testing.T) {
agentServer.AssertExpectations(t)
}
+func TestAttachApprovalActionPlanRecordsPendingActionAudit(t *testing.T) {
+ store := unifiedresources.NewMemoryStore()
+ now := time.Date(2026, 5, 7, 9, 30, 0, 0, time.UTC)
+ req := &approval.ApprovalRequest{
+ ID: " approval-patrol-queued ",
+ OrgID: "tenant-1",
+ ToolID: "investigation_fix",
+ Command: "systemctl restart nginx",
+ TargetType: "investigation",
+ TargetID: "finding-123",
+ TargetName: "web-1",
+ Context: "Restart nginx after Patrol investigation",
+ RiskLevel: approval.RiskHigh,
+ }
+
+ AttachApprovalActionPlan(req, now)
+
+ if req.ID != "approval-patrol-queued" {
+ t.Fatalf("approval id = %q", req.ID)
+ }
+ if req.Plan == nil {
+ t.Fatal("expected governed action plan")
+ }
+ if req.Plan.ActionID == "" {
+ t.Fatalf("expected action id: %#v", req.Plan)
+ }
+ if req.Plan.RequestID != req.ID {
+ t.Fatalf("plan request id = %q, want %q", req.Plan.RequestID, req.ID)
+ }
+ if !req.Plan.Allowed || !req.Plan.RequiresApproval || req.Plan.ApprovalPolicy != unifiedresources.ApprovalAdmin {
+ t.Fatalf("approval plan posture = %#v", req.Plan)
+ }
+ if !req.Plan.PlannedAt.Equal(now) {
+ t.Fatalf("planned at = %s, want %s", req.Plan.PlannedAt, now)
+ }
+ if req.Preflight == nil || req.ContextConfidence == nil || req.Plan.Preflight != req.Preflight {
+ t.Fatalf("expected preflight and context confidence on approval: %#v", req)
+ }
+
+ RecordPendingApprovalAction(store, req)
+
+ audit, ok, err := store.GetActionAudit(req.Plan.ActionID)
+ if err != nil {
+ t.Fatalf("GetActionAudit: %v", err)
+ }
+ if !ok {
+ t.Fatal("expected pending approval action audit")
+ }
+ if audit.State != unifiedresources.ActionStatePending {
+ t.Fatalf("audit state = %q, want pending", audit.State)
+ }
+ if audit.Request.RequestID != req.ID {
+ t.Fatalf("audit request id = %q, want %q", audit.Request.RequestID, req.ID)
+ }
+ if audit.Request.ResourceID != "investigation:finding-123" {
+ t.Fatalf("audit resource id = %q", audit.Request.ResourceID)
+ }
+ if audit.Request.RequestedBy != approvalAuditActor {
+ t.Fatalf("audit requested by = %q", audit.Request.RequestedBy)
+ }
+
+ events, err := store.GetActionLifecycleEvents(req.Plan.ActionID, time.Time{}, 10)
+ if err != nil {
+ t.Fatalf("GetActionLifecycleEvents: %v", err)
+ }
+ states := map[unifiedresources.ActionState]bool{}
+ for _, event := range events {
+ states[event.State] = true
+ }
+ if !states[unifiedresources.ActionStatePlanned] || !states[unifiedresources.ActionStatePending] {
+ t.Fatalf("expected planned and pending lifecycle states, got %#v", events)
+ }
+}
+
func TestExecuteNativeActionWithApprovedAuditRecordsDecisionBeforeExecution(t *testing.T) {
actionStore := unifiedresources.NewMemoryStore()
approvalStore, err := approval.NewStore(approval.StoreConfig{
diff --git a/internal/ai/tools/tools_control.go b/internal/ai/tools/tools_control.go
index 37b5b42da8..fd4a1d6222 100644
--- a/internal/ai/tools/tools_control.go
+++ b/internal/ai/tools/tools_control.go
@@ -1373,23 +1373,6 @@ func createApprovalRecordForOrgWithExecutor(e *PulseToolExecutor, orgID, command
approvalID := uuid.NewString()
now := time.Now().UTC()
- capabilityName := approvalCapabilityForTargetType(targetType)
- resourceID := approvalAuditResourceID(targetType, targetID, targetName)
- actionID := uuid.NewString()
- plan := unifiedresources.ActionPlan{
- ActionID: actionID,
- RequestID: approvalID,
- Allowed: true,
- RequiresApproval: true,
- ApprovalPolicy: unifiedresources.ApprovalAdmin,
- PredictedBlastRadius: approvalBlastRadius(targetType, command),
- RollbackAvailable: approvalRollbackAvailable(targetType, command),
- Message: strings.TrimSpace(context),
- PlannedAt: now,
- ExpiresAt: now.Add(5 * time.Minute),
- PlanHash: approvalPlanHash(actionID, approvalID, capabilityName, resourceID, command, targetType, targetID, context),
- }
-
req := &approval.ApprovalRequest{
ID: approvalID,
OrgID: strings.TrimSpace(orgID),
@@ -1398,10 +1381,8 @@ func createApprovalRecordForOrgWithExecutor(e *PulseToolExecutor, orgID, command
TargetID: targetID,
TargetName: targetName,
Context: context,
- Plan: &plan,
}
- req.ContextConfidence = approvalContextConfidence(req)
- req.Preflight = approvalPreflight(req)
+ AttachApprovalActionPlan(req, now)
if err := store.CreateApproval(req); err != nil {
log.Warn().Err(err).Msg("failed to create approval record")
diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go
index 1a8fa520b2..e750c987a6 100644
--- a/internal/api/ai_handlers.go
+++ b/internal/api/ai_handlers.go
@@ -28,6 +28,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/ai/memory"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/providers"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/proxmox"
+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/tools"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/unified"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/internal/metrics"
@@ -1873,7 +1874,11 @@ func (h *AISettingsHandler) setupInvestigationOrchestrator(orgID string, svc *ai
// Create approval adapter from the global approval store
var approvalAdapter aicontracts.OrchestratorApprovalStore
if approvalStoreInst := approval.GetStore(); approvalStoreInst != nil {
- approvalAdapter = &orchestratorApprovalAdapter{store: approvalStoreInst, orgID: approval.NormalizeOrgID(orgID)}
+ approvalAdapter = &orchestratorApprovalAdapter{
+ store: approvalStoreInst,
+ orgID: approval.NormalizeOrgID(orgID),
+ actionAuditStore: chatService.GetActionAuditStore(),
+ }
}
// Get config for investigation settings
@@ -2084,8 +2089,9 @@ func (a *orchestratorFindingsAdapter) Update(f *aicontracts.Finding) bool {
// orchestratorApprovalAdapter wraps *approval.Store to implement
// aicontracts.OrchestratorApprovalStore.
type orchestratorApprovalAdapter struct {
- store *approval.Store
- orgID string
+ store *approval.Store
+ orgID string
+ actionAuditStore unifiedresources.ResourceStore
}
func (a *orchestratorApprovalAdapter) Create(appr *aicontracts.OrchestratorApproval) error {
@@ -2115,7 +2121,12 @@ func (a *orchestratorApprovalAdapter) Create(appr *aicontracts.OrchestratorAppro
if req.TargetName == "" {
req.TargetName = appr.Description
}
- return a.store.CreateApproval(req)
+ tools.AttachApprovalActionPlan(req, time.Now().UTC())
+ if err := a.store.CreateApproval(req); err != nil {
+ return err
+ }
+ tools.RecordPendingApprovalAction(a.actionAuditStore, req)
+ return nil
}
// patrolFixVerifierAdapter wraps *ai.PatrolService to implement
diff --git a/internal/api/ai_handlers_test.go b/internal/api/ai_handlers_test.go
index 686abb2440..27855f6c91 100644
--- a/internal/api/ai_handlers_test.go
+++ b/internal/api/ai_handlers_test.go
@@ -2740,6 +2740,59 @@ func TestAISettingsHandler_Approvals(t *testing.T) {
})
}
+func TestOrchestratorApprovalAdapterRecordsPendingActionAudit(t *testing.T) {
+ approvalStore, err := approval.NewStore(approval.StoreConfig{
+ DataDir: t.TempDir(),
+ DisablePersistence: true,
+ })
+ require.NoError(t, err)
+
+ actionStore := unifiedresources.NewMemoryStore()
+ adapter := &orchestratorApprovalAdapter{
+ store: approvalStore,
+ orgID: "tenant-1",
+ actionAuditStore: actionStore,
+ }
+
+ err = adapter.Create(&aicontracts.OrchestratorApproval{
+ ID: "approval-investigation-1",
+ FindingID: "finding-123",
+ Command: "systemctl restart nginx",
+ TargetHost: "web-1",
+ Description: "Restart nginx after Patrol investigation",
+ RiskLevel: "high",
+ })
+ require.NoError(t, err)
+
+ req, ok := approvalStore.GetApproval("approval-investigation-1")
+ require.True(t, ok, "expected approval to be persisted")
+ require.NotNil(t, req.Plan, "expected Patrol investigation approval to carry a governed action plan")
+ require.NotEmpty(t, req.Plan.ActionID)
+ require.Equal(t, req.ID, req.Plan.RequestID)
+ require.True(t, req.Plan.RequiresApproval)
+ require.Equal(t, unifiedresources.ApprovalAdmin, req.Plan.ApprovalPolicy)
+ require.NotNil(t, req.Preflight)
+ require.NotNil(t, req.ContextConfidence)
+
+ audit, ok, err := actionStore.GetActionAudit(req.Plan.ActionID)
+ require.NoError(t, err)
+ require.True(t, ok, "expected queued Patrol fix approval to seed action audit")
+ require.Equal(t, unifiedresources.ActionStatePending, audit.State)
+ require.Equal(t, req.ID, audit.Request.RequestID)
+ require.Equal(t, "investigation:finding-123", audit.Request.ResourceID)
+ require.Equal(t, "pulse_assistant", audit.Request.RequestedBy)
+ require.NotNil(t, audit.Plan.Preflight)
+
+ events, err := actionStore.GetActionLifecycleEvents(req.Plan.ActionID, time.Time{}, 10)
+ require.NoError(t, err)
+ states := map[unifiedresources.ActionState]bool{}
+ for _, event := range events {
+ states[event.State] = true
+ }
+ require.True(t, states[unifiedresources.ActionStatePlanned], "missing planned lifecycle event: %#v", events)
+ require.True(t, states[unifiedresources.ActionStatePending], "missing pending lifecycle event: %#v", events)
+}
+
func TestAISettingsHandler_Approvals_RejectCrossOrgAccess(t *testing.T) {
tmp := t.TempDir()
cfg := &config.Config{DataPath: tmp}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index d797657c4a..14478be5ee 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -166,6 +166,10 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
if err != nil {
t.Fatalf("read ai_handler.go: %v", err)
}
+ settingsHandlerSource, err := os.ReadFile(filepath.Clean("ai_handlers.go"))
+ if err != nil {
+ t.Fatalf("read ai_handlers.go: %v", err)
+ }
chatServiceSource, err := os.ReadFile(filepath.Clean("../ai/chat/service.go"))
if err != nil {
t.Fatalf("read chat service: %v", err)
@@ -271,6 +275,17 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
t.Fatal("ai_handler.go must not prepend finding context into the persisted prompt")
}
+ settingsHandlerText := string(settingsHandlerSource)
+ for _, required := range []string{
+ "actionAuditStore: chatService.GetActionAuditStore()",
+ "tools.AttachApprovalActionPlan(req, time.Now().UTC())",
+ "tools.RecordPendingApprovalAction(a.actionAuditStore, req)",
+ } {
+ if !strings.Contains(settingsHandlerText, required) {
+ t.Fatalf("ai_handlers.go must preserve Patrol queued-fix action-audit seeding: missing %q", required)
+ }
+ }
+
patrolHandoffText := string(patrolHandoffSource)
for _, required := range []string{
"func BuildPatrolRunAssistantHandoff(run PatrolRunRecord) PatrolRunAssistantHandoff",
@@ -300,6 +315,7 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
"sessions.GetModelHandoffResources(session.ID)",
"sessions.SetModelHandoffActions(session.ID, handoffActions)",
"sessions.GetModelHandoffActions(session.ID)",
+ "GetActionAuditStore",
"refreshHandoffActionStatus(handoffActions, s.orgID, s.actionAuditStore)",
"HydrateHandoffActionFromApproval(&actions[idx], req)",
"func HydrateHandoffActionFromApproval(action *HandoffAction, req *approval.ApprovalRequest)",