refusal.test.ts
This file
Path
packages/protocol/test/refusal.test.ts
252 lines · 7.0 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 1why, one step back1import { describe, expect, it } from "@effect/vitest";Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7
line 2why, one step back2import { Brand } from "@repo/brand";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 3–4why, one step back3import { Schema } from "effect";4Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097
line 5why, one step back5import { AskId, Handle, LandedSha, RepoPath } from "../src/ids.ts";Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7
line 6why, one step back6import { CapReached, groups, Refusal, StaleBase } from "../src/refusal.ts";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 7–31why, one step back7import { base, examples, main } from "./examples.ts";89// What Effect's MCP server sends for a declared tool failure that has no10// message: the failure schema's encoding, through JSON.stringify11// (`effect/src/ai/McpServer.ts` l.1864-1867 in 4.0.1).12const overTheWire = (refusal: Refusal) =>13 JSON.stringify(Schema.encodeSync(Refusal)(refusal));1415describe("the refusal union", () => {16 it("reaches MCP as JSON with its tag, fields, retryable and next", () => {17 const refusal = new StaleBase({18 base,19 conflicts: [RepoPath.make("src/a.ts")],20 main,21 });2223 expect(refusal.message).toBe("");24 expect(JSON.parse(overTheWire(refusal))).toStrictEqual({25 _tag: refusal._tag,26 base,27 conflicts: ["src/a.ts"],28 main,29 next: "git pull --rebase",30 retryable: true,31 });Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097
lines 32–64why, one step back32 });3334 it("sends who moved each conflicting path as JSON, and decodes it back", () => {35 const landing = LandedSha.make("3333333333333333333333333333333333333333");3637 const moved = new StaleBase({38 base,39 conflicts: [RepoPath.make("src/a.ts")],40 main,41 movedBy: [42 {43 ask: AskId.make("fix-parser"),44 author: Handle.make("alice"),45 landing,46 path: RepoPath.make("src/a.ts"),47 },48 ],49 });5051 expect(JSON.parse(overTheWire(moved))).toStrictEqual({52 _tag: moved._tag,53 base,54 conflicts: ["src/a.ts"],55 main,56 movedBy: [57 { ask: "fix-parser", author: "alice", landing, path: "src/a.ts" },58 ],59 next: "git pull --rebase",60 retryable: true,61 });62 expect(63 Schema.decodeUnknownSync(Refusal)(JSON.parse(overTheWire(moved)))64 ).toStrictEqual(moved);Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 65–73why, one step back65 });6667 it.each(examples)("$_tag comes back from the wire as it left", (refusal) => {68 const decoded = Schema.decodeUnknownSync(Refusal)(69 JSON.parse(overTheWire(refusal))70 );7172 expect(decoded.message).toBe("");73 expect(decoded).toStrictEqual(refusal);Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7
lines 74–111why, one step back74 });7576 it("sends a cap's limit and wait as JSON keys, and decodes one without them as before", () => {77 const rate = new CapReached({ cap: 2, limit: "drafts", retryAfter: 60 });78 const held = new CapReached({ cap: 3 });7980 expect(JSON.parse(overTheWire(rate))).toStrictEqual({81 _tag: rate._tag,82 cap: 2,83 limit: "drafts",84 next: `${Brand.cli} status`,85 retryAfter: 60,86 retryable: true,87 });88 expect(JSON.parse(overTheWire(held))).toStrictEqual({89 _tag: held._tag,90 cap: 3,91 next: `${Brand.cli} status`,92 retryable: true,93 });94 expect(95 [rate, held].map((refusal) =>96 Schema.decodeUnknownSync(Refusal)(JSON.parse(overTheWire(refusal)))97 )98 ).toStrictEqual([rate, held]);99 });100101 it("refuses a cap's wait below one second", () => {102 const zero = {103 ...Schema.encodeSync(CapReached)(104 new CapReached({ cap: 3, retryAfter: 60 })105 ),106 retryAfter: 0,107 };108109 expect(() => Schema.decodeUnknownSync(Refusal)(zero)).toThrow(110 /retryAfter/u111 );Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 112–127why, one step back112 });113114 it("has a JSON Schema with no non-finite numbers and no nulls", () => {115 const document = JSON.stringify(Schema.toJsonSchemaDocument(Refusal));116117 expect(document).not.toMatch(/Infinity|NaN|"null"/u);118 });119120 it("files every member under exactly one group, in union order", () => {121 expect(122 groups.flatMap((group) =>123 group.members.map((member) => member.identifier)124 )125 ).toStrictEqual(Refusal.members.map((member) => member.identifier));126 });127Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 128why, one step back128 it("lists all forty-five tags in union order, group by group", () => {Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 129–160why, one step back129 expect(Refusal.members.map((member) => member.identifier)).toStrictEqual([130 "NotClaimed",131 "ClaimLapsed",132 "NotVouched",133 "CapReached",134 "AskFull",135 "NoAsk",136 "RepoBusy",137 "DirectPush",138 "AskBlocked",139 "Denounced",140 "OutOfScope",141 "TouchedJudge",142 "Weakened",143 "PrivatePathInPublicTree",144 "ReachedInternals",145 "StaleBase",146 "StaleLayer",147 "ChecksFailed",148 "HeldBackFailed",149 "AttemptsExhausted",150 "Flake",151 "VerifierBlocked",152 "NotRedFirst",153 "WeakCheck",154 "IncompleteBrief",155 "LayerContentInPublicTree",156 "SecretInOutput",157 "UnstatedRequirement",158 "PostureChange",159 "NotDecider",160 "DecisionClosed",Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 161–162why, one step back161 "ProposalClosed",162 "DraftInProgress",Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 163–166why, one step back163 "UnknownProject",164 "UnknownAsk",165 "UnknownCommit",166 "UnknownDecision",Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 167–169why, one step back167 "UnknownPath",168 "UnknownRevision",169 "UnknownProposal",Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 170why, one step back170 "ProjectExists",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 171why, one step back171 "NotYourNamespace",Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 172–212why, one step back172 "ImportFailed",173 "UnknownEnvItem",174 "NotSensitive",175 "ValueTooShort",176 ]);177 expect(groups.map((group) => group.name)).toStrictEqual([178 "Push and claim",179 "Shape",180 "Merge",181 "Checks",182 "Never counted against the answerer",183 "At ask open",184 "Maintainers only",185 "Decision",186 "Lookup",187 "Setup",188 "Env",189 ]);190 });191192 // A failure here means a tag was added, removed or renamed, or a refusal193 // changed whether retrying helps. Both are public contract: rename a tag only194 // with an alias, and update the reference docs.195 it("is closed: exactly these tags, each saying whether retrying can help", () => {196 expect(Refusal.members.map((member) => member.identifier)).toStrictEqual(197 examples.map((refusal) => refusal._tag)198 );199 expect(200 Object.fromEntries(201 examples.map((refusal) => [refusal._tag, refusal.retryable])202 )203 ).toStrictEqual({204 AskBlocked: true,205 AskFull: true,206 AttemptsExhausted: true,207 CapReached: true,208 ChecksFailed: false,209 ClaimLapsed: true,210 DecisionClosed: false,211 Denounced: false,212 DirectPush: false,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 213why, one step back213 DraftInProgress: true,Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 214–224why, one step back214 Flake: true,215 HeldBackFailed: false,216 ImportFailed: true,217 IncompleteBrief: false,218 LayerContentInPublicTree: false,219 NoAsk: false,220 NotClaimed: true,221 NotDecider: false,222 NotRedFirst: false,223 NotSensitive: false,224 NotVouched: false,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 225why, one step back225 NotYourNamespace: false,Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 226–229why, one step back226 OutOfScope: false,227 PostureChange: false,228 PrivatePathInPublicTree: false,229 ProjectExists: false,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 230why, one step back230 ProposalClosed: false,Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 231–240why, one step back231 ReachedInternals: false,232 RepoBusy: true,233 SecretInOutput: false,234 StaleBase: true,235 StaleLayer: true,236 TouchedJudge: false,237 UnknownAsk: false,238 UnknownCommit: false,239 UnknownDecision: false,240 UnknownEnvItem: false,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 241why, one step back241 UnknownPath: false,Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 242why, one step back242 UnknownProject: false,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 243–244why, one step back243 UnknownProposal: false,244 UnknownRevision: false,Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 245–252why, one step back245 UnstatedRequirement: false,246 ValueTooShort: false,247 VerifierBlocked: true,248 WeakCheck: false,249 Weakened: false,250 });251 });252});