mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-15 15:13:48 -06:00
test(system-agent): reuse CLI backend fixture (#118541)
Co-authored-by: Peter Steinberger <steipete@mac-studio-sf2.local>
This commit is contained in:
committed by
GitHub
parent
fb692c47f2
commit
ad46acf102
@@ -16,6 +16,7 @@ import { SystemAgentInferenceUnavailableError } from "./inference-error.js";
|
||||
import { resolveSystemAgentConfiguredRouteFromConfig } from "./inference-route.js";
|
||||
import {
|
||||
createSystemAgentVerifiedInferenceTestFixture,
|
||||
installSystemAgentClaudeCliBackendTestFixture,
|
||||
installSystemAgentPluginMetadataTestSnapshot,
|
||||
type SystemAgentPluginMetadataTestSnapshot,
|
||||
} from "./system-agent.test-helpers.js";
|
||||
@@ -62,6 +63,7 @@ vi.mock("../config/config.js", async (importOriginal) => ({
|
||||
}));
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
let restoreCliBackendFixture: (() => void) | undefined;
|
||||
let pluginMetadataSnapshot: SystemAgentPluginMetadataTestSnapshot | undefined;
|
||||
|
||||
function useTempStateDir(): string {
|
||||
@@ -109,36 +111,12 @@ afterAll(() => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// Core tests install a contract-level selectable backend instead of loading
|
||||
// a plugin's generated setup artifact from dist/.
|
||||
cliBackendsTesting.setDepsForTest({
|
||||
resolveRuntimeCliBackends: () => [
|
||||
{
|
||||
id: "claude-cli",
|
||||
pluginId: "anthropic",
|
||||
modelProvider: "anthropic",
|
||||
bundleMcp: true,
|
||||
bundleMcpMode: "claude-config-file",
|
||||
config: { command: "claude" },
|
||||
normalizeConfig: (config, context) => ({
|
||||
...config,
|
||||
args: [
|
||||
...(config.args ?? []),
|
||||
"--test-exec-policy",
|
||||
JSON.stringify(context?.config?.tools?.exec ?? null),
|
||||
],
|
||||
}),
|
||||
nativeToolMode: "selectable",
|
||||
toolAvailabilityEnforcement: "execution-args",
|
||||
sideQuestionToolMode: "disabled",
|
||||
resolveExecutionArgs: (context) => context.baseArgs,
|
||||
},
|
||||
],
|
||||
});
|
||||
restoreCliBackendFixture = installSystemAgentClaudeCliBackendTestFixture();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cliBackendsTesting.resetDepsForTest();
|
||||
restoreCliBackendFixture?.();
|
||||
restoreCliBackendFixture = undefined;
|
||||
vi.unstubAllEnvs();
|
||||
pluginMetadataSnapshot?.rebindForCurrentEnv();
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import { verifyConfigAfterSystemAgentWrite } from "./post-write-verification.js";
|
||||
import {
|
||||
createSystemAgentVerifiedInferenceTestFixture,
|
||||
installSystemAgentClaudeCliBackendTestFixture,
|
||||
installSystemAgentPluginMetadataTestSnapshot,
|
||||
type SystemAgentPluginMetadataTestSnapshot,
|
||||
} from "./system-agent.test-helpers.js";
|
||||
@@ -3147,6 +3148,18 @@ describe("SystemAgentChatEngine", () => {
|
||||
});
|
||||
|
||||
describe("OpenClaw agent loop backends", () => {
|
||||
let restoreCliBackendFixture: (() => void) | undefined;
|
||||
|
||||
beforeAll(() => {
|
||||
// These cases own chat routing and CLI session continuity. Anthropic setup tests own loading
|
||||
// the generated backend artifact, so keep this integration on the same contract-level fixture.
|
||||
restoreCliBackendFixture = installSystemAgentClaudeCliBackendTestFixture();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
restoreCliBackendFixture?.();
|
||||
});
|
||||
|
||||
it("runs a configured claude-cli model through the CLI loop with the ring-zero MCP tool", async () => {
|
||||
useTempStateDir();
|
||||
const config = {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { expect } from "vitest";
|
||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { resolveCliBackendConfig } from "../agents/cli-backends.js";
|
||||
import { testing as cliBackendsTesting } from "../agents/cli-backends.test-support.js";
|
||||
// OpenClaw test helpers build runtime environments for rescue tests.
|
||||
import {
|
||||
fingerprintAuthProfileOwnerShape,
|
||||
@@ -37,6 +38,35 @@ export type SystemAgentPluginMetadataTestSnapshot = {
|
||||
restore: () => void;
|
||||
};
|
||||
|
||||
/** Install the contract-level selectable CLI backend used by core system-agent tests. */
|
||||
export function installSystemAgentClaudeCliBackendTestFixture(): () => void {
|
||||
cliBackendsTesting.setDepsForTest({
|
||||
resolveRuntimeCliBackends: () => [
|
||||
{
|
||||
id: "claude-cli",
|
||||
pluginId: "anthropic",
|
||||
modelProvider: "anthropic",
|
||||
bundleMcp: true,
|
||||
bundleMcpMode: "claude-config-file",
|
||||
config: { command: "claude" },
|
||||
normalizeConfig: (config, context) => ({
|
||||
...config,
|
||||
args: [
|
||||
...(config.args ?? []),
|
||||
"--test-exec-policy",
|
||||
JSON.stringify(context?.config?.tools?.exec ?? null),
|
||||
],
|
||||
}),
|
||||
nativeToolMode: "selectable",
|
||||
toolAvailabilityEnforcement: "execution-args",
|
||||
sideQuestionToolMode: "disabled",
|
||||
resolveExecutionArgs: (context) => context.baseArgs,
|
||||
},
|
||||
],
|
||||
});
|
||||
return () => cliBackendsTesting.resetDepsForTest();
|
||||
}
|
||||
|
||||
/** Install the process-stable plugin metadata snapshot that the real Gateway owns. */
|
||||
export function installSystemAgentPluginMetadataTestSnapshot(
|
||||
config: OpenClawConfig = {},
|
||||
|
||||
Reference in New Issue
Block a user