test: guard auto reply command mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 10:47:15 +01:00
parent 163eb08a34
commit 768637a595
10 changed files with 22 additions and 20 deletions

View File

@@ -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();
}

View File

@@ -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 () => {

View File

@@ -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;

View File

@@ -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<string, unknown>,
Record<string, unknown>,
];

View File

@@ -186,7 +186,8 @@ describe("handleModelsCommand", () => {
expect(result?.reply?.text).toContain("Use: /models <provider>");
expect(result?.reply?.text).toContain("Switch: /model <provider/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");
});

View File

@@ -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");

View File

@@ -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");
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);