perf(test): preload runReplyAgent in typing heartbeat harness

This commit is contained in:
Peter Steinberger
2026-02-14 21:01:26 +00:00
parent 32aea365ed
commit 7f660d59da

View File

@@ -1,4 +1,4 @@
import { beforeEach, vi } from "vitest"; import { beforeAll, beforeEach, vi } from "vitest";
import type { SessionEntry } from "../../config/sessions.js"; import type { SessionEntry } from "../../config/sessions.js";
import type { TypingMode } from "../../config/types.js"; import type { TypingMode } from "../../config/types.js";
import type { TemplateContext } from "../templating.js"; import type { TemplateContext } from "../templating.js";
@@ -14,11 +14,26 @@ const state = vi.hoisted(() => ({
runEmbeddedPiAgentMock: vi.fn(), runEmbeddedPiAgentMock: vi.fn(),
})); }));
let runReplyAgentPromise:
| Promise<(typeof import("./agent-runner.js"))["runReplyAgent"]>
| undefined;
async function getRunReplyAgent() {
if (!runReplyAgentPromise) {
runReplyAgentPromise = import("./agent-runner.js").then((m) => m.runReplyAgent);
}
return await runReplyAgentPromise;
}
export function getRunEmbeddedPiAgentMock(): AnyMock { export function getRunEmbeddedPiAgentMock(): AnyMock {
return state.runEmbeddedPiAgentMock; return state.runEmbeddedPiAgentMock;
} }
export function installRunReplyAgentTypingHeartbeatTestHooks() { export function installRunReplyAgentTypingHeartbeatTestHooks() {
beforeAll(async () => {
// Avoid attributing the initial agent-runner import cost to the first test case.
await getRunReplyAgent();
});
beforeEach(() => { beforeEach(() => {
state.runEmbeddedPiAgentMock.mockReset(); state.runEmbeddedPiAgentMock.mockReset();
}); });
@@ -103,7 +118,7 @@ export function createMinimalRun(params?: {
typing, typing,
opts, opts,
run: async () => { run: async () => {
const { runReplyAgent } = await import("./agent-runner.js"); const runReplyAgent = await getRunReplyAgent();
return runReplyAgent({ return runReplyAgent({
commandBody: "hello", commandBody: "hello",
followupRun, followupRun,