| 1 | import assert from "node:assert/strict"; |
| 2 | import { normalizeCompletionSummary, completionSummaryNeedsAttention } from "../lib/completionSummary"; |
| 3 | import { historyMessagesToItems } from "../lib/historyItems"; |
| 4 | import type { HistoryMessage, WireCompletionSummary } from "../lib/types"; |
| 5 | import { createLegacyRemotePolicyNoticeTracker } from "../lib/legacyRemotePolicyNotice"; |
| 6 | |
| 7 | const base: WireCompletionSummary = { preset: "standard", constraint_degraded: false, verdict: "unknown", mutations: 1, checks_passed: 0, checks_failed: 0, checks_suppressed: 0, review: "", receipt: { assessmentKind: "facts", verdict: "unknown", changes: [{path: "auth.go", reviewed: false}] } }; |
| 8 | assert.equal(normalizeCompletionSummary(base).receipt?.assessmentKind, "facts"); |
| 9 | assert.equal(completionSummaryNeedsAttention(base), false, "unknown facts do not imply failure"); |
| 10 | const failed = structuredClone(base); |
| 11 | failed.receipt!.verifications = [{ command: "go test ./...", passed: false, exitCode: 1 }]; |
| 12 | assert.equal(completionSummaryNeedsAttention(failed), true, "actual failure remains visible"); |
| 13 | assert.equal(normalizeCompletionSummary(failed).receipt?.verifications?.[0].exitCode, 1); |
| 14 | const old: HistoryMessage[] = [{ role: "notice", content: "historical", code: "historical_checks", pending: false, readiness: { missing: ["verification"], attempts: 1 } }]; |
| 15 | const snapshot = structuredClone(old); |
| 16 | const history = historyMessagesToItems(old, "history"); |
| 17 | assert.deepEqual(old, snapshot, "history projection is read-only"); |
| 18 | assert.equal(history.items.some(item => item.kind === "notice" && item.action === "continue_delivery"), false, "retired local checks do not block"); |
| 19 | const remoteOld: HistoryMessage[] = [{ ...old[0], code: "final_readiness", pending: true }]; |
| 20 | assert.equal(historyMessagesToItems(remoteOld, "remote").items.some(item => item.kind === "notice" && item.action === "continue_delivery"), true, "old remote recovery remains available"); |
| 21 | console.log("execution facts and historical compatibility passed"); |
| 22 | const notice = createLegacyRemotePolicyNoticeTracker(); |
| 23 | assert.equal(notice("remote:a"), undefined, "missing version or state does not imply an old policy"); |
| 24 | assert.equal(notice("remote:a", "standard", "evaluator_unavailable"), "remote.legacyExecutionPolicy"); |
| 25 | assert.equal(notice("remote:a", "delivery"), undefined, "polling and policy updates do not repeat warnings"); |
| 26 | assert.equal(notice("remote:b", "delivery"), "remote.legacyDeliveryPolicy", "another session gets its own warning"); |
| 27 | assert.equal(notice("remote:c", "standard", undefined, true), "remote.legacyExecutionPolicy"); |
| 28 | assert.equal(notice("remote:d", "standard", "budget_spend"), undefined, "actual budget pauses are not retired quality policy"); |
| 29 |