import { describe, expect, test } from "bun:test"; import { readFileSync, readdirSync } from "node:fs"; import { join } from "node:path"; import { KNOWN_AREAS, UPDATE_ALIASES } from "./runner.js"; /** * Documentation cross-check: every command a maintained doc shows a reader must * still dispatch. * * The hand-written docs drifted once already — README kept documenting * `seal-use tool ` and `seal-use tools list` for two releases after * the dispatcher dropped both areas, and it described `./enterprises` as loaded * when a test explicitly asserts it is not. Nothing failed, so nothing got * fixed. This test turns the docs into a checked claim. * * Scope is deliberate: `CHANGELOG.md` records history (old commands belong * there) and `docs/proposals/` is forward-looking by definition, so both are * excluded. Commands are read from code spans (`` `seal-use area …` ``) and * from example lines, which is where a reader would copy one from — bare prose * like "the seal-use wrapped API" is not a command and is not matched. */ const REPO_ROOT = join(import.meta.dir, "..", ".."); const DOC_FILES = [ "README.md", "AGENTS.md", "SECURITY.md", "skills/seal-use/SKILL.md", ...readdirSync(join(REPO_ROOT, "skills/seal-use/references")).map( (name) => `skills/seal-use/references/${name}` ), ...readdirSync(join(REPO_ROOT, ".agents/rules")).map((name) => `.agents/rules/${name}`) ]; /** * Names the dispatcher accepts before the `KNOWN_AREAS` gate — `seal-use help`, * `seal-use version` — plus `v`. Everything else must be a known area; update * spellings (`upgrade`, `self-update`, …) come from UPDATE_ALIASES. */ const EARLY_DISPATCH = new Set(["version", "v", "help"]); function referencedAreas(markdown: string): Set { const found = new Set(); // Inline code spans: `seal-use …` for (const match of markdown.matchAll(/`seal-use ([a-z][a-z0-9-]*)/g)) found.add(match[1]!); // Example lines a reader would copy and paste. for (const match of markdown.matchAll(/^\s*seal-use ([a-z][a-z0-9-]*)/gm)) found.add(match[1]!); return found; } function isDispatchable(area: string): boolean { return KNOWN_AREAS.has(area) || UPDATE_ALIASES.has(area) || EARLY_DISPATCH.has(area); } describe("documentation references live commands", () => { test("every `seal-use ` in the maintained docs is dispatchable", () => { const stale: Record = {}; for (const file of DOC_FILES) { const unknown = [...referencedAreas(readFileSync(join(REPO_ROOT, file), "utf8"))] .filter((area) => !isDispatchable(area)) .sort(); if (unknown.length) stale[file] = unknown; } expect(stale).toEqual({}); }); });