From f8dc6d3d1843bd9c0c85d966dee30882c8448aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=A1=B6?= Date: Sat, 5 Dec 2026 01:36:26 +0800 Subject: [PATCH] Test that every s1 command and flag in the shipped skill exists The agent skill teaches agents which commands and flags to use. A renamed or removed option now fails CI instead of silently misleading agents. Co-Authored-By: Claude Opus 5.5 --- tests/skill-docs.test.mjs | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/skill-docs.test.mjs diff --git a/tests/skill-docs.test.mjs b/tests/skill-docs.test.mjs new file mode 100644 index 0000000..7dce8ab --- /dev/null +++ b/tests/skill-docs.test.mjs @@ -0,0 +1,54 @@ +// The agent skill ships with the CLI and teaches agents which `s1` commands and +// flags exist. Every command and flag it shows must exist in the built CLI, so a +// renamed or removed option fails here instead of misleading agents. +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; + +const DOCS = ["skills/search1api/SKILL.md", "skills/search1api/reference/examples.md"]; +const CLI = new URL("../dist/index.js", import.meta.url).pathname; + +/** `s1 ... --flag` uses, from inline code and fenced code lines. */ +function documentedUses() { + const uses = new Map(); // command -> Set(flags) + for (const file of DOCS) { + const text = readFileSync(new URL(`../${file}`, import.meta.url), "utf8"); + const snippets = [ + ...text.matchAll(/`(s1 [^`\n]+)`/g), + ...text.matchAll(/^\s*(?:\$\s*)?(s1 .+)$/gm), + ].map((m) => m[1]); + for (const snippet of snippets) { + for (const part of snippet.split(/\s*(?:\||&&|;)\s*/)) { + const m = part.match(/^s1 ([a-z][a-z-]*)\b(.*)$/); + if (!m) continue; + const [, command, rest] = m; + const flags = uses.get(command) ?? new Set(); + for (const f of rest.matchAll(/(?:^|\s)(--[a-z][a-z0-9-]*)/g)) flags.add(f[1]); + uses.set(command, flags); + } + } + } + return uses; +} + +function help(args) { + return execFileSync(process.execPath, [CLI, ...args, "--help"], { + encoding: "utf8", + env: { ...process.env, NO_UPDATE_NOTIFIER: "1", NO_COLOR: "1" }, + }); +} + +test("every s1 command and flag in the shipped skill exists", () => { + const uses = documentedUses(); + assert.ok(uses.size >= 5, `found only ${uses.size} documented commands`); + const top = help([]); + for (const [command, flags] of uses) { + assert.match(top, new RegExp(`^\\s+${command}\\b`, "m"), `skill documents unknown command: s1 ${command}`); + const own = help([command]); + for (const flag of flags) { + if (flag === "--help" || flag === "--version") continue; + assert.ok(own.includes(flag) || top.includes(flag), `skill documents unknown flag: s1 ${command} ${flag}`); + } + } +});