


























@@ -1,4 +1,4 @@
1-import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
1+import { beforeAll, beforeEach, describe, expect, it, vi, type Mock } from "vitest";
22import type { ExecApprovalFollowupTarget } from "./bash-tools.exec-host-shared.js";
33import type { ExecApprovalFollowupFactory } from "./bash-tools.exec-types.js";
44@@ -138,6 +138,43 @@ vi.mock("../infra/command-analysis/inline-eval.js", () => ({
138138let processGatewayAllowlist: typeof import("./bash-tools.exec-host-gateway.js").processGatewayAllowlist;
139139type GatewayAllowlistParams = Parameters<typeof processGatewayAllowlist>[0];
140140141+function requireBuildFollowupTargetInput(callIndex: number): ExecApprovalFollowupTarget {
142+const call = buildExecApprovalFollowupTargetMock.mock.calls[callIndex];
143+if (!call) {
144+throw new Error(`expected build followup target call ${callIndex}`);
145+}
146+return call[0];
147+}
148+149+function requireSentFollowupTarget(
150+callIndex: number,
151+): Parameters<SendExecApprovalFollowupResult>[0] {
152+const call = sendExecApprovalFollowupResultMock.mock.calls[callIndex];
153+if (!call) {
154+throw new Error(`expected sent followup call ${callIndex}`);
155+}
156+return call[0];
157+}
158+159+function requireSentFollowupText(callIndex: number): string {
160+const call = sendExecApprovalFollowupResultMock.mock.calls[callIndex];
161+if (!call) {
162+throw new Error(`expected sent followup call ${callIndex}`);
163+}
164+return call[1] ?? "";
165+}
166+167+function requireApprovalFollowupInput(
168+mock: Mock<ExecApprovalFollowupFactory>,
169+callIndex: number,
170+): Parameters<ExecApprovalFollowupFactory>[0] {
171+const call = mock.mock.calls[callIndex];
172+if (!call) {
173+throw new Error(`expected approval followup call ${callIndex}`);
174+}
175+return call[0];
176+}
177+141178describe("processGatewayAllowlist", () => {
142179beforeAll(async () => {
143180({ processGatewayAllowlist } = await import("./bash-tools.exec-host-gateway.js"));
@@ -311,10 +348,7 @@ describe("processGatewayAllowlist", () => {
311348sessionKey: "agent:main:telegram:direct:123",
312349});
313350314-const followupTargetInput = buildExecApprovalFollowupTargetMock.mock.calls.at(0)?.[0] as
315-| { sessionKey?: string }
316-| undefined;
317-expect(followupTargetInput?.sessionKey).toBe("agent:main:telegram:direct:123");
351+expect(requireBuildFollowupTargetInput(0).sessionKey).toBe("agent:main:telegram:direct:123");
318352});
319353320354it("formats diagnostics approvals as direct pasteable followups", async () => {
@@ -375,31 +409,18 @@ describe("processGatewayAllowlist", () => {
375409await vi.waitFor(() => {
376410expect(sendExecApprovalFollowupResultMock).toHaveBeenCalledTimes(1);
377411});
378-const followupTargetInput = buildExecApprovalFollowupTargetMock.mock.calls.at(0)?.[0] as
379-| { direct?: boolean }
380-| undefined;
381-expect(followupTargetInput?.direct).toBe(true);
382-383-const followupTarget = sendExecApprovalFollowupResultMock.mock.calls.at(0)?.[0] as
384-| { direct?: boolean }
385-| null
386-| undefined;
412+expect(requireBuildFollowupTargetInput(0).direct).toBe(true);
413+414+const followupTarget = requireSentFollowupTarget(0);
387415expect(followupTarget?.direct).toBe(true);
388-const followupText = sendExecApprovalFollowupResultMock.mock.calls.at(0)?.[1] ?? "";
416+const followupText = requireSentFollowupText(0);
389417expect(followupText).toContain("Diagnostics export created.");
390418expect(followupText).toContain("Path: /tmp/openclaw-diagnostics.zip");
391419expect(followupText).toContain("Contents (2 files):");
392420expect(followupText).toContain("OpenAI Codex harness:");
393421expect(followupText).toContain("Codex diagnostics sent to OpenAI servers:");
394422expect(followupText).toContain("Codex thread id: `thread-1`");
395-const approvalInput = approvalFollowup.mock.calls.at(0)?.[0] as
396-| {
397-approvalId?: string;
398-sessionId?: string;
399-trigger?: string;
400-outcome?: { status?: string; exitCode?: number | null };
401-}
402-| undefined;
423+const approvalInput = requireApprovalFollowupInput(approvalFollowup, 0);
403424expect(approvalInput?.approvalId).toBe("req-1");
404425expect(approvalInput?.sessionId).toBe("sess-1");
405426expect(approvalInput?.trigger).toBe("diagnostics");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。