feat: install development build globally

This commit is contained in:
gitea committed 2026-09-11 17:35:29 +08:00
1 parent 7cfb68e434
commit 3e072b490e
9 files changed
+249 -9

No files matched your search

+10
View File
@@ -25,6 +25,16 @@ describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
delete process.env.HOSE_APPROVAL_DB;
});
test("version/help --json only emit machine-readable stdout", async () => {
const version = await runAiProCli(["version", "--json"]);
const help = await runAiProCli(["help", "--json"]);
expect(JSON.parse(version.stdout)).toEqual({ name: "hose-aipro", version: expect.any(String) });
expect(JSON.parse(help.stdout).help).toContain("hose-aipro");
expect(version.stderr).toBe("");
expect(help.stderr).toBe("");
});
test("完整闭环:bind 挂载 ➔ review 证据核验 ➔ decide 网关阻拦与裁决 ➔ logs 审计追溯", async () => {
const db = getApprovalDatabase(":memory:");
const repo = new ApprovalRepository(db);
+22 -5
View File
@@ -53,6 +53,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
}
const command = (positional[0] || "help").toLowerCase();
const jsonMode = booleanOption(parsed.options, ["json", "j"]);
const targetSn = positional[1] || stringOption(parsed.options, ["code", "sn", "id", "target"]);
const args = positional.slice(1);
const corpId = corp?.corpId || corp?.id;
@@ -73,6 +74,16 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
};
try {
if (command === "version" || command === "v" || booleanOption(parsed.options, ["version", "v"])) {
return {
stdout: jsonMode
? printJson({ name: "hose-aipro", version: VERSION }) + "\n"
: `hose-aipro v${VERSION}\n`,
stderr: "",
exitCode: 0,
};
}
switch (command) {
// ── 0. 运行时上下文与身份诊断 (status / whoami / context / info) ────────
case "status":
@@ -1136,7 +1147,11 @@ ${corpBanner}
7. 全流程监控日志流水查看:
hose-aipro logs [单号] # 追溯所有 AI PRO 操作流水
`;
return { stdout: helpText.trim() + "\n", stderr: "", exitCode: 0 };
return {
stdout: jsonMode ? printJson({ help: helpText.trim() }) + "\n" : helpText.trim() + "\n",
stderr: "",
exitCode: 0,
};
}
}
} catch (err: any) {
@@ -1151,8 +1166,8 @@ ${corpBanner}
summary: err.message.replace(/\n+/g, " "),
});
return {
stdout: "",
stderr: `\n${err.message}\n`,
stdout: jsonMode ? printJson({ error: true, message: err.message, exitCode: 1 }) + "\n" : "",
stderr: jsonMode ? "" : `\n${err.message}\n`,
exitCode: 1,
};
}
@@ -1167,8 +1182,10 @@ ${corpBanner}
});
return {
stdout: "",
stderr: `[AI PRO 错误] ${err?.message || err}\n`,
stdout: jsonMode
? printJson({ error: true, message: String(err?.message || err), exitCode: 1 }) + "\n"
: "",
stderr: jsonMode ? "" : `[AI PRO 错误] ${err?.message || err}\n`,
exitCode: 1,
};
}
+10
View File
@@ -88,4 +88,14 @@ describe("CLI runner - version and help aliases", () => {
expect(command.stdout).toContain("publish");
expect(command.stdout).toContain("发布并启用工作流");
});
it("keeps help and version machine-readable when --json is requested", async () => {
const help = await runCli(["help", "workflow", "--json"]);
const version = await runCli(["version", "--json"]);
expect(JSON.parse(help.stdout).help).toContain("workflow -");
expect(JSON.parse(version.stdout)).toEqual({ name: "hose-use", version: VERSION });
expect(help.stderr).toBe("");
expect(version.stderr).toBe("");
});
});
+15 -4
View File
@@ -66,11 +66,13 @@ async function runCliOnce(
): Promise<CliResult> {
const stdoutChunks: string[] = [];
const stderrChunks: string[] = [];
const machineJson = booleanOption(parseArgs(rawArgs).options, ["json", "j"]);
const originalLog = console.log;
const originalError = console.error;
console.log = (...values: unknown[]) => {
stdoutChunks.push(values.map((v) => (typeof v === "string" ? v : String(v))).join(" "));
const line = values.map((v) => (typeof v === "string" ? v : String(v))).join(" ");
(machineJson ? stderrChunks : stdoutChunks).push(line);
};
console.error = (...values: unknown[]) => {
stderrChunks.push(values.map((v) => (typeof v === "string" ? v : String(v))).join(" "));
@@ -129,16 +131,25 @@ async function dispatchCli(
options: CliRunOptions = {}
): Promise<CliResult> {
const parsed = parseArgs(rawArgs);
const jsonMode = booleanOption(parsed.options, ["json", "j"]);
if (isHelpRequested(parsed)) {
return { stdout: printHelp(resolveHelpTarget(parsed)) + "\n", stderr: "", exitCode: 0 };
const help = printHelp(resolveHelpTarget(parsed));
return {
stdout: jsonMode ? printJson({ help }) : `${help}\n`,
stderr: "",
exitCode: 0,
};
}
if (isVersionRequested(parsed)) {
return { stdout: `hose-use v${VERSION}\n`, stderr: "", exitCode: 0 };
return {
stdout: jsonMode ? printJson({ name: "hose-use", version: VERSION }) : `hose-use v${VERSION}\n`,
stderr: "",
exitCode: 0,
};
}
const jsonMode = booleanOption(parsed.options, ["json", "j"]);
const corpIdOption = stringOption(parsed.options, ["corp", "c"]);
const statelessOption = booleanOption(parsed.options, ["stateless"]);
const statefulOption = booleanOption(parsed.options, ["stateful"]);