From e15cce76c7fbd04dbb21d08ea0a765caf82fa326 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 13 May 2026 00:06:48 +0100 Subject: [PATCH] test: dedupe get reply mock reads --- .../reply/get-reply.fast-path.test.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) 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 14b203d68dd..d1f4d68bae1 100644 --- a/src/auto-reply/reply/get-reply.fast-path.test.ts +++ b/src/auto-reply/reply/get-reply.fast-path.test.ts @@ -68,6 +68,24 @@ async function loadGetReplyRuntimeForTest() { ({ runPreparedReply: runPreparedReplyMock } = await import("./get-reply-run.js")); } +function requirePreparedReplyParams() { + const preparedReplyParams = vi.mocked(runPreparedReplyMock).mock.calls[0]?.[0]; + if (!preparedReplyParams) { + throw new Error("expected prepared reply params"); + } + return preparedReplyParams; +} + +function requireDirectiveParams() { + const directiveParams = mocks.resolveReplyDirectives.mock.calls[0]?.[0] as + | { sessionKey?: string; workspaceDir?: string } + | undefined; + if (!directiveParams) { + throw new Error("expected directive params"); + } + return directiveParams; +} + describe("getReplyFromConfig fast test bootstrap", () => { beforeAll(async () => { await loadGetReplyRuntimeForTest(); @@ -133,10 +151,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.at(0)?.[0]; - if (!preparedReplyParams) { - throw new Error("expected prepared reply params"); - } + const preparedReplyParams = requirePreparedReplyParams(); expect(preparedReplyParams.cfg).toBe(cfg); }); @@ -443,12 +458,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.at(0)?.[0] as - | { sessionKey?: string; workspaceDir?: string } - | undefined; - if (!directiveParams) { - throw new Error("expected directive params"); - } + const directiveParams = requireDirectiveParams(); expect(directiveParams.sessionKey).toBe(targetSessionKey); expect(directiveParams.workspaceDir).toBe("/tmp/workspace"); });