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.

Align narration contract assertions with upstream resolver guard

pulse-triage[bot]84264d7d2291
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 35c5383ec8..fd367b21b3 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -10234,8 +10234,9 @@ it. `generate-multi` and the manual schedule run endpoint
(`POST /api/admin/reports/schedules/{id}/run`) were already POST-only; due
schedules run from the server's scheduler, not an HTTP request.
POST alone does not authorise narration by an API token. Both the
-single-resource and fleet generation paths call `reportCallerMayUseAI` before
-`resolveNarrator`: a token must carry `ai:execute` (including full-access
+single-resource and fleet generation paths use `resolveNarrator`, whose shared
+gate calls `reportCallerMayUseAI` before resolving AI narrators: a token must
+carry `ai:execute` (including full-access
tokens), in addition to the route's `settings:read` generation scope. A
read-only token still receives the report, but with deterministic narration
and an existing-service-only findings lookup, never an AI service resolution
diff --git a/frontend-modern/src/utils/__tests__/docsLinks.test.ts b/frontend-modern/src/utils/__tests__/docsLinks.test.ts
index 00f4ad1414..729b1c65b8 100644
--- a/frontend-modern/src/utils/__tests__/docsLinks.test.ts
+++ b/frontend-modern/src/utils/__tests__/docsLinks.test.ts
@@ -634,29 +634,33 @@ describe('docsLinks', () => {
.split('func (h *ReportingHandlers) generateMultiReportFromBody(')[1]
.split('\nfunc ')[0];
const caller = handler.split('func reportCallerMayUseAI(')[1].split('\nfunc ')[0];
+ const resolver = handler
+ .split('func (h *ReportingHandlers) resolveNarrator(')[1]
+ .split('\nfunc ')[0];
- // Whitespace is not the contract. Both permission checks and the separate
- // deterministic paths are; behavioural Go tests exercise every caller.
+ // The shared resolver owns spending permission; the handler still owns
+ // GET's deterministic path. Behavioural Go tests exercise every caller.
expect(single).toMatch(
- /case r\.Method == http\.MethodPost && reportCallerMayUseAI\(r\.Context\(\)\):\s*narrator, _, findings = h\.resolveNarrator\(r\.Context\(\)\)/,
+ /if r\.Method == http\.MethodPost \{\s*narrator, _, findings = h\.resolveNarrator\(r\.Context\(\)\)/,
);
expect(single.match(/h\.resolveNarrator\(/g)).toHaveLength(1);
expect(single).toMatch(
- /case r\.Method == http\.MethodPost:\s*findings = h\.resolveExistingFindings\(r\.Context\(\)\)\s*req\.Narrator = scopeLimitedReportNarrator\{\}/,
+ /if !reportCallerMayUseAI\(r\.Context\(\)\) \{\s*(?:\/\/[^\n]*\n\s*)*req\.Narrator = scopeLimitedReportNarrator\{\}/,
);
expect(single).toMatch(
- /default:\s*findings = h\.resolveExistingFindings\(r\.Context\(\)\)\s*req\.Narrator = getReportNarrator\{\}/,
+ /\} else \{\s*findings = h\.resolveExistingFindings\(r\.Context\(\)\)\s*req\.Narrator = getReportNarrator\{\}/,
);
expect(caller).toContain('internalauth.GetAPIToken(ctx).(*config.APITokenRecord)');
expect(caller).toMatch(/if !ok \|\| record == nil \{\s*return true/);
expect(caller).toContain('return record.HasScope(config.ScopeAIExecute)');
- expect(fleet).toMatch(
- /if reportCallerMayUseAI\(ctx\) \{\s*_, fleetNarrator, findings = h\.resolveNarrator\(ctx\)/,
+ expect(resolver).toMatch(
+ /if !reportCallerMayUseAI\(ctx\) \{\s*return nil, nil, h\.resolveExistingFindings\(ctx\)\s*\}\s*return h\.narratorResolver\(ctx\)/,
);
- expect(fleet.match(/h\.resolveNarrator\(/g)).toHaveLength(1);
+ expect(resolver.match(/h\.narratorResolver\(/g)).toHaveLength(1);
expect(fleet).toMatch(
- /\} else \{\s*(?:\/\/[^\n]*\n\s*)*findings = h\.resolveExistingFindings\(ctx\)/,
+ /_, fleetNarrator, findings := h\.resolveNarrator\(ctx\)/,
);
+ expect(fleet.match(/h\.resolveNarrator\(/g)).toHaveLength(1);
});
it('ships report help that separates read permission from AI spending', () => {