perf(test): trim fixture and import overhead in hot suites

This commit is contained in:
Peter Steinberger
2026-02-13 22:28:50 +00:00
parent b8703546e9
commit dac8f5ba3f
10 changed files with 262 additions and 166 deletions

View File

@@ -39,23 +39,20 @@ describe("block streaming", () => {
]);
});
async function waitForCalls(fn: () => number, calls: number) {
const deadline = Date.now() + 5000;
while (fn() < calls) {
if (Date.now() > deadline) {
throw new Error(`Expected ${calls} call(s), got ${fn()}`);
}
await new Promise((resolve) => setTimeout(resolve, 5));
}
}
it("waits for block replies before returning final payloads", async () => {
await withTempHome(async (home) => {
let releaseTyping: (() => void) | undefined;
const typingGate = new Promise<void>((resolve) => {
releaseTyping = resolve;
});
const onReplyStart = vi.fn(() => typingGate);
let resolveOnReplyStart: (() => void) | undefined;
const onReplyStartCalled = new Promise<void>((resolve) => {
resolveOnReplyStart = resolve;
});
const onReplyStart = vi.fn(() => {
resolveOnReplyStart?.();
return typingGate;
});
const onBlockReply = vi.fn().mockResolvedValue(undefined);
const impl = async (params: RunEmbeddedPiAgentParams) => {
@@ -95,7 +92,7 @@ describe("block streaming", () => {
},
);
await waitForCalls(() => onReplyStart.mock.calls.length, 1);
await onReplyStartCalled;
releaseTyping?.();
const res = await replyPromise;
@@ -110,7 +107,14 @@ describe("block streaming", () => {
const typingGate = new Promise<void>((resolve) => {
releaseTyping = resolve;
});
const onReplyStart = vi.fn(() => typingGate);
let resolveOnReplyStart: (() => void) | undefined;
const onReplyStartCalled = new Promise<void>((resolve) => {
resolveOnReplyStart = resolve;
});
const onReplyStart = vi.fn(() => {
resolveOnReplyStart?.();
return typingGate;
});
const seen: string[] = [];
const onBlockReply = vi.fn(async (payload) => {
seen.push(payload.text ?? "");
@@ -154,7 +158,7 @@ describe("block streaming", () => {
},
);
await waitForCalls(() => onReplyStart.mock.calls.length, 1);
await onReplyStartCalled;
releaseTyping?.();
const res = await replyPromise;