Skip to content
Myr

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).

authored by oscabriel · committed by oscabriel · parent b2c2b51 · Browse files · 3 files+214 added−62 removed
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

3 files+214 added−62 removed

modified:packages/config/test/agents-table.test.ts+127 added-15 removed
modified:packages/config/test/agents-table.ts+86 added-46 removed
16 unmodified lines
17 * `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 */23import { NodeServices } from "@effect/platform-node";24import { Effect, FileSystem, Path, Schema } from "effect";25import { ChildProcess, ChildProcessSpawner } from "effect/process";26import type { DummyRule, OxlintConfig } from "oxlint";27
18 unmodified lines
46/** One principle's row: its number and the enforcers it claims. */47export 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}5354type Kind =55 | "file"
85 unmodified lines
141 .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};148149const GLOB_PART = /\{[^{}]*\}|\*\*\/|\*\*|\*|\?|[.+^$()|[\]{}\\]/gu;
102 unmodified lines
252253 return PASCAL.test(token) ? ["refusal", "id"] : [];254};255253/** One line for each enforcer in `row` that the repo doesn't hold. */254export 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 */260export 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 }266267 return row.enforcers.flatMap((token) => {268 const kinds = kindsOf(token, repo);269270 if (kinds.length === 0) {271 return [
8 unmodified lines
280 .map((kind) => described[kind])281 .join(" or ")}`,282 ];283 });284};285286const isError = (setting: DummyRule | undefined) => {287 const severity = Array.isArray(setting) ? setting[0] : setting;288
24 unmodified lines
313 isError(setting) ? [rule] : []314 );315};316304/** 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 */321const 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 ]);330331const isJsonArray = Schema.is(Schema.Array(Schema.Json));332333const isJsonObject = Schema.is(Schema.JsonObject);
41 unmodified lines
375 Array.from(source.matchAll(pattern), (match) => match.groups?.name ?? "")376 ),377];378379/** The texts and config a "Held by" cell is checked against. */380export 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}393394/** What the repo holds, out of its sources. */395export const repoOf = (sources: Sources) =>396 Effect.gen(function* () {397 const { scripts } = yield* Schema.decodeEffect(398 Schema.fromJsonString(RootPackage)399 )(sources.rootPackage);400401 const tsconfig = yield* Schema.decodeEffect(402 Schema.fromJsonString(Schema.Json)403 )(sources.tsconfig);404405 const { compilerOptions } =406 yield* Schema.decodeUnknownEffect(TsconfigBase)(tsconfig);407408 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 };422423 return repo;424 });425361/** 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. */427export 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 lines
436 spawner.lines(437 ChildProcess.make("git", ["ls-files", ...args], { cwd: root })438 );439375 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 lines
457 );458459 const deleted = new Set(yield* lsFiles("--deleted"));460396 const { scripts } = yield* Schema.decodeEffect(397 Schema.fromJsonString(RootPackage)398 )(rootPackage);399400 const tsconfig = yield* Schema.decodeEffect(401 Schema.fromJsonString(Schema.Json)402 )(tsconfigText);403404 const { compilerOptions } =405 yield* Schema.decodeUnknownEffect(TsconfigBase)(tsconfig);406407 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 });469470 return { repo, rows: principleRows(agents) };471});424425/**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 */430export const loadAgentsTable = () =>431 Effect.runPromise(readAgentsTable.pipe(Effect.provide(NodeServices.layer)));
modified:AGENTS.md+1 added-1 removed
14 unmodified lines
15## Principles1617Fence 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.1819In "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.19In "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.2021| # | 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