fix: name matched risk inputs in policy block messages (#1471)

The auto-update, bulk-label, scheduler, and blueprint deploy block
messages hardcoded "image(s) exceed <max_severity>", which is wrong
under the risk-first policy model: a block can be driven by a
known-exploited (KEV) or fixable Critical/High input while the severity
threshold was never the trigger. In those cases the message named a
severity ceiling the policy did not enforce.

Route all four message paths through a shared summarizeBlockReasons
helper (the same reason text the deploy-gate 409 response and the block
dialog already use), so every surface names the inputs that actually
matched. Falls back to a generic phrase when no reason was recorded.
This commit is contained in:
Anso
2026-06-26 15:34:24 -04:00
committed by GitHub
parent 5e2194f4a3
commit ca496c89dc
10 changed files with 104 additions and 17 deletions
+18
View File
@@ -107,6 +107,24 @@ export function describeReason(reason: PolicyBlockReason): string {
}
}
/**
* De-duplicated, human-readable summary of the inputs that actually matched
* across a set of policy violations, joined with " + ". Used wherever a policy
* block is reported to a user (the gate's 409 response, thrown gate errors, and
* the deploy/auto-update block messages), so a KEV- or fixable-driven block
* never reads as a severity-threshold block. Falls back to a generic phrase
* when no reason was recorded (e.g. an image that could not be scanned).
*/
export function summarizeBlockReasons(
violations: ReadonlyArray<{ reasons: readonly PolicyBlockReason[] }>,
): string {
const labels = new Set<string>();
for (const v of violations) {
for (const r of v.reasons) labels.add(describeReason(r));
}
return labels.size > 0 ? [...labels].join(' + ') : 'scan policy conditions';
}
/** Compact descriptor of a policy's active inputs, for log and audit lines. */
export function describePolicyInputs(inputs: PolicyRiskInputs): string {
const parts: string[] = [];