`approval-runs get --flow` 至今仍是 `approval-runs hose-flow` 的静默遗留 别名:解析器的布尔标志白名单里还留着它,命令实现里也仍在转发。但 CLI 协议第 6 节要求兼容拼写只能停留在实现层,不得出现在 help、Skill、 references、README 或正常运行时提示中。 问题在于这条规矩被自己的文档破了:`get --help` 中 `--raw-json` 的描述写着 "incompatible with --summary, --fields and --flow",references 里同一句话也 照抄了一遍。用户只要撞上一次参数冲突,就会被 CLI 主动教一遍退役拼写。 - help:`--raw-json` 描述去掉 `--flow`,改为指向规范命令 `approval-runs hose-flow <recordId|SN>`。 - approval-run-lightweight.md:同步修正,并补上原生合思流程时间线的入口。 - 运行时:冲突报错改为只列调用方实际传入的标志,不再主动广播退役拼写。 - naming-charter:新增裸 `--flow` 的边界守卫。原有 LEGACY_SURFACE_TOKENS 是子串匹配,无法表达这个概念(`--flow-id`、 `--flow-ids`、`--flow-concurrency` 都是规范参数),这正是该泄漏存活 八个版本的根因。
133 lines
5.0 KiB
TypeScript
133 lines
5.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { HELP_REGISTRY } from "./help.js";
|
|
import { parseArgs } from "./parser.js";
|
|
|
|
/**
|
|
* Naming charter guard (.agents/rules/cli-protocol.md "Naming Charter").
|
|
*
|
|
* The visible surface (help registry, mirrored into the skill docs) must present
|
|
* one canonical spelling per concept; legacy spellings keep working as silent
|
|
* dispatcher/parser aliases but must never appear in documentation. This test
|
|
* fails when a camelCase flag or a retired verb/flag leaks back onto the
|
|
* visible surface, or when a canonical flag loses its parser registration.
|
|
*/
|
|
|
|
const LEGACY_SURFACE_TOKENS = [
|
|
"--to-downloads",
|
|
"--show-secret",
|
|
"--maxResults",
|
|
"--maxRuns",
|
|
"--humanResult",
|
|
"--manualApprovalStatus",
|
|
"--startDate",
|
|
"--endDate",
|
|
"--includeBridge",
|
|
"--ruleVersion",
|
|
"--documentLimit"
|
|
];
|
|
|
|
const VALUE_FLAG_PAIRS: Array<[kebab: string, legacyCamel: string]> = [
|
|
["--start-date", "--startDate"],
|
|
["--end-date", "--endDate"],
|
|
["--max-results", "--maxResults"],
|
|
["--human-result", "--humanResult"],
|
|
["--manual-approval-status", "--manualApprovalStatus"],
|
|
["--rule-version", "--ruleVersion"],
|
|
["--document-limit", "--documentLimit"],
|
|
["--context-lines", "--contextLines"],
|
|
["--source-document-sn", "--sourceDocumentSN"],
|
|
["--source-document-id", "--sourceDocumentId"]
|
|
];
|
|
|
|
const BOOLEAN_FLAG_CANONICAL = ["--downloads", "--include-bridge", "--reveal"];
|
|
|
|
function collectSurfaceFlags(): string[] {
|
|
const flags: string[] = [];
|
|
const scan = (text: string) => {
|
|
// Strip <placeholder> segments first: values like <YYYY-MM-DD|ms> contain
|
|
// dash-led uppercase fragments that are not flags.
|
|
for (const match of text.replace(/<[^>]*>/g, " ").matchAll(/--?[A-Za-z][A-Za-z0-9-]*/g)) {
|
|
flags.push(match[0]);
|
|
}
|
|
};
|
|
for (const area of HELP_REGISTRY) {
|
|
for (const command of area.commands) {
|
|
for (const usage of command.usage) {
|
|
scan(usage);
|
|
}
|
|
for (const option of command.options ?? []) {
|
|
scan(option.flag);
|
|
}
|
|
}
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
describe("naming charter: visible help surface", () => {
|
|
test("documents only lowercase kebab-case flags", () => {
|
|
const offenders = collectSurfaceFlags().filter((flag) => /[A-Z]/.test(flag));
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
test("never documents retired flag spellings", () => {
|
|
const serialized = JSON.stringify(HELP_REGISTRY);
|
|
const offenders = LEGACY_SURFACE_TOKENS.filter((token) => serialized.includes(token));
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
test("never documents the retired bare flow switch", () => {
|
|
// `--flow` on `approval-runs get` is a silent legacy alias for
|
|
// `approval-runs hose-flow`, so the visible surface must not name it.
|
|
// LEGACY_SURFACE_TOKENS matches by substring and cannot express this:
|
|
// `--flow-id`, `--flow-ids` and `--flow-concurrency` are canonical.
|
|
const serialized = JSON.stringify(HELP_REGISTRY);
|
|
const offenders = serialized.match(/--flow(?![A-Za-z0-9-])/g) ?? [];
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("naming charter: parser accepts canonical and legacy spellings", () => {
|
|
test("kebab canonical and camel legacy value flags both parse", () => {
|
|
for (const [kebab, legacy] of VALUE_FLAG_PAIRS) {
|
|
const canonical = parseArgs(["x", kebab, "v"]);
|
|
const legacyArgs = parseArgs(["x", legacy, "v"]);
|
|
expect(canonical.options[kebab.slice(2)]).toBe("v");
|
|
expect(legacyArgs.options[legacy.slice(2)]).toBe("v");
|
|
}
|
|
});
|
|
|
|
test("canonical boolean flags parse without a value", () => {
|
|
for (const flag of BOOLEAN_FLAG_CANONICAL) {
|
|
const parsed = parseArgs(["x", flag]);
|
|
expect(parsed.options[flag.slice(2)]).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("naming charter: canonical accept-sets are wired in commands", () => {
|
|
const read = (path: string) => readFileSync(fileURLToPath(new URL(path, import.meta.url)), "utf8");
|
|
|
|
test("webhook resource-pack export reads --out and --downloads (no silent ignore)", () => {
|
|
const source = read("./commands/webhook.ts");
|
|
expect(source).toContain("stringOption(args.options.out) ??");
|
|
expect(source).toContain("booleanOption(args.options.downloads) ??");
|
|
expect(source).toContain("booleanOption(args.options.download) ??");
|
|
});
|
|
|
|
test("webhook secret reveal accepts --reveal alongside legacy --show-secret", () => {
|
|
const source = read("./parser.ts");
|
|
expect(source).toContain("booleanOption(options.reveal)");
|
|
expect(source).toContain('booleanOption(options["show-secret"])');
|
|
});
|
|
|
|
test("approval-runs reads canonical --start-date/--end-date everywhere", () => {
|
|
const source = read("./commands/approval-runs.ts");
|
|
const startDateReads = source.match(/args\.options\["start-date"\]/g)?.length ?? 0;
|
|
const endDateReads = source.match(/args\.options\["end-date"\]/g)?.length ?? 0;
|
|
expect(startDateReads).toBeGreaterThanOrEqual(3);
|
|
expect(endDateReads).toBeGreaterThanOrEqual(3);
|
|
});
|
|
});
|