Skip to content

Commit ca3d163

Browse files
author
Peter Steinberger
committed
test(system-agent): reuse CLI backend fixture
1 parent fbc45c9 commit ca3d163

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

‎src/system-agent/agent-turn.test.ts‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SystemAgentInferenceUnavailableError } from "./inference-error.js";
1616
import { resolveSystemAgentConfiguredRouteFromConfig } from "./inference-route.js";
1717
import {
1818
createSystemAgentVerifiedInferenceTestFixture,
19+
installSystemAgentClaudeCliBackendTestFixture,
1920
installSystemAgentPluginMetadataTestSnapshot,
2021
type SystemAgentPluginMetadataTestSnapshot,
2122
} from "./system-agent.test-helpers.js";
@@ -62,6 +63,7 @@ vi.mock("../config/config.js", async (importOriginal) => ({
6263
}));
6364

6465
const tempDirs: string[] = [];
66+
let restoreCliBackendFixture: (() => void) | undefined;
6567
let pluginMetadataSnapshot: SystemAgentPluginMetadataTestSnapshot | undefined;
6668

6769
function useTempStateDir(): string {
@@ -109,36 +111,12 @@ afterAll(() => {
109111
});
110112

111113
beforeEach(() => {
112-
// Core tests install a contract-level selectable backend instead of loading
113-
// a plugin's generated setup artifact from dist/.
114-
cliBackendsTesting.setDepsForTest({
115-
resolveRuntimeCliBackends: () => [
116-
{
117-
id: "claude-cli",
118-
pluginId: "anthropic",
119-
modelProvider: "anthropic",
120-
bundleMcp: true,
121-
bundleMcpMode: "claude-config-file",
122-
config: { command: "claude" },
123-
normalizeConfig: (config, context) => ({
124-
...config,
125-
args: [
126-
...(config.args ?? []),
127-
"--test-exec-policy",
128-
JSON.stringify(context?.config?.tools?.exec ?? null),
129-
],
130-
}),
131-
nativeToolMode: "selectable",
132-
toolAvailabilityEnforcement: "execution-args",
133-
sideQuestionToolMode: "disabled",
134-
resolveExecutionArgs: (context) => context.baseArgs,
135-
},
136-
],
137-
});
114+
restoreCliBackendFixture = installSystemAgentClaudeCliBackendTestFixture();
138115
});
139116

140117
afterEach(() => {
141-
cliBackendsTesting.resetDepsForTest();
118+
restoreCliBackendFixture?.();
119+
restoreCliBackendFixture = undefined;
142120
vi.unstubAllEnvs();
143121
pluginMetadataSnapshot?.rebindForCurrentEnv();
144122
vi.clearAllMocks();

‎src/system-agent/chat-engine.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { verifyConfigAfterSystemAgentWrite } from "./post-write-verification.js";
2828
import {
2929
createSystemAgentVerifiedInferenceTestFixture,
30+
installSystemAgentClaudeCliBackendTestFixture,
3031
installSystemAgentPluginMetadataTestSnapshot,
3132
type SystemAgentPluginMetadataTestSnapshot,
3233
} from "./system-agent.test-helpers.js";
@@ -3147,6 +3148,18 @@ describe("SystemAgentChatEngine", () => {
31473148
});
31483149

31493150
describe("OpenClaw agent loop backends", () => {
3151+
let restoreCliBackendFixture: (() => void) | undefined;
3152+
3153+
beforeAll(() => {
3154+
// These cases own chat routing and CLI session continuity. Anthropic setup tests own loading
3155+
// the generated backend artifact, so keep this integration on the same contract-level fixture.
3156+
restoreCliBackendFixture = installSystemAgentClaudeCliBackendTestFixture();
3157+
});
3158+
3159+
afterAll(() => {
3160+
restoreCliBackendFixture?.();
3161+
});
3162+
31503163
it("runs a configured claude-cli model through the CLI loop with the ring-zero MCP tool", async () => {
31513164
useTempStateDir();
31523165
const config = {

‎src/system-agent/system-agent.test-helpers.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from "vitest";
22
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
33
import { resolveCliBackendConfig } from "../agents/cli-backends.js";
4+
import { testing as cliBackendsTesting } from "../agents/cli-backends.test-support.js";
45
// OpenClaw test helpers build runtime environments for rescue tests.
56
import {
67
fingerprintAuthProfileOwnerShape,
@@ -37,6 +38,35 @@ export type SystemAgentPluginMetadataTestSnapshot = {
3738
restore: () => void;
3839
};
3940

41+
/** Install the contract-level selectable CLI backend used by core system-agent tests. */
42+
export function installSystemAgentClaudeCliBackendTestFixture(): () => void {
43+
cliBackendsTesting.setDepsForTest({
44+
resolveRuntimeCliBackends: () => [
45+
{
46+
id: "claude-cli",
47+
pluginId: "anthropic",
48+
modelProvider: "anthropic",
49+
bundleMcp: true,
50+
bundleMcpMode: "claude-config-file",
51+
config: { command: "claude" },
52+
normalizeConfig: (config, context) => ({
53+
...config,
54+
args: [
55+
...(config.args ?? []),
56+
"--test-exec-policy",
57+
JSON.stringify(context?.config?.tools?.exec ?? null),
58+
],
59+
}),
60+
nativeToolMode: "selectable",
61+
toolAvailabilityEnforcement: "execution-args",
62+
sideQuestionToolMode: "disabled",
63+
resolveExecutionArgs: (context) => context.baseArgs,
64+
},
65+
],
66+
});
67+
return () => cliBackendsTesting.resetDepsForTest();
68+
}
69+
4070
/** Install the process-stable plugin metadata snapshot that the real Gateway owns. */
4171
export function installSystemAgentPluginMetadataTestSnapshot(
4272
config: OpenClawConfig = {},

0 commit comments

Comments
 (0)