Skip to content

Commit ce35a26

Browse files
committed
test(system-agent): restore scoped CLI fixture and reuse suites
Keep delegated approval coverage inside existing suites without increasing shard or file-size limits. Restore the CLI backend fixture dropped when chat-engine tests were split, avoiding real plugin setup loading in routing and continuity tests.
1 parent 8e4edf8 commit ce35a26

3 files changed

Lines changed: 100 additions & 90 deletions

File tree

‎src/system-agent/chat-turn-router.approval.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import "./chat-engine.mocks.test-support.js";
22
import { describe, expect, it, vi } from "vitest";
3+
import { extractToolResultText } from "../agents/embedded-agent-tool-results.js";
4+
import { createSystemAgentTool } from "../agents/tools/system-agent-tool.js";
5+
import type { SystemAgentTurnRunner } from "./agent-turn.js";
36
import {
47
fakeOverviewLoader,
58
sharedVerifiedInference,
@@ -1048,4 +1051,67 @@ describe("SystemAgentChatEngine approval", () => {
10481051
expect(userTurns.some((text) => text.includes("very-secret"))).toBe(false);
10491052
expect(userTurns.some((text) => text.includes("<redacted secret>"))).toBe(true);
10501053
});
1054+
1055+
it("returns the delegated tool handoff through the engine without planner fallback", async () => {
1056+
const runAgentTurn = vi.fn<SystemAgentTurnRunner>(async (params) => {
1057+
const tool = createSystemAgentTool({
1058+
surface: params.surface,
1059+
approvalArmed: params.approvalArmed,
1060+
operatorApprovalOnly: params.operatorApprovalOnly,
1061+
proposalRef: params.session.proposalRef,
1062+
});
1063+
const result = await tool.execute("delegated-proposal", {
1064+
action: "config_set",
1065+
path: "agents.defaults.subagents.thinking",
1066+
value: "high",
1067+
});
1068+
return { text: extractToolResultText(result) ?? "" };
1069+
});
1070+
const planner = vi.fn(async () => {
1071+
throw new Error("planner must not run when the loop replies");
1072+
});
1073+
const engine = new SystemAgentChatEngine({
1074+
operatorApprovalOnly: true,
1075+
runAgentTurn,
1076+
planWithAssistant: planner,
1077+
deps: { loadOverview: fakeOverviewLoader() },
1078+
});
1079+
1080+
const reply = await engine.handle("switch the thinking level");
1081+
1082+
expect(runAgentTurn).toHaveBeenCalledOnce();
1083+
expect(planner).not.toHaveBeenCalled();
1084+
expect(reply.text).toContain("OpenClaw operator UI");
1085+
expect(reply.text).toContain("cannot be applied from this chat");
1086+
expect(reply.text).not.toContain("ask the user to reply yes");
1087+
expect(reply.action).toBe("none");
1088+
expect(engine.getPendingOperatorProposal()?.operation).toEqual({
1089+
kind: "config-set",
1090+
path: "agents.defaults.subagents.thinking",
1091+
value: "high",
1092+
});
1093+
});
1094+
1095+
it("tells delegated messaging users an approval can't be applied from chat", async () => {
1096+
const planner = vi.fn(async () => ({
1097+
reply: "Let's point your agent at gpt-5.5.",
1098+
command: "set default model openai/gpt-5.5",
1099+
modelLabel: "claude-cli",
1100+
}));
1101+
const engine = new SystemAgentChatEngine({
1102+
operatorApprovalOnly: true,
1103+
runAgentTurn: async () => null,
1104+
planWithAssistant: planner,
1105+
deps: { loadOverview: fakeOverviewLoader() },
1106+
});
1107+
1108+
const reply = await engine.handle("actually use an openai model");
1109+
1110+
expect(reply.text).toContain("cannot be applied from this chat");
1111+
expect(reply.text).toContain("OpenClaw operator UI");
1112+
expect(reply.text).toContain("Refused:");
1113+
expect(reply.text).toContain("was not applied from this chat");
1114+
expect(reply.text).not.toContain("Say yes to apply");
1115+
expect(engine.hasPendingProposal()).toBe(true);
1116+
});
10511117
});

‎src/system-agent/chat-turn-router.delegated-approval.test.ts‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎src/system-agent/chat-turn-router.operations.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "./chat-engine.mocks.test-support.js";
2-
import { describe, expect, it, vi } from "vitest";
2+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
33
import {
44
fakeOverviewLoader,
55
sharedVerifiedInference,
@@ -21,6 +21,7 @@ import {
2121
} from "./chat-engine.test-support.js";
2222
import { ChatTurnRouter } from "./chat-turn-router.js";
2323
import { ChatWizardHost } from "./chat-wizard-host.js";
24+
import { installSystemAgentClaudeCliBackendTestFixture } from "./system-agent.test-helpers.js";
2425

2526
const loggingMocks = vi.hoisted(() => ({ chatWarn: vi.fn() }));
2627

@@ -611,6 +612,38 @@ describe("SystemAgentChatEngine operations", () => {
611612
expect(resolveRepair).not.toHaveBeenCalled();
612613
});
613614

615+
it.each([
616+
["config set auth.profiles.invalid true", "Direct config writes cannot change"],
617+
[
618+
"config set agents.defaults.model.primary openai/gpt-5.6-luna",
619+
"Direct config writes cannot change",
620+
],
621+
])("rejects forbidden delegated plans before offering approval: %s", async (command, error) => {
622+
const engine = new SystemAgentChatEngine({
623+
operatorApprovalOnly: true,
624+
runAgentTurn: async () => null,
625+
planWithAssistant: async () => ({ command }),
626+
deps: { loadOverview: fakeOverviewLoader() },
627+
});
628+
629+
await expect(engine.handle("make the requested change")).rejects.toThrow(error);
630+
expect(engine.getPendingOperatorProposal()).toBeNull();
631+
});
632+
});
633+
634+
describe("SystemAgentChatEngine CLI loop backends", () => {
635+
let restoreCliBackendFixture: (() => void) | undefined;
636+
637+
beforeAll(() => {
638+
// These cases own routing and session continuity; plugin setup tests own
639+
// loading the generated backend artifact.
640+
restoreCliBackendFixture = installSystemAgentClaudeCliBackendTestFixture();
641+
});
642+
643+
afterAll(() => {
644+
restoreCliBackendFixture?.();
645+
});
646+
614647
it("runs a configured claude-cli model through the CLI loop with the ring-zero MCP tool", async () => {
615648
useTempStateDir();
616649
const config = {

0 commit comments

Comments
 (0)