perf(test): speed up block streaming tests

This commit is contained in:
Peter Steinberger
2026-02-14 19:49:57 +00:00
parent cfc2604d3e
commit 9762e48134
2 changed files with 105 additions and 55 deletions

View File

@@ -125,4 +125,109 @@ describe("runReplyAgent block streaming", () => {
expect(onBlockReply.mock.calls[0][0].text).toBe("Hello");
expect(result).toBeUndefined();
});
it("returns the final payload when onBlockReply times out", async () => {
vi.useFakeTimers();
let sawAbort = false;
const onBlockReply = vi.fn((_payload, context) => {
return new Promise<void>((resolve) => {
context?.abortSignal?.addEventListener(
"abort",
() => {
sawAbort = true;
resolve();
},
{ once: true },
);
});
});
runEmbeddedPiAgentMock.mockImplementationOnce(async (params) => {
const block = params.onBlockReply as ((payload: { text?: string }) => void) | undefined;
block?.({ text: "Chunk" });
return {
payloads: [{ text: "Final message" }],
meta: {},
};
});
const typing = createMockTypingController();
const sessionCtx = {
Provider: "discord",
OriginatingTo: "channel:C1",
AccountId: "primary",
MessageSid: "msg",
} as unknown as TemplateContext;
const resolvedQueue = { mode: "interrupt" } as unknown as QueueSettings;
const followupRun = {
prompt: "hello",
summaryLine: "hello",
enqueuedAt: Date.now(),
run: {
sessionId: "session",
sessionKey: "main",
messageProvider: "discord",
sessionFile: "/tmp/session.jsonl",
workspaceDir: "/tmp",
config: {
agents: {
defaults: {
blockStreamingCoalesce: {
minChars: 1,
maxChars: 200,
idleMs: 0,
},
},
},
},
skillsSnapshot: {},
provider: "anthropic",
model: "claude",
thinkLevel: "low",
verboseLevel: "off",
elevatedLevel: "off",
bashElevated: {
enabled: false,
allowed: false,
defaultLevel: "off",
},
timeoutMs: 1_000,
blockReplyBreak: "text_end",
},
} as unknown as FollowupRun;
const resultPromise = runReplyAgent({
commandBody: "hello",
followupRun,
queueKey: "main",
resolvedQueue,
shouldSteer: false,
shouldFollowup: false,
isActive: false,
isStreaming: false,
opts: { onBlockReply, blockReplyTimeoutMs: 1 },
typing,
sessionCtx,
defaultModel: "anthropic/claude-opus-4-5",
resolvedVerboseLevel: "off",
isNewSession: false,
blockStreamingEnabled: true,
blockReplyChunking: {
minChars: 1,
maxChars: 200,
breakPreference: "paragraph",
},
resolvedBlockStreamingBreak: "text_end",
shouldInjectGroupIntro: false,
typingMode: "instant",
});
await vi.advanceTimersByTimeAsync(5);
const result = await resultPromise;
vi.useRealTimers();
expect(sawAbort).toBe(true);
expect(result).toMatchObject({ text: "Final message" });
});
});