exit-code.test.ts
This file
Path
packages/protocol/test/exit-code.test.ts
101 lines · 2.5 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
lines 1–40why, 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";1819const pinned = {20 AskBlocked: 75,21 AskFull: 75,22 AttemptsExhausted: 75,23 CapReached: 75,24 ChecksFailed: 65,25 ClaimLapsed: 75,26 DecisionClosed: 66,27 Denounced: 77,28 DirectPush: 77,29 DraftInProgress: 75,30 Flake: 75,31 HeldBackFailed: 65,32 ImportFailed: 75,33 IncompleteBrief: 65,34 LayerContentInPublicTree: 65,35 NoAsk: 66,36 NotClaimed: 75,37 NotDecider: 77,38 NotRedFirst: 65,39 NotSensitive: 65,40 NotVouched: 77,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 41why, one step back41 NotYourNamespace: 77,Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
lines 42–101why, one step back42 OutOfScope: 65,43 PostureChange: 65,44 PrivatePathInPublicTree: 65,45 ProjectExists: 65,46 ProposalClosed: 66,47 ReachedInternals: 65,48 RepoBusy: 75,49 SecretInOutput: 65,50 StaleBase: 75,51 StaleLayer: 75,52 TouchedJudge: 65,53 UnknownAsk: 66,54 UnknownCommit: 66,55 UnknownDecision: 66,56 UnknownEnvItem: 66,57 UnknownPath: 66,58 UnknownProject: 66,59 UnknownProposal: 66,60 UnknownRevision: 66,61 UnstatedRequirement: 65,62 ValueTooShort: 65,63 VerifierBlocked: 75,64 WeakCheck: 65,65 Weakened: 65,66} as const satisfies Record<Refusal["_tag"], number>;6768describe("a refusal's exit code", () => {69 it.each(examples)("$_tag ends the CLI with its pinned code", (refusal) => {70 expect(exitCodeOf(refusal)).toBe(pinned[refusal._tag]);71 });7273 it.each(examples)("$_tag has the same code by its tag alone", (refusal) => {74 expect(exitCodeOfTag(refusal._tag)).toBe(exitCodeOf(refusal));75 });7677 it.each(examples)("$_tag is 75 exactly when it is retryable", (refusal) => {78 expect(exitCodeOf(refusal) === ExitCode.tempFail).toBe(refusal.retryable);79 });80});8182describe("refusals met together", () => {83 const stale = new StaleBase({ base, conflicts: [path], main });84 const outOfScope = new OutOfScope({ paths: [path] });8586 it("end with 75 only when every one is retryable", () => {87 expect([88 exitCodeFor([stale, new AskFull({ ask })]),89 exitCodeFor([stale, outOfScope]),90 ]).toStrictEqual([ExitCode.tempFail, ExitCode.dataErr]);91 });9293 it("end with who is asking first, then what was named, then what was sent", () => {94 const unknown = new UnknownAsk({ ask });9596 expect([97 exitCodeFor([outOfScope, unknown, new NotVouched({})]),98 exitCodeFor([outOfScope, unknown]),99 ]).toStrictEqual([ExitCode.noPerm, ExitCode.noInput]);100 });101});