mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-22 06:08:13 +00:00
test: guard cron fast-mode mock calls
This commit is contained in:
@@ -34,6 +34,14 @@ function mockSuccessfulModelFallback() {
|
||||
});
|
||||
}
|
||||
|
||||
function requireFirstMockCall<T>(mock: { mock: { calls: T[][] } }, label: string): T[] {
|
||||
const call = mock.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
async function runFastModeCase(params: {
|
||||
configFastMode: boolean;
|
||||
expectedFastMode: boolean;
|
||||
@@ -96,7 +104,7 @@ async function runFastModeCase(params: {
|
||||
|
||||
expect(result.status).toBe("ok");
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
||||
const [embeddedRunParams] = runEmbeddedPiAgentMock.mock.calls[0];
|
||||
const [embeddedRunParams] = requireFirstMockCall(runEmbeddedPiAgentMock, "embedded run");
|
||||
expect(embeddedRunParams.provider).toBe("openai");
|
||||
expect(embeddedRunParams.model).toBe(EXPECTED_OPENAI_MODEL);
|
||||
expect(embeddedRunParams.fastMode).toBe(params.expectedFastMode);
|
||||
@@ -106,7 +114,10 @@ async function runFastModeCase(params: {
|
||||
expect(embeddedRunParams.allowGatewaySubagentBinding).toBe(true);
|
||||
if (params.expectedRetiredSessionId) {
|
||||
expect(retireSessionMcpRuntimeMock).toHaveBeenCalledOnce();
|
||||
const [retireParams] = retireSessionMcpRuntimeMock.mock.calls[0];
|
||||
const [retireParams] = requireFirstMockCall(
|
||||
retireSessionMcpRuntimeMock,
|
||||
"retire session mcp runtime",
|
||||
);
|
||||
expect(retireParams.sessionId).toBe(params.expectedRetiredSessionId);
|
||||
expect(retireParams.reason).toBe("cron-session-rollover");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user