test: share agent command runtime fixture

This commit is contained in:
Peter Steinberger
2026-04-19 02:35:30 +01:00
parent b73103ab85
commit a4ac25972b
4 changed files with 16 additions and 21 deletions

View File

@@ -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<string, unknown>; 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<T>(fn: (home: string) => Promise<T>): Promise<T> {
return withTempHomeBase(fn, { prefix: "openclaw-agent-acp-" });

View File

@@ -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<T>(fn: (home: string) => Promise<T>): Promise<T> {
return withTempHomeBase(fn, { prefix: "openclaw-agent-" });

View File

@@ -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<T>(fn: (home: string) => Promise<T>): Promise<T> {
return withTempHomeBase(fn, { prefix: "openclaw-agent-", skipSessionCleanup: true });

View File

@@ -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");
}),
};
}