
























11import { Command } from "commander";
2-import { describe, expect, it } from "vitest";
2+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+4+const { runQaMatrixCommand } = vi.hoisted(() => ({
5+runQaMatrixCommand: vi.fn(),
6+}));
7+8+vi.mock("./cli.runtime.js", () => ({
9+ runQaMatrixCommand,
10+}));
11+312import { matrixQaCliRegistration } from "./cli.js";
41314+function mockProcessWrite(
15+_chunk: string | Uint8Array,
16+encodingOrCallback?: BufferEncoding | ((err?: Error | null) => void),
17+callback?: (err?: Error | null) => void,
18+) {
19+if (typeof encodingOrCallback === "function") {
20+encodingOrCallback();
21+} else {
22+callback?.();
23+}
24+return true;
25+}
26+527describe("matrix qa cli registration", () => {
28+const originalDisableForceExit = process.env.OPENCLAW_QA_MATRIX_DISABLE_FORCE_EXIT;
29+let exitSpy: ReturnType<typeof vi.spyOn>;
30+let stderrSpy: ReturnType<typeof vi.spyOn>;
31+let stdoutSpy: ReturnType<typeof vi.spyOn>;
32+33+beforeEach(() => {
34+runQaMatrixCommand.mockReset();
35+exitSpy = vi.spyOn(process, "exit").mockImplementation((code?: string | number | null) => {
36+throw new Error(`process.exit(${String(code)})`);
37+});
38+stderrSpy = vi.spyOn(process.stderr, "write").mockImplementation(mockProcessWrite);
39+stdoutSpy = vi.spyOn(process.stdout, "write").mockImplementation(mockProcessWrite);
40+});
41+42+afterEach(() => {
43+if (originalDisableForceExit === undefined) {
44+delete process.env.OPENCLAW_QA_MATRIX_DISABLE_FORCE_EXIT;
45+} else {
46+process.env.OPENCLAW_QA_MATRIX_DISABLE_FORCE_EXIT = originalDisableForceExit;
47+}
48+exitSpy.mockRestore();
49+stderrSpy.mockRestore();
50+stdoutSpy.mockRestore();
51+});
52+653it("keeps disposable Matrix lane flags focused", () => {
754const qa = new Command();
855@@ -26,4 +73,27 @@ describe("matrix qa cli registration", () => {
2673expect(optionNames).not.toContain("--credential-source");
2774expect(optionNames).not.toContain("--credential-role");
2875});
76+77+it("exits with failure after Matrix artifacts are written for a failed run", async () => {
78+const qa = new Command();
79+matrixQaCliRegistration.register(qa);
80+runQaMatrixCommand.mockRejectedValue(new Error("Matrix QA failed.\nreport: /tmp/report.md"));
81+82+await expect(qa.parseAsync(["node", "openclaw", "matrix"])).rejects.toThrow("process.exit(1)");
83+84+expect(runQaMatrixCommand).toHaveBeenCalledOnce();
85+expect(stderrSpy).toHaveBeenCalledWith("Matrix QA failed.\nreport: /tmp/report.md\n");
86+expect(exitSpy).toHaveBeenCalledWith(1);
87+});
88+89+it("can disable the forced exit for direct test harnesses", async () => {
90+process.env.OPENCLAW_QA_MATRIX_DISABLE_FORCE_EXIT = "1";
91+const qa = new Command();
92+matrixQaCliRegistration.register(qa);
93+runQaMatrixCommand.mockRejectedValue(new Error("scenario failed"));
94+95+await expect(qa.parseAsync(["node", "openclaw", "matrix"])).rejects.toThrow("scenario failed");
96+97+expect(exitSpy).not.toHaveBeenCalled();
98+});
2999});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。