diff --git a/src/auto-reply/reply/agent-runner-utils.secret-resolution.test.ts b/src/auto-reply/reply/agent-runner-utils.secret-resolution.test.ts index f5e1e9679f1..b09bd081058 100644 --- a/src/auto-reply/reply/agent-runner-utils.secret-resolution.test.ts +++ b/src/auto-reply/reply/agent-runner-utils.secret-resolution.test.ts @@ -22,6 +22,23 @@ const { resolveQueuedReplyExecutionConfig, resolveQueuedReplyRuntimeConfig } = const { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } = await import("../../config/config.js"); +type ResolveCommandSecretRefsCall = { + config: OpenClawConfig; + commandName: string; + targetIds?: Set; + allowedPaths?: Set; +}; + +function resolveCommandSecretRefsCall(callIndex = 0): ResolveCommandSecretRefsCall { + const call = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls[callIndex]?.[0] as + | ResolveCommandSecretRefsCall + | undefined; + if (!call) { + throw new Error(`expected command secret resolution call ${callIndex}`); + } + return call; +} + describe("resolveQueuedReplyExecutionConfig channel scope", () => { beforeEach(() => { clearRuntimeConfigSnapshot(); @@ -70,11 +87,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => { expect(resolved).toBe(scopedResolved); expect(hoisted.resolveCommandSecretRefsViaGatewayMock).toHaveBeenCalledTimes(2); - const baseCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(0)?.[0] as { - config: OpenClawConfig; - commandName: string; - targetIds: Set; - }; + const baseCall = resolveCommandSecretRefsCall(); expect(baseCall.config).toBe(sourceConfig); expect(baseCall.commandName).toBe("reply"); expect(baseCall.targetIds).toEqual(new Set(["skills.entries.*.apiKey"])); @@ -83,12 +96,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => { channel: "discord", accountId: "work", }); - const scopedCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(1)?.[0] as { - config: OpenClawConfig; - commandName: string; - targetIds: Set; - allowedPaths?: Set; - }; + const scopedCall = resolveCommandSecretRefsCall(1); expect(scopedCall.config).toBe(baseResolved); expect(scopedCall.commandName).toBe("reply"); expect(scopedCall.targetIds).toEqual(new Set(["channels.discord.token"])); @@ -134,10 +142,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => { messageProvider: "discord", }); - const baseCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(0)?.[0] as { - config: OpenClawConfig; - commandName: string; - }; + const baseCall = resolveCommandSecretRefsCall(); expect(baseCall.config).toBe(runtimeConfig); expect(baseCall.commandName).toBe("reply"); expect(hoisted.getScopedChannelsCommandSecretTargetsMock).toHaveBeenCalledWith({