

























@@ -107,6 +107,14 @@ function createFakeClient(): FakeClient {
107107return client;
108108}
109109110+function mockCall(mock: ReturnType<typeof vi.fn>, index = 0): unknown[] {
111+const call = mock.mock.calls.at(index);
112+if (!call) {
113+throw new Error(`Expected mock call ${index}`);
114+}
115+return call;
116+}
117+110118function threadResult(threadId: string) {
111119return {
112120thread: {
@@ -252,7 +260,7 @@ describe("runCodexAppServerSideQuestion", () => {
252260const result = await runCodexAppServerSideQuestion(sideParams());
253261254262expect(result).toEqual({ text: "Side answer." });
255-const forkCall = client.request.mock.calls[0];
263+const forkCall = mockCall(client.request);
256264expect(forkCall?.[0]).toBe("thread/fork");
257265const forkParams = forkCall?.[1] as Record<string, unknown> | undefined;
258266expect(Object.keys(forkParams ?? {}).toSorted()).toEqual([
@@ -285,7 +293,7 @@ describe("runCodexAppServerSideQuestion", () => {
285293);
286294expect(forkCall?.[2]).toEqual({ timeoutMs: 60_000, signal: undefined });
287295288-const injectCall = client.request.mock.calls[1];
296+const injectCall = mockCall(client.request, 1);
289297expect(injectCall?.[0]).toBe("thread/inject_items");
290298const injectParams = injectCall?.[1] as
291299| { threadId?: string; items?: Array<{ type?: string; role?: string; content?: unknown }> }
@@ -335,7 +343,7 @@ describe("runCodexAppServerSideQuestion", () => {
335343]);
336344expect(client.request.mock.calls.some(([method]) => method === "turn/interrupt")).toBe(false);
337345338-const [toolOptions] = createOpenClawCodingToolsMock.mock.calls[0] ?? [];
346+const [toolOptions] = mockCall(createOpenClawCodingToolsMock);
339347expect(toolOptions).toHaveProperty("agentDir", "/tmp/agent");
340348expect(toolOptions).toHaveProperty("workspaceDir", "/tmp/workspace");
341349expect(toolOptions).toHaveProperty("sessionId", "session-1");
@@ -382,8 +390,7 @@ describe("runCodexAppServerSideQuestion", () => {
382390const result = await runCodexAppServerSideQuestion(sideParams());
383391384392expect(result).toEqual({ text: "Tool answer." });
385-const [toolCallId, toolArguments, toolSignal, toolOptions] =
386-toolExecuteMock.mock.calls[0] ?? [];
393+const [toolCallId, toolArguments, toolSignal, toolOptions] = mockCall(toolExecuteMock);
387394expect(toolExecuteMock).toHaveBeenCalledTimes(1);
388395expect(toolCallId).toBe("tool-1");
389396expect(toolArguments).toEqual({ topic: "AGENTS.md" });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。