exit-code.test.ts
This file
Path
packages/protocol/test/exit-code.test.ts
102 lines · 2.7 KiB · TypeScript
Last changed by
Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
History of this fileTake it
Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
lines 1–102why, one step back1import { describe, expect, it } from "@effect/vitest";23import {4 ExitCode,5 exitCodeFor,6 exitCodeOf,7 exitCodeOfTag,8} from "../src/exit-code.ts";9import {10 AskFull,11 NotVouched,12 OutOfScope,13 StaleBase,14 UnknownAsk,15} from "../src/refusal.ts";16import type { Refusal } from "../src/refusal.ts";17import { ask, base, examples, main, path } from "./examples.ts";1819// Each tag's code, as scripts and agents branch on it: a public contract,20// pinned here so a change to one is a change to this table.21const pinned = {22 AskBlocked: 75,23 AskFull: 75,24 AttemptsExhausted: 75,25 CapReached: 75,26 ChecksFailed: 65,27 ClaimLapsed: 75,28 DecisionClosed: 66,29 Denounced: 77,30 DirectPush: 77,31 DraftInProgress: 75,32 Flake: 75,33 HeldBackFailed: 65,34 ImportFailed: 75,35 IncompleteBrief: 65,36 LayerContentInPublicTree: 65,37 NoAsk: 66,38 NotClaimed: 75,39 NotDecider: 77,40 NotRedFirst: 65,41 NotSensitive: 65,42 NotVouched: 77,43 OutOfScope: 65,44 PostureChange: 65,45 PrivatePathInPublicTree: 65,46 ProjectExists: 65,47 ProposalClosed: 66,48 ReachedInternals: 65,49 RepoBusy: 75,50 SecretInOutput: 65,51 StaleBase: 75,52 StaleLayer: 75,53 TouchedJudge: 65,54 UnknownAsk: 66,55 UnknownCommit: 66,56 UnknownDecision: 66,57 UnknownEnvItem: 66,58 UnknownPath: 66,59 UnknownProject: 66,60 UnknownProposal: 66,61 UnknownRevision: 66,62 UnstatedRequirement: 65,63 ValueTooShort: 65,64 VerifierBlocked: 75,65 WeakCheck: 65,66 Weakened: 65,67} as const satisfies Record<Refusal["_tag"], number>;6869describe("a refusal's exit code", () => {70 it.each(examples)("$_tag ends the CLI with its pinned code", (refusal) => {71 expect(exitCodeOf(refusal)).toBe(pinned[refusal._tag]);72 });7374 it.each(examples)("$_tag has the same code by its tag alone", (refusal) => {75 expect(exitCodeOfTag(refusal._tag)).toBe(exitCodeOf(refusal));76 });7778 it.each(examples)("$_tag is 75 exactly when it is retryable", (refusal) => {79 expect(exitCodeOf(refusal) === ExitCode.tempFail).toBe(refusal.retryable);80 });81});8283describe("refusals met together", () => {84 const stale = new StaleBase({ base, conflicts: [path], main });85 const outOfScope = new OutOfScope({ paths: [path] });8687 it("end with 75 only when every one is retryable", () => {88 expect([89 exitCodeFor([stale, new AskFull({ ask })]),90 exitCodeFor([stale, outOfScope]),91 ]).toStrictEqual([ExitCode.tempFail, ExitCode.dataErr]);92 });9394 it("end with who is asking first, then what was named, then what was sent", () => {95 const unknown = new UnknownAsk({ ask });9697 expect([98 exitCodeFor([outOfScope, unknown, new NotVouched({})]),99 exitCodeFor([outOfScope, unknown]),100 ]).toStrictEqual([ExitCode.noPerm, ExitCode.noInput]);101 });102});