diff --git a/src/agents/bash-tools.exec.approval-id.test.ts b/src/agents/bash-tools.exec.approval-id.test.ts index 868715edf06..f339a5628cc 100644 --- a/src/agents/bash-tools.exec.approval-id.test.ts +++ b/src/agents/bash-tools.exec.approval-id.test.ts @@ -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"); }); diff --git a/src/agents/pi-embedded-runner/transcript-rewrite.test.ts b/src/agents/pi-embedded-runner/transcript-rewrite.test.ts index dbf3ab9335c..84cde33a15a 100644 --- a/src/agents/pi-embedded-runner/transcript-rewrite.test.ts +++ b/src/agents/pi-embedded-runner/transcript-rewrite.test.ts @@ -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[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", () => {