Fix architecture review findings and align CLI metadata

This commit is contained in:
gitea committed 2026-10-17 20:17:06 +08:00
1 parent 780a4ba9c0
commit 50e4e492b4
83 files changed
+966 -792

No files matched your search

+22 -16
View File
@@ -1,6 +1,5 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { HELP_REGISTRY } from "./help.js";
import {
booleanOption,
BOOLEAN_FLAGS,
@@ -203,23 +202,30 @@ describe("option helpers", () => {
describe("flag registry cross-check", () => {
test("every flag documented in help.ts is registered", () => {
const help = readFileSync(join(import.meta.dirname, "help.ts"), "utf-8");
const documented = new Set(
[...help.matchAll(/flag: "--([a-z][a-z0-9-]*)"/g)].map((match) => match[1]!)
);
for (const flag of documented) {
expect(KNOWN_FLAGS.has(flag)).toBe(true);
}
const documented = new Set(HELP_REGISTRY.flatMap((area) => area.commands.flatMap((command) =>
(command.options ?? []).flatMap((option) => [...option.flag.matchAll(/--([a-zA-Z][a-zA-Z0-9-]*)/g)].map((match) => match[1]!))
)));
expect([...documented].filter((flag) => !KNOWN_FLAGS.has(flag))).toEqual([]);
expect(documented.size).toBeGreaterThanOrEqual(20);
});
test("every flag shown in a help usage line is registered", () => {
const help = readFileSync(join(import.meta.dirname, "help.ts"), "utf-8");
const usageFlags = new Set(
[...help.matchAll(/ --([a-z][a-z0-9-]*)/g)].map((match) => match[1]!)
);
const missing = [...usageFlags].filter((flag) => !KNOWN_FLAGS.has(flag));
expect(missing).toEqual([]);
test("every flag shown in a help usage line is registered, including bracket and pipe forms", () => {
const usageFlags = new Set(HELP_REGISTRY.flatMap((area) => area.commands.flatMap((command) =>
command.usage.flatMap((usage) => [...usage.matchAll(/--([a-zA-Z][a-zA-Z0-9-]*)/g)].map((match) => match[1]!))
)));
expect([...usageFlags].filter((flag) => !KNOWN_FLAGS.has(flag))).toEqual([]);
});
test("formerly rejected public flags retain their boolean and value arity", () => {
const parsed = parseArgs(["report", "data", "--templates", "one,two", "--latest", "record"]);
expect(parsed.options).toEqual({ templates: "one,two", latest: true });
expect(parsed.command).toEqual(["report", "data", "record"]);
expect(parseArgs(["config", "test-dir", "--clear"]).options.clear).toBe(true);
expect(parseArgs(["webhook", "get", "id", "--show-secret"]).options["show-secret"]).toBe(true);
expect(parseArgs(["webhook", "update", "id", "--min-file-size", "10", "--clear-max-file-size"]).options)
.toEqual({ "min-file-size": "10", "clear-max-file-size": true });
expect(() => parseArgs(["report", "data", "--templates"])).toThrow("requires a value");
expect(() => parseArgs(["corps", "list", "--limitt=5"])).toThrow("Unknown option: --limitt");
});
test("boolean and value sets partition the registry apart from the ambiguous three", () => {