@firstpick/pi-package-webui 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +34 -5
  2. package/bin/pi-webui.mjs +606 -102
  3. package/lib/component-update-state.mjs +126 -0
  4. package/lib/npm-command.mjs +81 -0
  5. package/lib/queue-mutation.mjs +6 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/workspace-files-live-watcher.mjs +138 -0
  8. package/package.json +8 -3
  9. package/public/app.js +4231 -376
  10. package/public/index.html +265 -52
  11. package/public/mobile-shell-state.mjs +166 -0
  12. package/public/service-worker.js +60 -13
  13. package/public/styles.css +1790 -383
  14. package/public/subagent-gate-visibility.mjs +16 -0
  15. package/public/subagent-launch-slot-state.mjs +16 -0
  16. package/public/transcript-renderer.mjs +433 -0
  17. package/tests/boot-failure-diagnostics.test.mjs +63 -5
  18. package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
  19. package/tests/browser/interaction-continuity.spec.mjs +897 -0
  20. package/tests/browser/mobile-foundation.spec.mjs +363 -0
  21. package/tests/browser/optimistic-prompt.spec.mjs +130 -0
  22. package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
  23. package/tests/browser/stats-overlay.spec.mjs +265 -0
  24. package/tests/chat-scroll-intent-static.test.mjs +6 -1
  25. package/tests/codex-fast-mode-static.test.mjs +8 -5
  26. package/tests/compact-sections-static.test.mjs +20 -2
  27. package/tests/compaction-mutation-contract.test.mjs +18 -4
  28. package/tests/compaction-static.test.mjs +1 -0
  29. package/tests/completion-signal-contract.test.mjs +13 -2
  30. package/tests/component-update-api-static.test.mjs +67 -0
  31. package/tests/component-update-state.test.mjs +80 -0
  32. package/tests/control-deck-component-updates-static.test.mjs +251 -0
  33. package/tests/fast-mode-client-static.test.mjs +7 -4
  34. package/tests/fixtures/fake-pi.mjs +305 -2
  35. package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
  36. package/tests/git-panel-gitignore-static.test.mjs +104 -0
  37. package/tests/http-endpoints-harness.test.mjs +228 -2
  38. package/tests/interaction-state-stability-static.test.mjs +271 -0
  39. package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
  40. package/tests/mobile-foundation-static.test.mjs +71 -0
  41. package/tests/mobile-phone-experience-static.test.mjs +65 -0
  42. package/tests/mobile-shell-state.test.mjs +69 -0
  43. package/tests/mobile-static.test.mjs +246 -39
  44. package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
  45. package/tests/native-parity-harness.test.mjs +2 -0
  46. package/tests/npm-command.test.mjs +64 -1
  47. package/tests/open-issue-wizard-static.test.mjs +2 -1
  48. package/tests/queue-edit-reorder-static.test.mjs +9 -1
  49. package/tests/queue-mutation-contract.test.mjs +22 -0
  50. package/tests/service-worker-lifecycle.test.mjs +120 -0
  51. package/tests/side-panel-section-reorder-static.test.mjs +68 -0
  52. package/tests/sse-backpressure-harness.test.mjs +137 -0
  53. package/tests/stats-dashboard-static.test.mjs +266 -0
  54. package/tests/streaming-ui-coupling.test.mjs +7 -1
  55. package/tests/subagent-gate-visibility.test.mjs +18 -2
  56. package/tests/subagent-launch-slot-state.test.mjs +32 -0
  57. package/tests/subagent-launch-slots-static.test.mjs +8 -2
  58. package/tests/subagents-helper.test.mjs +90 -0
  59. package/tests/terminal-tab-workspace-static.test.mjs +1 -1
  60. package/tests/update-commands.test.mjs +4 -0
  61. package/tests/workspace-files-live-updates-static.test.mjs +76 -0
  62. package/tests/workspace-files-live-watcher.test.mjs +95 -0
  63. package/webui-rpc-helper.mjs +175 -3
