Files
seal-use/src/cli/docs-commands.test.ts
T
gitea b8de4cc800 Correct README drift and check the docs against the dispatcher
README documented commands the dispatcher no longer accepts: `seal-use tool
<toolName>` and `seal-use tools list` were both dropped in v0.10.39 while the
README kept telling readers to run them (verified: both answer "Unknown
command"). It also described `./enterprises` as loaded by default, which a test
explicitly asserts is *not*, claimed the HTTP adapter does not serve the
OpenAPI document it serves at `/openapi.json`, described `service start` as a
stdio wrapper rather than the HTTP adapter it runs, and said the MCP server
advertises exactly one tool when it advertises two (and none without
`SEAL_USE_MCP_ENABLED`).

Each claim was rewritten against the code. The `seal-use update` paragraph now
describes all three installation modes instead of only the source-checkout one.

To keep the docs from drifting again, the suite now scans README, AGENTS.md,
SECURITY.md, the skill references, and the `.agents/rules` for `seal-use <area>`
and fails if any area is not dispatchable — it flags `tool` and `tools` on the
pre-fix README, so the check is live rather than decorative.
2026-09-30 01:17:39 +08:00

70 lines
2.7 KiB
TypeScript

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 <toolName>` 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<string> {
const found = new Set<string>();
// Inline code spans: `seal-use <area> …`
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 <area>` in the maintained docs is dispatchable", () => {
const stale: Record<string, string[]> = {};
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({});
});
});