Skip to content
Myr

do-reads.test.ts

This file

Path

packages/project/test/do-reads.test.ts

312 lines · 8.8 KiB · TypeScript

Last changed by

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

History of this file

Take it

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 1–3why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Brand } from "@repo/brand";3import { CheckSpec } from "@repo/protocol/domain/check";

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

line 4why, one step back
4import { ProjectEvent } from "@repo/protocol/domain/event";

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 5–11why, one step back
5import type { LandingView } from "@repo/protocol/domain/landing";
6import {7 AskId,8 CommitSha,9 LandedSha,10 LaneName,11 RepoName,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 12why, one step back
12 keyOf,

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 13–14why, one step back
13 RepoPath,
14} from "@repo/protocol/ids";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 15why, one step back
15import { Person } from "@repo/protocol/principal";

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 16why, one step back
16import { RulesEvaluator, RulesFailed } from "@repo/rules/rules-evaluator";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 17–19why, one step back
17import { advanceTo } from "@repo/testkit/clock";
18import type { Files } from "@repo/testkit/git-client";19import { aProject, withAsk, withVouches } from "@repo/testkit/scenarios";

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 20why, one step back
20import { Array, DateTime, Effect, Layer, Option } from "effect";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 21–22why, one step back
21
22import { NoEnv } from "../src/env-port.ts";

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 23why, one step back
23import { ProjectStore } from "../src/project-store.ts";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 24–34why, one step back
24import { projectService } from "../src/project.ts";
25import { NoVisibility } from "../src/visibility-port.ts";26import { CheckScript, composedAt, Pusher, worldOf } from "./world.ts";2728const scenario = aProject({ people: ["bob"] }).pipe(29 withVouches(["bob"]),30 withAsk({ id: "parse-iso", territory: "packages/parser" })31);3233const { project } = scenario;34

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 35why, one step back
35const repo = RepoName.make(keyOf(project));

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 36–43why, one step back
36
37const alice = Person.make({ handle: scenario.initializer });3839const bob = Person.make({40 handle: scenario.people.get("bob") ?? scenario.initializer,41});4243const start: Files = [

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 44–47why, one step back
44 [
45 "package.json",46 '{ "name": "alice/datekit", "workspaces": ["packages/*"] }\n',47 ],

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 48–108why, one step back
48 ["packages/parser/src/parse.ts", "export const parse = (s) => ({});\n"],
49];5051const parseIso = Option.getOrThrow(52 Array.findFirst(scenario.policy.asks, (ask) => ask.id === "parse-iso")53);5455const askFiles = Array.make(56 { content: 'export default "parse-iso";\n', path: parseIso.file },57 {58 content: [59 'import { expect, it } from "vitest";',60 'import { parser } from "../src/parser.ts";',61 "",62 'it("parse-iso", () => {',63 ' expect(parser(" 2026 ")).toStrictEqual("2026");',64 "});",65 "",66 ].join("\n"),67 path: CheckSpec.guards.RedThenGreen(parseIso.check)68 ? parseIso.check.path69 : RepoPath.make(`${Brand.configDir}/checks/parse-iso.test.ts`),70 }71);7273const imported = CommitSha.make("b".repeat(40));7475const read = Effect.gen(function* () {76 yield* advanceTo("2026-10-07T12:00:00Z");7778 const api = yield* projectService(project);7980 yield* api.initProject(alice, {});8182 const before = {83 forks: yield* api.forks(),84 head: yield* api.head(),85 policy: yield* api.policy(),86 };8788 const first = yield* Pusher.use((pusher) =>89 pusher.push(repo, Option.none(), start, "Start")90 );9192 const { landed: adopted } = yield* api.recordFirstPush(alice, first);93 const composed = yield* composedAt(repo, adopted, askFiles);9495 yield* CheckScript.use((checker) =>96 checker.script(composed, LaneName.make("redThenGreen"), [97 "failed",98 "failed",99 ])100 );101102 const { landed } = yield* api.openAsk(alice, {103 ask: parseIso.id,104 files: askFiles,105 });106107 const { claim } = yield* api.claim(bob, parseIso.id);108

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

lines 109–112why, one step back
109 const landedEvents = (yield* api.events(0, 100)).flatMap(({ event }) =>
110 ProjectEvent.guards.Landed(event) ? [event.landing] : []111 );112

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 113–123why, one step back
113 return {
114 adopted,115 after: {116 forks: yield* api.forks(),117 head: yield* api.head(),118 landings: yield* api.landings([landed, imported]),119 policy: yield* api.policy(),120 },121 before,122 claim,123 landed,

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

line 124why, one step back
124 landedEvents,

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 125–130why, one step back
125 };
126});127128const world = Layer.mergeAll(worldOf(scenario, "memory"), NoVisibility, NoEnv);129130describe("a project's reads for its code and its people", () => {

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

line 131why, one step back
131 it.effect(

Merge build/1316-adoption-heard into mainoscabrielbefore adoption2f3d065

line 132why, one step back
132 "hear the adoption and an ask's opening as landings, the opening naming the ask it opened, so a list of landings shows both",

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

lines 133–137why, one step back
133 () =>
134 Effect.map(read.pipe(Effect.provide(world)), (got) => {135 expect(136 got.landedEvents.map(({ ask, opened, sha }) => ({ ask, opened, sha }))137 ).toStrictEqual([

Merge build/1316-adoption-heard into mainoscabrielbefore adoption2f3d065

line 138why, one step back
138 { ask: undefined, opened: undefined, sha: got.adopted },

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

lines 139–143why, one step back
139 { ask: undefined, opened: parseIso.id, sha: got.landed },
140 ]);141 })142 );143

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 144–147why, one step back
144 it.effect(
145 "say where main landed, which commits are landings, the forks and the public policy",146 () =>147 Effect.map(read.pipe(Effect.provide(world)), (got) => {

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 148why, one step back
148 expect(got.before).toStrictEqual({ forks: [], head: {}, policy: {} });

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 149–150why, one step back
149 expect(got.after.head).toStrictEqual({ landed: got.landed });
150 expect(

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 151–164why, one step back
151 got.after.landings.map(({ ask, opened, parent, sha }) => ({
152 ask,153 opened,154 parent,155 sha,156 }))157 ).toStrictEqual([158 {159 ask: undefined,160 opened: parseIso.id,161 parent: got.adopted,162 sha: got.landed,163 },164 ]);

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 165–174why, one step back
165 expect(got.after.forks).toStrictEqual([
166 {167 ask: parseIso.id,168 handle: bob.handle,169 kind: "claim",170 repo: got.claim.fork,171 state: "live",172 },173 ]);174

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 175–177why, one step back
175 const policy = Option.getOrThrow(
176 Option.fromUndefinedOr(got.after.policy.policy)177 );

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 178–183why, one step back
178
179 expect({180 deciders: policy.deciders,181 hidden: ["asks", "functions", "visibility"].filter(182 (key) => key in policy183 ),

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 184–189why, one step back
184 keys: Object.keys(got.after.policy),
185 }).toStrictEqual({186 deciders: scenario.policy.deciders,187 hidden: [],188 keys: ["policy"],189 });

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 190why, one step back
190 })

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 191–195why, one step back
191 );
192});193194const shaOf = (digit: string) => LandedSha.make(digit.repeat(40));195

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

