mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 18:34:33 +00:00
perf(test): preload runReplyAgent in typing heartbeat harness
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user