Read AGENTS.md's principles table inside a test, and fail a row that names no enforcer
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- The real table is now read inside it.live, not by a hand-run Effect.runPromise in test/agents-table.ts while vitest collects. That was the only hand-run Effect in any test folder, and it got past fence/no-manual-effect-runtime-in-tests only because the helper isn't named *.test.*: an escape the debt count never saw (principles 9, 10). One test now checks every row. Each reported line starts "principle N", so a failure still names its row, which was the Interface's reason for one it per row. Proven red: a planted `scripts/nope.ts` in row 5 fails with "principle 5 names `scripts/nope.ts`, but the repo has no such file". - A row with no enforcer before the cut and no "No fence yet" used to pass without checking anything, so a plain-text claim could stand in for a fence. It now fails with "principle N names no enforcer; name one, or what will hold it after No fence yet:". Row gains `waiting`. AGENTS.md's Held-by convention line says so. - pluginsOf reads the plugins an override turns on. Before, a rule at error whose plugin is on only for test files (vitest/no-disabled-tests) was classed as a file and failed as "no such file". - repoOf(sources) builds the repo facts, so planted sources reach the same code as the real ones. New it.effect tests cover: a rule counts as on only at error after every extends layer, overrides included; an "off" diagnostic fails and is not taken for a config key; only refusal classes and exported ids are read. Red first by assertion for the override plugin; the severity and diagnostic tests went red when isError was planted to accept any severity and when diagnostics were planted as config keys. - Not changed: principle 12's Effect.sleep lint still says "(no wave yet)". It needs an oxlint.config.ts override, which this territory doesn't own (noted in the issue's Comments for 199).
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+214 added−62 removed
- tests:+213 added−61 removed
- other:+1 added−1 removed
Provenance
- Commit
44d40e8- Tree
e28e58b- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
b2c2b51
3 files changed+214 added−62 removed
modified:packages/config/test/agents-table.test.ts+127 added-15 removed
12343565789101112131470 unmodified lines85868788899091929394959697989910010110221 unmodified lines124125126127115116128129130131132133121122123134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230126127128231232233234130131132133134235236237238239240241242243244245246247248import { NodeServices } from "@effect/platform-node";import { describe, expect, it } from "@effect/vitest";import { Effect } from "effect";
import type { Repo } from "./agents-table.ts";import type { Repo, Sources } from "./agents-table.ts";import { loadAgentsTable, missingEnforcers, principleRows, readAgentsTable, repoOf,} from "./agents-table.ts";
/** A repo with one enforcer of each kind, and nothing else. */const plantedRepo: Repo = {70 unmodified lines ) ).toStrictEqual([]); });
it("fails a row that names no enforcer and says no fence is coming", () => { expect(audit("The union test and an MCP tools/call test")).toStrictEqual([ "principle 4 names no enforcer; name one, or what will hold it after No fence yet:", ]); });
it("passes a row whose every enforcer is still to come", () => { expect(audit("No fence yet: the union test (W9 901)")).toStrictEqual([]); });
it("fails an enforcer it cannot classify", () => { expect(audit("`git push --force`")).toStrictEqual([ "unclassified enforcer `git push --force` in principle 4; name a file, script, rule, diagnostic or tag", ]);21 unmodified lines "| 3 | Another table. | `scripts/elsewhere.ts` |", ].join("\n");
expect(principleRows(markdown)).toStrictEqual([ { enforcers: ["verify"], principle: "1" }, { enforcers: ["a|b", "gen:check"], principle: "2" }, { enforcers: ["verify"], principle: "1", waiting: false }, { enforcers: ["a|b", "gen:check"], principle: "2", waiting: false }, ]); });});
// Vitest registers every test before it runs one, and a test per row needs the// rows then, so AGENTS.md and the repo are read once, here.const { repo, rows } = await loadAgentsTable();/** * Sources shaped like the repo's: a lint preset our config extends and * overrides, and a test-file override that turns on its own plugin. */const plantedSources: Sources = { files: [], idsSource: [ 'export const AskId = Schema.String.pipe(Schema.brand("AskId"));', "export type AskId = typeof AskId.Type;", ].join("\n"), oxlint: { extends: [ { plugins: ["eslint", "typescript"], rules: { "no-alert": "error", "no-console": "error" }, }, ], overrides: [ { files: ["**/*.test.ts"], plugins: ["vitest"], rules: { "vitest/no-disabled-tests": ["error"] }, }, ], rules: { "no-console": "off", "typescript/no-explicit-any": "warn" }, }, refusalSource: [ 'export class StaleBase extends Schema.TaggedError<StaleBase>()("StaleBase", {}) {}', "export const Refusal = Schema.Union([StaleBase]);", ].join("\n"), rootPackage: JSON.stringify({ scripts: { verify: "bun run check" } }), tsconfig: JSON.stringify({ compilerOptions: { plugins: [ { allowedUnstableApis: ["effect/rpc"], diagnosticSeverity: { globalDate: "error", globalRandom: "off" }, name: "@effect/language-service", }, ], }, }),};
const auditSources = (cell: string) => Effect.map(repoOf(plantedSources), (repo) => principleRows(plantedTable(cell)).flatMap((row) => missingEnforcers(row, repo) ) );
describe("what the repo holds, read from planted sources", () => { it.effect( "counts a lint rule as on only at error after every layer, overrides included", () => Effect.gen(function* () { expect( yield* auditSources( "`no-alert`, `no-console`, `typescript/no-explicit-any` and `vitest/no-disabled-tests`" ) ).toStrictEqual([ "principle 4 names `no-console`, but the repo has no such lint rule at error in oxlint.config.ts or root package.json script", "principle 4 names `typescript/no-explicit-any`, but the repo has no such lint rule at error in oxlint.config.ts", ]); }) );
it.effect( "counts a diagnostic as on only at error, and never as a config key", () => Effect.gen(function* () { expect( yield* auditSources( "`globalDate`, `globalRandom` and `allowedUnstableApis`" ) ).toStrictEqual([ "principle 4 names `globalRandom`, but the repo has no such Effect diagnostic at error in tsconfig.base.json or key in tsconfig.base.json", ]); }) );
it.effect( "reads root scripts, refusal classes and exported ids, and nothing else", () => Effect.gen(function* () { expect( yield* auditSources("`verify`, `StaleBase`, `AskId` and `Refusal`") ).toStrictEqual([ "principle 4 names `Refusal`, but the repo has no such refusal class in packages/protocol/src/refusal.ts or id exported from packages/protocol/src/ids.ts", ]); }) );});
// The rows are known only once a test has read AGENTS.md, so one test checks// every row; each line it reports names its principle.describe("AGENTS.md's principles table", () => { it("is under ## Principles, with a Held by column", () => { expect(rows).not.toHaveLength(0); }); it.live("is under ## Principles, with a Held by column", () => Effect.gen(function* () { const { rows } = yield* readAgentsTable;
it.each(rows)( "principle $principle names only enforcers the repo has", (row) => { expect(missingEnforcers(row, repo)).toStrictEqual([]); } expect(rows).not.toHaveLength(0); }).pipe(Effect.provide(NodeServices.layer)) );
it.live("names, in every row, only enforcers the repo has", () => Effect.gen(function* () { const { repo, rows } = yield* readAgentsTable;
expect(rows.flatMap((row) => missingEnforcers(row, repo))).toStrictEqual( [] ); }).pipe(Effect.provide(NodeServices.layer)) );});modified:packages/config/test/agents-table.ts+86 added-46 removed
16 unmodified lines17 * `tsconfig.base.json`'s `diagnosticSeverity`, or a key elsewhere in it;18 * - a refusal or an id (PascalCase): a refusal class in `refusal.ts`, or an19 * export of `ids.ts`, in `packages/protocol/src/`.20 *21- * Anything else is unclassified, and fails.21+ * Anything else is unclassified, and fails. So does a row that names no22+ * enforcer and says nothing after "No fence yet": prose alone holds nothing.23 */23-import { NodeServices } from "@effect/platform-node";24 import { Effect, FileSystem, Path, Schema } from "effect";25 import { ChildProcess, ChildProcessSpawner } from "effect/process";26 import type { DummyRule, OxlintConfig } from "oxlint";27 18 unmodified lines46 /** One principle's row: its number and the enforcers it claims. */47 export interface Row {48 readonly principle: string;49 readonly enforcers: readonly string[];50+ /** The cell says, after "No fence yet", what will hold the rest. */51+ readonly waiting: boolean;52 }53 54 type Kind =55 | "file"85 unmodified lines141 .map(cellsOf)142 .map((cells, index) => ({143 enforcers: enforcersIn(cells[heldBy] ?? ""),144 principle: cells[numbered] ?? String(index + 1),145+ waiting: (cells[heldBy] ?? "").includes(CUT),146 }));147 };148 149 const GLOB_PART = /\{[^{}]*\}|\*\*\/|\*\*|\*|\?|[.+^$()|[\]{}\\]/gu;102 unmodified lines252 253 return PASCAL.test(token) ? ["refusal", "id"] : [];254 };255 253-/** One line for each enforcer in `row` that the repo doesn't hold. */254-export const missingEnforcers = (row: Row, repo: Repo): readonly string[] =>255- row.enforcers.flatMap((token) => {256+/**257+ * One line for each enforcer in `row` that the repo doesn't hold, or one line258+ * when the row names no enforcer and no fence still to come.259+ */260+export const missingEnforcers = (row: Row, repo: Repo): readonly string[] => {261+ if (row.enforcers.length === 0 && !row.waiting) {262+ return [263+ `principle ${row.principle} names no enforcer; name one, or what will hold it after ${CUT}:`,264+ ];265+ }266+267+ return row.enforcers.flatMap((token) => {268 const kinds = kindsOf(token, repo);269 270 if (kinds.length === 0) {271 return [8 unmodified lines280 .map((kind) => described[kind])281 .join(" or ")}`,282 ];283 });284+};285 286 const isError = (setting: DummyRule | undefined) => {287 const severity = Array.isArray(setting) ? setting[0] : setting;288 24 unmodified lines313 isError(setting) ? [rule] : []314 );315 };316 304-/** Built-in plugins each layer turns on, and each JavaScript plugin's name. */317+/**318+ * Built-in plugins each layer or override turns on, and each JavaScript319+ * plugin's name: the vitest plugin, for one, is on only for test files.320+ */321 const pluginsOf = (config: OxlintConfig) =>322+ layersOf(config)323+ .flatMap((layer) => [layer, ...(layer.overrides ?? [])])306- layersOf(config).flatMap((layer) => [307- ...(layer.plugins ?? []),308- ...(layer.jsPlugins ?? []).map((plugin) =>309- Schema.is(Schema.String)(plugin) ? plugin : plugin.name310- ),311- ]);324+ .flatMap((scope) => [325+ ...(scope.plugins ?? []),326+ ...(scope.jsPlugins ?? []).map((plugin) =>327+ Schema.is(Schema.String)(plugin) ? plugin : plugin.name328+ ),329+ ]);330 331 const isJsonArray = Schema.is(Schema.Array(Schema.Json));332 333 const isJsonObject = Schema.is(Schema.JsonObject);41 unmodified lines375 Array.from(source.matchAll(pattern), (match) => match.groups?.name ?? "")376 ),377 ];378 379+/** The texts and config a "Held by" cell is checked against. */380+export interface Sources {381+ /** Every file git tracks or would add, relative to the repo root. */382+ readonly files: readonly string[];383+ /** The root `package.json`. */384+ readonly rootPackage: string;385+ readonly oxlint: OxlintConfig;386+ /** `tsconfig.base.json`. */387+ readonly tsconfig: string;388+ /** `packages/protocol/src/refusal.ts`. */389+ readonly refusalSource: string;390+ /** `packages/protocol/src/ids.ts`. */391+ readonly idsSource: string;392+}393+394+/** What the repo holds, out of its sources. */395+export const repoOf = (sources: Sources) =>396+ Effect.gen(function* () {397+ const { scripts } = yield* Schema.decodeEffect(398+ Schema.fromJsonString(RootPackage)399+ )(sources.rootPackage);400+401+ const tsconfig = yield* Schema.decodeEffect(402+ Schema.fromJsonString(Schema.Json)403+ )(sources.tsconfig);404+405+ const { compilerOptions } =406+ yield* Schema.decodeUnknownEffect(TsconfigBase)(tsconfig);407+408+ const repo: Repo = {409+ configKeys: [...new Set(keysOf(tsconfig))],410+ diagnosticsAtError: compilerOptions.plugins.flatMap((plugin) =>411+ Object.entries(plugin.diagnosticSeverity ?? {}).flatMap(412+ ([diagnostic, severity]) => (severity === "error" ? [diagnostic] : [])413+ )414+ ),415+ files: sources.files,416+ ids: namesIn(sources.idsSource, EXPORTED),417+ lintPlugins: [...new Set(pluginsOf(sources.oxlint))],418+ lintRulesAtError: [...new Set(rulesAtError(sources.oxlint))],419+ refusals: namesIn(sources.refusalSource, REFUSAL_CLASS),420+ scripts: Object.keys(scripts),421+ };422+423+ return repo;424+ });425+361-/** AGENTS.md's text, and what the repo holds, read from the repo root. */426+/** AGENTS.md's principle rows, and what the repo holds, read from the repo root. */427 export const readAgentsTable = Effect.gen(function* () {428 const fs = yield* FileSystem.FileSystem;429 const path = yield* Path.Path;430 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;5 unmodified lines436 spawner.lines(437 ChildProcess.make("git", ["ls-files", ...args], { cwd: root })438 );439 375- const [agents, rootPackage, tsconfigText, refusalSource, idsSource] =440+ const [agents, rootPackage, tsconfig, refusalSource, idsSource] =441 yield* Effect.all(442 [443 read("AGENTS.md"),444 read("package.json"),12 unmodified lines457 );458 459 const deleted = new Set(yield* lsFiles("--deleted"));460 396- const { scripts } = yield* Schema.decodeEffect(397- Schema.fromJsonString(RootPackage)398- )(rootPackage);399-400- const tsconfig = yield* Schema.decodeEffect(401- Schema.fromJsonString(Schema.Json)402- )(tsconfigText);403-404- const { compilerOptions } =405- yield* Schema.decodeUnknownEffect(TsconfigBase)(tsconfig);406-407- const repo: Repo = {408- configKeys: [...new Set(keysOf(tsconfig))],409- diagnosticsAtError: compilerOptions.plugins.flatMap((plugin) =>410- Object.entries(plugin.diagnosticSeverity ?? {}).flatMap(411- ([diagnostic, severity]) => (severity === "error" ? [diagnostic] : [])412- )413- ),461+ const repo = yield* repoOf({462 files: listed.filter((file) => file.length > 0 && !deleted.has(file)),415- ids: namesIn(idsSource, EXPORTED),416- lintPlugins: [...new Set(pluginsOf(oxlintConfig))],417- lintRulesAtError: [...new Set(rulesAtError(oxlintConfig))],418- refusals: namesIn(refusalSource, REFUSAL_CLASS),419- scripts: Object.keys(scripts),420- };463+ idsSource,464+ oxlint: oxlintConfig,465+ refusalSource,466+ rootPackage,467+ tsconfig,468+ });469 470 return { repo, rows: principleRows(agents) };471 });424-425-/**426- * `readAgentsTable`, run once while vitest collects the tests: a test per427- * principle row needs the rows before any test runs, and `@effect/vitest`428- * runs Effects only inside a test.429- */430-export const loadAgentsTable = () =>431- Effect.runPromise(readAgentsTable.pipe(Effect.provide(NodeServices.layer)));modified:AGENTS.md+1 added-1 removed
14 unmodified lines15 ## Principles16 17 Fence wins over prose: if this file and an enforced check disagree, the check wins; fix this file. A rule held by "No fence yet" is debt: give it a fence.18 19-In "Held by", each code-formatted name before "No fence yet:" is an enforcer: a file, a root script, a lint rule, an Effect diagnostic, a tsconfig key, a refusal tag or a branded id. Principle 1's test fails on any the repo lacks, so write everything else in the cell as plain text. After "No fence yet:", name what will hold the rule and the wave that builds it.19+In "Held by", each code-formatted name before "No fence yet:" is an enforcer: a file, a root script, a lint rule, an Effect diagnostic, a tsconfig key, a refusal tag or a branded id. Write everything else in the cell as plain text. Principle 1's test fails on an enforcer the repo lacks, and on a row with neither an enforcer nor "No fence yet:". After "No fence yet:", name what will hold the rule and the wave that builds it.20 21 | # | Principle | Held by |22 | --- | --- | --- |23 | 1 | **Encode lessons in structure; prose is the last rung.** When a mistake repeats, make it unrepresentable, then a lint or test, then a skill. | `packages/config/test/agents-table.test.ts`: every enforcer this column names exists and is on |129 unmodified lines