Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/skill-docs.test.mjs
Original file line number Diff line number Diff line change
@@ -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 <command> ... --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}`);
}
}
});