fix(cli): 补齐显式机器输出边界

This commit is contained in:
Codex
2026-07-12 02:17:05 +02:00
parent 80edc6c08b
commit bcc7807c3d
5 changed files with 181 additions and 38 deletions
+37
View File
@@ -109,6 +109,43 @@ describe("ssh bounded progressive help", () => {
expect(download).not.toContain("outputTruncated");
});
test("returns the existing bounded JSON model only for explicit machine output", () => {
const top = JSON.parse(runTransHelp("--help", "--json")) as {
ok: boolean;
command: string;
data: { command: string; output: string; routeSyntax: Record<string, string>; dump?: unknown };
};
expect(top.ok).toBe(true);
expect(top.command).toBe("trans --help --json");
expect(top.data.command).toBe("trans --help");
expect(top.data.output).toBe("json");
expect(top.data.routeSyntax.general).toContain("<route> <operation>");
expect(top.data.dump).toBeUndefined();
const prefixed = JSON.parse(runTransHelp("--json", "--help")) as typeof top;
expect(prefixed.ok).toBe(true);
expect(prefixed.data.command).toBe("trans --help");
const topOutput = JSON.parse(runTransHelp("--help", "-o", "json")) as typeof top;
expect(topOutput.ok).toBe(true);
expect(topOutput.data.output).toBe("json");
const scoped = JSON.parse(runTransHelp("--help", "download", "-o", "json")) as {
ok: boolean;
data: { command: string; output: string; scope: string; runtime: { repoRoot: string }; dump?: unknown };
};
expect(scoped.ok).toBe(true);
expect(scoped.data.command).toBe("trans --help download");
expect(scoped.data.output).toBe("json");
expect(scoped.data.scope).toBe("download");
expect(scoped.data.runtime.repoRoot).toBe(repoRoot);
expect(scoped.data.dump).toBeUndefined();
const routeTop = JSON.parse(runTransHelp("NC01:k3s", "--help", "--json")) as typeof top;
expect(routeTop.ok).toBe(true);
expect(routeTop.data.command).toBe("trans --help");
});
test("returns compact no-stack input errors for unknown help scopes", () => {
const result = spawnSync("bun", ["scripts/ssh-cli.ts", "--help", "unknown-operation"], {
cwd: repoRoot,