|
| 1 | +import { expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { |
| 4 | + deriveVerificationBlockedOutcome, |
| 5 | + decideEscalation, |
| 6 | + parseEscalationAssessment, |
| 7 | + parseEscalationResolution, |
| 8 | + renderEscalationDecision, |
| 9 | +} from "./escalation-policy.js"; |
| 10 | + |
| 11 | +const assessment = { |
| 12 | + policyVersion: "1", |
| 13 | + classification: "operator_decision_required", |
| 14 | + blockedOutcome: "The authenticated verification result cannot be produced.", |
| 15 | + unavailableDirectorPath: "The director has no credential authority.", |
| 16 | + permittedAlternatives: [ |
| 17 | + { |
| 18 | + attempted: "focused local test", |
| 19 | + result: "requires the missing credential", |
| 20 | + comparableConfidence: false, |
| 21 | + }, |
| 22 | + ], |
| 23 | + minimumAddition: "Allow an authenticated read-only snapshot.", |
| 24 | + declineConsequence: "Implementation is complete but verification is blocked.", |
| 25 | + recommendation: "Decline unless the snapshot is necessary.", |
| 26 | + safeDefault: "Decline.", |
| 27 | + requestedMechanism: "broad web access", |
| 28 | + minimumAuthority: "authenticated read-only snapshot", |
| 29 | + verification: { |
| 30 | + verificationOutcome: "integration verification", |
| 31 | + rootCause: "missing test credential", |
| 32 | + attemptedNarrowChecks: ["focused local test"], |
| 33 | + reducedConfidence: "integration behavior remains unverified", |
| 34 | + }, |
| 35 | +} as const; |
| 36 | + |
| 37 | +test("routine alternatives remain internal and never produce a parked directive", () => { |
| 38 | + const parsed = parseEscalationAssessment({ |
| 39 | + ...assessment, |
| 40 | + classification: "routine", |
| 41 | + permittedAlternatives: [ |
| 42 | + { |
| 43 | + attempted: "focused test", |
| 44 | + result: "passed", |
| 45 | + comparableConfidence: true, |
| 46 | + }, |
| 47 | + ], |
| 48 | + }); |
| 49 | + expect(parsed).not.toBeInstanceOf(Error); |
| 50 | + if (parsed instanceof Error) return; |
| 51 | + expect(decideEscalation(parsed).kind).toBe("continue_internal"); |
| 52 | +}); |
| 53 | + |
| 54 | +test("decision rendering distinguishes requested mechanism from minimum authority", () => { |
| 55 | + const parsed = parseEscalationAssessment(assessment); |
| 56 | + expect(parsed).not.toBeInstanceOf(Error); |
| 57 | + if (parsed instanceof Error) return; |
| 58 | + const rendered = renderEscalationDecision({ |
| 59 | + sessionId: "worker-1", |
| 60 | + questionId: "ask-1", |
| 61 | + assessment: parsed, |
| 62 | + }); |
| 63 | + expect(rendered).toContain("Requested mechanism: broad web access"); |
| 64 | + expect(rendered).toContain( |
| 65 | + "Minimum authority/decision: authenticated read-only snapshot", |
| 66 | + ); |
| 67 | + expect(rendered).toContain("Decline/proceed-without consequence:"); |
| 68 | +}); |
| 69 | + |
| 70 | +test("declined verification produces a distinct durable blocked outcome", () => { |
| 71 | + const parsed = parseEscalationAssessment(assessment); |
| 72 | + expect(parsed).not.toBeInstanceOf(Error); |
| 73 | + if (parsed instanceof Error) return; |
| 74 | + expect( |
| 75 | + deriveVerificationBlockedOutcome(parsed, { |
| 76 | + kind: "declined", |
| 77 | + answer: "No credential grant.", |
| 78 | + }), |
| 79 | + ).toMatchObject({ |
| 80 | + kind: "verification_blocked", |
| 81 | + implementationReviewComplete: true, |
| 82 | + rootCause: "missing test credential", |
| 83 | + resolution: "declined", |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
| 87 | +test("incomplete material requests are rejected", () => { |
| 88 | + expect( |
| 89 | + parseEscalationAssessment({ |
| 90 | + policyVersion: "1", |
| 91 | + classification: "operator_decision_required", |
| 92 | + }), |
| 93 | + ).toBeInstanceOf(Error); |
| 94 | +}); |
| 95 | + |
| 96 | +test("structured parent resolution is closed and carries no authority", () => { |
| 97 | + expect( |
| 98 | + parseEscalationResolution({ |
| 99 | + kind: "minimum_grant_available", |
| 100 | + answer: "The minimum decision is available; continue your next turn.", |
| 101 | + }), |
| 102 | + ).toEqual({ |
| 103 | + kind: "minimum_grant_available", |
| 104 | + answer: "The minimum decision is available; continue your next turn.", |
| 105 | + }); |
| 106 | + expect( |
| 107 | + parseEscalationResolution({ |
| 108 | + kind: "grant", |
| 109 | + answer: "retry this command", |
| 110 | + command: "unsafe", |
| 111 | + }), |
| 112 | + ).toBeInstanceOf(Error); |
| 113 | +}); |
0 commit comments