Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(plan): qualify session permissions through native approval

Linuxdazhao2ddd1997a202
diff --git a/apps/desktop/electron/main/plan-ui-probe.ts b/apps/desktop/electron/main/plan-ui-probe.ts
index a007aed63..3302a3694 100644
--- a/apps/desktop/electron/main/plan-ui-probe.ts
+++ b/apps/desktop/electron/main/plan-ui-probe.ts
@@ -283,7 +283,7 @@ export function createPlanUiProbe(deps: PlanUiProbeDeps) {
);
const turnId = turnResponse?.turnId;
if (!turnId) throw new Error("session.beginTurn returned no turn");
- const toolCallId = `plan-ui-probe-${revision}`;
+ const toolCallId = `plan-ui-probe-${sessionId}-${revision}`;
const response = await activeHost.call<{
status?: string;
proposal?: Record<string, any> | null;
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index e7fc8e873..b6fe0e640 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -8618,8 +8618,16 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
approved execution emitted the exact durable marker, and a private
env-gated WeakMap check proved the same `DesktopAgentRuntime` object before
and after approval. Main/Host/sidecar PIDs remained stable; credentials never
- entered CDP or output. The default no-key run remains 5/5 with the live case
- explicitly skipped.
+ entered CDP or output. The no-key run also covers
+ `E2E-106-session-permissions`: eight native main-button/menu/rejection cases
+ verify explicit Ask/Accept edits/Auto, inherited global modes, ignored legacy
+ device history, durable Plan-to-Agent permission and renderer reload. Run
+ `node scripts/e2e-plan-ui.mjs --permissions-only` for this focused gate.
+ Each seeded Session owns a distinct probe tool-call identity. No provider is
+ configured for these cases; automatic execution reports the expected missing
+ provider while approval persistence is verified through the real Host.
+ The default no-key run has six required cases; the live case is explicitly
+ skipped.
#### E2E-CHAT-opaque-floating-decision-and-retry-surfaces: Dock, Plan approval, and retry surfaces occlude transcript text
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 3e44b643a..902a5db5a 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,14 @@
# 04. E2E 测试 Plan
+### E2E-106-session-permissions
+
+Run `node scripts/e2e-plan-ui.mjs --permissions-only` against the candidate
+Desktop and Host with isolated data and no provider. Eight native approval,
+menu, rejection and reload cases verify explicit Ask/Accept edits/Auto,
+inherited global permissions and ignored legacy device history. Each seeded
+Session owns a distinct probe tool-call identity. Approval persists through
+the real preload/Main/Host path; missing-provider execution is expected.
+
### E2E-FILE-INDEX-git-deadline
对真实测试文件调用 `getWorkspaceFileIndex` 和 `searchWorkspaceFiles`,
diff --git a/scripts/e2e-plan-ui.mjs b/scripts/e2e-plan-ui.mjs
index ca98d4674..9b409ae51 100644
--- a/scripts/e2e-plan-ui.mjs
+++ b/scripts/e2e-plan-ui.mjs
@@ -14,12 +14,15 @@ import { resolveHostBinary } from "./e2e/host.mjs";
const root = repositoryRoot();
const { appDir } = desktopPaths(root);
-const REQUIRED_CASE_IDS = [
+const PERMISSIONS_ONLY = process.argv.includes("--permissions-only");
+const PERMISSION_CASE_ID = "E2E-106-session-permissions";
+const REQUIRED_CASE_IDS = PERMISSIONS_ONLY ? [PERMISSION_CASE_ID] : [
"E2E-106-renderer",
"E2E-111-renderer",
"E2E-117-en",
"E2E-117-zh-CN",
"E2E-117-responsive",
+ PERMISSION_CASE_ID,
];
const LIVE_CASE_ID = "E2E-106-live-agent";
const LIVE_ENV_AVAILABLE = [
@@ -27,7 +30,7 @@ const LIVE_ENV_AVAILABLE = [
"PI_DESKTOP_TEST_BASE_URL",
"PI_DESKTOP_TEST_MODEL",
].every((name) => Boolean(process.env[name]?.trim()));
-const CASE_IDS = LIVE_ENV_AVAILABLE
+const CASE_IDS = LIVE_ENV_AVAILABLE && !PERMISSIONS_ONLY
? [...REQUIRED_CASE_IDS, LIVE_CASE_ID]
: REQUIRED_CASE_IDS;
@@ -1072,7 +1075,7 @@ async function submitPlan(state, sessionId, revision) {
assert(proposal.sessionId === sessionId, `proposal session mismatch: ${jsonText(proposal)}`);
assert(proposal.turnId === result.turnId, `proposal turn mismatch: ${jsonText(proposal)}`);
assert(
- proposal.toolCallId === `plan-ui-probe-${revision}`,
+ proposal.toolCallId === `plan-ui-probe-${sessionId}-${revision}`,
`proposal tool identity mismatch: ${jsonText(proposal)}`,
);
assert(proposal.markdown === checkpoint.markdown, "proposal Markdown is not byte-identical");
@@ -1271,6 +1274,61 @@ async function settleExpectedExecutionError(state) {
throw new Error(`unexpected visible execution error: ${snapshot.executionErrorText}`);
}
+async function runPermissionAcceptance(state) {
+ const cases = [
+ { permission: "auto", global: "ask", remembered: "ask", expected: "auto" },
+ { permission: "ask", global: "auto", remembered: "auto", expected: "ask" },
+ { permission: "accept-edits", global: "ask", remembered: "auto", expected: "accept-edits" },
+ { permission: "inherit", global: "auto", remembered: "ask", expected: "auto" },
+ { permission: "inherit", global: "accept-edits", remembered: "auto", expected: "accept-edits" },
+ { permission: "inherit", global: "ask", remembered: "auto", expected: "ask" },
+ { permission: "auto", global: "ask", remembered: "auto", expected: "auto", choice: "ask" },
+ { permission: "auto", global: "ask", remembered: "ask", expected: "auto", reject: true },
+ ];
+ for (const [index, scenario] of cases.entries()) {
+ const { defaultCommandShell: _shell, ...settings } = await getSettings(state);
+ await getPreloadResult(state, "settingsSet", [{ ...settings, defaultPermissionMode: scenario.global }]);
+ const { session } = await getPreloadResult(state, "sessionCreate", [{
+ title: `Permission acceptance ${index}`, mode: "agent", projectPath: state.workspace,
+ }]);
+ await getPreloadResult(state, "sessionConfigure", [session.id, {
+ mode: "agent", permissionMode: scenario.permission,
+ }]);
+ await getPreloadResult(state, "sessionConfigure", [session.id, { mode: "plan" }]);
+ await state.cdp.evaluate(`localStorage.setItem("pi.desktop.planApprovalMode", ${JSON.stringify(scenario.remembered)})`);
+ await reloadRenderer(state);
+ await selectSession(state, session.id);
+ const submitted = await submitPlan(state, session.id, "first");
+ await waitFor(async () => (await inspectUi(state)).bar?.status === "pending", "permission approval card", state);
+ const expectedLabel = {
+ ask: ["Ask", "每次询问"], "accept-edits": ["Accept edits", "自动接受编辑"], auto: ["Auto", "全自动"],
+ }[scenario.expected];
+ const snapshot = await inspectUi(state);
+ assert(expectedLabel.some(label => snapshot.bar.approveLabel?.includes(label)),
+ `case ${index}: approval default does not follow ${scenario.expected}: ${jsonText(snapshot.bar)}`);
+ const action = scenario.reject ? "reject" : "approve";
+ if (scenario.choice) {
+ await clickSelector(state, ".plan-approval-approve-menu", "explicit approval menu");
+ await clickSelector(state, `[data-approval-mode="${scenario.choice}"]`, "explicit Ask approval");
+ } else {
+ await clickSelector(state, scenario.reject ? ".plan-approval-reject" : ".plan-approval-approve-main", action);
+ }
+ const expectedPermission = scenario.reject ? scenario.permission : scenario.choice ?? scenario.expected;
+ await waitFor(async () => {
+ const current = await getSession(state, session.id);
+ return current?.mode === (scenario.reject ? "plan" : "agent") && current.permissionMode === expectedPermission;
+ }, `case ${index}: durable ${action} permission ${expectedPermission}`, state);
+ await settlePlanProbe(state, session.id, submitted.turnId, scenario.reject ? "aborted" : "completed");
+ await reloadRenderer(state);
+ await selectSession(state, session.id);
+ const restored = await getSession(state, session.id);
+ assert(restored.permissionMode === expectedPermission, `case ${index}: reload lost the permission`);
+ assert((await inspectUi(state)).bar === null, `case ${index}: reload restored a terminal approval`);
+ console.log(`PASS permission case ${index}: ${scenario.permission}/${scenario.global} -> ${expectedPermission} (${action})`);
+ }
+ record(PERMISSION_CASE_ID, true, "eight native approval/reload cases: explicit/inherited permissions, stale device history, override and rejection");
+}
+
async function runLiveAcceptance(state) {
const baselineFiles = await workspaceFiles(state.workspace);
const setup = await runPlanProbe(state, {
@@ -1448,6 +1506,11 @@ async function runAcceptance(state) {
await setViewport(state, 1280, 800);
await selectSession(state, state.sessionId);
+ if (PERMISSIONS_ONLY) {
+ await runPermissionAcceptance(state);
+ return;
+ }
+
const settings = await getSettings(state);
assert(settings.defaultMode === "agent", `new-session default is not Agent: ${jsonText(settings)}`);
// The shell no longer creates a session at boot (temporary chats start on
@@ -1605,6 +1668,8 @@ async function runAcceptance(state) {
"zh-CN labels, Ask default, terminal Agent state, pending-only reload hydration, and no stale actions verified",
);
+ await runPermissionAcceptance(state);
+
if (!LIVE_ENV_AVAILABLE) {
console.log(
`SKIP ${LIVE_CASE_ID} - set PI_DESKTOP_TEST_API_KEY, PI_DESKTOP_TEST_BASE_URL, and PI_DESKTOP_TEST_MODEL for the optional live acceptance case`,