From 768637a5957bf1cfec3db0d161ea21cc7706defe Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 10:47:15 +0100 Subject: [PATCH] test: guard auto reply command mock calls --- src/auto-reply/command-control.test.ts | 4 ++-- src/auto-reply/reply/agent-runner-execution.test.ts | 4 ++-- src/auto-reply/reply/commands-acp.test.ts | 4 ++-- src/auto-reply/reply/commands-core.test.ts | 4 ++-- src/auto-reply/reply/commands-models.test.ts | 6 ++++-- src/auto-reply/reply/commands-session-restart.test.ts | 4 ++-- src/auto-reply/reply/commands-subagents-focus.test.ts | 4 ++-- .../reply/dispatch-from-config.reply-dispatch.test.ts | 4 ++-- src/auto-reply/reply/get-reply.fast-path.test.ts | 4 ++-- src/auto-reply/reply/session-updates.lifecycle.test.ts | 4 ++-- 10 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/auto-reply/command-control.test.ts b/src/auto-reply/command-control.test.ts index 673b208d367..91ff7a8eee7 100644 --- a/src/auto-reply/command-control.test.ts +++ b/src/auto-reply/command-control.test.ts @@ -1013,8 +1013,8 @@ describe("resolveCommandAuthorization", () => { commandAuthorized: true, }); expect(warn).toHaveBeenCalledTimes(1); - expect(String(warn.mock.calls[0]?.[0] ?? "")).toContain("Error"); - expect(String(warn.mock.calls[0]?.[0] ?? "")).not.toContain("SECRET-TOKEN-123"); + expect(String(warn.mock.calls.at(0)?.[0] ?? "")).toContain("Error"); + expect(String(warn.mock.calls.at(0)?.[0] ?? "")).not.toContain("SECRET-TOKEN-123"); } finally { warn.mockRestore(); } diff --git a/src/auto-reply/reply/agent-runner-execution.test.ts b/src/auto-reply/reply/agent-runner-execution.test.ts index 7dff08438cd..c01f5ad7cba 100644 --- a/src/auto-reply/reply/agent-runner-execution.test.ts +++ b/src/auto-reply/reply/agent-runner-execution.test.ts @@ -830,7 +830,7 @@ describe("runAgentTurnWithFallback", () => { expect(result.kind).toBe("success"); expect(state.runCliAgentMock).not.toHaveBeenCalled(); expect(state.runEmbeddedPiAgentMock).toHaveBeenCalledOnce(); - expect(state.runEmbeddedPiAgentMock.mock.calls[0]?.[0]).not.toHaveProperty( + expect(state.runEmbeddedPiAgentMock.mock.calls.at(0)?.[0]).not.toHaveProperty( "agentHarnessId", "claude-cli", ); @@ -880,7 +880,7 @@ describe("runAgentTurnWithFallback", () => { expectMockCallArgFields(onToolResult, 0, "tool result payload", { mediaUrls: ["/tmp/generated.png"], }); - expect(onToolResult.mock.calls[0]?.[0]?.text).toBeUndefined(); + expect(onToolResult.mock.calls.at(0)?.[0]?.text).toBeUndefined(); }); it("surfaces model capacity errors from no-text mid-turn failures", async () => { diff --git a/src/auto-reply/reply/commands-acp.test.ts b/src/auto-reply/reply/commands-acp.test.ts index d24f85fe45e..75e7b338e97 100644 --- a/src/auto-reply/reply/commands-acp.test.ts +++ b/src/auto-reply/reply/commands-acp.test.ts @@ -1144,7 +1144,7 @@ describe("/acp command", () => { expectBoundIntroTextToExclude("session ids: pending (available after the first reply)"); expectGatewayMethodNotCalled("sessions.patch"); expect(hoisted.upsertAcpSessionMetaMock).toHaveBeenCalledTimes(1); - const upsertArgs = hoisted.upsertAcpSessionMetaMock.mock.calls[0]?.[0] as + const upsertArgs = hoisted.upsertAcpSessionMetaMock.mock.calls.at(0)?.[0] as | { sessionKey: string; mutate: ( @@ -1632,7 +1632,7 @@ describe("/acp command", () => { reason: "manual", }); expect(hoisted.upsertAcpSessionMetaMock).toHaveBeenCalledTimes(1); - const clearMetaArgs = hoisted.upsertAcpSessionMetaMock.mock.calls[0]?.[0] as + const clearMetaArgs = hoisted.upsertAcpSessionMetaMock.mock.calls.at(0)?.[0] as | { sessionKey: string; mutate: (current: unknown, entry: { sessionId: string; updatedAt: number }) => unknown; diff --git a/src/auto-reply/reply/commands-core.test.ts b/src/auto-reply/reply/commands-core.test.ts index 3715d6e2c45..fb8ed02d180 100644 --- a/src/auto-reply/reply/commands-core.test.ts +++ b/src/auto-reply/reply/commands-core.test.ts @@ -60,7 +60,7 @@ describe("emitResetCommandHooks", () => { }); expect(hookRunnerMocks.runBeforeReset).toHaveBeenCalledTimes(1); - const [, ctx] = hookRunnerMocks.runBeforeReset.mock.calls[0] ?? []; + const [, ctx] = hookRunnerMocks.runBeforeReset.mock.calls.at(0) ?? []; return ctx; } @@ -136,7 +136,7 @@ describe("emitResetCommandHooks", () => { }); await vi.waitFor(() => expect(hookRunnerMocks.runBeforeReset).toHaveBeenCalledTimes(1)); - const [event, ctx] = hookRunnerMocks.runBeforeReset.mock.calls[0] as unknown as [ + const [event, ctx] = hookRunnerMocks.runBeforeReset.mock.calls.at(0) as unknown as [ Record, Record, ]; diff --git a/src/auto-reply/reply/commands-models.test.ts b/src/auto-reply/reply/commands-models.test.ts index 29b59e6ef15..867e56768f8 100644 --- a/src/auto-reply/reply/commands-models.test.ts +++ b/src/auto-reply/reply/commands-models.test.ts @@ -186,7 +186,8 @@ describe("handleModelsCommand", () => { expect(result?.reply?.text).toContain("Use: /models "); expect(result?.reply?.text).toContain("Switch: /model "); expect(result?.reply?.text).not.toContain("Add: /models add"); - const authCheckerParams = modelProviderAuthMocks.createProviderAuthChecker.mock.calls[0]?.[0]; + const authCheckerParams = + modelProviderAuthMocks.createProviderAuthChecker.mock.calls.at(0)?.[0]; expect(authCheckerParams?.workspaceDir).toBe("/tmp"); }); @@ -411,7 +412,8 @@ describe("handleModelsCommand", () => { const result = await handleModelsCommand(params, true); expect(result?.reply?.text).toContain("- anthropic (2)"); - const authCheckerParams = modelProviderAuthMocks.createProviderAuthChecker.mock.calls[0]?.[0]; + const authCheckerParams = + modelProviderAuthMocks.createProviderAuthChecker.mock.calls.at(0)?.[0]; expect(authCheckerParams?.workspaceDir).toBe("/tmp/spawned-workspace"); }); diff --git a/src/auto-reply/reply/commands-session-restart.test.ts b/src/auto-reply/reply/commands-session-restart.test.ts index e6c118fa563..08087e83ab0 100644 --- a/src/auto-reply/reply/commands-session-restart.test.ts +++ b/src/auto-reply/reply/commands-session-restart.test.ts @@ -128,7 +128,7 @@ describe("handleRestartCommand", () => { expect(result?.shouldContinue).toBe(false); expect(mocks.writeRestartSentinel).toHaveBeenCalledOnce(); - const sentinelPayload = mocks.writeRestartSentinel.mock.calls[0]?.[0]; + const sentinelPayload = mocks.writeRestartSentinel.mock.calls.at(0)?.[0]; expect(sentinelPayload?.kind).toBe("restart"); expect(sentinelPayload?.status).toBe("ok"); expect(typeof sentinelPayload?.ts).toBe("number"); @@ -166,7 +166,7 @@ describe("handleRestartCommand", () => { await scheduledArgs?.emitHooks?.beforeEmit?.(); expect(mocks.writeRestartSentinel).toHaveBeenCalledOnce(); - const sentinelPayload = mocks.writeRestartSentinel.mock.calls[0]?.[0]; + const sentinelPayload = mocks.writeRestartSentinel.mock.calls.at(0)?.[0]; expect(sentinelPayload?.kind).toBe("restart"); expect(sentinelPayload?.status).toBe("ok"); expect(sentinelPayload?.sessionKey).toBe("agent:main:telegram:direct:123:thread:thread-1"); diff --git a/src/auto-reply/reply/commands-subagents-focus.test.ts b/src/auto-reply/reply/commands-subagents-focus.test.ts index fe085a1b4f5..8d94420fbd1 100644 --- a/src/auto-reply/reply/commands-subagents-focus.test.ts +++ b/src/auto-reply/reply/commands-subagents-focus.test.ts @@ -178,7 +178,7 @@ type SessionBindingBindInput = { }; function firstFocusTargetSessionParams(): FocusTargetSessionParams { - const firstCall = hoisted.resolveFocusTargetSessionMock.mock.calls[0]; + const firstCall = hoisted.resolveFocusTargetSessionMock.mock.calls.at(0); if (!firstCall) { throw new Error("Expected focus target session call"); } @@ -186,7 +186,7 @@ function firstFocusTargetSessionParams(): FocusTargetSessionParams { } function firstSessionBindingBindInput(): SessionBindingBindInput { - const firstCall = hoisted.sessionBindingBindMock.mock.calls[0]; + const firstCall = hoisted.sessionBindingBindMock.mock.calls.at(0); if (!firstCall) { throw new Error("Expected session binding bind call"); } diff --git a/src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts b/src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts index 43405383169..5a82bf4ebdd 100644 --- a/src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts +++ b/src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts @@ -109,7 +109,7 @@ describe("dispatchReplyFromConfig reply_dispatch hook", () => { }); expect(runtimePluginMocks.ensureRuntimePluginsLoaded).toHaveBeenCalledOnce(); - const runtimeLoadCall = runtimePluginMocks.ensureRuntimePluginsLoaded.mock.calls[0]?.[0] as + const runtimeLoadCall = runtimePluginMocks.ensureRuntimePluginsLoaded.mock.calls.at(0)?.[0] as | { config?: unknown; workspaceDir?: unknown } | undefined; expect(runtimeLoadCall?.config).toBe(emptyConfig); @@ -118,7 +118,7 @@ describe("dispatchReplyFromConfig reply_dispatch hook", () => { expect(hookMocks.runner.runReplyDispatch).toHaveBeenCalledOnce(); const [replyDispatchEvent, replyDispatchRuntime] = - (hookMocks.runner.runReplyDispatch.mock.calls[0] as + (hookMocks.runner.runReplyDispatch.mock.calls.at(0) as | [ { sessionKey?: string; diff --git a/src/auto-reply/reply/get-reply.fast-path.test.ts b/src/auto-reply/reply/get-reply.fast-path.test.ts index d2f964d54f9..14b203d68dd 100644 --- a/src/auto-reply/reply/get-reply.fast-path.test.ts +++ b/src/auto-reply/reply/get-reply.fast-path.test.ts @@ -133,7 +133,7 @@ describe("getReplyFromConfig fast test bootstrap", () => { expect(mocks.initSessionState).not.toHaveBeenCalled(); expect(mocks.resolveReplyDirectives).not.toHaveBeenCalled(); expect(vi.mocked(runPreparedReplyMock)).toHaveBeenCalledOnce(); - const preparedReplyParams = vi.mocked(runPreparedReplyMock).mock.calls[0]?.[0]; + const preparedReplyParams = vi.mocked(runPreparedReplyMock).mock.calls.at(0)?.[0]; if (!preparedReplyParams) { throw new Error("expected prepared reply params"); } @@ -443,7 +443,7 @@ describe("getReplyFromConfig fast test bootstrap", () => { expect(mocks.initSessionState).not.toHaveBeenCalled(); expect(vi.mocked(runPreparedReplyMock)).not.toHaveBeenCalled(); expect(mocks.resolveReplyDirectives).toHaveBeenCalledOnce(); - const directiveParams = mocks.resolveReplyDirectives.mock.calls[0]?.[0] as + const directiveParams = mocks.resolveReplyDirectives.mock.calls.at(0)?.[0] as | { sessionKey?: string; workspaceDir?: string } | undefined; if (!directiveParams) { diff --git a/src/auto-reply/reply/session-updates.lifecycle.test.ts b/src/auto-reply/reply/session-updates.lifecycle.test.ts index 1ec9dc943f2..a928a2d802e 100644 --- a/src/auto-reply/reply/session-updates.lifecycle.test.ts +++ b/src/auto-reply/reply/session-updates.lifecycle.test.ts @@ -80,8 +80,8 @@ describe("session-updates lifecycle hooks", () => { expect(hookRunnerMocks.runSessionEnd).toHaveBeenCalledTimes(1); expect(hookRunnerMocks.runSessionStart).toHaveBeenCalledTimes(1); - const [endEvent, endContext] = hookRunnerMocks.runSessionEnd.mock.calls[0] ?? []; - const [startEvent, startContext] = hookRunnerMocks.runSessionStart.mock.calls[0] ?? []; + const [endEvent, endContext] = hookRunnerMocks.runSessionEnd.mock.calls.at(0) ?? []; + const [startEvent, startContext] = hookRunnerMocks.runSessionStart.mock.calls.at(0) ?? []; expect(endEvent?.sessionId).toBe("s1"); expect(endEvent?.sessionKey).toBe(sessionKey);