evidence.test.ts
This file
Path
packages/project/test/evidence.test.ts
312 lines · 8.9 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–12why, one step back1import { describe, expect, it } from "@effect/vitest";2import { RefName, RepoHost } from "@repo/artifacts/repo-host";3import { EvidenceStore, LogRef, logRefOf } from "@repo/checks/evidence-store";4import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";5import { CheckSpec } from "@repo/protocol/domain/check";6import {7 AskId,8 LandedSha,9 LaneName,10 ProjectName,11 RepoName,12 RepoPath,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 13why, one step back13 keyOf,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 14–32why, one step back14 RequestId,15} from "@repo/protocol/ids";16import { Anonymous, Person } from "@repo/protocol/principal";17import { NotDecider, UnknownProject } from "@repo/protocol/refusal";18import { advanceTo } from "@repo/testkit/clock";19import type { Files } from "@repo/testkit/git-client";20import { aProject, withAsk, withVouches } from "@repo/testkit/scenarios";21import { Array, Effect, Layer, Option } from "effect";2223import { projectService } from "../src/project.ts";24import { CheckScript, composedAt, Pusher, worldOf } from "./world.ts";2526const scenario = aProject({ people: ["bob", "carol"] }).pipe(27 withVouches(["bob", "carol"]),28 withAsk({ id: "parse-iso", territory: "packages/parser" })29);3031const { project } = scenario;32Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 33why, one step back33const repo = RepoName.make(keyOf(project));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 34–52why, one step back3435const person = (name: string) =>36 Person.make({ handle: scenario.people.get(name) ?? scenario.initializer });3738const alice = person("alice");3940const bob = person("bob");4142const carol = person("carol");4344const parseIso = AskId.make("parse-iso");4546const unit = LaneName.make("unit");4748const requestId = RequestId.make("req-fix-0001");4950const mainRef = RefName.make("refs/heads/main");5152const start: Files = [Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 53–56why, one step back53 [54 "package.json",55 '{ "name": "alice/datekit", "workspaces": ["packages/*"] }\n',56 ],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 57–155why, one step back57 ["packages/parser/src/parse.ts", "export const parse = (s) => ({});\n"],58];5960const askFiles = () => {61 const ask = Option.getOrThrow(62 Array.findFirst(scenario.policy.asks, ({ id }) => id === parseIso)63 );6465 return Array.make(66 { content: `export default "${parseIso}";\n`, path: ask.file },67 {68 content: [69 `import { expect, it } from "vitest";`,70 `import { parser } from "../src/parser.ts";`,71 ``,72 `it("${parseIso}", () => {`,73 ` expect(parser("2026-10-07")).toStrictEqual({ year: 2026 });`,74 `});`,75 ``,76 ].join("\n"),77 path: CheckSpec.guards.RedThenGreen(ask.check)78 ? ask.check.path79 : RepoPath.make("test/parse-iso.test.ts"),80 }81 );82};8384const failing = [85 "FAIL packages/parser/test/parse.test.ts > parses ISO weeks",86 "AssertionError: expected 52 to be 53",87].join("\n");8889const bobsLog = logRefOf({ attempt: 1, lane: unit, project, requestId });9091const mainTip = Effect.gen(function* () {92 const refs = yield* (yield* RepoHost).refs(repo).pipe(Effect.orDie);9394 return LandedSha.make(95 Option.getOrThrow(Option.fromNullishOr(refs.get(mainRef)))96 );97});9899const answered = (text: string = failing) =>100 Effect.gen(function* () {101 yield* advanceTo("2026-10-07T12:00:00Z");102103 const api = yield* projectService(project);104105 yield* api.initProject(alice, {});106107 const first = yield* Pusher.use((pusher) =>108 pusher.push(repo, Option.none(), start, "Start")109 );110111 yield* api.recordFirstPush(alice, first);112113 const files = askFiles();114 const composed = yield* composedAt(repo, yield* mainTip, files);115116 yield* CheckScript.use((checker) =>117 checker.script(composed, LaneName.make("redThenGreen"), [118 "failed",119 "failed",120 ])121 );122123 const { landed } = yield* api.openAsk(alice, { ask: parseIso, files });124 const { claim } = yield* api.claim(bob, parseIso);125126 const head = yield* Pusher.use((pusher) =>127 pusher.push(claim.fork, Option.some(landed), [128 ...start.filter(([path]) => !path.startsWith("packages/parser/")),129 ["packages/parser/src/parse.ts", "export const parse = () => 2026;\n"],130 ...files.map(({ content, path }) => [path, content] as const),131 ])132 );133134 yield* api.submitAnswer(bob, {135 ask: parseIso,136 base: landed,137 head,138 requestId,139 });140141 yield* (yield* EvidenceStore).put({142 attempt: 1,143 lane: unit,144 project,145 requestId,146 text,147 });148149 return api;150 });151152const world = Layer.merge(worldOf(scenario, "memory"), EvidenceStoreMemory);153154describe("reading a failing lane's log", () => {155 it.effect(Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 156why, one step back156 "gives the answer's claimant and the project's maintainers the log, whole",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 157–207why, one step back157 () =>158 Effect.gen(function* () {159 const api = yield* answered();160161 expect({162 alice: yield* api.evidence(alice, bobsLog),163 bob: yield* api.evidence(bob, bobsLog),164 }).toStrictEqual({165 alice: { lane: unit, text: failing, truncated: false },166 bob: { lane: unit, text: failing, truncated: false },167 });168 }).pipe(Effect.provide(world))169 );170171 it.effect(172 "refuses everyone else NotDecider, whether or not a log is kept under the name",173 () =>174 Effect.gen(function* () {175 const api = yield* answered();176177 const never = logRefOf({178 attempt: 7,179 lane: unit,180 project,181 requestId: RequestId.make("req-none-0001"),182 });183184 expect(185 yield* Effect.forEach(186 [187 api.evidence(carol, bobsLog),188 api.evidence(carol, never),189 api.evidence(Anonymous.make({}), bobsLog),190 api.evidence(bob, never),191 ],192 Effect.flip193 )194 ).toStrictEqual([195 new NotDecider({}),196 new NotDecider({}),197 new NotDecider({}),198 new NotDecider({}),199 ]);200 }).pipe(Effect.provide(world))201 );202203 it.effect(204 "refuses a name that points at another project as that project unknown, for anyone",205 () =>206 Effect.gen(function* () {207 const api = yield* answered();Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 208why, one step back208 const other = ProjectName.make("alice/burrow");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 209–312why, one step back209210 const elsewhere = logRefOf({211 attempt: 1,212 lane: unit,213 project: other,214 requestId,215 });216217 expect(218 yield* Effect.forEach(219 [220 api.evidence(alice, elsewhere),221 api.evidence(bob, elsewhere),222 api.evidence(carol, elsewhere),223 ],224 Effect.flip225 )226 ).toStrictEqual([227 new UnknownProject({ project: other }),228 new UnknownProject({ project: other }),229 new UnknownProject({ project: other }),230 ]);231 }).pipe(Effect.provide(world))232 );233234 it.effect(235 "refuses a name that is no log's, or names no kept log, as nothing in the project",236 () =>237 Effect.gen(function* () {238 const api = yield* answered();239240 const passed = logRefOf({241 attempt: 1,242 lane: LaneName.make("lint"),243 project,244 requestId,245 });246247 // bob's own log's name, spelled as `logRefOf` never spells one.248 const respelled = LogRef.make(bobsLog.replace(/#1$/u, "#01"));249250 expect(251 yield* Effect.forEach(252 [253 api.evidence(alice, LogRef.make("not a log's name")),254 api.evidence(carol, LogRef.make("not a log's name")),255 api.evidence(alice, respelled),256 api.evidence(carol, respelled),257 api.evidence(alice, passed),258 ],259 Effect.flip260 )261 ).toStrictEqual([262 new UnknownProject({ project }),263 new UnknownProject({ project }),264 new UnknownProject({ project }),265 new UnknownProject({ project }),266 new UnknownProject({ project }),267 ]);268 }).pipe(Effect.provide(world))269 );270271 it.effect(272 "gives a log over 256 KiB as its last 256 KiB, where the failure prints",273 () =>274 Effect.gen(function* () {275 const tail = "AssertionError: expected 52 to be 53\n";276 const long = `${"x".repeat(300 * 1024)}${tail}`;277 const api = yield* answered(long);278 const read = yield* api.evidence(bob, bobsLog);279280 expect({281 bytes: new TextEncoder().encode(read.text).length,282 endsWithFailure: read.text.endsWith(tail),283 isTail: long.endsWith(read.text),284 truncated: read.truncated,285 }).toStrictEqual({286 bytes: 256 * 1024,287 endsWithFailure: true,288 isTail: true,289 truncated: true,290 });291 }).pipe(Effect.provide(world))292 );293294 it.effect("cuts a long log between characters, never inside one", () =>295 Effect.gen(function* () {296 // Each "é" is two bytes, so 256 KiB from the end falls inside one.297 const long = `${"é".repeat(150 * 1024)}x`;298 const api = yield* answered(long);299 const read = yield* api.evidence(alice, bobsLog);300301 expect({302 bytes: new TextEncoder().encode(read.text).length,303 isTail: long.endsWith(read.text),304 truncated: read.truncated,305 }).toStrictEqual({306 bytes: 256 * 1024 - 1,307 isTail: true,308 truncated: true,309 });310 }).pipe(Effect.provide(world))311 );312});