Skip to content

Commit 67d30e8

Browse files
committed
test: deduplicate agent runner fixtures
1 parent 1e10c44 commit 67d30e8

3 files changed

Lines changed: 225 additions & 696 deletions

File tree

‎src/auto-reply/reply/agent-runner-execution-compaction.test.ts‎

Lines changed: 54 additions & 261 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { describe, expect, it, vi } from "vitest";
22
import { resetLogger, setLoggerOverride } from "../../logging/logger.js";
33
import { loggingState } from "../../logging/state.js";
4-
import type { TemplateContext } from "../templating.js";
54
import {
65
setupAgentRunnerExecutionTestState,
76
getExecuteAgentTurnForTest,
8-
createMockTypingSignaler,
97
createFollowupRun,
108
expectBlockReplyCall,
119
createMinimalRunAgentTurnParams,
@@ -14,9 +12,26 @@ import type {
1412
FallbackRunnerParams,
1513
EmbeddedAgentParams,
1614
} from "./agent-runner-execution.test-support.js";
15+
import type { AgentTurnParams } from "./agent-runner-execution.types.js";
1716

1817
const state = setupAgentRunnerExecutionTestState();
1918

19+
async function executeTestTurn(
20+
params?: Parameters<typeof createMinimalRunAgentTurnParams>[0],
21+
overrides?: Partial<AgentTurnParams>,
22+
) {
23+
const executeAgentTurn = await getExecuteAgentTurnForTest();
24+
return executeAgentTurn({ ...createMinimalRunAgentTurnParams(params), ...overrides });
25+
}
26+
27+
function createNotifyUserRun() {
28+
const followupRun = createFollowupRun();
29+
followupRun.run.config = {
30+
agents: { defaults: { compaction: { notifyUser: true } } },
31+
};
32+
return followupRun;
33+
}
34+
2035
describe("executeAgentTurn: compaction events", () => {
2136
it("keeps compaction start notices silent by default", async () => {
2237
const onBlockReply = vi.fn();
@@ -25,29 +40,7 @@ describe("executeAgentTurn: compaction events", () => {
2540
return { payloads: [{ text: "final" }], meta: {} };
2641
});
2742

28-
const executeAgentTurn = await getExecuteAgentTurnForTest();
29-
const result = await executeAgentTurn({
30-
commandBody: "hello",
31-
followupRun: createFollowupRun(),
32-
sessionCtx: {
33-
Provider: "whatsapp",
34-
MessageSid: "msg",
35-
} as unknown as TemplateContext,
36-
opts: { onBlockReply },
37-
typingSignals: createMockTypingSignaler(),
38-
blockReplyPipeline: null,
39-
blockStreamingEnabled: false,
40-
resolvedBlockStreamingBreak: "message_end",
41-
applyReplyToMode: (payload) => payload,
42-
shouldEmitToolResult: () => true,
43-
shouldEmitToolOutput: () => false,
44-
pendingToolTasks: new Set(),
45-
resetSessionAfterRoleOrderingConflict: async () => false,
46-
isHeartbeat: false,
47-
sessionKey: "main",
48-
getActiveSessionEntry: () => undefined,
49-
resolvedVerboseLevel: "off",
50-
});
43+
const result = await executeTestTurn({ opts: { onBlockReply } }, { commandBody: "hello" });
5144

5245
expect(result.kind).toBe("success");
5346
expect(onBlockReply).not.toHaveBeenCalled();
@@ -66,33 +59,16 @@ describe("executeAgentTurn: compaction events", () => {
6659
return { payloads: [{ text: "final" }], meta: {} };
6760
});
6861

69-
const executeAgentTurn = await getExecuteAgentTurnForTest();
70-
const result = await executeAgentTurn({
71-
commandBody: "hello",
72-
followupRun: createFollowupRun(),
73-
sessionCtx: {
74-
Provider: "whatsapp",
75-
MessageSid: "msg",
76-
} as unknown as TemplateContext,
77-
opts: {
78-
onBlockReply,
79-
onCompactionStart,
80-
onCompactionEnd,
62+
const result = await executeTestTurn(
63+
{
64+
opts: {
65+
onBlockReply,
66+
onCompactionStart,
67+
onCompactionEnd,
68+
},
8169
},
82-
typingSignals: createMockTypingSignaler(),
83-
blockReplyPipeline: null,
84-
blockStreamingEnabled: false,
85-
resolvedBlockStreamingBreak: "message_end",
86-
applyReplyToMode: (payload) => payload,
87-
shouldEmitToolResult: () => true,
88-
shouldEmitToolOutput: () => false,
89-
pendingToolTasks: new Set(),
90-
resetSessionAfterRoleOrderingConflict: async () => false,
91-
isHeartbeat: false,
92-
sessionKey: "main",
93-
getActiveSessionEntry: () => undefined,
94-
resolvedVerboseLevel: "off",
95-
});
70+
{ commandBody: "hello" },
71+
);
9672

9773
expect(result.kind).toBe("success");
9874
expect(onCompactionStart).toHaveBeenCalledTimes(1);
@@ -144,12 +120,7 @@ describe("executeAgentTurn: compaction events", () => {
144120
return { payloads: [{ text: "final" }], meta: {} };
145121
});
146122

147-
const executeAgentTurn = await getExecuteAgentTurnForTest();
148-
const result = await executeAgentTurn({
149-
...createMinimalRunAgentTurnParams({
150-
opts: { onBlockReply },
151-
}),
152-
});
123+
const result = await executeTestTurn({ opts: { onBlockReply } });
153124

154125
expect(result.kind).toBe("success");
155126
expect(onBlockReply).not.toHaveBeenCalled();
@@ -170,40 +141,10 @@ describe("executeAgentTurn: compaction events", () => {
170141
return { payloads: [{ text: "final" }], meta: {} };
171142
});
172143

173-
const followupRun = createFollowupRun();
174-
followupRun.run.config = {
175-
agents: {
176-
defaults: {
177-
compaction: {
178-
notifyUser: true,
179-
},
180-
},
181-
},
182-
};
183-
184-
const executeAgentTurn = await getExecuteAgentTurnForTest();
185-
const result = await executeAgentTurn({
186-
commandBody: "hello",
187-
followupRun,
188-
sessionCtx: {
189-
Provider: "whatsapp",
190-
MessageSid: "msg",
191-
} as unknown as TemplateContext,
192-
opts: { onBlockReply },
193-
typingSignals: createMockTypingSignaler(),
194-
blockReplyPipeline: null,
195-
blockStreamingEnabled: false,
196-
resolvedBlockStreamingBreak: "message_end",
197-
applyReplyToMode: (payload) => payload,
198-
shouldEmitToolResult: () => true,
199-
shouldEmitToolOutput: () => false,
200-
pendingToolTasks: new Set(),
201-
resetSessionAfterRoleOrderingConflict: async () => false,
202-
isHeartbeat: false,
203-
sessionKey: "main",
204-
getActiveSessionEntry: () => undefined,
205-
resolvedVerboseLevel: "off",
206-
});
144+
const result = await executeTestTurn(
145+
{ followupRun: createNotifyUserRun(), opts: { onBlockReply } },
146+
{ commandBody: "hello" },
147+
);
207148

208149
expect(result.kind).toBe("success");
209150
expect(onBlockReply).toHaveBeenCalledTimes(1);
@@ -226,40 +167,10 @@ describe("executeAgentTurn: compaction events", () => {
226167
return { payloads: [{ text: "final" }], meta: {} };
227168
});
228169

229-
const followupRun = createFollowupRun();
230-
followupRun.run.config = {
231-
agents: {
232-
defaults: {
233-
compaction: {
234-
notifyUser: true,
235-
},
236-
},
237-
},
238-
};
239-
240-
const executeAgentTurn = await getExecuteAgentTurnForTest();
241-
const result = await executeAgentTurn({
242-
commandBody: "hello",
243-
followupRun,
244-
sessionCtx: {
245-
Provider: "whatsapp",
246-
MessageSid: "msg",
247-
} as unknown as TemplateContext,
248-
opts: { onBlockReply },
249-
typingSignals: createMockTypingSignaler(),
250-
blockReplyPipeline: null,
251-
blockStreamingEnabled: false,
252-
resolvedBlockStreamingBreak: "message_end",
253-
applyReplyToMode: (payload) => payload,
254-
shouldEmitToolResult: () => true,
255-
shouldEmitToolOutput: () => false,
256-
pendingToolTasks: new Set(),
257-
resetSessionAfterRoleOrderingConflict: async () => false,
258-
isHeartbeat: false,
259-
sessionKey: "main",
260-
getActiveSessionEntry: () => undefined,
261-
resolvedVerboseLevel: "off",
262-
});
170+
const result = await executeTestTurn(
171+
{ followupRun: createNotifyUserRun(), opts: { onBlockReply } },
172+
{ commandBody: "hello" },
173+
);
263174

264175
expect(result.kind).toBe("success");
265176
expectBlockReplyCall(onBlockReply, 0, {
@@ -290,40 +201,10 @@ describe("executeAgentTurn: compaction events", () => {
290201
return { payloads: [{ text: "final" }], meta: {} };
291202
});
292203

293-
const followupRun = createFollowupRun();
294-
followupRun.run.config = {
295-
agents: {
296-
defaults: {
297-
compaction: {
298-
notifyUser: true,
299-
},
300-
},
301-
},
302-
};
303-
304-
const executeAgentTurn = await getExecuteAgentTurnForTest();
305-
const result = await executeAgentTurn({
306-
commandBody: "hello",
307-
followupRun,
308-
sessionCtx: {
309-
Provider: "whatsapp",
310-
MessageSid: "msg",
311-
} as unknown as TemplateContext,
312-
opts: { onBlockReply },
313-
typingSignals: createMockTypingSignaler(),
314-
blockReplyPipeline: null,
315-
blockStreamingEnabled: false,
316-
resolvedBlockStreamingBreak: "message_end",
317-
applyReplyToMode: (payload) => payload,
318-
shouldEmitToolResult: () => true,
319-
shouldEmitToolOutput: () => false,
320-
pendingToolTasks: new Set(),
321-
resetSessionAfterRoleOrderingConflict: async () => false,
322-
isHeartbeat: false,
323-
sessionKey: "main",
324-
getActiveSessionEntry: () => undefined,
325-
resolvedVerboseLevel: "off",
326-
});
204+
const result = await executeTestTurn(
205+
{ followupRun: createNotifyUserRun(), opts: { onBlockReply } },
206+
{ commandBody: "hello" },
207+
);
327208

328209
expect(result.kind).toBe("success");
329210
expect(onBlockReply).toHaveBeenCalledTimes(4);
@@ -366,40 +247,13 @@ describe("executeAgentTurn: compaction events", () => {
366247
return { payloads: [{ text: "final" }], meta: {} };
367248
});
368249

369-
const followupRun = createFollowupRun();
370-
followupRun.run.config = {
371-
agents: {
372-
defaults: {
373-
compaction: {
374-
notifyUser: true,
375-
},
376-
},
250+
const result = await executeTestTurn(
251+
{
252+
followupRun: createNotifyUserRun(),
253+
opts: { onBlockReply, onCompactionStart, onCompactionEnd },
377254
},
378-
};
379-
380-
const executeAgentTurn = await getExecuteAgentTurnForTest();
381-
const result = await executeAgentTurn({
382-
commandBody: "hello",
383-
followupRun,
384-
sessionCtx: {
385-
Provider: "whatsapp",
386-
MessageSid: "msg",
387-
} as unknown as TemplateContext,
388-
opts: { onBlockReply, onCompactionStart, onCompactionEnd },
389-
typingSignals: createMockTypingSignaler(),
390-
blockReplyPipeline: null,
391-
blockStreamingEnabled: false,
392-
resolvedBlockStreamingBreak: "message_end",
393-
applyReplyToMode: (payload) => payload,
394-
shouldEmitToolResult: () => true,
395-
shouldEmitToolOutput: () => false,
396-
pendingToolTasks: new Set(),
397-
resetSessionAfterRoleOrderingConflict: async () => false,
398-
isHeartbeat: false,
399-
sessionKey: "main",
400-
getActiveSessionEntry: () => undefined,
401-
resolvedVerboseLevel: "off",
402-
});
255+
{ commandBody: "hello" },
256+
);
403257

404258
expect(result.kind).toBe("success");
405259
// Internal callbacks (Control UI etc.) and the user-channel notifyUser
@@ -428,40 +282,10 @@ describe("executeAgentTurn: compaction events", () => {
428282
return { payloads: [{ text: "final" }], meta: {} };
429283
});
430284

431-
const followupRun = createFollowupRun();
432-
followupRun.run.config = {
433-
agents: {
434-
defaults: {
435-
compaction: {
436-
notifyUser: true,
437-
},
438-
},
439-
},
440-
};
441-
442-
const executeAgentTurn = await getExecuteAgentTurnForTest();
443-
const result = await executeAgentTurn({
444-
commandBody: "hello",
445-
followupRun,
446-
sessionCtx: {
447-
Provider: "whatsapp",
448-
MessageSid: "msg",
449-
} as unknown as TemplateContext,
450-
opts: { onBlockReply },
451-
typingSignals: createMockTypingSignaler(),
452-
blockReplyPipeline: null,
453-
blockStreamingEnabled: false,
454-
resolvedBlockStreamingBreak: "message_end",
455-
applyReplyToMode: (payload) => payload,
456-
shouldEmitToolResult: () => true,
457-
shouldEmitToolOutput: () => false,
458-
pendingToolTasks: new Set(),
459-
resetSessionAfterRoleOrderingConflict: async () => false,
460-
isHeartbeat: false,
461-
sessionKey: "main",
462-
getActiveSessionEntry: () => undefined,
463-
resolvedVerboseLevel: "off",
464-
});
285+
const result = await executeTestTurn(
286+
{ followupRun: createNotifyUserRun(), opts: { onBlockReply } },
287+
{ commandBody: "hello" },
288+
);
465289

466290
expect(result.kind).toBe("success");
467291
expectBlockReplyCall(onBlockReply, 0, {
@@ -485,41 +309,10 @@ describe("executeAgentTurn: compaction events", () => {
485309
return { payloads: [{ text: "final" }], meta: {} };
486310
});
487311

488-
const followupRun = createFollowupRun();
489-
followupRun.run.config = {
490-
agents: {
491-
defaults: {
492-
compaction: {
493-
notifyUser: true,
494-
},
495-
},
496-
},
497-
};
498-
499-
const executeAgentTurn = await getExecuteAgentTurnForTest();
500-
const result = await executeAgentTurn({
501-
commandBody: "hello",
502-
followupRun,
503-
sessionCtx: {
504-
Provider: "whatsapp",
505-
MessageSid: "msg",
506-
} as unknown as TemplateContext,
507-
opts: {},
508-
typingSignals: createMockTypingSignaler(),
509-
blockReplyPipeline: null,
510-
blockStreamingEnabled: false,
511-
resolvedBlockStreamingBreak: "message_end",
512-
applyReplyToMode: (payload) => payload,
513-
shouldEmitToolResult: () => true,
514-
shouldEmitToolOutput: () => false,
515-
pendingToolTasks: new Set(),
516-
resetSessionAfterRoleOrderingConflict: async () => false,
517-
isHeartbeat: false,
518-
sessionKey: "main",
519-
getActiveSessionEntry: () => undefined,
520-
resolvedVerboseLevel: "off",
521-
onCompactionNoticePayload,
522-
});
312+
const result = await executeTestTurn(
313+
{ followupRun: createNotifyUserRun() },
314+
{ commandBody: "hello", onCompactionNoticePayload },
315+
);
523316

524317
expect(result.kind).toBe("success");
525318
expect(onCompactionNoticePayload).toHaveBeenCalledTimes(2);

0 commit comments

Comments
 (0)