docs-public.test.ts
This file
Path
packages/config/test/docs-public.test.ts
201 lines · 5.5 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 1–2why, one step back1import { NodeServices } from "@effect/platform-node";2import { describe, expect, it } from "@effect/vitest";Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
line 3why, one step back3import { Array, Effect, FileSystem, Option, Order, Path, Schema } from "effect";Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
line 4why, one step back4Keep W10 group A's merged gate green under a full test runoscabrielbefore adoptionbd3598e
line 5why, one step back5import { committable, readsAtOnce, repoRoot, textOf } from "./root.ts";Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
line 6why, one step back6Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
lines 7–15why, one step back7const PRIVATE_FOLDERS = [8 ".agents/adr",9 ".agents/demo",10 ".agents/ops",11 ".agents/workflow",12 ".agents/scratch",13 ".agents/README",14] as const;15Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 16–20why, one step back16const PRIVATE = [17 "~/",18 "/home/",19 "wanted-explainer",20 "plans.gneiss.run",Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
line 21why, one step back21 ...PRIVATE_FOLDERS,Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 22–24why, one step back22] as const;2324/**Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
lines 25–27why, one step back25 * A reference into the build's private plan: a section of its spec26 * (`spec §8`, `W9 §14`), a decision (`spec D6`, `W9-D14`), an issue by wave27 * (`W3 313`), or the research synthesis (`SYN`).Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
line 28why, one step back28 */Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 29–31why, one step back29const PLAN_REFERENCES = [30 /\bspec §/u,31 /\bspec D\d/u,Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c
lines 32–33why, one step back32 /\bW\d+ §/u,33 /\bW\d+-D\d/u,Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 34–36why, one step back34 /\bW\d \d{3}\b/u,35 /\bSYN\b/u,36] as const;Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
line 37why, one step back37Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 38–48why, one step back38const TEXT_FILE =39 /(?:\.(?:css|html|json|jsonc|md|mjs|sh|sql|toml|ts|tsx|ya?ml)|(?:^|\/)(?:\.gitignore|\.env\.schema|[^/]*Dockerfile))$/u;4041/** This file, which spells the references out to find them. */42const QUOTES_THE_REFERENCES = "packages/config/test/docs-public.test.ts";4344const planReferencesIn = (text: string) =>45 PLAN_REFERENCES.flatMap((reference) =>46 reference.test(text) ? [reference.source] : []47 );48Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
lines 49–62why, one step back49/**50 * Where the private folders may be named: the maintainer's folder itself,51 * while it is still on disk, and `.gitignore`, which keeps it out.52 */53const NAMES_THE_PRIVATE_FOLDERS = (file: string) =>54 file.startsWith(".agents/") || file === ".gitignore";5556const privateIn = (file: string, text: string) => [57 ...planReferencesIn(text),58 ...(NAMES_THE_PRIVATE_FOLDERS(file)59 ? []60 : PRIVATE_FOLDERS.filter((folder) => text.includes(folder))),61];62Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 63–68why, one step back63const TERMS = [64 "Claim fork",65 "Decision",66 "Family",67 "Landed SHA",68 "Outcome",Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 69why, one step back69 "Owner",Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 70–71why, one step back70 "Patch id",71 "Policy",Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 72why, one step back72 "Project name",Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
line 73why, one step back73 "Proposal",Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 74why, one step back74 "Source namespace",Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 75–96why, one step back75 "Today",76 "Working fork",77] as const;7879const RootPackage = Schema.Struct({80 scripts: Schema.Record(Schema.String, Schema.String),81});8283const read = (relative: string) =>84 Effect.gen(function* () {85 const fs = yield* FileSystem.FileSystem;86 const path = yield* Path.Path;87 const root = yield* repoRoot;8889 return yield* fs.readFileString(path.join(root, relative));90 });9192const withText = (paths: readonly string[]) =>93 Effect.forEach(paths, (path) =>94 Effect.map(read(path), (text) => ({ path, text }))95 );96Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
line 97why, one step back97const publicDocs = withText(["AGENTS.md", "GLOSSARY.md"]);Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 98–124why, one step back9899const sectionOf = (text: string, title: string): readonly string[] => {100 const lines = text.split("\n");101 const start = lines.indexOf(`## ${title}`);102103 if (start === -1) {104 return [];105 }106107 const rest = lines.slice(start + 1);108 const end = rest.findIndex((line) => /^#{1,2} /u.test(line));109110 return end === -1 ? rest : rest.slice(0, end);111};112113const commandOf = (line: string) =>114 /^- `(?<name>[^`\s]+)/u.exec(line)?.groups?.name;115116describe("the repo's public docs", () => {117 it.live("point at no home folder and no private plan", () =>118 Effect.gen(function* () {119 const docs = yield* publicDocs;120121 expect(122 docs.flatMap(({ path, text }) =>123 [124 ...PRIVATE.filter((pointer) => text.includes(pointer)),Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
line 125why, one step back125 ...planReferencesIn(text),Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 126–129why, one step back126 ].map((found) => `${path}: ${found}`)127 )128 ).toStrictEqual([]);129 }).pipe(Effect.provide(NodeServices.layer))Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 130–132why, one step back130 );131132 it.live(Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
line 133why, one step back133 "and no file the repo would commit cites the private plan or points into the private folders, comments included",Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 134–139why, one step back134 () =>135 Effect.gen(function* () {136 const files = (yield* committable).filter(137 (file) => TEXT_FILE.test(file) && file !== QUOTES_THE_REFERENCES138 );139Keep W10 group A's merged gate green under a full test runoscabrielbefore adoptionbd3598e
lines 140–146why, one step back140 const found = yield* Effect.forEach(141 files,142 (file) =>143 Effect.map(textOf(file), (text) =>144 Option.match(text, {145 onNone: () => [],146 onSome: (content) =>Merge build/agents-private into mainoscabrielbefore adoptionb1f69d8
line 147why, one step back147 privateIn(file, content).map(Keep W10 group A's merged gate green under a full test runoscabrielbefore adoptionbd3598e
lines 148–152why, one step back148 (pattern) => `${file}: ${pattern}`149 ),150 })151 ),152 readsAtOnceDrop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
lines 153–156why, one step back153 );154155 expect(found.flat()).toStrictEqual([]);156 }).pipe(Effect.provide(NodeServices.layer))Merge branch 'build/707-adr-glossary-agents-fold-ins'oscabrielbefore adoption2b1fd3c
lines 157–201why, one step back157 );158159 it.live("AGENTS.md describes today, with no Day 0 paragraph", () =>160 Effect.gen(function* () {161 const agents = yield* read("AGENTS.md");162163 expect(164 agents.split("\n").filter((line) => /\bDay 0\b/u.test(line))165 ).toStrictEqual([]);166 }).pipe(Effect.provide(NodeServices.layer))167 );168169 it.live(170 "AGENTS.md's Commands section names every root script, and only those",171 () =>172 Effect.gen(function* () {173 const agents = yield* read("AGENTS.md");174175 const { scripts } = yield* Schema.decodeEffect(176 Schema.fromJsonString(RootPackage)177 )(yield* read("package.json"));178179 expect(180 Array.sort(181 sectionOf(agents, "Commands").flatMap((line) => {182 const name = commandOf(line);183184 return name === undefined ? [] : [name];185 }),186 Order.String187 )188 ).toStrictEqual(Array.sort(Object.keys(scripts), Order.String));189 }).pipe(Effect.provide(NodeServices.layer))190 );191192 it.live("GLOSSARY.md defines each term the code uses", () =>193 Effect.gen(function* () {194 const glossary = (yield* read("GLOSSARY.md")).split("\n");195196 expect(197 TERMS.filter((term) => !glossary.includes(`**${term}**:`))198 ).toStrictEqual([]);199 }).pipe(Effect.provide(NodeServices.layer))200 );201});