Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
test(chat): drive the radial menu in Chromium
Linuxdazhao08ac3a611483
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 50f03091b..44b21f3e3 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -5262,8 +5262,10 @@ window; opening a normal panel afterward must still work.`04-ux/06-settings-ia.md`- **Acceptance**: C (chat stream), Quality- **Milestone**: M5-- **Status**: Unit-covered (`radial-menu.test.mjs`,- `settings-roundtrip.test.mjs`); full UI scenario Draft+- **Status**: Chromium component check (`node scripts/e2e-radial-menu.mjs`:+ sector labels, pointer highlight, click/hub/disabled/Escape paths, arrow-key+ focus, and viewport clamping) plus unit coverage (`radial-menu.test.mjs`,+ `settings-roundtrip.test.mjs`); full desktop journey Draft### E2E-CHAT-delete-turn-preserves-other-live-outputsdiff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex fef2f7000..aa91c4ea8 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@@ -2689,7 +2689,7 @@ MainChat 弥补了缺口。 Maximized/fullscreen 调用保留最新的- **关联规范**:`04-ux/09-interaction-patterns.md` §1.11、`04-ux/06-settings-ia.md`- **验收**:C(聊天流)、质量- **里程碑**:M5-- **状态**:单元覆盖(`radial-menu.test.mjs`、`settings-roundtrip.test.mjs`);完整 UI 场景草稿+- **状态**:Chromium 组件检查(`node scripts/e2e-radial-menu.mjs`:扇区文案、指针高亮、点击/中心圆/禁用/Escape 路径、方向键焦点和视口限制)加单元覆盖(`radial-menu.test.mjs`、`settings-roundtrip.test.mjs`);完整桌面旅程仍为草稿#### E2E-CHAT-delete-turn-preserves-other-live-outputs:删除回合后保留其他实时输出diff --git a/package.json b/package.jsonindex b91451644..5592e1d5d 100644--- a/package.json+++ b/package.json@@ -46,6 +46,7 @@"test:e2e:renderer-responsiveness": "node scripts/e2e-renderer-responsiveness.mjs","test:e2e:transcript-minimap-jump": "node scripts/e2e-transcript-minimap-jump.mjs","test:e2e:copy-tex": "node scripts/e2e-copy-tex.mjs",+ "test:e2e:radial-menu": "node scripts/e2e-radial-menu.mjs","test:e2e:transcript-disclosure": "node scripts/e2e-transcript-disclosure-anchor.mjs","test:e2e:images": "node scripts/e2e-image-generation.mjs && node scripts/e2e-image-generation-ui.mjs && node scripts/e2e-image-chat.mjs","test:e2e:provider-client-certificate": "node --test scripts/e2e/wait-for-child-exit.test.mjs && node scripts/e2e-provider-client-certificate.mjs",diff --git a/scripts/e2e-radial-menu.mjs b/scripts/e2e-radial-menu.mjsnew file mode 100755index 000000000..cbe01d893--- /dev/null+++ b/scripts/e2e-radial-menu.mjs@@ -0,0 +1,55 @@+#!/usr/bin/env node+// Real Chromium rendering of the radial menu component; no host or provider.+import { spawnSync } from "node:child_process";+import { createRequire } from "node:module";+import { mkdir, mkdtemp, writeFile } from "node:fs/promises";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { resolveElectronBinary } from "./e2e/boot.mjs";++const root = join(dirname(fileURLToPath(import.meta.url)), "..");+const desktop = join(root, "apps/desktop");+const require = createRequire(join(root, "packages/agent-runtime/package.json"));+const cache = join(root, ".cache/radial-menu");+await mkdir(cache, { recursive: true });+const temp = await mkdtemp(join(cache, "run-"));+await require("esbuild").build({+ entryPoints: [join(root, "scripts/e2e/radial-menu.tsx")],+ outfile: join(temp, "renderer.js"),+ bundle: true,+ platform: "browser",+ format: "iife",+ loader: { ".css": "empty" },+ jsx: "automatic",+ define: { "process.env.NODE_ENV": '"production"' },+ alias: {+ react: join(desktop, "node_modules/react"),+ "react-dom": join(desktop, "node_modules/react-dom"),+ },+ nodePaths: [join(desktop, "node_modules")],+});+await writeFile(+ join(temp, "index.html"),+ '<!doctype html><html><body style="margin:0"><script src="renderer.js"></script></body></html>',+);+await writeFile(+ join(temp, "main.cjs"),+ `+const {app,BrowserWindow}=require('electron');+app.setPath('userData',require('node:path').join(__dirname,'profile'));+app.disableHardwareAcceleration();+app.whenReady().then(async()=>{+ try {+ const win=new BrowserWindow({show:false,width:900,height:700,webPreferences:{backgroundThrottling:false,sandbox:true,contextIsolation:true}});+ await win.loadFile(require('node:path').join(__dirname,'index.html'));+ console.log(await win.webContents.executeJavaScript('globalThis.radialMenuProbe()'));+ app.exit(0);+ } catch(error) { console.error(error); app.exit(1); }+});`,+);+const result = spawnSync(resolveElectronBinary(root).electronBinary, [join(temp, "main.cjs")], {+ stdio: "inherit",+ timeout: 30000,+});+if (result.error) throw result.error;+process.exitCode = result.status ?? 1;diff --git a/scripts/e2e/radial-menu.tsx b/scripts/e2e/radial-menu.tsxnew file mode 100644index 000000000..10f178f49--- /dev/null+++ b/scripts/e2e/radial-menu.tsx@@ -0,0 +1,179 @@+import React from "react";+import { createRoot } from "react-dom/client";+import { flushSync } from "react-dom";+import { RadialMenu, type RadialMenuSlot } from "../../apps/desktop/src/components/RadialMenu";++const check = (ok: boolean, label: string) => {+ if (!ok) throw new Error(label);+};+const settle = () => {+ const { promise, resolve } = Promise.withResolvers<void>();+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));+ return promise;+};++const RING = 320;+const CENTER = 160;+const ITEM_RADIUS = 108;++type ProbeState = {+ calls: string[];+ closes: number;+ disabledCalls: string[];+};++const state: ProbeState = { calls: [], closes: 0, disabledCalls: [] };++const items = (disabledLeft = false): RadialMenuSlot[] => [+ { id: "up", label: "Copy conversation", icon: <span>U</span>, onSelect: () => state.calls.push("up") },+ { id: "right", label: "Select text", icon: <span>R</span>, onSelect: () => state.calls.push("right") },+ { id: "down", label: "Jump to latest", icon: <span>D</span>, onSelect: () => state.calls.push("down") },+ {+ id: "left",+ label: "Leave empty",+ icon: <span>L</span>,+ disabled: disabledLeft,+ onSelect: () => state.disabledCalls.push("left"),+ },+];++function Probe({ disabledLeft }: { disabledLeft: boolean }) {+ const [open, setOpen] = React.useState(true);+ return open ? (+ <RadialMenu+ point={{ x: 420, y: 340 }}+ items={items(disabledLeft)}+ label="Transcript ring"+ onClose={() => {+ state.closes += 1;+ setOpen(false);+ }}+ />+ ) : (+ <div id="ring-closed" />+ );+}++const mount = (disabledLeft = false) => {+ document.body.replaceChildren();+ const host = document.createElement("div");+ document.body.append(host);+ const root = createRoot(host);+ flushSync(() => root.render(<Probe disabledLeft={disabledLeft} />));+ const menu = document.querySelector<HTMLElement>(".radial-menu");+ check(!!menu, "ring did not mount");+ return menu as HTMLElement;+};++const pointFor = (menu: HTMLElement, degrees: number) => {+ const rect = menu.getBoundingClientRect();+ const x = rect.left + CENTER + Math.cos((degrees * Math.PI) / 180) * ITEM_RADIUS;+ const y = rect.top + CENTER + Math.sin((degrees * Math.PI) / 180) * ITEM_RADIUS;+ return { x, y };+};++const pointerMove = async (menu: HTMLElement, degrees: number) => {+ const { x, y } = pointFor(menu, degrees);+ flushSync(() =>+ menu.dispatchEvent(+ new PointerEvent("pointermove", { bubbles: true, clientX: x, clientY: y }),+ ),+ );+ await settle();+};++const clickAt = async (menu: HTMLElement, degrees: number | "hub") => {+ const rect = menu.getBoundingClientRect();+ const { x, y } =+ degrees === "hub"+ ? { x: rect.left + CENTER, y: rect.top + CENTER }+ : pointFor(menu, degrees);+ flushSync(() =>+ menu.dispatchEvent(+ new MouseEvent("click", { bubbles: true, cancelable: true, clientX: x, clientY: y }),+ ),+ );+ await settle();+};++Object.assign(globalThis, {+ radialMenuProbe: async () => {+ // 1. Four sectors render with their labels.+ let menu = mount();+ const labels = [...menu.querySelectorAll(".radial-menu-label")].map((node) => node.textContent);+ check(labels.join("|") === "Copy conversation|Select text|Jump to latest|Leave empty", `labels: ${labels.join("|")}`);+ check(menu.querySelectorAll(".radial-menu-item").length === 4, "expected four item buttons");++ // 2. The sector under the pointer highlights.+ await pointerMove(menu, 0);+ check(menu.querySelector(".radial-menu-sector.is-active") !== null, "no sector highlighted at 0°");+ check(menu.querySelectorAll(".radial-menu-sector.is-active").length === 1, "more than one sector highlighted");++ // 3. Clicking the sector runs it and closes the ring.+ await clickAt(menu, 0);+ check(state.calls.join("|") === "right", `click ran ${state.calls.join("|")}`);+ check(document.getElementById("ring-closed") !== null, "ring stayed mounted after running an item");++ // 4. A click on the hub closes without running anything.+ const before = state.calls.length;+ menu = mount();+ await clickAt(menu, "hub");+ check(state.calls.length === before, "hub click ran an action");+ check(document.getElementById("ring-closed") !== null, "hub click did not close the ring");++ // 5. A disabled direction stays open and runs nothing.+ const closesBefore = state.closes;+ menu = mount(true);+ await clickAt(menu, 180);+ check(state.disabledCalls.length === 0, "disabled sector ran its action");+ check(state.closes === closesBefore, "disabled sector closed the ring");+ check(document.querySelector(".radial-menu") !== null, "disabled sector removed the ring");++ // 6. Arrow keys move the highlight and Enter activates the focused slot.+ const buttons = [...menu.querySelectorAll<HTMLButtonElement>(".radial-menu-item")];+ buttons[0]?.focus();+ flushSync(() =>+ buttons[0]?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true })),+ );+ await settle();+ const focused = document.activeElement as HTMLButtonElement | null;+ check(focused?.className.includes("radial-menu-item") === true, "arrow key did not move focus");+ check(focused?.textContent?.includes("Select text") === true, `arrow key landed on ${focused?.textContent}`);+ flushSync(() => focused?.click());+ await settle();+ check(state.calls.at(-1) === "right", `Enter path ran ${state.calls.at(-1)}`);++ // 7. Escape closes the ring.+ menu = mount();+ flushSync(() =>+ window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })),+ );+ await settle();+ check(document.querySelector(".radial-menu") === null, "Escape did not close the ring");++ // 8. The ring is clamped inside a small viewport.+ document.body.replaceChildren();+ const host = document.createElement("div");+ document.body.append(host);+ const root = createRoot(host);+ flushSync(() =>+ root.render(+ <RadialMenu+ point={{ x: window.innerWidth - 4, y: window.innerHeight - 4 }}+ items={items()}+ label="Edge ring"+ onClose={() => {}}+ />,+ ),+ );+ const edge = document.querySelector<HTMLElement>(".radial-menu");+ check(!!edge, "edge ring did not mount");+ const rect = (edge as HTMLElement).getBoundingClientRect();+ check(+ rect.right <= window.innerWidth && rect.bottom <= window.innerHeight && rect.width === RING,+ `edge ring escaped the viewport: ${JSON.stringify({ right: rect.right, bottom: rect.bottom, width: rect.width })}`,+ );++ return `radial menu ok: ${state.calls.join(",")} | closes=${state.closes}`;+ },+});