























@@ -570,15 +570,16 @@ describe("runCli exit behavior", () => {
570570["tools", ["node", "openclaw", "tools", "effective"]],
571571])("keeps reserved %s command roots out of plugin command discovery", async (_name, argv) => {
572572const parseAsync = vi.fn().mockResolvedValueOnce(undefined);
573-buildProgramMock.mockReturnValueOnce({
573+const program = {
574574commands: [],
575575 parseAsync,
576-});
576+};
577+buildProgramMock.mockReturnValueOnce(program);
577578578579await runCli(argv);
579580580581expect(startProxyMock).not.toHaveBeenCalled();
581-expect(registerSubCliByNameMock).toHaveBeenCalledWith(expect.anything(), argv[2], argv);
582+expect(registerSubCliByNameMock.mock.calls).toEqual([[program, argv[2], argv]]);
582583expect(registerPluginCliCommandsFromValidatedConfigMock).not.toHaveBeenCalled();
583584expect(parseAsync).toHaveBeenCalledWith(argv);
584585});
@@ -801,47 +802,41 @@ describe("runCli exit behavior", () => {
801802802803it("swallows Commander parse exits after recording the exit code", async () => {
803804const exitCode = process.exitCode;
804-buildProgramMock.mockReturnValueOnce({
805+const program = {
805806commands: [{ name: () => "status" }],
806807parseAsync: vi
807808.fn()
808809.mockRejectedValueOnce(
809810new CommanderError(1, "commander.excessArguments", "too many arguments for 'status'"),
810811),
811-});
812+};
813+buildProgramMock.mockReturnValueOnce(program);
812814813815await expect(runCli(["node", "openclaw", "status"])).resolves.toBeUndefined();
814816815-expect(registerSubCliByNameMock).toHaveBeenCalledWith(expect.anything(), "status", [
816-"node",
817-"openclaw",
818-"status",
817+expect(registerSubCliByNameMock.mock.calls).toEqual([
818+[program, "status", ["node", "openclaw", "status"]],
819819]);
820820expect(process.exitCode).toBe(1);
821821process.exitCode = exitCode;
822822});
823823824824it("loads the real primary command before rendering command help", async () => {
825-buildProgramMock.mockReturnValueOnce({
825+const program = {
826826commands: [{ name: () => "doctor" }],
827827parseAsync: vi.fn().mockResolvedValueOnce(undefined),
828-});
828+};
829+buildProgramMock.mockReturnValueOnce(program);
829830const ctx = { programVersion: "0.0.0-test" };
830831getProgramContextMock.mockReturnValueOnce(ctx as never);
831832832833await runCli(["node", "openclaw", "doctor", "--help"]);
833834834-expect(registerCoreCliByNameMock).toHaveBeenCalledWith(expect.anything(), ctx, "doctor", [
835-"node",
836-"openclaw",
837-"doctor",
838-"--help",
835+expect(registerCoreCliByNameMock.mock.calls).toEqual([
836+[program, ctx, "doctor", ["node", "openclaw", "doctor", "--help"]],
839837]);
840-expect(registerSubCliByNameMock).toHaveBeenCalledWith(expect.anything(), "doctor", [
841-"node",
842-"openclaw",
843-"doctor",
844-"--help",
838+expect(registerSubCliByNameMock.mock.calls).toEqual([
839+[program, "doctor", ["node", "openclaw", "doctor", "--help"]],
845840]);
846841});
847842@@ -907,10 +902,9 @@ describe("runCli exit behavior", () => {
907902code: "EHOSTUNREACH",
908903});
909904expect(handler(hostUnreachable)).toBeUndefined();
910-expect(consoleWarnSpy).toHaveBeenCalledWith(
911-"[openclaw] Non-fatal uncaught exception (continuing):",
912-expect.stringContaining("EHOSTUNREACH"),
913-);
905+expect(consoleWarnSpy.mock.calls).toEqual([
906+["[openclaw] Non-fatal uncaught exception (continuing):", hostUnreachable.stack],
907+]);
914908expect(restoreTerminalStateMock).not.toHaveBeenCalled();
915909expect(exitSpy).not.toHaveBeenCalled();
916910} finally {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。