@firstpick/pi-package-webui 0.8.1 → 0.8.3
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.
- package/README.md +21 -3
- package/bin/pi-webui.mjs +287 -32
- package/lib/component-update-state.mjs +126 -0
- package/lib/git-workflow-preferences.mjs +246 -19
- package/lib/thinking-stream-recovery.mjs +156 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/lib/ui-layout-settings.mjs +254 -0
- package/package.json +5 -3
- package/public/app.js +3072 -142
- package/public/index.html +188 -39
- package/public/service-worker.js +1 -1
- package/public/styles.css +1091 -39
- package/tests/boot-failure-diagnostics.test.mjs +63 -5
- package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
- package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
- package/tests/browser/interaction-continuity.spec.mjs +187 -0
- package/tests/browser/mobile-foundation.spec.mjs +11 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
- package/tests/browser/stats-overlay.spec.mjs +265 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/component-update-api-static.test.mjs +67 -0
- package/tests/component-update-state.test.mjs +80 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +63 -0
- package/tests/control-deck-component-updates-static.test.mjs +251 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +172 -0
- package/tests/fixtures/fake-pi.mjs +180 -6
- package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
- package/tests/git-workflow-preferences.test.mjs +4 -2
- package/tests/http-endpoints-harness.test.mjs +88 -1
- package/tests/interaction-state-stability-static.test.mjs +24 -4
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +6 -4
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +34 -16
- package/tests/native-parity-harness.test.mjs +2 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +267 -0
- package/tests/questionnaire-dialog.test.mjs +511 -0
- package/tests/queue-edit-reorder-static.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +1 -0
- package/tests/side-panel-section-reorder-static.test.mjs +68 -0
- package/tests/sse-backpressure-harness.test.mjs +51 -12
- package/tests/stats-dashboard-static.test.mjs +266 -0
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/thinking-stream-recovery.test.mjs +88 -0
- package/tests/ui-layout-settings.test.mjs +92 -0
- package/tests/webui-settings-locking.test.mjs +159 -0
|
@@ -48,7 +48,15 @@ class FakeResponse {
|
|
|
48
48
|
async json() { return this._json; }
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function makeEnvironment({
|
|
51
|
+
function makeEnvironment({
|
|
52
|
+
importApp,
|
|
53
|
+
stylesheetLoaded = true,
|
|
54
|
+
stylesheetStatus = 200,
|
|
55
|
+
workflowModuleStatus = 404,
|
|
56
|
+
manifestStatus = 200,
|
|
57
|
+
manifestText = '{"name":"Pi Web UI"}',
|
|
58
|
+
hangingHealth = false,
|
|
59
|
+
} = {}) {
|
|
52
60
|
const elements = {
|
|
53
61
|
panel: new FakeElement({ hidden: true }),
|
|
54
62
|
reason: new FakeElement(),
|
|
@@ -57,7 +65,7 @@ function makeEnvironment({ importApp, stylesheetLoaded = true, stylesheetStatus
|
|
|
57
65
|
reload: new FakeElement(),
|
|
58
66
|
copyStatus: new FakeElement(),
|
|
59
67
|
};
|
|
60
|
-
const styleLink = new FakeElement({ href: "http://127.0.0.1:31415/styles.css?v=
|
|
68
|
+
const styleLink = new FakeElement({ href: "http://127.0.0.1:31415/styles.css?v=98", sheet: stylesheetLoaded ? {} : null });
|
|
61
69
|
const listeners = new Map();
|
|
62
70
|
const timers = new Map();
|
|
63
71
|
let timerId = 0;
|
|
@@ -76,7 +84,7 @@ function makeEnvironment({ importApp, stylesheetLoaded = true, stylesheetStatus
|
|
|
76
84
|
removeEventListener(name) { listeners.delete(name); },
|
|
77
85
|
};
|
|
78
86
|
const document = {
|
|
79
|
-
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=
|
|
87
|
+
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=112" } }),
|
|
80
88
|
readyState: "complete",
|
|
81
89
|
querySelector(selector) {
|
|
82
90
|
return {
|
|
@@ -94,10 +102,14 @@ function makeEnvironment({ importApp, stylesheetLoaded = true, stylesheetStatus
|
|
|
94
102
|
|
|
95
103
|
async function fetch(input) {
|
|
96
104
|
const url = String(input);
|
|
97
|
-
if (url.includes("/api/health"))
|
|
105
|
+
if (url.includes("/api/health")) {
|
|
106
|
+
if (hangingHealth) return new Promise(() => {});
|
|
107
|
+
return new FakeResponse(url, 200, { type: "application/json", json: { ok: true, webuiVersion: "0.7.6", remoteAuthPin: "1234" } });
|
|
108
|
+
}
|
|
98
109
|
if (url.includes("/app.js")) return new FakeResponse(url, 200, { type: "text/javascript", text: 'import "./workflow-status-stack.mjs";\nimport "./fast-output-live.mjs";' });
|
|
99
110
|
if (url.includes("workflow-status-stack.mjs")) return new FakeResponse(url, workflowModuleStatus, { type: workflowModuleStatus === 200 ? "text/javascript" : "application/json" });
|
|
100
111
|
if (url.includes("fast-output-live.mjs")) return new FakeResponse(url, 200, { type: "text/javascript" });
|
|
112
|
+
if (url.includes("manifest.webmanifest")) return new FakeResponse(url, manifestStatus, { type: manifestStatus === 200 ? "application/manifest+json" : "text/html", text: manifestText });
|
|
101
113
|
if (url.includes("styles.css")) return new FakeResponse(url, stylesheetStatus, { type: "text/css" });
|
|
102
114
|
return new FakeResponse(url, 404);
|
|
103
115
|
}
|
|
@@ -124,6 +136,12 @@ function makeEnvironment({ importApp, stylesheetLoaded = true, stylesheetStatus
|
|
|
124
136
|
elements,
|
|
125
137
|
listeners,
|
|
126
138
|
timers,
|
|
139
|
+
fireTimers() {
|
|
140
|
+
for (const [id, callback] of [...timers]) {
|
|
141
|
+
timers.delete(id);
|
|
142
|
+
callback();
|
|
143
|
+
}
|
|
144
|
+
},
|
|
127
145
|
copied: () => copied,
|
|
128
146
|
reloaded: () => reloaded,
|
|
129
147
|
};
|
|
@@ -168,13 +186,53 @@ await settleAsyncWork();
|
|
|
168
186
|
assert.equal(stylesheetFailure.elements.panel.hidden, false, "a missing critical stylesheet should expose the boot-failure panel");
|
|
169
187
|
assert.match(stylesheetFailure.elements.report.value, /Critical stylesheet returned HTTP 404/);
|
|
170
188
|
|
|
189
|
+
const syntaxFailureWithManifestNoise = makeEnvironment({
|
|
190
|
+
importApp: async () => {
|
|
191
|
+
const error = new Error("Unexpected token '}'");
|
|
192
|
+
error.name = "SyntaxError";
|
|
193
|
+
throw error;
|
|
194
|
+
},
|
|
195
|
+
workflowModuleStatus: 200,
|
|
196
|
+
manifestText: "<!doctype html><title>wrong response</title>",
|
|
197
|
+
});
|
|
198
|
+
vm.runInNewContext(loaderSource, syntaxFailureWithManifestNoise.context, { filename: "webui-boot-loader.js" });
|
|
199
|
+
await settleAsyncWork();
|
|
200
|
+
assert.match(syntaxFailureWithManifestNoise.elements.reason.textContent, /JavaScript failed during startup: SyntaxError: Unexpected token/);
|
|
201
|
+
assert.match(syntaxFailureWithManifestNoise.elements.report.value, /entry module: HTTP 200 text\/javascript/);
|
|
202
|
+
assert.match(syntaxFailureWithManifestNoise.elements.report.value, /optional web manifest: HTTP 200 application\/manifest\+json.*invalid JSON/);
|
|
203
|
+
assert.match(syntaxFailureWithManifestNoise.elements.report.value, /web manifest has a separate problem.*does not execute or block app\.js startup/i, "manifest parse noise should be identified as non-blocking");
|
|
204
|
+
|
|
205
|
+
const stalledBoot = makeEnvironment({
|
|
206
|
+
importApp: async () => new Promise(() => {}),
|
|
207
|
+
workflowModuleStatus: 200,
|
|
208
|
+
});
|
|
209
|
+
vm.runInNewContext(loaderSource, stalledBoot.context, { filename: "webui-boot-loader.js" });
|
|
210
|
+
stalledBoot.fireTimers();
|
|
211
|
+
await settleAsyncWork();
|
|
212
|
+
assert.match(stalledBoot.elements.reason.textContent, /WebUI startup stalled even though the current HTTP checks succeeded/);
|
|
213
|
+
assert.match(stalledBoot.elements.report.value, /Error: Error: Startup watchdog timed out/);
|
|
214
|
+
|
|
215
|
+
const hangingDiagnostic = makeEnvironment({
|
|
216
|
+
importApp: async () => { throw new Error("Startup module failed before diagnostics"); },
|
|
217
|
+
workflowModuleStatus: 200,
|
|
218
|
+
hangingHealth: true,
|
|
219
|
+
});
|
|
220
|
+
vm.runInNewContext(loaderSource, hangingDiagnostic.context, { filename: "webui-boot-loader.js" });
|
|
221
|
+
await settleAsyncWork();
|
|
222
|
+
hangingDiagnostic.fireTimers();
|
|
223
|
+
await settleAsyncWork();
|
|
224
|
+
assert.equal(hangingDiagnostic.elements.panel.hidden, false, "the failure panel should remain usable while a diagnostic request hangs");
|
|
225
|
+
assert.doesNotMatch(hangingDiagnostic.elements.report.value, /Collecting diagnostics/, "bounded probes must always replace the collecting placeholder");
|
|
226
|
+
assert.match(hangingDiagnostic.elements.reason.textContent, /diagnostic check timed out while probing \/api\/health/i);
|
|
227
|
+
assert.match(hangingDiagnostic.elements.report.value, /backend health: diagnostic timed out after 3 seconds/);
|
|
228
|
+
|
|
171
229
|
const startupModuleNames = [...new Set([...app.matchAll(/(?:\bfrom\s+|\bimport\s*(?:\(\s*)?)["']\.\/([^"'?]+)(?:\?[^"']*)?["']/g)].map((match) => match[1]))];
|
|
172
230
|
assert.ok(startupModuleNames.length >= 1, "the startup-module invariant should discover app.js imports");
|
|
173
231
|
for (const moduleName of startupModuleNames) {
|
|
174
232
|
assert.ok(serviceWorker.includes(`"/${moduleName}"`), `the PWA app shell should include every app.js startup module: ${moduleName}`);
|
|
175
233
|
}
|
|
176
234
|
assert.match(serviceWorker, /pi-webui-pwa-v\d+/, "the app-shell cache should retain a versioned identity");
|
|
177
|
-
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=
|
|
235
|
+
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=112"), "the inline loader should own app module startup");
|
|
178
236
|
assert.doesNotMatch(html, /<script type="module" src="\/app\.js/, "the app module should not bypass the guarded loader");
|
|
179
237
|
|
|
180
238
|
console.log("boot-failure-diagnostics.test.mjs passed");
|
|
@@ -0,0 +1,303 @@
|
|
|
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
|
+
const storageKey = "pi-webui-composer-action-order-v1";
|
|
14
|
+
const layoutStorageKey = "pi-webui-composer-action-layout-v2";
|
|
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
|
+
test.beforeAll(async () => {
|
|
30
|
+
const port = await freePort();
|
|
31
|
+
tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-composer-action-order-"));
|
|
32
|
+
baseURL = `http://127.0.0.1:${port}`;
|
|
33
|
+
child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
34
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
35
|
+
env: {
|
|
36
|
+
...process.env,
|
|
37
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
38
|
+
PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
|
|
39
|
+
PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
child.stdout.on("data", (chunk) => { output += String(chunk); });
|
|
43
|
+
child.stderr.on("data", (chunk) => { output += String(chunk); });
|
|
44
|
+
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
45
|
+
if (child.exitCode !== null) break;
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
|
|
48
|
+
if (response.ok) return;
|
|
49
|
+
} catch {
|
|
50
|
+
// Wait for the real server and fake Pi fixture to start.
|
|
51
|
+
}
|
|
52
|
+
await delay(100);
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`Pi Web UI did not start:\n${output}`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test.afterAll(async () => {
|
|
58
|
+
child?.kill("SIGTERM");
|
|
59
|
+
if (child) await new Promise((resolve) => child.once("exit", resolve));
|
|
60
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test.beforeEach(async () => {
|
|
64
|
+
const currentResponse = await fetch(`${baseURL}/api/interface-preferences`);
|
|
65
|
+
const current = await currentResponse.json();
|
|
66
|
+
expect(currentResponse.ok).toBe(true);
|
|
67
|
+
const resetResponse = await fetch(`${baseURL}/api/interface-preferences`, {
|
|
68
|
+
method: "PUT",
|
|
69
|
+
headers: { "content-type": "application/json" },
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
layout: { version: 1, composerActions: null },
|
|
72
|
+
expectedLayoutRevision: current.data.layoutRevision,
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
expect(resetResponse.ok).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
async function storedOrder(page) {
|
|
79
|
+
return page.evaluate((key) => JSON.parse(localStorage.getItem(key) || "[]"), storageKey);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function storedLayout(page) {
|
|
83
|
+
return page.evaluate((key) => JSON.parse(localStorage.getItem(key) || "null"), layoutStorageKey);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
test("composer actions persist pointer and keyboard grid reordering", async ({ page }) => {
|
|
87
|
+
await page.setViewportSize({ width: 1440, height: 900 });
|
|
88
|
+
await page.goto(baseURL);
|
|
89
|
+
await expect(page.locator("body")).toHaveClass(/composer-action-grid-enabled/);
|
|
90
|
+
|
|
91
|
+
const send = page.locator('[data-composer-action-id="send"]');
|
|
92
|
+
const newSession = page.locator('[data-composer-action-id="new"]');
|
|
93
|
+
await expect(send).toBeVisible();
|
|
94
|
+
await expect(newSession).toBeVisible();
|
|
95
|
+
|
|
96
|
+
const sendBox = await send.boundingBox();
|
|
97
|
+
const newBox = await newSession.boundingBox();
|
|
98
|
+
expect(sendBox).toBeTruthy();
|
|
99
|
+
expect(newBox).toBeTruthy();
|
|
100
|
+
const newLabelCenterOffset = await newSession.evaluate((button) => {
|
|
101
|
+
const range = document.createRange();
|
|
102
|
+
range.selectNodeContents(button);
|
|
103
|
+
const labelRect = range.getBoundingClientRect();
|
|
104
|
+
const buttonRect = button.getBoundingClientRect();
|
|
105
|
+
return (labelRect.left + labelRect.width / 2) - (buttonRect.left + buttonRect.width / 2);
|
|
106
|
+
});
|
|
107
|
+
expect(Math.abs(newLabelCenterOffset)).toBeLessThan(1);
|
|
108
|
+
const minimumCellWidth = await page.evaluate(() => 3.2 * Number.parseFloat(getComputedStyle(document.documentElement).fontSize));
|
|
109
|
+
const gridGuide = page.locator("#composerActionGridGuide");
|
|
110
|
+
await expect(gridGuide).toBeHidden();
|
|
111
|
+
await page.mouse.move(sendBox.x + sendBox.width / 2, sendBox.y + sendBox.height / 2);
|
|
112
|
+
await page.mouse.down();
|
|
113
|
+
await page.mouse.move(sendBox.x + sendBox.width / 2 - 12, sendBox.y + sendBox.height / 2, { steps: 2 });
|
|
114
|
+
await expect(gridGuide).toBeVisible();
|
|
115
|
+
|
|
116
|
+
const [rowBox, guideBox, firstCellBox, lastCellBox] = await Promise.all([
|
|
117
|
+
page.locator(".composer-row").boundingBox(),
|
|
118
|
+
gridGuide.boundingBox(),
|
|
119
|
+
gridGuide.locator(".composer-action-grid-cell").first().boundingBox(),
|
|
120
|
+
gridGuide.locator(".composer-action-grid-cell").last().boundingBox(),
|
|
121
|
+
]);
|
|
122
|
+
expect(rowBox).toBeTruthy();
|
|
123
|
+
expect(guideBox).toBeTruthy();
|
|
124
|
+
expect(firstCellBox).toBeTruthy();
|
|
125
|
+
expect(lastCellBox).toBeTruthy();
|
|
126
|
+
expect(Math.abs(guideBox.x - rowBox.x)).toBeLessThan(1);
|
|
127
|
+
expect(Math.abs(guideBox.width - rowBox.width)).toBeLessThan(1);
|
|
128
|
+
expect(Math.abs(firstCellBox.width - lastCellBox.width)).toBeLessThan(1);
|
|
129
|
+
expect(firstCellBox.width).toBeGreaterThanOrEqual(minimumCellWidth - 1);
|
|
130
|
+
expect(Math.abs(firstCellBox.width - newBox.width)).toBeLessThan(1);
|
|
131
|
+
expect(Math.abs(firstCellBox.height - newBox.height)).toBeLessThan(1);
|
|
132
|
+
expect(await gridGuide.locator(".composer-action-grid-cell").count()).toBeGreaterThan(await page.locator("[data-composer-action-id]:visible").count());
|
|
133
|
+
|
|
134
|
+
await page.mouse.move(newBox.x + 3, newBox.y + newBox.height / 2, { steps: 8 });
|
|
135
|
+
await page.mouse.up();
|
|
136
|
+
await expect(gridGuide).toBeHidden();
|
|
137
|
+
|
|
138
|
+
await expect.poll(async () => (await storedOrder(page)).slice(0, 2)).toEqual(["send", "new"]);
|
|
139
|
+
await expect.poll(async () => {
|
|
140
|
+
const [sendRect, newRect] = await Promise.all([send.boundingBox(), newSession.boundingBox()]);
|
|
141
|
+
return sendRect.x < newRect.x;
|
|
142
|
+
}).toBe(true);
|
|
143
|
+
|
|
144
|
+
await page.reload();
|
|
145
|
+
await expect.poll(async () => (await storedOrder(page)).slice(0, 2)).toEqual(["send", "new"]);
|
|
146
|
+
await expect.poll(async () => {
|
|
147
|
+
const [sendRect, newRect] = await Promise.all([send.boundingBox(), newSession.boundingBox()]);
|
|
148
|
+
return sendRect.x < newRect.x;
|
|
149
|
+
}).toBe(true);
|
|
150
|
+
|
|
151
|
+
await newSession.focus();
|
|
152
|
+
await newSession.press("Alt+ArrowLeft");
|
|
153
|
+
await expect.poll(async () => (await storedOrder(page)).slice(0, 2)).toEqual(["new", "send"]);
|
|
154
|
+
await expect(newSession).toBeFocused();
|
|
155
|
+
await expect(page.locator("#composerActionOrderStatus")).toContainText("New moved to position 1");
|
|
156
|
+
|
|
157
|
+
const movedNewBox = await newSession.boundingBox();
|
|
158
|
+
expect(movedNewBox).toBeTruthy();
|
|
159
|
+
await page.mouse.move(movedNewBox.x + movedNewBox.width / 2, movedNewBox.y + movedNewBox.height / 2);
|
|
160
|
+
await page.mouse.down();
|
|
161
|
+
await page.mouse.move(movedNewBox.x + movedNewBox.width / 2 + 12, movedNewBox.y + movedNewBox.height / 2, { steps: 2 });
|
|
162
|
+
await expect(gridGuide).toBeVisible();
|
|
163
|
+
const emptyEndCellBox = await gridGuide.locator(".composer-action-grid-cell").last().boundingBox();
|
|
164
|
+
expect(emptyEndCellBox).toBeTruthy();
|
|
165
|
+
await page.mouse.move(emptyEndCellBox.x + emptyEndCellBox.width / 2, emptyEndCellBox.y + emptyEndCellBox.height / 2, { steps: 8 });
|
|
166
|
+
await expect(gridGuide.locator(".composer-action-grid-cell-target")).toHaveCount(1);
|
|
167
|
+
await page.mouse.up();
|
|
168
|
+
await expect(gridGuide).toBeHidden();
|
|
169
|
+
await expect.poll(async () => {
|
|
170
|
+
const [nextNewRect, nextSendRect] = await Promise.all([newSession.boundingBox(), send.boundingBox()]);
|
|
171
|
+
return nextNewRect.x > nextSendRect.x;
|
|
172
|
+
}).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("empty composer grid cells retain their space and accept later drops", async ({ page }) => {
|
|
176
|
+
await page.setViewportSize({ width: 1440, height: 900 });
|
|
177
|
+
await page.goto(baseURL);
|
|
178
|
+
|
|
179
|
+
const options = page.locator('[data-composer-action-id="options"]');
|
|
180
|
+
const appRunner = page.locator('[data-composer-action-id="app-runner"]');
|
|
181
|
+
const newSession = page.locator('[data-composer-action-id="new"]');
|
|
182
|
+
const gridGuide = page.locator("#composerActionGridGuide");
|
|
183
|
+
await expect(options).toBeVisible();
|
|
184
|
+
await expect(appRunner).toBeVisible();
|
|
185
|
+
await expect(newSession).toBeVisible();
|
|
186
|
+
|
|
187
|
+
const optionsBox = await options.boundingBox();
|
|
188
|
+
expect(optionsBox).toBeTruthy();
|
|
189
|
+
const optionsCenter = { x: optionsBox.x + optionsBox.width / 2, y: optionsBox.y + optionsBox.height / 2 };
|
|
190
|
+
await page.mouse.move(optionsCenter.x, optionsCenter.y);
|
|
191
|
+
await page.mouse.down();
|
|
192
|
+
await page.mouse.move(optionsCenter.x + 12, optionsCenter.y, { steps: 2 });
|
|
193
|
+
await expect(gridGuide).toBeVisible();
|
|
194
|
+
|
|
195
|
+
const endCellIndex = await gridGuide.locator(".composer-action-grid-cell").count() - 1;
|
|
196
|
+
const endCellBox = await gridGuide.locator(".composer-action-grid-cell").last().boundingBox();
|
|
197
|
+
expect(endCellBox).toBeTruthy();
|
|
198
|
+
const endCellCenter = { x: endCellBox.x + endCellBox.width / 2, y: endCellBox.y + endCellBox.height / 2 };
|
|
199
|
+
await page.mouse.move(endCellCenter.x, endCellCenter.y, { steps: 8 });
|
|
200
|
+
await page.mouse.up();
|
|
201
|
+
await expect.poll(async () => page.evaluate((key) => JSON.parse(localStorage.getItem(key) || "null")?.positions?.options, layoutStorageKey)).toBe(endCellIndex);
|
|
202
|
+
|
|
203
|
+
await expect.poll(async () => {
|
|
204
|
+
const box = await options.boundingBox();
|
|
205
|
+
return Math.abs((box.x + box.width / 2) - endCellCenter.x);
|
|
206
|
+
}).toBeLessThan(1);
|
|
207
|
+
await page.reload();
|
|
208
|
+
await expect(appRunner).toBeVisible();
|
|
209
|
+
const expectedOptionColumn = String((endCellIndex % (endCellIndex + 1)) + 1);
|
|
210
|
+
await expect.poll(async () => options.evaluate((node) => node.style.getPropertyValue("--composer-action-grid-column"))).toBe(expectedOptionColumn);
|
|
211
|
+
await expect.poll(async () => {
|
|
212
|
+
const box = await options.boundingBox();
|
|
213
|
+
return Math.abs((box.x + box.width / 2) - endCellCenter.x);
|
|
214
|
+
}).toBeLessThan(1);
|
|
215
|
+
|
|
216
|
+
const movedNewBox = await newSession.boundingBox();
|
|
217
|
+
expect(movedNewBox).toBeTruthy();
|
|
218
|
+
await page.mouse.move(movedNewBox.x + movedNewBox.width / 2, movedNewBox.y + movedNewBox.height / 2);
|
|
219
|
+
await page.mouse.down();
|
|
220
|
+
await page.mouse.move(movedNewBox.x + movedNewBox.width / 2 + 12, movedNewBox.y + movedNewBox.height / 2, { steps: 2 });
|
|
221
|
+
await expect(gridGuide).toBeVisible();
|
|
222
|
+
const middleEmptyCellIndex = await gridGuide.locator(".composer-action-grid-cell").evaluateAll((cells) => {
|
|
223
|
+
const actions = Array.from(document.querySelectorAll("[data-composer-action-id]"))
|
|
224
|
+
.filter((action) => !action.hidden && action.getClientRects().length > 0);
|
|
225
|
+
return cells.findIndex((cell, index) => {
|
|
226
|
+
if (index === 0 || index === cells.length - 1) return false;
|
|
227
|
+
const rect = cell.getBoundingClientRect();
|
|
228
|
+
const centerX = rect.left + rect.width / 2;
|
|
229
|
+
const centerY = rect.top + rect.height / 2;
|
|
230
|
+
return !actions.some((action) => {
|
|
231
|
+
const actionRect = action.getBoundingClientRect();
|
|
232
|
+
return centerX >= actionRect.left && centerX <= actionRect.right && centerY >= actionRect.top && centerY <= actionRect.bottom;
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
expect(middleEmptyCellIndex).toBeGreaterThan(0);
|
|
237
|
+
const middleEmptyCellBox = await gridGuide.locator(".composer-action-grid-cell").nth(middleEmptyCellIndex).boundingBox();
|
|
238
|
+
expect(middleEmptyCellBox).toBeTruthy();
|
|
239
|
+
const middleEmptyCellCenter = { x: middleEmptyCellBox.x + middleEmptyCellBox.width / 2, y: middleEmptyCellBox.y + middleEmptyCellBox.height / 2 };
|
|
240
|
+
await page.mouse.move(middleEmptyCellCenter.x, middleEmptyCellCenter.y, { steps: 8 });
|
|
241
|
+
await expect(gridGuide.locator(".composer-action-grid-cell-target")).toHaveCount(1);
|
|
242
|
+
await page.mouse.up();
|
|
243
|
+
await expect.poll(async () => {
|
|
244
|
+
const box = await newSession.boundingBox();
|
|
245
|
+
return Math.abs((box.x + box.width / 2) - middleEmptyCellCenter.x);
|
|
246
|
+
}).toBeLessThan(1);
|
|
247
|
+
await expect.poll(async () => page.evaluate((key) => JSON.parse(localStorage.getItem(key) || "null")?.positions?.new, layoutStorageKey)).toBe(middleEmptyCellIndex);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("sparse composer buttons keep responsive positions when the Control Deck width changes", async ({ page }) => {
|
|
251
|
+
await page.setViewportSize({ width: 1440, height: 900 });
|
|
252
|
+
await page.goto(baseURL);
|
|
253
|
+
|
|
254
|
+
const row = page.locator(".composer-row");
|
|
255
|
+
const options = page.locator('[data-composer-action-id="options"]');
|
|
256
|
+
const gridGuide = page.locator("#composerActionGridGuide");
|
|
257
|
+
const resizeHandle = page.locator("#sidePanelResizeHandle");
|
|
258
|
+
const wideRowBox = await row.boundingBox();
|
|
259
|
+
const optionsBox = await options.boundingBox();
|
|
260
|
+
expect(wideRowBox).toBeTruthy();
|
|
261
|
+
expect(optionsBox).toBeTruthy();
|
|
262
|
+
|
|
263
|
+
await page.mouse.move(optionsBox.x + optionsBox.width / 2, optionsBox.y + optionsBox.height / 2);
|
|
264
|
+
await page.mouse.down();
|
|
265
|
+
await page.mouse.move(optionsBox.x + optionsBox.width / 2 + 12, optionsBox.y + optionsBox.height / 2, { steps: 2 });
|
|
266
|
+
await expect(gridGuide).toBeVisible();
|
|
267
|
+
const lastCellBox = await gridGuide.locator(".composer-action-grid-cell").last().boundingBox();
|
|
268
|
+
expect(lastCellBox).toBeTruthy();
|
|
269
|
+
await page.mouse.move(lastCellBox.x + lastCellBox.width / 2, lastCellBox.y + lastCellBox.height / 2, { steps: 8 });
|
|
270
|
+
await page.mouse.up();
|
|
271
|
+
|
|
272
|
+
const wideColumn = await options.evaluate((node) => node.style.getPropertyValue("--composer-action-grid-column"));
|
|
273
|
+
const savedWideLayout = await storedLayout(page);
|
|
274
|
+
expect(Number(wideColumn)).toBeGreaterThan(1);
|
|
275
|
+
expect(savedWideLayout?.columns).toBeGreaterThan(1);
|
|
276
|
+
|
|
277
|
+
await resizeHandle.focus();
|
|
278
|
+
await resizeHandle.press("Shift+ArrowLeft");
|
|
279
|
+
await resizeHandle.press("Shift+ArrowLeft");
|
|
280
|
+
await resizeHandle.press("Shift+ArrowLeft");
|
|
281
|
+
|
|
282
|
+
await expect.poll(async () => (await row.boundingBox()).width).toBeLessThan(wideRowBox.width - 50);
|
|
283
|
+
await expect.poll(async () => options.evaluate((node) => node.style.getPropertyValue("--composer-action-grid-column"))).not.toBe("");
|
|
284
|
+
await expect.poll(async () => page.evaluate(() => {
|
|
285
|
+
const composerRow = document.querySelector(".composer-row");
|
|
286
|
+
const action = document.querySelector('[data-composer-action-id="options"]');
|
|
287
|
+
const rowRect = composerRow.getBoundingClientRect();
|
|
288
|
+
const actionRect = action.getBoundingClientRect();
|
|
289
|
+
return Math.abs(rowRect.right - actionRect.right);
|
|
290
|
+
})).toBeLessThan(2);
|
|
291
|
+
expect(await storedLayout(page)).toEqual(savedWideLayout);
|
|
292
|
+
|
|
293
|
+
await page.reload();
|
|
294
|
+
await expect.poll(async () => options.evaluate((node) => node.style.getPropertyValue("--composer-action-grid-column"))).not.toBe("");
|
|
295
|
+
await expect.poll(async () => page.evaluate(() => {
|
|
296
|
+
const composerRow = document.querySelector(".composer-row");
|
|
297
|
+
const action = document.querySelector('[data-composer-action-id="options"]');
|
|
298
|
+
const rowRect = composerRow.getBoundingClientRect();
|
|
299
|
+
const actionRect = action.getBoundingClientRect();
|
|
300
|
+
return Math.abs(rowRect.right - actionRect.right);
|
|
301
|
+
})).toBeLessThan(2);
|
|
302
|
+
expect(await storedLayout(page)).toEqual(savedWideLayout);
|
|
303
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createServer } from "node:net";
|
|
4
|
+
import { mkdtemp, rm } 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 { expect, test } from "@playwright/test";
|
|
10
|
+
|
|
11
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
12
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
13
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
14
|
+
|
|
15
|
+
async function freePort() {
|
|
16
|
+
const server = createServer();
|
|
17
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
18
|
+
const { port } = server.address();
|
|
19
|
+
await new Promise((resolve) => server.close(resolve));
|
|
20
|
+
return port;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let child;
|
|
24
|
+
let baseURL;
|
|
25
|
+
let tempRoot;
|
|
26
|
+
let output = "";
|
|
27
|
+
|
|
28
|
+
test.beforeAll(async () => {
|
|
29
|
+
const port = await freePort();
|
|
30
|
+
tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-component-updates-"));
|
|
31
|
+
baseURL = `http://127.0.0.1:${port}`;
|
|
32
|
+
child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
33
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
37
|
+
PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
|
|
38
|
+
PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
|
|
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 package server and fake Pi fixture to start.
|
|
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
|
+
child?.kill("SIGTERM");
|
|
58
|
+
if (child) await new Promise((resolve) => child.once("exit", resolve));
|
|
59
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("component tags and dialogs expose safe background update lifecycle", async ({ page }) => {
|
|
63
|
+
const requests = [];
|
|
64
|
+
let statusPollsAfterStart = 0;
|
|
65
|
+
const status = {
|
|
66
|
+
updateAvailable: true,
|
|
67
|
+
updateInProgress: false,
|
|
68
|
+
canRunUpdate: true,
|
|
69
|
+
pi: { checked: true, currentVersion: "0.83.0", latestVersion: "0.84.0", updateAvailable: true },
|
|
70
|
+
webui: { checked: true, currentVersion: "0.8.1", latestVersion: "0.8.2", updateAvailable: true },
|
|
71
|
+
componentUpdates: {
|
|
72
|
+
pi: { target: "pi", state: "idle", message: "", error: "", canStart: true, unavailableReason: "", restartRequired: false },
|
|
73
|
+
webui: {
|
|
74
|
+
target: "webui",
|
|
75
|
+
state: "idle",
|
|
76
|
+
message: "",
|
|
77
|
+
error: "",
|
|
78
|
+
canStart: false,
|
|
79
|
+
unavailableReason: "Automatic Web UI update is unavailable from a source or development checkout.",
|
|
80
|
+
restartRequired: true,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
await page.route("**/api/pi-release-notes", async (route) => {
|
|
86
|
+
await route.fulfill({
|
|
87
|
+
status: 200,
|
|
88
|
+
contentType: "application/json",
|
|
89
|
+
body: JSON.stringify({ ok: true, data: { version: "0.83.0", body: "Fixture release notes", url: "https://example.test/pi" } }),
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
await page.route("**/api/component-update", async (route) => {
|
|
93
|
+
const body = route.request().postDataJSON();
|
|
94
|
+
requests.push({ method: route.request().method(), body });
|
|
95
|
+
const target = body?.target;
|
|
96
|
+
status.updateInProgress = true;
|
|
97
|
+
status.componentUpdates[target] = {
|
|
98
|
+
...status.componentUpdates[target],
|
|
99
|
+
state: "running",
|
|
100
|
+
canStart: false,
|
|
101
|
+
message: `Updating ${target === "pi" ? "Pi" : "Web UI"}…`,
|
|
102
|
+
error: "",
|
|
103
|
+
};
|
|
104
|
+
await route.fulfill({
|
|
105
|
+
status: 202,
|
|
106
|
+
contentType: "application/json",
|
|
107
|
+
body: JSON.stringify({ ok: true, data: status.componentUpdates[target] }),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await page.route("**/api/update-status*", async (route) => {
|
|
111
|
+
if (status.componentUpdates.pi.state === "running") {
|
|
112
|
+
statusPollsAfterStart += 1;
|
|
113
|
+
status.componentUpdates.pi = {
|
|
114
|
+
...status.componentUpdates.pi,
|
|
115
|
+
state: "succeeded",
|
|
116
|
+
canStart: true,
|
|
117
|
+
message: "Pi update completed.",
|
|
118
|
+
};
|
|
119
|
+
status.updateInProgress = false;
|
|
120
|
+
}
|
|
121
|
+
await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, data: status }) });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await page.goto(baseURL);
|
|
125
|
+
const piTag = page.locator("#piVersionButton");
|
|
126
|
+
const webuiTag = page.locator("#webuiVersionButton");
|
|
127
|
+
await expect(piTag).toHaveAttribute("data-update-state", "available", { timeout: 8_000 });
|
|
128
|
+
await expect(piTag).toHaveAccessibleName(/Pi .*update available/);
|
|
129
|
+
await expect(webuiTag).toHaveAttribute("data-update-state", "available");
|
|
130
|
+
await expect(webuiTag).toHaveAccessibleName(/Web UI .*update available/);
|
|
131
|
+
await page.locator("#updateNotificationDismissButton").click();
|
|
132
|
+
await expect(page.locator("#updateNotification")).toBeHidden();
|
|
133
|
+
|
|
134
|
+
await webuiTag.click();
|
|
135
|
+
const webuiDialog = page.locator("#webuiPackageDialog");
|
|
136
|
+
await expect(webuiDialog).toBeVisible();
|
|
137
|
+
await expect(page.locator("#webuiPackageCurrentVersion")).toHaveText("v0.8.1");
|
|
138
|
+
await expect(page.locator("#webuiPackageLatestVersion")).toHaveText("v0.8.2");
|
|
139
|
+
await expect(page.locator("#webuiPackageNpmButton")).toHaveText("View on npm");
|
|
140
|
+
await expect(page.locator("#webuiComponentUpdateStatus")).toContainText("source or development checkout");
|
|
141
|
+
await expect(page.locator("#webuiComponentUpdateButton")).toBeDisabled();
|
|
142
|
+
await page.locator("#webuiPackageCloseButton").click();
|
|
143
|
+
|
|
144
|
+
await piTag.click();
|
|
145
|
+
const piDialog = page.locator("#piReleaseNotesDialog");
|
|
146
|
+
await expect(piDialog).toBeVisible();
|
|
147
|
+
await expect(page.locator("#piComponentUpdateStatus")).toContainText("Pi v0.83.0 → v0.84.0 is available");
|
|
148
|
+
await page.locator("#piComponentUpdateButton").click();
|
|
149
|
+
await expect(page.locator("#confirmationDialog")).toBeVisible();
|
|
150
|
+
await expect(page.locator("#confirmationSummary")).toContainText("Web UI server and running Pi tabs are not restarted");
|
|
151
|
+
await page.locator("#confirmationConfirmButton").click();
|
|
152
|
+
|
|
153
|
+
await expect(piTag).toHaveAttribute("data-update-state", "running");
|
|
154
|
+
await expect(piTag).toHaveAccessibleName(/update running/);
|
|
155
|
+
await expect(page.locator("#piComponentUpdateButton")).toBeDisabled();
|
|
156
|
+
assert.deepEqual(requests, [{ method: "POST", body: { target: "pi" } }], "the dialog must submit exactly one Pi-only POST");
|
|
157
|
+
|
|
158
|
+
await expect(piTag).toHaveAttribute("data-update-state", "succeeded", { timeout: 5_000 });
|
|
159
|
+
await expect(page.locator("#piComponentUpdateStatus")).toContainText("New or reloaded Pi sessions use the update");
|
|
160
|
+
await expect(page.locator("#piComponentUpdateStatus")).toContainText("already-running tabs keep their current runtime");
|
|
161
|
+
assert.ok(statusPollsAfterStart >= 1, "the browser should poll while the accepted job is running");
|
|
162
|
+
const pollsAtSuccess = statusPollsAfterStart;
|
|
163
|
+
await page.waitForTimeout(1_300);
|
|
164
|
+
assert.equal(statusPollsAfterStart, pollsAtSuccess, "short polling should stop after terminal success");
|
|
165
|
+
await page.locator("#piReleaseNotesCloseButton").click();
|
|
166
|
+
await expect(piDialog).toBeHidden();
|
|
167
|
+
|
|
168
|
+
status.componentUpdates.webui = {
|
|
169
|
+
...status.componentUpdates.webui,
|
|
170
|
+
state: "failed",
|
|
171
|
+
canStart: true,
|
|
172
|
+
message: "Web UI update failed.",
|
|
173
|
+
error: "bounded fixture failure",
|
|
174
|
+
};
|
|
175
|
+
await webuiTag.click();
|
|
176
|
+
await expect(page.locator("#webuiComponentUpdateStatus")).toContainText("bounded fixture failure");
|
|
177
|
+
await expect(page.locator("#webuiComponentUpdateStatus")).toContainText("retry the update");
|
|
178
|
+
await expect(page.locator("#webuiComponentUpdateButton")).toBeEnabled();
|
|
179
|
+
await expect(page.locator("#webuiComponentUpdateButton")).toHaveText("Retry Web UI update");
|
|
180
|
+
});
|