line 196why, one step back
196/** Rows as an older build wrote them: landings with no `opened`. */

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

lines 197–310why, one step back
197const olderRows = Effect.gen(function* () {
198 yield* advanceTo("2026-10-07T12:00:00Z");199200 const api = yield* projectService(project);201202 yield* api.initProject(alice, {});203204 const landedAt = DateTime.makeUnsafe("2026-10-07T12:00:00Z");205206 const row = (sha: LandedSha): LandingView => ({207 assisted: [],208 author: alice.handle,209 credits: [{ handle: alice.handle, role: "Asked-by" }],210 landedAt,211 project,212 sha,213 });214215 const parent = AskId.make("migrate-p");216217 yield* ProjectStore.use((store) =>218 store.commit({219 asks: [220 { ...parseIso, openedIn: shaOf("c") },221 {222 ...parseIso,223 id: AskId.make("migrate-p-1"),224 openedIn: shaOf("d"),225 parent,226 },227 { ...parseIso, id: parent, openedIn: shaOf("d") },228 ],229 landings: [230 row(shaOf("c")),231 row(shaOf("d")),232 { ...row(shaOf("e")), ask: parseIso.id },233 ],234 })235 );236237 return {238 landing: yield* api.landing(alice, shaOf("d")),239 landings: yield* api.landings([shaOf("c"), shaOf("d"), shaOf("e")]),240 };241});242243describe("an opening's landing", () => {244 it.effect(245 "names the ask it opened when read, though its row was written without it: a migrate family's parent, never a step, and never on an answer",246 () =>247 Effect.map(olderRows.pipe(Effect.provide(world)), (got) => {248 expect(249 got.landings.map(({ ask, opened, sha }) => ({ ask, opened, sha }))250 ).toStrictEqual([251 { ask: undefined, opened: parseIso.id, sha: shaOf("c") },252 { ask: undefined, opened: "migrate-p", sha: shaOf("d") },253 { ask: parseIso.id, opened: undefined, sha: shaOf("e") },254 ]);255 expect(got.landing.landing.opened).toBe("migrate-p");256 })257 );258});259260const failingRules = Layer.succeed(261 RulesEvaluator,262 RulesEvaluator.of({263 call: () => Effect.succeed(false),264 evaluate: () =>265 Effect.fail(266 new RulesFailed({ detail: "no test command", reason: "threw" })267 ),268 })269);270271const unevaluatedAfter = (files: Files) =>272 Effect.gen(function* () {273 yield* advanceTo("2026-10-07T12:00:00Z");274275 const api = yield* projectService(project);276277 yield* api.initProject(alice, {});278279 const first = yield* Pusher.use((pusher) =>280 pusher.push(repo, Option.none(), files, "Start")281 );282283 const { landed } = yield* api.recordFirstPush(alice, first);284285 return { landed, policy: yield* api.policy() };286 }).pipe(Effect.provide(Layer.merge(world, failingRules)));287288describe("a policy that has not evaluated", () => {289 it.effect("says the landed tree has no config folder, when it has none", () =>290 Effect.map(unevaluatedAfter(start), ({ landed, policy }) => {291 expect(policy).toStrictEqual({292 unevaluated: { at: landed, reason: "noConfig" },293 });294 })295 );296297 it.effect(298 "says the config folder did not evaluate, when the landed tree has one",299 () =>300 Effect.map(301 unevaluatedAfter([302 ...start,303 [`${Brand.configDir}/project.ts`, "export default {};\n"],304 ]),305 ({ landed, policy }) => {306 expect(policy).toStrictEqual({307 unevaluated: { at: landed, reason: "configFailed" },308 });309 }310 )

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 311–312why, one step back
311 );
312});