render.test.ts
This file
Path
packages/protocol/test/render.test.ts
509 lines · 16.3 KiB · TypeScript
Last changed by
Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
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
lines 1–7why, one step back1import { describe, expect, it } from "@effect/vitest";2import { Brand } from "@repo/brand";3import { Result } from "effect";45import { Outcome } from "../src/domain/outcome.ts";6import {7 AskId,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 8why, one step back8 CommitSha,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 9–10why, one step back9 DecisionId,10 EnvKey,Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097
line 11why, one step back11 Handle,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 12–13why, one step back12 LandedSha,13 ProjectName,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 14why, one step back14 ProposalId,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 15–18why, one step back15 RepoPath,16 RequestId,17} from "../src/ids.ts";18import {Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7
line 19why, one step back19 CapReached,Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff
line 20why, one step back20 ChecksFailed,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 21why, one step back21 DirectPush,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 22why, one step back22 DraftInProgress,Merge build/1105 into mainoscabrielbefore adoption1fc92ed
line 23why, one step back23 NotDecider,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 24–25why, one step back24 OutOfScope,25 PrivatePathInPublicTree,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 26why, one step back26 ProposalClosed,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 27–29why, one step back27 ReachedInternals,28 StaleBase,29 TouchedJudge,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 30–32why, one step back30 UnknownPath,31 UnknownProposal,32 UnknownRevision,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 33–65why, one step back33 ValueTooShort,34 Weakened,35} from "../src/refusal.ts";36import { explain, headline, receiptLine } from "../src/render.ts";37import { ask, base, examples, main, path } from "./examples.ts";3839const outOfScope = new OutOfScope({ paths: [path] });4041const touchedJudge = new TouchedJudge({ paths: [path] });4243describe(headline, () => {44 it("names the refusal for git's ng line", () => {45 expect(headline([new StaleBase({ base, conflicts: [], main })])).toBe(46 "StaleBase"47 );48 });4950 it("names the first refusal and counts the rest", () => {51 expect(headline([outOfScope, touchedJudge, outOfScope])).toBe(52 "OutOfScope and 2 more"53 );54 });55});5657describe(explain, () => {58 it("gives the reason, then next, then whether retrying can help", () => {59 expect(60 explain([new StaleBase({ base, conflicts: [path], main })])61 ).toStrictEqual([62 "StaleBase: main moved to 2222222, past your base 1111111; conflicts in src/a.ts",63 " next: git pull --rebase",64 " retryable: yes",65 ]);Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097
lines 66–86why, one step back66 });6768 it("names the landing that last changed each conflicting path it knows of", () => {69 const landing = LandedSha.make("3333333333333333333333333333333333333333");70 const other = RepoPath.make("src/b.ts");7172 expect(73 explain([74 new StaleBase({75 base,76 conflicts: [path, other, RepoPath.make("src/c.ts")],77 main,78 movedBy: [79 { ask, author: Handle.make("alice"), landing, path },80 { author: Handle.make("dora"), landing, path: other },81 ],82 }),83 ])[0]84 ).toBe(85 "StaleBase: main moved to 2222222, past your base 1111111; conflicts in src/a.ts (last changed by alice in 3333333, for fix-parser), src/b.ts (last changed by dora in 3333333), src/c.ts"86 );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 87–97why, one step back87 });8889 it("points at the line when the refusal has one", () => {90 expect(91 explain([92 new Weakened({93 at: { line: 3, path },94 weakening: { marker: "it.skip" },95 }),96 ])97 ).toStrictEqual([Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 98why, one step back98 'Weakened: adds it.skip without a reason; remove it, or give a reason after " -- " for a maintainer to weigh',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 99–132why, one step back99 " at: src/a.ts:3",100 ` next: ${Brand.cli} check`,101 " retryable: no",102 ]);103 });104105 it.each(examples)("explains $_tag, opening with its tag", (refusal) => {106 expect(explain([refusal])[0]).toMatch(107 new RegExp(`^${refusal._tag}: \\S`, "u")108 );109 });110111 it.each(examples)(112 "explains $_tag with every field it names filled in",113 (refusal) => {114 expect(explain([refusal]).join("\n")).not.toMatch(115 /undefined|null|\[object Object\]/u116 );117 }118 );119120 it.each([121 {122 ends: "; put those files back, or flag the ask if the want needs them",123 refusal: outOfScope,124 starts: "OutOfScope: changes paths outside the ask's territory: src/a.ts",125 },126 {127 ends: "; the checks are fixed for this ask, so put them back, or flag the ask if a check is wrong",128 refusal: touchedJudge,129 starts:130 "TouchedJudge: changes files that decide what the checks do: src/a.ts",131 },132 {Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 133why, one step back133 ends: '; remove it, or give a reason after " -- " for a maintainer to weigh',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 134–140why, one step back134 refusal: new Weakened({135 at: { line: 3, path },136 weakening: { marker: ".skip(" },137 }),138 starts: "Weakened: adds .skip( without a reason",139 },140 {Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 141why, one step back141 ends: "; a maintainer declined it, so take the marker out",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 142–145why, one step back142 refusal: new Weakened({143 at: { line: 3, path },144 weakening: { marker: "oxlint-disable", reason: "generated code" },145 }),Merge build/1105 into mainoscabrielbefore adoption1fc92ed
line 146why, one step back146 starts: 'Weakened: adds oxlint-disable with the reason "generated code"',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 147–199why, one step back147 },148 {149 ends: "; import it through that module's public exports instead",150 refusal: new ReachedInternals({151 at: { line: 1, path },152 from: path,153 to: "../../b/src/internal.ts",154 }),155 starts:156 "ReachedInternals: src/a.ts reaches into ../../b/src/internal.ts, which its module does not export",157 },158 {159 ends: "; those paths belong to a layer, so remove them from the answer",160 refusal: new PrivatePathInPublicTree({ paths: [path] }),161 starts:162 "PrivatePathInPublicTree: would put held-back paths in a public tree: src/a.ts",163 },164 ])(165 "ends $refusal._tag's reason with how to repair it",166 ({ ends, refusal, starts }) => {167 expect(explain([refusal])[0]).toBe(`${starts}${ends}`);168 }169 );170171 it("explains every refusal of one push in the gate's order, each with its line", () => {172 const a = RepoPath.make("packages/a/src/x.ts");173 const test = RepoPath.make("packages/a/test/x.test.ts");174175 const refusals = [176 new OutOfScope({ paths: [RepoPath.make("packages/b/src/y.ts")] }),177 new TouchedJudge({ paths: [RepoPath.make("oxlint.config.ts")] }),178 new Weakened({179 at: { line: 3, path: test },180 weakening: { marker: ".skip(" },181 }),182 new Weakened({183 at: { line: 9, path: test },184 weakening: { marker: ".only(" },185 }),186 new ReachedInternals({187 at: { line: 1, path: a },188 from: a,189 to: "../../b/src/internal.ts",190 }),191 ] as const;192193 expect(explain(refusals)).toStrictEqual([194 "OutOfScope: changes paths outside the ask's territory: packages/b/src/y.ts; put those files back, or flag the ask if the want needs them",195 ` next: ${Brand.cli} check`,196 " retryable: no",197 "TouchedJudge: changes files that decide what the checks do: oxlint.config.ts; the checks are fixed for this ask, so put them back, or flag the ask if a check is wrong",198 ` next: ${Brand.cli} check`,199 " retryable: no",Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 200why, one step back200 'Weakened: adds .skip( without a reason; remove it, or give a reason after " -- " for a maintainer to weigh',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 201–203why, one step back201 " at: packages/a/test/x.test.ts:3",202 ` next: ${Brand.cli} check`,203 " retryable: no",Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 204why, one step back204 'Weakened: adds .only( without a reason; remove it, or give a reason after " -- " for a maintainer to weigh',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 205–214why, one step back205 " at: packages/a/test/x.test.ts:9",206 ` next: ${Brand.cli} check`,207 " retryable: no",208 "ReachedInternals: packages/a/src/x.ts reaches into ../../b/src/internal.ts, which its module does not export; import it through that module's public exports instead",209 " at: packages/a/src/x.ts:1",210 ` next: ${Brand.cli} check`,211 " retryable: no",212 ]);213 });214Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 215why, one step back215 it("says a maintainer declined a reasoned marker, and to take it out", () => {Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 216–223why, one step back216 const lines = explain([217 new Weakened({218 at: { line: 3, path },219 weakening: { marker: ".skip(", reason: "flaky" },220 }),221 ]);222223 expect(lines).toStrictEqual([Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 224why, one step back224 'Weakened: adds .skip( with the reason "flaky"; a maintainer declined it, so take the marker out',Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 225–228why, one step back225 " at: src/a.ts:3",226 ` next: ${Brand.cli} check`,227 " retryable: no",228 ]);Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 229why, one step back229 expect(lines.join("\n")).not.toContain("waits for a maintainer");Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 230–231why, one step back230 });231Merge 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 232–256why, one step back232 it("leaves a raised ratchet's reason as it was", () => {233 expect(234 explain([235 new Weakened({236 weakening: {237 after: 4,238 before: 3,239 ratchet: "no-explicit-any",240 territory: "parser",241 },242 }),243 ])[0]244 ).toBe(245 "Weakened: raises the no-explicit-any ratchet in parser from 3 to 4"246 );247 });248249 it("tells a direct push to main where answers go instead", () => {250 expect(explain([new DirectPush({ ref: "refs/heads/main" })])).toStrictEqual(251 [252 "DirectPush: main moves only by a landing, so refs/heads/main takes no direct push; push your answer to your claim's fork",253 ` next: ${Brand.cli} asks`,254 " retryable: no",255 ]256 );Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7
lines 257–328why, one step back257 });258259 it("tells a push to a ref the platform writes that a fork takes branches only", () => {260 expect(261 explain([new DirectPush({ ref: `refs/notes/${Brand.slug}` })])262 ).toStrictEqual([263 `DirectPush: refs/notes/${Brand.slug} is written by the platform, not pushed; a fork takes branches only, so push your answer with git push ${Brand.slug} HEAD:main`,264 ` next: ${Brand.cli} asks`,265 " retryable: no",266 ]);267 });268269 it.each([270 {271 reason: "you already hold 3 claims, the most this project allows",272 refusal: new CapReached({ cap: 3 }),273 },274 {275 reason: "you already hold 1 claim, the most this project allows",276 refusal: new CapReached({ cap: 1, limit: "claims" }),277 },278 {279 reason:280 "you made 10 claims in the last minute, the most the platform allows; try again in 60s",281 refusal: new CapReached({ cap: 10, limit: "claims", retryAfter: 60 }),282 },283 {284 reason:285 "you made 5 proposals in the last minute, the most the platform allows; try again in 60s",286 refusal: new CapReached({ cap: 5, limit: "proposals", retryAfter: 60 }),287 },288 {289 reason:290 "you made 1 proposal in the last minute, the most the platform allows; try again in 60s",291 refusal: new CapReached({ cap: 1, limit: "proposals", retryAfter: 60 }),292 },293 {294 reason:295 "you already have 2 open proposals here, the most this project allows",296 refusal: new CapReached({ cap: 2, limit: "proposals" }),297 },298 {299 reason:300 "you already have 1 open proposal here, the most this project allows",301 refusal: new CapReached({ cap: 1, limit: "proposals" }),302 },303 {304 reason:305 "you started 2 drafts in the last minute, the most the platform allows; try again in 60s",306 refusal: new CapReached({ cap: 2, limit: "drafts", retryAfter: 60 }),307 },308 {309 reason:310 "you started 1 draft in the last minute, the most the platform allows; try again in 30s",311 refusal: new CapReached({ cap: 1, limit: "drafts", retryAfter: 30 }),312 },313 {314 reason:315 "this proposal was already drafted 3 times, the most one proposal takes",316 refusal: new CapReached({ cap: 3, limit: "drafts" }),317 },318 {319 reason:320 "this proposal was already drafted once, the most one proposal takes",321 refusal: new CapReached({ cap: 1, limit: "drafts" }),322 },323 ])("reads CapReached as: $reason", ({ refusal, reason }) => {324 expect(explain([refusal])).toStrictEqual([325 `CapReached: ${reason}`,326 ` next: ${Brand.cli} status`,327 " retryable: yes",328 ]);Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 329–386why, one step back329 });330331 it.each([332 {333 lines: [334 "UnknownPath: 2222222 has no file or folder at src/a.ts",335 " next: git ls-tree",336 " retryable: no",337 ],338 refusal: new UnknownPath({ commit: main, path }),339 },340 {341 lines: [342 "UnknownRevision: v9 is neither main, a commit this project holds, nor one of its tags",343 " next: git ls-remote",344 " retryable: no",345 ],346 refusal: new UnknownRevision({ rev: "v9" }),347 },348 {349 lines: [350 "UnknownProposal: this project has no proposal prop-000007",351 ` next: ${Brand.cli} today`,352 " retryable: no",353 ],354 refusal: new UnknownProposal({355 proposal: ProposalId.make("prop-000007"),356 }),357 },358 {359 lines: [360 "ProposalClosed: prop-000007 was already accepted, declined or expired",361 ` next: ${Brand.cli} today`,362 " retryable: no",363 ],364 refusal: new ProposalClosed({ proposal: ProposalId.make("prop-000007") }),365 },366 {367 lines: [368 "DraftInProgress: the platform is already drafting prop-000007's ask",369 ` next: ${Brand.cli} proposal prop-000007`,370 " retryable: yes",371 ],372 refusal: DraftInProgress.of(ProposalId.make("prop-000007")),373 },374 ])("explains $refusal._tag with its next command", ({ lines, refusal }) => {375 expect(explain([refusal])).toStrictEqual(lines);376 });377378 it("names the commit a missing path was looked for at", () => {379 expect(380 explain([381 new UnknownPath({382 commit: CommitSha.make("abcdef0".padEnd(40, "0")),383 path,384 }),385 ])[0]386 ).toBe("UnknownPath: abcdef0 has no file or folder at src/a.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 387–394why, one step back387 });388389 it("says a value is too short by the minimum alone", () => {390 expect(391 explain([ValueTooShort.of(EnvKey.make("PAYMENTS_KEY"), 32)])392 ).toStrictEqual([393 "ValueTooShort: the value for PAYMENTS_KEY is shorter than the 32 characters it needs",394 ` next: ${Brand.cli} env set PAYMENTS_KEY --acknowledge-short`,Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff
lines 395–412why, one step back395 " retryable: no",396 ]);397 });398399 it("says a lane's log was withheld rather than where it is", () => {400 expect(401 explain([402 new ChecksFailed({403 lane: "unit",404 logRef: ChecksFailed.withheld,405 next: "bun test",406 }),407 ])408 ).toStrictEqual([409 "ChecksFailed: the unit checks failed; their log was withheld",410 " next: bun test",411 " retryable: no",412 ]);Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 413–420why, one step back413 });414415 it("says the checks failed on the answer, the command that shows it, and where the log is kept", () => {416 const logRef = "datekit/push-2222222/unit#1";417418 expect(419 explain([new ChecksFailed({ lane: "unit", logRef, next: "bun test" })])420 ).toStrictEqual([Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 421why, one step back421 `ChecksFailed: the unit checks failed on the answer; run bun test in a clone of the fork to see the failure; the log is kept as ${logRef}, which the answerer and the project's maintainers read with ${Brand.cli} evidence`,Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 422–443why, one step back422 " next: bun test",423 " retryable: no",424 ]);425 });426427 it("says a lane the local check ran failed here, with no kept log to read", () => {428 const lines = explain([429 new ChecksFailed({430 lane: "unit",431 logRef: ChecksFailed.localRef("unit"),432 next: "bun test",433 }),434 ]);435436 expect(lines).toStrictEqual([437 "ChecksFailed: the unit checks failed on this commit; run bun test to see the failure",438 " next: bun test",439 " retryable: no",440 ]);441 expect(lines.join("\n")).not.toContain("evidence");442 });443Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 444why, one step back444 it("tells a caller they are not a maintainer without naming a project", () => {Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 445–447why, one step back445 const [line] = explain([new NotDecider({})]);446447 expect(line).toBe(Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 448why, one step back448 "NotDecider: you are not a maintainer here: only the maintainers a project's config names may do this"Merge build/1105 into mainoscabrielbefore adoption1fc92ed
lines 449–450why, one step back449 );450 expect(line).not.toContain("this project's");Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff
lines 451–458why, one step back451 });452453 it("says a value below the floor needs another value, not an acknowledgement", () => {454 expect(455 explain([ValueTooShort.belowFloor(EnvKey.make("PAYMENTS_KEY"), 3)])456 ).toStrictEqual([457 "ValueTooShort: the value for PAYMENTS_KEY is shorter than the 3 characters it needs",458 ` next: ${Brand.cli} env set PAYMENTS_KEY`,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 459–468why, one step back459 " retryable: no",460 ]);461 });462});463464const receiptAt = (outcome: Outcome) => ({465 ask,466 base,467 head: main,468 outcome,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 469why, one step back469 project: ProjectName.make("oscabriel/datekit"),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 470–492why, one step back470 requestId: RequestId.make("push-2222222"),471});472473describe(receiptLine, () => {474 const follow = `follow with ${Brand.cli} status`;475476 it("says where the push's answer stands, in one line", () => {477 expect(478 [479 Outcome.cases.Checking.make({ stage: "merge" }),480 Outcome.cases.AwaitingDecision.make({481 decision: DecisionId.make("dec-000001"),482 }),483 Outcome.cases.AwaitingFinish.make({}),484 Outcome.cases.WaitingOnParent.make({ ask: AskId.make("parse-iso") }),485 Outcome.cases.Landed.make({ sha: LandedSha.make("3".repeat(40)) }),486 ].map((outcome) => receiptLine(receiptAt(outcome)))487 ).toStrictEqual([488 Result.succeed(`checking fix-parser at 2222222; ${follow}`),489 Result.succeed(490 `fix-parser at 2222222 waits on decision dec-000001; ${follow}`491 ),492 Result.succeed(Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 493why, one step back493 `fix-parser at 2222222 passed and waits for a maintainer's finish; ${follow}`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 494–509why, one step back494 ),495 Result.succeed(496 `fix-parser at 2222222 passed and waits for parse-iso to land; ${follow}`497 ),498 Result.succeed("fix-parser at 2222222 landed as 3333333"),499 ]);500 });501502 it("gives a refused answer's refusals back, for explain", () => {503 expect(504 receiptLine(505 receiptAt(Outcome.cases.Refused.make({ refusals: [outOfScope] }))506 )507 ).toStrictEqual(Result.fail([outOfScope]));508 });509});