From d68afbcb5f12201d39650f7fefdf578858852fad Mon Sep 17 00:00:00 2001 From: Vivswan Shah <58091053+Vivswan@users.noreply.github.com> Date: Mon, 5 Oct 2026 00:53:12 -0400 Subject: [PATCH] test: name the schema build step before tsc runs and register a helper's kind argument as data The library-examples test rewrote the page's schema subpath import to lib/settings.schema.json, a built and ignored artifact, so a clean checkout failed with TS2307 against the page line, which reads as a docs defect. The generator only writes into the tree, so the test cannot build the schema elsewhere; compileExamples now checks, before tsc and only when the program imports the schema path, that the file exists, and rejects with the one line readSettingsSchema already uses: lib/settings.schema.json is not built; run bun run build:schema. The line is minted once in test/settings-schema.ts. Every other test reads the schema through readSettingsSchema and already failed closed. The refusal-messages scanner read a bare string argument of a local helper in a schema slice or shared helper as a message unless the DATA_ARGUMENTS registry named the position, so a kind tag such as "knobbed" passed to the minting helpers needed a line-end pin, and the kinds were carried in a table to avoid it. The registry now names the kind parameter of wrappedList and knobbedList, and takes over commitMessageFamily's two key names and githubName's noun from PIECE_ARGUMENTS, where their containment pins held wherever any test spelled the key or the word. The real census drops those six key-name and noun literals and nothing else. One planted row holds the control: knobbedList(entry, "knobbed", shape) reports "knobbed" on main and is silent here. --- test/docs/library-examples.test.ts | 71 ++++++++++++++++++++--- test/sections/refusal-messages.test.ts | 80 ++++++++++++++------------ test/settings-schema.ts | 13 ++++- 3 files changed, 116 insertions(+), 48 deletions(-) diff --git a/test/docs/library-examples.test.ts b/test/docs/library-examples.test.ts index b3a4c4832..2955d73aa 100644 --- a/test/docs/library-examples.test.ts +++ b/test/docs/library-examples.test.ts @@ -8,10 +8,10 @@ import { describe, expect, test } from "bun:test"; import { spawnSync } from "node:child_process"; -import { readFileSync, symlinkSync, writeFileSync } from "node:fs"; +import { existsSync, readFileSync, symlinkSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; import { ROOT } from "../root.js"; -import { SETTINGS_SCHEMA_PATH } from "../settings-schema.js"; +import { SETTINGS_SCHEMA_PATH, schemaNotBuilt } from "../settings-schema.js"; import { withTempDir } from "../temp-dir.js"; const PAGE = "docs/reference/library.md"; @@ -55,9 +55,13 @@ export function tsFences(markdown: string): Fence[] { * The fences as one module: only the two package paths are rewritten, on the * lines they already occupy, so a program line is a page line by offset alone * and nothing else about a fence is repaired before tsc sees it. The page - * imports each name once, in the first example that uses it. + * imports each name once, in the first example that uses it. `schema` is where + * the package's schema subpath lands. */ -export function examplesProgram(fences: readonly Fence[]): { +export function examplesProgram( + fences: readonly Fence[], + schema: string, +): { text: string; pageLine: (programLine: number) => number; } { @@ -67,7 +71,7 @@ export function examplesProgram(fences: readonly Fence[]): { for (const fence of fences) { starts.push(line); const body = fence.body - .replaceAll(`"${PACKAGE}/settings.schema.json"`, JSON.stringify(SETTINGS_SCHEMA_PATH)) + .replaceAll(`"${PACKAGE}/settings.schema.json"`, JSON.stringify(schema)) .replaceAll(`"${PACKAGE}"`, JSON.stringify(ENTRY)); parts.push(body); line += body.split("\n").length; @@ -92,15 +96,39 @@ export function examplesProgram(fences: readonly Fence[]): { /** `tsc --pretty false` prints `(,): error TS: `, continuation lines indented. */ const DIAGNOSTIC = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/; +/** + * Whether the program imports `module` (a static import, a re-export, a dynamic import, each spelled as the page + * spells it: `from`, or `import` and an optional parenthesis, then the quoted path); a string value naming the path + * is not a dependency. + */ +function importsModule(program: string, module: string): boolean { + const quoted = JSON.stringify(module); + for (let at = program.indexOf(quoted); at !== -1; at = program.indexOf(quoted, at + 1)) { + if (/\b(?:from|import)\s*\(?\s*$/.test(program.slice(0, at))) { + return true; + } + } + return false; +} + /** * Every diagnostic tsc reports for the page's fences, as `