generated.test.ts
This file
Path
packages/project/test/generated.test.ts
310 lines · 8.5 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–138why, one step back1import { describe, expect, it } from "@effect/vitest";2import { creditsOf, parseTrailers } from "@repo/git/trailers";3import type { LandingView } from "@repo/protocol/domain/landing";4import type { Policy } from "@repo/protocol/domain/policy";5import { RunBlock } from "@repo/protocol/domain/run";6import { Handle, LandedSha } from "@repo/protocol/ids";7import { aProject } from "@repo/testkit/scenarios";8import { DateTime, Effect, Option, Schema } from "effect";910import { platformHandle } from "../src/attention/effects.ts";11import { generatedFollowUp } from "../src/generated.ts";12import type { Generate } from "../src/generated.ts";1314const scenario = aProject({ deciders: ["alice", "dora"], people: ["bob"] });1516const { initializer, project } = scenario;1718const alice = initializer;1920const dora = Handle.make("dora");2122const bob = Handle.make("bob");2324const parent = LandedSha.make("1".repeat(40));2526const landed = LandedSha.make("2".repeat(40));2728const before: Policy = { ...scenario.policy, at: parent };2930const unchanged: Policy = { ...scenario.policy, at: landed };3132const withUnit: Policy = {33 ...unchanged,34 run: Schema.decodeSync(RunBlock)({35 checks: {36 lint: "bun run lint",37 types: "bun run typecheck",38 unit: "bun run test",39 },40 test: "bun test {path}",41 }),42};4344const skill = `.agents/skills/${project}-contribute/SKILL.md`;4546const claudeSkill = `.claude/skills/${project}-contribute/SKILL.md`;4748const generate: Generate = ({ landed: at, policy, read }) =>49 Effect.gen(function* () {50 const lanes = Object.entries(policy.run.checks)51 .map(([lane, command]) => `${lane}: ${command}`)52 .join(", ");5354 const content = `---\nlanded: ${at}\n---\nLanes: ${lanes}\n`;55 const block = `<!-- BEGIN -->\nLanes: ${lanes}\n<!-- END -->`;56 const existing = Option.getOrElse(yield* read("AGENTS.md"), () => "");57 const begin = existing.indexOf("<!-- BEGIN -->");58 const end = existing.indexOf("<!-- END -->");5960 const agents =61 begin === -1 || end === -162 ? `${existing}${block}\n`63 : `${existing.slice(0, begin)}${block}${existing.slice(end + "<!-- END -->".length)}`;6465 return [66 { content, path: skill },67 { content, path: claudeSkill },68 { content: agents, path: "AGENTS.md" },69 ];70 });7172const ownAgents = [73 "# Datekit",74 "",75 "Our notes.",76 "",77 "<!-- BEGIN -->",78 "Lanes: lint: bun run lint",79 "<!-- END -->",80 "",81 "More notes.",82 "",83].join("\n");8485const treeOf =86 (files: Readonly<Record<string, string>>) =>87 (path: string): Effect.Effect<Option.Option<string>> =>88 Effect.succeed(Option.fromUndefinedOr(files[path]));8990const at = DateTime.makeUnsafe("2026-10-07T12:00:00Z");9192const aliceLands: LandingView = {93 assisted: [],94 author: alice,95 credits: [{ handle: alice, role: "Signed-off-by" }],96 landedAt: at,97 parent,98 project,99 sha: landed,100};101102const firstPush: LandingView = {103 assisted: [],104 author: alice,105 credits: [],106 landedAt: at,107 project,108 sha: landed,109};110111const followUp = (input: {112 readonly before: Option.Option<Policy>;113 readonly after: Policy;114 readonly landing: LandingView;115 readonly tree?: Readonly<Record<string, string>>;116}) =>117 generatedFollowUp(118 {119 after: input.after,120 before: input.before,121 initializer,122 landing: input.landing,123 project,124 read: treeOf(input.tree ?? { "AGENTS.md": ownAgents }),125 },126 generate127 );128129const subjectOf = (message: string) => message.split("\n")[0] ?? "";130131const creditOf = (landing: LandingView) =>132 Effect.map(133 followUp({ after: withUnit, before: Option.some(before), landing }),134 Option.map(({ credits }) => credits)135 );136137describe(generatedFollowUp, () => {138 it.effect(Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 139why, one step back139 "follows a landing that changed the run block with the regenerated files alone, credited to its maintainer",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 140–310why, one step back140 () =>141 Effect.gen(function* () {142 const made = yield* followUp({143 after: withUnit,144 before: Option.some(before),145 landing: aliceLands,146 });147148 const lanes =149 "Lanes: lint: bun run lint, types: bun run typecheck, unit: bun run test";150151 const skillText = `---\nlanded: ${landed}\n---\n${lanes}\n`;152153 expect(Option.map(made, ({ files }) => files)).toStrictEqual(154 Option.some([155 { content: skillText, path: skill },156 { content: skillText, path: claudeSkill },157 {158 content: [159 "# Datekit",160 "",161 "Our notes.",162 "",163 "<!-- BEGIN -->",164 lanes,165 "<!-- END -->",166 "",167 "More notes.",168 "",169 ].join("\n"),170 path: "AGENTS.md",171 },172 ])173 );174175 const { author, credits, message, requestId } = Option.getOrThrow(made);176177 expect({178 author,179 credits,180 requestId,181 subject: subjectOf(message),182 trailers: creditsOf(message).credits,183 trailersRequest: parseTrailers(message).find(184 ({ key }) => key === "Request-Id"185 )?.value,186 }).toStrictEqual({187 author: platformHandle,188 credits: [{ handle: alice, role: "Decided-by" }],189 requestId: `gen-${landed}`,190 subject: "Regenerate the contribute skill and the AGENTS.md block",191 trailers: [{ handle: alice, role: "Decided-by" }],192 trailersRequest: `gen-${landed}`,193 });194 })195 );196197 it.effect("lands nothing after a landing that changed only src/", () =>198 Effect.gen(function* () {199 expect(200 yield* followUp({201 after: unchanged,202 before: Option.some(before),203 landing: aliceLands,204 tree: {},205 })206 ).toStrictEqual(Option.none());207 })208 );209210 it.effect("makes the same files from the same input", () =>211 Effect.gen(function* () {212 const input = {213 after: withUnit,214 before: Option.some(before),215 landing: aliceLands,216 };217218 expect(yield* followUp(input)).toStrictEqual(yield* followUp(input));219 })220 );221222 it.effect(223 "lands nothing when the tree already holds the regenerated files, as after a replay",224 () =>225 Effect.gen(function* () {226 const made = Option.getOrThrow(227 yield* followUp({228 after: withUnit,229 before: Option.some(before),230 landing: aliceLands,231 })232 );233234 const regenerated = Object.fromEntries(235 made.files.map(({ content, path }) => [path, content])236 );237238 expect(239 yield* followUp({240 after: withUnit,241 before: Option.some(before),242 landing: aliceLands,243 tree: regenerated,244 })245 ).toStrictEqual(Option.none());246 })247 );248249 it.effect(250 "follows the first adoption, which had no policy before, crediting the initializer",251 () =>252 Effect.gen(function* () {253 const made = yield* followUp({254 after: unchanged,255 before: Option.none(),256 landing: firstPush,257 tree: {},258 });259260 expect(261 Option.map(made, ({ credits, files }) => ({262 credits,263 paths: files.map(({ path }) => path),264 }))265 ).toStrictEqual(266 Option.some({267 credits: [{ handle: alice, role: "Decided-by" }],268 paths: [skill, claudeSkill, "AGENTS.md"],269 })270 );271 })272 );273274 it.effect(275 "credits the landing's Decided-by first, then its author if they decide the config, else the initializer",276 () =>277 Effect.gen(function* () {278 const decidedByDora: LandingView = {279 ...aliceLands,280 author: bob,281 credits: [282 { handle: bob, role: "Signed-off-by" },283 { handle: dora, role: "Decided-by" },284 ],285 };286287 const doraLands: LandingView = {288 ...aliceLands,289 author: dora,290 credits: [{ handle: dora, role: "Signed-off-by" }],291 };292293 const bobAlone: LandingView = {294 ...aliceLands,295 author: bob,296 credits: [{ handle: bob, role: "Signed-off-by" }],297 };298299 expect({300 decidedBy: yield* creditOf(decidedByDora),301 deciderAuthor: yield* creditOf(doraLands),302 neither: yield* creditOf(bobAlone),303 }).toStrictEqual({304 decidedBy: Option.some([{ handle: dora, role: "Decided-by" }]),305 deciderAuthor: Option.some([{ handle: dora, role: "Decided-by" }]),306 neither: Option.some([{ handle: alice, role: "Decided-by" }]),307 });308 })309 );310});