@@ -0,0 +1,363 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { createServer } from "node:net";
4
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { setTimeout as delay } from "node:timers/promises";
8
+ import { fileURLToPath } from "node:url";
9
+ import AxeBuilder from "@axe-core/playwright";
10
+ import { expect, test } from "@playwright/test";
11
+
12
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
13
+ const serverScript = join(root, "bin", "pi-webui.mjs");
14
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
15
+
16
+ async function freePort() {
17
+ const server = createServer();
18
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
19
+ const { port } = server.address();
20
+ await new Promise((resolve) => server.close(resolve));
21
+ return port;
22
+ }
23
+
24
+ let child;
25
+ let baseURL;
26
+ let tempRoot;
27
+ let output = "";
28
+
29
+ async function assertAxeClean(page, label, selector = "#mobileShellV2") {
30
+ const accessibility = await new AxeBuilder({ page }).include(selector).analyze();
31
+ const serious = accessibility.violations.filter((violation) => ["serious", "critical"].includes(violation.impact));
32
+ assert.deepEqual(serious, [], `${label} should not introduce serious/critical axe violations: ${serious.map((item) => item.id).join(", ")}`);
33
+ }
34
+
35
+ test.beforeAll(async () => {
36
+ const port = await freePort();
37
+ tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-mobile-browser-"));
38
+ await writeFile(join(tempRoot, "tablet-example.txt"), "tablet file viewer fixture\n", "utf8");
39
+ baseURL = `http://127.0.0.1:${port}`;
40
+ child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
41
+ stdio: ["ignore", "pipe", "pipe"],
42
+ env: {
43
+ ...process.env,
44
+ PI_WEBUI_RPC_SUPERVISOR: "0",
45
+ PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
46
+ PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
47
+ },
48
+ });
49
+ child.stdout.on("data", (chunk) => { output += String(chunk); });
50
+ child.stderr.on("data", (chunk) => { output += String(chunk); });
51
+ for (let attempt = 0; attempt < 80; attempt += 1) {
52
+ if (child.exitCode !== null) break;
53
+ try {
54
+ const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
55
+ if (response.ok) return;
56
+ } catch {
57
+ // Wait for the real server and fake Pi fixture to start.
58
+ }
59
+ await delay(100);
60
+ }
61
+ throw new Error(`Pi Web UI did not start:\n${output}`);
62
+ });
63
+
64
+ test.afterAll(async () => {
65
+ child?.kill("SIGTERM");
66
+ if (child) await new Promise((resolve) => child.once("exit", resolve));
67
+ await rm(tempRoot, { recursive: true, force: true });
68
+ });
69
+
70
+ test("v2 flag is isolated on desktop and rollback remains explicit", async ({ page }) => {
71
+ await page.setViewportSize({ width: 1440, height: 900 });
72
+ await page.goto(`${baseURL}/?mobileShell=v2`);
73
+ await expect(page.locator("#promptInput")).toBeVisible();
74
+ await expect(page.locator("html")).toHaveAttribute("data-mobile-shell", "v2");
75
+ await expect(page.locator(".layout")).toHaveCSS("grid-template-columns", /.+/);
76
+ await page.setViewportSize({ width: 390, height: 844 });
77
+ await page.goto(`${baseURL}/?mobileShell=legacy`);
78
+ await expect(page.locator("#promptInput")).toBeVisible();
79
+ await expect(page.locator("html")).not.toHaveAttribute("data-mobile-shell");
80
+ await page.evaluate(() => window.dispatchEvent(new PopStateEvent("popstate", {
81
+ state: {
82
+ piMobileShellV2: true,
83
+ mobileShellState: { featureMode: "v2", tabletFeatureMode: "v2", viewportMode: "phone", route: "sessions", surface: "none", routeHistory: ["chat"] },
84
+ },
85
+ })));
86
+ await expect(page.locator("html")).not.toHaveAttribute("data-mobile-shell");
87
+ await expect(page.locator("#mobileShellV2")).toBeHidden();
88
+ });
89
+
90
+ test("phone v2 destinations, canonical actions, history, and presentation remain functional", async ({ browser }) => {
91
+ const phoneContext = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
92
+ const page = await phoneContext.newPage();
93
+ await page.goto(`${baseURL}/?mobileShell=v2`);
94
+ await expect(page.locator("html")).toHaveAttribute("data-mobile-shell", "v2");
95
+ await expect(page.locator("#mobileShellV2")).toBeVisible();
96
+ for (const selector of ["#mobileSessionButton", "#mobileSearchButton", "#mobileMoreButton", "#attachButton", "#composerActionsButton", "#sendButton"]) {
97
+ const box = await page.locator(selector).boundingBox();
98
+ assert.ok(box, `${selector} should have a box`);
99
+ assert.ok(box.width >= 44 && box.height >= 44, `${selector} should meet the 44px target floor, got ${box.width}×${box.height}`);
100
+ }
101
+ const phoneNav = page.getByRole("navigation", { name: "Phone destinations" });
102
+ await expect(phoneNav.getByRole("button")).toHaveCount(4);
103
+ await expect(page.locator("#chat")).not.toHaveAttribute("aria-live");
104
+ await assertAxeClean(page, "phone Chat route");
105
+
106
+ await phoneNav.getByRole("button", { name: "Sessions", exact: true }).click();
107
+ await expect(page.locator("#mobileSessionsRoute")).toBeVisible();
108
+ await expect(page.locator("#mobileSessionsTitle")).toBeFocused();
109
+ await expect(page.locator(".layout")).toHaveAttribute("inert", "");
110
+ await expect(page.locator(".layout")).toHaveAttribute("aria-hidden", "true");
111
+ await expect(page.locator("#mobileShellDestination")).toHaveAttribute("role", "main");
112
+ await expect(page.locator("#mobileSessionsSearchInput")).toBeVisible();
113
+ await page.locator("#promptInput").evaluate((node) => { node.value = "draft survives switch"; node.dispatchEvent(new Event("input", { bubbles: true })); });
114
+ await page.locator("#mobileNewCurrentDirectoryButton").click();
115
+ await expect(page.locator(".mobile-session-select")).toHaveCount(2);
116
+ await page.locator(".mobile-session-select").first().click();
117
+ await expect(page.locator("#promptInput")).toHaveValue("draft survives switch");
118
+ await assertAxeClean(page, "phone Sessions route");
119
+
120
+ await phoneNav.getByRole("button", { name: "Activity", exact: true }).click();
121
+ await expect(page.locator("#mobileActivityRoute")).toBeVisible();
122
+ await expect(page.locator("#mobileActivityTitle")).toBeFocused();
123
+ await expect(page.locator("#mobileActivityStatus")).toBeVisible();
124
+ await assertAxeClean(page, "phone Activity route");
125
+ await phoneNav.getByRole("button", { name: "Project", exact: true }).click();
126
+ await expect(page.locator("#mobileProjectRoute")).toBeVisible();
127
+ await expect(page.locator("#mobileProjectTitle")).toBeFocused();
128
+ await page.getByRole("tab", { name: "Files" }).focus();
129
+ await page.keyboard.press("ArrowRight");
130
+ await expect(page.getByRole("tab", { name: "Git" })).toBeFocused();
131
+ await expect(page.getByRole("tab", { name: "Git" })).toHaveAttribute("aria-selected", "true");
132
+ await page.getByRole("tab", { name: "Files" }).click();
133
+ await expect(page.locator("#fileTreeRoot")).toBeVisible();
134
+ await page.getByRole("tab", { name: "Queue" }).click();
135
+ await expect(page.locator("#queueBox")).toBeVisible();
136
+ await assertAxeClean(page, "phone Project route");
137
+
138
+ await phoneNav.getByRole("button", { name: "Chat", exact: true }).click();
139
+ await page.locator("#composerActionsButton").focus();
140
+ await page.locator("#composerActionsButton").click();
141
+ await expect(page.locator("#mobileShellSurface")).toBeVisible();
142
+ await expect(page.locator("#mobileShellSurface")).toHaveAttribute("role", "dialog");
143
+ await expect(page.locator("#mobileShellSurface")).toHaveAttribute("aria-modal", "true");
144
+ await page.getByRole("button", { name: "Session actions" }).click();
145
+ await page.getByRole("button", { name: "Command palette", exact: true }).click();
146
+ await expect(page.locator("#commandPaletteDialog")).toBeVisible();
147
+ await page.keyboard.press("Escape");
148
+ await expect(page.locator("#commandPaletteDialog")).toBeHidden();
149
+ await expect(page.locator("#mobileShellSurface")).toBeVisible();
150
+ await expect(page.getByRole("heading", { name: "Session actions" })).toBeVisible();
151
+ await page.locator("#mobileSurfaceBackButton").click();
152
+ await page.getByRole("button", { name: "Voice" }).click();
153
+ await expect(page.getByRole("heading", { name: "Voice" })).toBeVisible();
154
+ await assertAxeClean(page, "phone action sheet");
155
+ await page.locator("#mobileSurfaceBackButton").click();
156
+ await page.locator("#mobileSurfaceCloseButton").click();
157
+ await expect(page.locator("#mobileShellSurface")).toBeHidden();
158
+ await expect(page.locator("#composerActionsButton")).toBeFocused();
159
+
160
+ await page.locator("#mobileMoreButton").click();
161
+ await page.getByRole("button", { name: "Settings" }).click();
162
+ await expect(page.locator("#modelSelect")).toBeVisible();
163
+ await page.locator("#thinkingSelect").focus();
164
+ await page.evaluate(() => window.dispatchEvent(new Event("online")));
165
+ await page.waitForTimeout(500);
166
+ await expect(page.locator("#thinkingSelect")).toBeFocused();
167
+ await page.locator("#mobileSurfaceBackButton").click();
168
+ await page.getByRole("button", { name: "Detailed" }).click();
169
+ await expect(page.locator("html")).toHaveAttribute("data-mobile-presentation", "detailed");
170
+ await assertAxeClean(page, "phone More/Settings surface");
171
+ await page.locator("#mobileSurfaceCloseButton").click();
172
+
173
+ await phoneNav.getByRole("button", { name: "Sessions", exact: true }).click();
174
+ await page.goBack();
175
+ await expect(phoneNav.getByRole("button", { name: "Chat", exact: true })).toHaveAttribute("aria-current", "page");
176
+ await page.setViewportSize({ width: 844, height: 390 });
177
+ await expect(page.locator("#mobileShellV2")).toBeVisible();
178
+
179
+ await assertAxeClean(page, "phone shell after history and rotation");
180
+ await phoneContext.close();
181
+ });
182
+
183
+ test("mobile continuity preserves drafts, restores metadata honestly, and retries only on command", async ({ browser }) => {
184
+ const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
185
+ const page = await context.newPage();
186
+ await page.goto(`${baseURL}/?mobileShell=v2`);
187
+ await page.locator("#promptInput").fill("offline continuity draft");
188
+ await page.locator("#attachmentInput").setInputFiles({ name: "context.txt", mimeType: "text/plain", buffer: Buffer.from("context") });
189
+ await expect(page.locator("#attachmentTray")).toContainText("context.txt");
190
+ await page.reload();
191
+ await expect(page.locator("#promptInput")).toHaveValue("offline continuity draft");
192
+ await expect(page.locator("#attachmentTray")).toContainText("Reselect required");
193
+
194
+ await page.locator("#attachButton").click();
195
+ await expect(page.getByRole("heading", { name: "Add Context" })).toBeVisible();
196
+ for (const name of ["Camera", "Photos", "Files"]) await expect(page.locator("#mobileSurfaceRoot").getByRole("button", { name, exact: true })).toBeVisible();
197
+ await expect(page.locator("#mobileSurfaceRoot").getByText("Paste text", { exact: true })).toBeVisible();
198
+ const pasteInput = page.locator(".mobile-paste-context-text");
199
+ const pasteDraft = Array.from({ length: 18 }, (_, index) => `pasted context line ${index}`).join("\n");
200
+ await pasteInput.fill(pasteDraft);
201
+ const pasteBefore = await pasteInput.evaluate((node) => {
202
+ node.focus();
203
+ node.setSelectionRange(14, 41, "backward");
204
+ node.scrollTop = 48;
205
+ return { value: node.value, selectionStart: node.selectionStart, selectionEnd: node.selectionEnd, selectionDirection: node.selectionDirection, scrollTop: node.scrollTop };
206
+ });
207
+ await page.evaluate(() => window.dispatchEvent(new Event("online")));
208
+ await expect(pasteInput).toBeFocused();
209
+ await expect.poll(() => pasteInput.evaluate((node) => ({
210
+ value: node.value,
211
+ selectionStart: node.selectionStart,
212
+ selectionEnd: node.selectionEnd,
213
+ selectionDirection: node.selectionDirection,
214
+ scrollTop: node.scrollTop,
215
+ }))).toEqual(pasteBefore);
216
+ await page.locator("#mobileSurfaceCloseButton").click();
217
+ await page.locator(".attachment-remove-button").click();
218
+
219
+ await context.setOffline(true);
220
+ await page.locator("#sendButton").click();
221
+ await expect(page.locator("#mobileFailedSendRecovery")).toBeVisible();
222
+ await expect(page.locator("#mobileFailedSendRecovery")).toContainText("never retry automatically");
223
+ await assertAxeClean(page, "failed-send recovery", "#mobileFailedSendRecovery");
224
+ await context.setOffline(false);
225
+ await page.locator("#mobileFailedSendRetryButton").click();
226
+ await expect(page.locator("#mobileFailedSendRecovery")).toBeHidden();
227
+
228
+ const tabsResponse = await page.request.get(`${baseURL}/api/tabs`);
229
+ const tabsPayload = await tabsResponse.json();
230
+ const tabId = tabsPayload.data.tabs[0].id;
231
+ await page.goto(`${baseURL}/?mobileShell=v2&mobileRoute=activity&tab=${encodeURIComponent(tabId)}`);
232
+ await expect(page.locator("#mobileActivityRoute")).toBeVisible();
233
+ await expect(page.locator("#mobileContinuityNotice")).toContainText("checking current server state");
234
+
235
+ await page.goto(`${baseURL}/?mobileShell=v2&mobileRoute=activity&tab=stale_tab_12345678`);
236
+ await expect(page.locator("#mobileContinuityNotice")).toContainText("no longer available");
237
+ await expect(page.locator("#mobileSessionsRoute")).toBeVisible();
238
+ await context.close();
239
+ });
240
+
241
+ test("an extension response clears stale local running state after canonical idle", async ({ page }) => {
242
+ await page.goto(baseURL);
243
+ await page.locator("#promptInput").fill("fixture mobile blocker");
244
+ await page.locator("#sendButton").click();
245
+ await expect(page.locator("#dialogTitle")).toHaveText("Fixture blocker");
246
+ await expect(page.locator("#chat .runIndicator")).toContainText("Waiting for your confirm response…");
247
+ await page.locator("#dialogActions").getByRole("button", { name: "Yes", exact: true }).click();
248
+ await expect(page.locator("#dialog")).not.toBeVisible();
249
+ await expect(page.locator("#chat .runIndicator")).toBeHidden({ timeout: 5_000 });
250
+ });
251
+
252
+ test("a blocker notification switches to its background tab before exact-target validation", async ({ browser }) => {
253
+ const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
254
+ const page = await context.newPage();
255
+ await page.goto(`${baseURL}/?mobileShell=v2`);
256
+ const initialTabs = await (await page.request.get(`${baseURL}/api/tabs`)).json();
257
+ const targetTabId = initialTabs.data.tabs[0].id;
258
+ await page.getByRole("button", { name: "Sessions", exact: true }).click();
259
+ await page.locator("#mobileNewCurrentDirectoryButton").click();
260
+ await expect(page.locator(".mobile-session-select")).toHaveCount(2);
261
+ const currentTabs = await (await page.request.get(`${baseURL}/api/tabs`)).json();
262
+ const activeTabId = currentTabs.data.activeTabId || currentTabs.data.tabs.find((tab) => tab.id !== targetTabId)?.id;
263
+ assert.notEqual(activeTabId, targetTabId, "fixture requires a different active tab");
264
+ const requestId = `fixture_request_${Date.now()}`;
265
+ const response = await page.request.post(`${baseURL}/api/prompt?tab=${encodeURIComponent(targetTabId)}`, { data: { message: "fixture mobile blocker", requestId } });
266
+ assert.equal(response.ok(), true);
267
+ await expect.poll(async () => {
268
+ const payload = await (await page.request.get(`${baseURL}/api/tabs`)).json();
269
+ return payload.data.tabs.find((tab) => tab.id === targetTabId)?.pendingExtensionUiRequestCount || 0;
270
+ }).toBe(1);
271
+ await page.evaluate(({ tabId }) => {
272
+ navigator.serviceWorker.dispatchEvent(new MessageEvent("message", {
273
+ data: { type: "pi-webui:navigate:v1", target: { v: 1, route: "activity", tabId, blockerId: "fixture_blocker_12345678" } },
274
+ }));
275
+ }, { tabId: targetTabId });
276
+ await expect(page.locator("#dialogTitle")).toHaveText("Fixture blocker");
277
+ await expect(page.locator("#mobileActivityRoute")).toBeVisible();
278
+ await expect(page.locator("#mobileContinuityNotice")).toContainText("Opened after reconnecting");
279
+ const cancel = await page.request.post(`${baseURL}/api/extension-ui-response?tab=${encodeURIComponent(targetTabId)}`, {
280
+ data: { id: "fixture_blocker_12345678", cancelled: true },
281
+ });
282
+ assert.equal(cancel.ok(), true);
283
+ await context.close();
284
+ });
285
+
286
+ test("tablet mode is independent, uses a rail and right inspector, and survives rotation and keyboard navigation", async ({ browser }) => {
287
+ const context = await browser.newContext({ viewport: { width: 820, height: 1180 }, hasTouch: true });
288
+ const page = await context.newPage();
289
+ await page.goto(`${baseURL}/?mobileShell=v2`);
290
+ await expect(page.locator("#mobileShellV2")).toBeHidden();
291
+
292
+ await page.goto(`${baseURL}/?tabletShell=v2`);
293
+ await expect(page.locator("html")).toHaveAttribute("data-tablet-shell", "v2");
294
+ await expect(page.locator("#mobileShellV2")).toBeVisible();
295
+ const rail = page.getByRole("navigation", { name: "Tablet destinations" });
296
+ await expect(rail).toBeVisible();
297
+ const railBox = await rail.boundingBox();
298
+ assert.ok(railBox && railBox.x === 0 && railBox.width >= 100 && railBox.width <= 120, `tablet rail geometry should remain stable, got ${JSON.stringify(railBox)}`);
299
+
300
+ await page.locator("#promptInput").fill("tablet rotation draft");
301
+ await rail.getByRole("button", { name: "Sessions", exact: true }).focus();
302
+ await page.keyboard.press("ArrowDown");
303
+ await expect(rail.getByRole("button", { name: "Activity", exact: true })).toBeFocused();
304
+ await rail.getByRole("button", { name: "Project", exact: true }).click();
305
+ await page.getByRole("tab", { name: "Files" }).click();
306
+ await expect(page.locator("#fileTreeRoot")).toBeVisible();
307
+ await page.locator('[role="treeitem"][data-path="tablet-example.txt"]').click();
308
+ await expect(page.locator("#fileViewerPane")).toBeVisible();
309
+ const fileBox = await page.locator("#fileViewerPane").boundingBox();
310
+ assert.ok(fileBox && fileBox.x === 0 && fileBox.y === 0 && fileBox.width === 820, `tablet file viewer must default to full-screen replacement, got ${JSON.stringify(fileBox)}`);
311
+ await page.locator("#fileViewerCloseButton").click();
312
+
313
+ await page.locator("#mobileMoreButton").click();
314
+ const inspectorBox = await page.locator("#mobileShellSurface").boundingBox();
315
+ assert.ok(inspectorBox && inspectorBox.width <= 480 && Math.abs(inspectorBox.x + inspectorBox.width - 820) <= 1, `tablet inspector must be a bounded right sheet, got ${JSON.stringify(inspectorBox)}`);
316
+ await page.setViewportSize({ width: 1024, height: 768 });
317
+ await expect(page.locator("#mobileShellSurface")).toBeVisible();
318
+ await page.locator("#mobileSurfaceCloseButton").click();
319
+ await rail.getByRole("button", { name: "Chat", exact: true }).click();
320
+ await expect(page.locator("#promptInput")).toHaveValue("tablet rotation draft");
321
+
322
+ for (const size of [{ width: 768, height: 1024 }, { width: 1024, height: 768 }]) {
323
+ await page.setViewportSize(size);
324
+ await expect(page.locator("#mobileShellV2")).toBeVisible();
325
+ }
326
+ await assertAxeClean(page, "tablet shell");
327
+
328
+ await page.goto(`${baseURL}/?tabletShell=legacy`);
329
+ await expect(page.locator("#mobileShellV2")).toBeHidden();
330
+ await context.close();
331
+ });
332
+
333
+ test("desktop remains equivalent at required viewport fixtures", async ({ page }) => {
334
+ for (const size of [{ width: 1280, height: 800 }, { width: 1440, height: 900 }, { width: 1920, height: 1080 }]) {
335
+ await page.setViewportSize(size);
336
+ await page.goto(`${baseURL}/?mobileShell=v2&tabletShell=v2`);
337
+ await expect(page.locator("#mobileShellV2")).toBeHidden();
338
+ await expect(page.locator("#promptInput")).toBeVisible();
339
+ await expect(page.locator(".terminal-tabs-shell")).toBeVisible();
340
+ await expect(page.locator(".side-panel")).toBeVisible();
341
+ }
342
+ });
343
+
344
+ test("desktop left-sidebar actions are compact accessible icon buttons", async ({ page }) => {
345
+ await page.setViewportSize({ width: 1440, height: 900 });
346
+ await page.goto(baseURL);
347
+ await page.locator("body").evaluate((body) => body.classList.add("terminal-tabs-left"));
348
+
349
+ const actions = page.locator(".terminal-sidebar-actions > button");
350
+ await expect(actions).toHaveCount(4);
351
+ const snapshots = await actions.evaluateAll((buttons) => buttons.map((button) => ({
352
+ text: button.textContent.trim(),
353
+ ariaLabel: button.getAttribute("aria-label"),
354
+ width: button.getBoundingClientRect().width,
355
+ height: button.getBoundingClientRect().height,
356
+ })));
357
+ for (const action of snapshots) {
358
+ assert.equal(action.text, "", "left-sidebar action buttons should not render visible text");
359
+ assert.ok(action.ariaLabel, "each icon-only action must retain an accessible name");
360
+ assert.ok(action.width >= 44 && action.height >= 44, `icon action must retain a 44px target, got ${action.width}×${action.height}`);
361
+ }
362
+ assert.ok(Math.max(...snapshots.map((action) => action.width)) - Math.min(...snapshots.map((action) => action.width)) <= 1, "icon actions should remain equal width");
363
+ });
@@ -0,0 +1,130 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createServer } from "node:net";
3
+ import { mkdtemp, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { setTimeout as delay } from "node:timers/promises";
7
+ import { fileURLToPath } from "node:url";
8
+ import { expect, test } from "@playwright/test";
9
+
10
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
11
+ const serverScript = join(root, "bin", "pi-webui.mjs");
12
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
13
+
14
+ async function freePort() {
15
+ const server = createServer();
16
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
17
+ const { port } = server.address();
18
+ await new Promise((resolve) => server.close(resolve));
19
+ return port;
20
+ }
21
+
22
+ let child;
23
+ let baseURL;
24
+ let tempRoot;
25
+ let output = "";
26
+
27
+ test.beforeAll(async () => {
28
+ const port = await freePort();
29
+ tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-optimistic-prompt-"));
30
+ baseURL = `http://127.0.0.1:${port}`;
31
+ child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ env: {
34
+ ...process.env,
35
+ PI_WEBUI_RPC_SUPERVISOR: "0",
36
+ PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
37
+ PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
38
+ FAKE_PI_CONTINUITY_MODE: "1",
39
+ },
40
+ });
41
+ child.stdout.on("data", (chunk) => { output += String(chunk); });
42
+ child.stderr.on("data", (chunk) => { output += String(chunk); });
43
+ for (let attempt = 0; attempt < 80; attempt += 1) {
44
+ if (child.exitCode !== null) break;
45
+ try {
46
+ const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
47
+ if (response.ok) return;
48
+ } catch {
49
+ // Wait for the isolated Web UI fixture.
50
+ }
51
+ await delay(100);
52
+ }
53
+ throw new Error(`Pi Web UI did not start:\n${output}`);
54
+ });
55
+
56
+ test.afterAll(async () => {
57
+ if (child?.exitCode === null) child.kill("SIGTERM");
58
+ if (child && child.exitCode === null) await new Promise((resolve) => child.once("exit", resolve));
59
+ await rm(tempRoot, { recursive: true, force: true });
60
+ });
61
+
62
+ test("submitted prompt remains visible during transcript reconciliation", async ({ page }) => {
63
+ const prompt = "optimistic prompt survives reconciliation";
64
+ await page.goto(baseURL);
65
+ await page.locator("#promptInput").fill(prompt);
66
+ await page.locator("#sendButton").click();
67
+
68
+ const visiblePrompt = page.locator("#chat .message.user", { hasText: prompt });
69
+ await expect(visiblePrompt).toHaveCount(1);
70
+ await expect(page.locator("#promptInput")).toHaveValue("");
71
+
72
+ // Changing transcript visibility forces the same keyed reconciliation used
73
+ // by message refreshes while the fake backend intentionally withholds a
74
+ // canonical user-message entry.
75
+ await page.keyboard.press("Control+t");
76
+
77
+ await expect(visiblePrompt).toHaveCount(1);
78
+ });
79
+
80
+ test("run indicator remains visible until delayed agent start is confirmed", async ({ page }) => {
81
+ const prompt = "fixture continuity delayed start";
82
+ await page.goto(baseURL);
83
+ await page.locator("#promptInput").fill(prompt);
84
+ await page.locator("#sendButton").click();
85
+
86
+ const runIndicator = page.locator("#chat .runIndicator");
87
+ await expect(runIndicator).toBeVisible();
88
+ await page.evaluate(() => {
89
+ window.__runIndicatorFrameGaps = 0;
90
+ window.__monitorRunIndicator = true;
91
+ const sample = () => {
92
+ if (!window.__monitorRunIndicator) return;
93
+ if (!document.querySelector("#chat .runIndicator")) window.__runIndicatorFrameGaps += 1;
94
+ requestAnimationFrame(sample);
95
+ };
96
+ requestAnimationFrame(sample);
97
+ });
98
+ await delay(3300);
99
+ await expect(runIndicator).toBeVisible();
100
+ await expect(runIndicator).toContainText("Agent is running:");
101
+ const frameGaps = await page.evaluate(() => {
102
+ window.__monitorRunIndicator = false;
103
+ return window.__runIndicatorFrameGaps;
104
+ });
105
+ expect(frameGaps).toBe(0);
106
+ await expect(page.locator("#chat .message.assistant").last()).toContainText("continuity stream complete");
107
+ });
108
+
109
+ test("confirmed streaming replaces routing status before delayed activity events", async ({ page }) => {
110
+ await page.goto(baseURL);
111
+ await page.locator("#promptInput").fill("fixture continuity confirmed before tool");
112
+ await page.locator("#sendButton").click();
113
+
114
+ const runIndicator = page.locator("#chat .runIndicator");
115
+ await expect(runIndicator).toContainText("Agent run confirmed; waiting for first output or action…");
116
+ await expect(runIndicator).not.toContainText(/Routing/i);
117
+ await expect(runIndicator).toContainText("Running tool: read…");
118
+ });
119
+
120
+ test("persisted user message replaces its optimistic bubble without duplication", async ({ page }) => {
121
+ const prompt = "fixture continuity delayed stream";
122
+ await page.goto(baseURL);
123
+ await page.locator("#promptInput").fill(prompt);
124
+ await page.locator("#sendButton").click();
125
+
126
+ const matchingPrompts = page.locator("#chat .message.user", { hasText: prompt });
127
+ await expect(matchingPrompts).toHaveCount(1);
128
+ await expect(page.locator("#chat .message.assistant").last()).toContainText("continuity stream complete");
129
+ await expect(matchingPrompts).toHaveCount(1);
130
+ });
@@ -0,0 +1,101 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createServer } from "node:net";
3
+ import { mkdtemp, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { setTimeout as delay } from "node:timers/promises";
7
+ import { fileURLToPath } from "node:url";
8
+ import { expect, test } from "@playwright/test";
9
+
10
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
11
+ const serverScript = join(root, "bin", "pi-webui.mjs");
12
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
13
+
14
+ async function freePort() {
15
+ const server = createServer();
16
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
17
+ const { port } = server.address();
18
+ await new Promise((resolve) => server.close(resolve));
19
+ return port;
20
+ }
21
+
22
+ let child;
23
+ let baseURL;
24
+ let tempRoot;
25
+ let output = "";
26
+
27
+ test.beforeAll(async () => {
28
+ const port = await freePort();
29
+ tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-side-panel-order-"));
30
+ baseURL = `http://127.0.0.1:${port}`;
31
+ child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ env: {
34
+ ...process.env,
35
+ PI_WEBUI_RPC_SUPERVISOR: "0",
36
+ PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
37
+ PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
38
+ },
39
+ });
40
+ child.stdout.on("data", (chunk) => { output += String(chunk); });
41
+ child.stderr.on("data", (chunk) => { output += String(chunk); });
42
+ for (let attempt = 0; attempt < 80; attempt += 1) {
43
+ if (child.exitCode !== null) break;
44
+ try {
45
+ const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
46
+ if (response.ok) return;
47
+ } catch {
48
+ // Wait for the real server and fake Pi fixture to start.
49
+ }
50
+ await delay(100);
51
+ }
52
+ throw new Error(`Pi Web UI did not start:\n${output}`);
53
+ });
54
+
55
+ test.afterAll(async () => {
56
+ child?.kill("SIGTERM");
57
+ if (child) await new Promise((resolve) => child.once("exit", resolve));
58
+ await rm(tempRoot, { recursive: true, force: true });
59
+ });
60
+
61
+ async function sectionOrder(page) {
62
+ return page.locator("#sidePanel .side-panel-body > [data-side-panel-section]").evaluateAll((sections) => (
63
+ sections.map((section) => section.dataset.sidePanelSection)
64
+ ));
65
+ }
66
+
67
+ test("Control Deck sections persist pointer and keyboard reordering", async ({ page }) => {
68
+ await page.setViewportSize({ width: 1440, height: 900 });
69
+ await page.goto(baseURL);
70
+ await expect(page.locator("#sidePanel")).toBeVisible();
71
+
72
+ const initialOrder = await sectionOrder(page);
73
+ expect(initialOrder.slice(0, 3)).toEqual(["controls", "files", "git"]);
74
+
75
+ const controls = page.locator('[data-side-panel-section-toggle="controls"]');
76
+ const git = page.locator('[data-side-panel-section-toggle="git"]');
77
+ const controlsBox = await controls.boundingBox();
78
+ const gitBox = await git.boundingBox();
79
+ expect(controlsBox).toBeTruthy();
80
+ expect(gitBox).toBeTruthy();
81
+ await page.mouse.move(controlsBox.x + controlsBox.width / 2, controlsBox.y + controlsBox.height / 2);
82
+ await page.mouse.down();
83
+ await page.mouse.move(controlsBox.x + controlsBox.width / 2, controlsBox.y + controlsBox.height / 2 + 12, { steps: 2 });
84
+ await page.mouse.move(gitBox.x + gitBox.width / 2, gitBox.y + gitBox.height - 4, { steps: 6 });
85
+ await page.mouse.up();
86
+
87
+ await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "git", "controls"]);
88
+ await expect.poll(async () => page.evaluate(() => JSON.parse(localStorage.getItem("pi-webui-side-panel-section-order-v1") || "[]").slice(0, 3))).toEqual(["files", "git", "controls"]);
89
+
90
+ await page.reload();
91
+ await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "git", "controls"]);
92
+
93
+ const movedControls = page.locator('[data-side-panel-section-toggle="controls"]');
94
+ await movedControls.focus();
95
+ await movedControls.press("Alt+ArrowUp");
96
+ await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "controls", "git"]);
97
+ await expect(movedControls).toBeFocused();
98
+
99
+ await page.reload();
100
+ await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "controls", "git"]);
101
+ });