mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
test: share agent command runtime fixture
This commit is contained in:
@@ -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-" });
|
||||
|
||||
@@ -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-" });
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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");
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user