Files
plugins/packages/agent-console/test/v1/autoapproved-trace.test.ts
T
qingnian108 2c4e76dbba agent-console 1.3.1: 全部自动同意 (Auto-approve all), split out of #727 (#747)
Auto-approve all (全部自动同意) ships in agent-console 1.3.1, split out of #727 (qingnian108).

The mode is off by default. In it, Codex runs with its sandbox off and Claude Code skips its checks. Cursor, OpenCode and dsh requests are answered allow-once by the console, never allow_always or acceptForSession. Each auto answer is saved with `auto: true` before the Agent goes on, and a banner shows while the mode is on. Plan confirmations and questions still ask. A 1.2 默认 of 全部放行 is not silently upgraded to real auto-approve. Pi keeps the `default` mode id ("Pi never asks"), so switching Agents before the first message never carries auto-approve into an Agent the user didn't pick.

Reviewed at 7e55c87ca merged onto main 20b89389:
- Linux (WSL2 Ubuntu 24.04): root `bun test packages/agent-console` 6/6; `bun scripts/check.mjs` OK; `npm run check` OK; vitest 461 passed / 17 skipped; `verify:build` 5/5 identical.
- Windows 11 (Edge): `e2e:v1` 29/29.
- Linux e2e stops at scenario 5 (steer timeout). It does the same on main 1.3.0, so it was filed as #753.
- Broken by hand:
  - Pi's modeMap back to bypassPermissions: 2 tests red.
  - The keeps line shown for every Agent: 1 test red.
  - Pi's label branch removed: 1 test red.
- An earlier round at 049449612 on macOS checked the daemon behaviour with probes. This version is published from the dist branch; the package isn't on npm.
2026-11-05 14:02:29 +08:00

59 lines
3.7 KiB
TypeScript

// 1.3 全部自动同意 (#727 review item 2): auto-approvals are in the timeline and shown as one quiet foldable row per run
import { describe, it, expect } from "vitest";
import { foldTimeline } from "../../web/src/timeline/fold.js";
import { collectAutoApproved, approvalTarget, approvalChoice } from "../../web/src/timeline/autoApproved.js";
import { reduceTimeline, type DisplayItem } from "../../web/src/timeline/reducer.js";
type Ev = Record<string, unknown>;
let seq = 0;
const tl = (evs: Ev[]) => evs.map((e) => ({ seq: ++seq, ts: 0, threadId: "t", turnId: "u1", ...e })) as never[];
const tool = (itemId: string, kind: string, status: string): Ev => ({ type: "tool_call", itemId, kind, title: `${kind} ${itemId}`, status });
const opts = [{ id: "once", label: "允许一次", kind: "allow_once" }, { id: "always", label: "总是允许", kind: "allow_always" }, { id: "no", label: "拒绝", kind: "reject_once" }];
const autoReq = (id: string, command: string): Ev[] => [
{ type: "permission_request", requestId: id, title: `运行 ${command}`, kind: "tool", detail: { command }, options: opts, auto: true },
{ type: "permission_resolved", requestId: id, optionId: "once", auto: true },
];
const show = (evs: Ev[], status = "idle") => foldTimeline(collectAutoApproved(reduceTimeline(tl(evs), { runtimeStatus: status }).items));
const kinds = (items: DisplayItem[]) => items.map((i) => i.kind);
describe("auto-approved trace", () => {
it("a run's auto approvals become one row after the run, and don't break the tool summary", () => {
const items = show([
{ type: "user_message", text: "跑测试" },
tool("a", "bash", "running"), ...autoReq("r1", "npm test"), tool("a", "bash", "ok"),
tool("b", "bash", "running"), ...autoReq("r2", "git status"), tool("b", "bash", "ok"),
{ type: "assistant_message", itemId: "m", text: "好了" },
]);
expect(kinds(items)).toEqual(["user", "toolgroup", "autoperm", "assistant"]);
const g = items[1] as Extract<DisplayItem, { kind: "toolgroup" }>;
expect(g.steps.map((s) => s.itemId)).toEqual(["a", "b"]);
const a = items[2] as Extract<DisplayItem, { kind: "autoperm" }>;
expect(a.items.map(approvalTarget)).toEqual(["npm test", "git status"]);
expect(a.items.map(approvalChoice)).toEqual(["允许一次", "允许一次"]);
expect(a.items.every((p) => p.status === "resolved" && p.auto)).toBe(true);
});
it("a card the user answered stays a normal card; a card approved when the mode was switched on joins the row", () => {
const items = show([
tool("a", "bash", "running"),
{ type: "permission_request", requestId: "u1", title: "运行 rm x", kind: "tool", detail: { command: "rm x" }, options: opts },
{ type: "permission_resolved", requestId: "u1", optionId: "once" },
tool("b", "bash", "running"),
{ type: "permission_request", requestId: "w1", title: "运行 ls", kind: "tool", detail: { command: "ls" }, options: opts },
{ type: "permission_resolved", requestId: "w1", optionId: "once", auto: true },
]);
expect(kinds(items)).toEqual(["toolgroup", "permission", "toolgroup", "autoperm"]);
expect((items[3] as Extract<DisplayItem, { kind: "autoperm" }>).items[0]!.requestId).toBe("w1");
});
it("an auto request is never a pending card with buttons, even before its answer arrives", () => {
const items = show([tool("a", "bash", "running"), autoReq("r1", "make")[0]!], "running");
expect(kinds(items)).toEqual(["toolgroup", "autoperm"]);
});
it("nothing auto: the items are passed through untouched", () => {
const base = reduceTimeline(tl([{ type: "user_message", text: "x" }, tool("a", "read", "ok")]), { runtimeStatus: "idle" }).items;
expect(collectAutoApproved(base)).toBe(base);
});
});