

























@@ -186,6 +186,14 @@ function userMessage(text: string, timestamp: number) {
186186};
187187}
188188189+function mockCall(mock: unknown, label: string, index = 0): unknown[] {
190+const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.at(index);
191+if (!call) {
192+throw new Error(`Expected ${label} call ${index + 1}`);
193+}
194+return call;
195+}
196+189197function createAppServerHarness(
190198requestImpl: (method: string, params: unknown) => Promise<unknown>,
191199options: {
@@ -2104,7 +2112,7 @@ describe("runCodexAppServerAttempt", () => {
21042112await run;
2105211321062114expect(beforePromptBuild).toHaveBeenCalledOnce();
2107-const [hookInput, hookContext] = beforePromptBuild.mock.calls[0] as unknown as [
2115+const [hookInput, hookContext] = mockCall(beforePromptBuild, "before_prompt_build") as [
21082116{ messages?: Array<{ role?: string }>; prompt?: string },
21092117{ runId?: string; sessionId?: string },
21102118];
@@ -2209,7 +2217,7 @@ describe("runCodexAppServerAttempt", () => {
22092217expect(llmInput).toHaveBeenCalled();
22102218await new Promise<void>((resolve) => setImmediate(resolve));
221122192212-const [llmInputPayload, llmInputContext] = llmInput.mock.calls[0] as unknown as [
2220+const [llmInputPayload, llmInputContext] = mockCall(llmInput, "llm_input") as [
22132221{
22142222historyMessages?: Array<{ role?: string }>;
22152223imagesCount?: number;
@@ -2289,7 +2297,7 @@ describe("runCodexAppServerAttempt", () => {
22892297expect(globalEndEvent?.runId).toBe("run-1");
22902298expect(globalEndEvent?.sessionKey).toBe("agent:main:session-1");
229122992292-const [llmOutputPayload, llmOutputContext] = llmOutput.mock.calls[0] as unknown as [
2300+const [llmOutputPayload, llmOutputContext] = mockCall(llmOutput, "llm_output") as [
22932301{
22942302assistantTexts?: string[];
22952303harnessId?: string;
@@ -2312,7 +2320,7 @@ describe("runCodexAppServerAttempt", () => {
23122320expect(llmOutputPayload.lastAssistant?.role).toBe("assistant");
23132321expect(llmOutputContext.runId).toBe("run-1");
23142322expect(llmOutputContext.sessionId).toBe("session-1");
2315-const [agentEndPayload, agentEndContext] = agentEnd.mock.calls[0] as unknown as [
2323+const [agentEndPayload, agentEndContext] = mockCall(agentEnd, "agent_end") as [
23162324{ messages?: Array<{ role?: string }>; success?: boolean },
23172325{ runId?: string; sessionId?: string },
23182326];
@@ -2916,7 +2924,7 @@ describe("runCodexAppServerAttempt", () => {
29162924expect(typeof errorEvent?.data.endedAt).toBe("number");
29172925expect(errorEvent?.data.error).toBe("codex exploded");
29182926expect(agentEvents.some((event) => event.stream === "assistant")).toBe(false);
2919-const [agentEndPayload, agentEndContext] = agentEnd.mock.calls[0] as unknown as [
2927+const [agentEndPayload, agentEndContext] = mockCall(agentEnd, "agent_end") as [
29202928{ error?: string; success?: boolean },
29212929{ runId?: string; sessionId?: string },
29222930];
@@ -2957,7 +2965,7 @@ describe("runCodexAppServerAttempt", () => {
29572965expect(llmInput).toHaveBeenCalledTimes(1);
29582966expect(llmOutput).toHaveBeenCalledTimes(1);
29592967expect(agentEnd).toHaveBeenCalledTimes(1);
2960-const [llmOutputPayload] = llmOutput.mock.calls[0] as unknown as [
2968+const [llmOutputPayload] = mockCall(llmOutput, "llm_output") as [
29612969{
29622970assistantTexts?: string[];
29632971harnessId?: string;
@@ -2976,7 +2984,7 @@ describe("runCodexAppServerAttempt", () => {
29762984expect(llmOutputPayload.harnessId).toBe("codex");
29772985expect(llmOutputPayload.runId).toBe("run-1");
29782986expect(llmOutputPayload.sessionId).toBe("session-1");
2979-const [agentEndPayload] = agentEnd.mock.calls[0] as unknown as [
2987+const [agentEndPayload] = mockCall(agentEnd, "agent_end") as [
29802988{ error?: string; messages?: Array<{ role?: string }>; success?: boolean },
29812989unknown,
29822990];
@@ -3003,7 +3011,7 @@ describe("runCodexAppServerAttempt", () => {
30033011const result = await run;
30043012expect(result.aborted).toBe(true);
30053013expect(agentEnd).toHaveBeenCalledTimes(1);
3006-const [agentEndPayload] = agentEnd.mock.calls[0] as unknown as [{ success?: boolean }, unknown];
3014+const [agentEndPayload] = mockCall(agentEnd, "agent_end") as [{ success?: boolean }, unknown];
30073015expect(agentEndPayload.success).toBe(false);
30083016});
30093017@@ -3648,7 +3656,7 @@ describe("runCodexAppServerAttempt", () => {
36483656content: { approve: true },
36493657_meta: null,
36503658});
3651-const [bridgeCall] = bridgeSpy.mock.calls[0] as unknown as [
3659+const [bridgeCall] = mockCall(bridgeSpy, "elicitation bridge") as [
36523660{ threadId?: string; turnId?: string },
36533661];
36543662expect(bridgeCall.threadId).toBe("thread-1");
@@ -3829,7 +3837,7 @@ describe("runCodexAppServerAttempt", () => {
38293837content: null,
38303838_meta: null,
38313839});
3832-const [bridgeCall] = bridgeSpy.mock.calls[0] as unknown as [
3840+const [bridgeCall] = mockCall(bridgeSpy, "elicitation bridge") as [
38333841{
38343842pluginAppPolicyContext?: {
38353843apps?: Record<string, { mcpServerNames?: string[]; pluginName?: string }>;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。