diff --git a/src/commands/agent.acp.test.ts b/src/commands/agent.acp.test.ts index 6903a040d7f..ac116d66652 100644 --- a/src/commands/agent.acp.test.ts +++ b/src/commands/agent.acp.test.ts @@ -10,6 +10,7 @@ import * as configIoModule from "../config/io.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import type { RuntimeEnv } from "../runtime.js"; import { agentCommand } from "./agent.js"; +import { createThrowingTestRuntime } from "./test-runtime-config-helpers.js"; const agentEventMocks = vi.hoisted(() => { type AgentEvent = { stream: string; data?: Record; runId?: string }; @@ -113,13 +114,7 @@ const loadConfigSpy = vi.spyOn(configIoModule, "loadConfig"); const runEmbeddedPiAgentSpy = vi.spyOn(embeddedModule, "runEmbeddedPiAgent"); const getAcpSessionManagerSpy = vi.spyOn(acpManagerModule, "getAcpSessionManager"); -const runtime: RuntimeEnv = { - log: vi.fn(), - error: vi.fn(), - exit: vi.fn(() => { - throw new Error("exit"); - }), -}; +const runtime = createThrowingTestRuntime(); async function withTempHome(fn: (home: string) => Promise): Promise { return withTempHomeBase(fn, { prefix: "openclaw-agent-acp-" }); diff --git a/src/commands/agent.runtime-config.test.ts b/src/commands/agent.runtime-config.test.ts index 88df3f8dd29..68995c26f0d 100644 --- a/src/commands/agent.runtime-config.test.ts +++ b/src/commands/agent.runtime-config.test.ts @@ -5,6 +5,7 @@ import { resolveAgentRuntimeConfig } from "../agents/agent-runtime-config.js"; import { resolveSession } from "../agents/command/session.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import type { RuntimeEnv } from "../runtime.js"; +import { createThrowingTestRuntime } from "./test-runtime-config-helpers.js"; type ConfigSnapshotForWrite = { snapshot: { valid: boolean; resolved: OpenClawConfig }; @@ -55,13 +56,7 @@ vi.mock("../cli/command-config-resolution.runtime.js", () => ({ resolveCommandConfigWithSecrets: resolveCommandConfigWithSecretsMock, })); -const runtime: RuntimeEnv = { - log: vi.fn(), - error: vi.fn(), - exit: vi.fn(() => { - throw new Error("exit"); - }), -}; +const runtime = createThrowingTestRuntime(); async function withTempHome(fn: (home: string) => Promise): Promise { return withTempHomeBase(fn, { prefix: "openclaw-agent-" }); diff --git a/src/commands/agent.test.ts b/src/commands/agent.test.ts index 198f4e884e2..609986caefa 100644 --- a/src/commands/agent.test.ts +++ b/src/commands/agent.test.ts @@ -19,6 +19,7 @@ import { } from "../infra/agent-events.js"; import type { RuntimeEnv } from "../runtime.js"; import { agentCommand, agentCommandFromIngress } from "./agent.js"; +import { createThrowingTestRuntime } from "./test-runtime-config-helpers.js"; const configIoMocks = vi.hoisted(() => ({ loadConfig: vi.fn(), @@ -223,13 +224,7 @@ vi.mock("../config/sessions/transcript-resolve.runtime.js", () => { }; }); -const runtime: RuntimeEnv = { - log: vi.fn(), - error: vi.fn(), - exit: vi.fn(() => { - throw new Error("exit"); - }), -}; +const runtime = createThrowingTestRuntime(); async function withTempHome(fn: (home: string) => Promise): Promise { return withTempHomeBase(fn, { prefix: "openclaw-agent-", skipSessionCleanup: true }); diff --git a/src/commands/test-runtime-config-helpers.ts b/src/commands/test-runtime-config-helpers.ts index e8bb67c3524..0ab88593e9b 100644 --- a/src/commands/test-runtime-config-helpers.ts +++ b/src/commands/test-runtime-config-helpers.ts @@ -29,3 +29,13 @@ export function createTestRuntime(): TestRuntime { exit, }; } + +export function createThrowingTestRuntime(): RuntimeEnv { + return { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(() => { + throw new Error("exit"); + }), + }; +}