test: reduce agent hotspot overhead

This commit is contained in:
Peter Steinberger
2026-04-18 22:22:46 +01:00
parent 7bc3019691
commit daabd058fc
2 changed files with 23 additions and 27 deletions

View File

@@ -595,7 +595,7 @@ describe("exec approvals", () => {
security: "allowlist",
approvalRunningNoticeMs: 0,
});
const command = `${JSON.stringify(process.execPath)} --version`;
const command = "echo allow-always";
const first = await tool.execute("call-gateway-allow-always-initial", {
command,
@@ -607,13 +607,16 @@ describe("exec approvals", () => {
const approvalsPath = path.join(process.env.HOME ?? "", ".openclaw", "exec-approvals.json");
await expect
.poll(async () => {
const raw = await fs.readFile(approvalsPath, "utf8");
const parsed = JSON.parse(raw) as {
agents?: { main?: { allowlist?: Array<{ source?: string }> } };
};
return parsed.agents?.main?.allowlist?.some((entry) => entry.source === "allow-always");
})
.poll(
async () => {
const raw = await fs.readFile(approvalsPath, "utf8");
const parsed = JSON.parse(raw) as {
agents?: { main?: { allowlist?: Array<{ source?: string }> } };
};
return parsed.agents?.main?.allowlist?.some((entry) => entry.source === "allow-always");
},
{ timeout: 1_000, interval: 1 },
)
.toBe(true);
calls.length = 0;
@@ -929,7 +932,7 @@ describe("exec approvals", () => {
return "";
}
},
{ timeout: 5_000, interval: 50 },
{ timeout: 1_000, interval: 1 },
)
.toBe("ok");
});
@@ -977,7 +980,7 @@ describe("exec approvals", () => {
return "";
}
},
{ timeout: 5_000, interval: 50 },
{ timeout: 1_000, interval: 1 },
)
.toBe("ok");
});

View File

@@ -1,10 +1,7 @@
import type { AgentMessage } from "@mariozechner/pi-agent-core";
import { SessionManager } from "@mariozechner/pi-coding-agent";
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
buildSessionWriteLockModuleMock,
resetModulesWithSessionWriteLockDoMock,
} from "../../test-utils/session-write-lock-module-mock.js";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { buildSessionWriteLockModuleMock } from "../../test-utils/session-write-lock-module-mock.js";
const acquireSessionWriteLockReleaseMock = vi.hoisted(() => vi.fn(async () => {}));
const acquireSessionWriteLockMock = vi.hoisted(() =>
@@ -23,16 +20,6 @@ let rewriteTranscriptEntriesInSessionManager: typeof import("./transcript-rewrit
let onSessionTranscriptUpdate: typeof import("../../sessions/transcript-events.js").onSessionTranscriptUpdate;
let installSessionToolResultGuard: typeof import("../session-tool-result-guard.js").installSessionToolResultGuard;
async function loadFreshTranscriptRewriteModuleForTest() {
resetModulesWithSessionWriteLockDoMock("../session-write-lock.js", (params) =>
acquireSessionWriteLockMock(params),
);
({ onSessionTranscriptUpdate } = await import("../../sessions/transcript-events.js"));
({ installSessionToolResultGuard } = await import("../session-tool-result-guard.js"));
({ rewriteTranscriptEntriesInSessionFile, rewriteTranscriptEntriesInSessionManager } =
await import("./transcript-rewrite.js"));
}
type AppendMessage = Parameters<SessionManager["appendMessage"]>[0];
function asAppendMessage(message: unknown): AppendMessage {
@@ -142,10 +129,16 @@ function findAssistantEntryByText(sessionManager: SessionManager, text: string)
);
}
beforeEach(async () => {
beforeAll(async () => {
({ onSessionTranscriptUpdate } = await import("../../sessions/transcript-events.js"));
({ installSessionToolResultGuard } = await import("../session-tool-result-guard.js"));
({ rewriteTranscriptEntriesInSessionFile, rewriteTranscriptEntriesInSessionManager } =
await import("./transcript-rewrite.js"));
});
beforeEach(() => {
acquireSessionWriteLockMock.mockClear();
acquireSessionWriteLockReleaseMock.mockClear();
await loadFreshTranscriptRewriteModuleForTest();
});
describe("rewriteTranscriptEntriesInSessionManager", () => {