@firstpick/pi-package-webui 0.8.8 → 0.9.0
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 +12 -0
- package/bin/pi-webui-rpc-supervisor.mjs +4 -1
- package/bin/pi-webui.mjs +15 -3
- package/lib/rpc-supervisor-protocol.mjs +6 -1
- package/package.json +1 -1
- package/public/app.js +659 -150
- package/public/index.html +28 -13
- package/public/service-worker.js +1 -1
- package/public/styles.css +789 -23
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +120 -0
- package/tests/browser/mobile-foundation.spec.mjs +363 -5
- package/tests/browser/optimistic-prompt.spec.mjs +24 -10
- package/tests/browser/persistent-ui-layout.spec.mjs +2 -0
- package/tests/browser/search-match-highlighting.spec.mjs +104 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +16 -1
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-tree-search-layout-static.test.mjs +261 -0
- package/tests/file-viewer-search-static.test.mjs +7 -2
- package/tests/fixtures/fake-pi.mjs +4 -1
- package/tests/foreground-transcript-catch-up-static.test.mjs +91 -0
- package/tests/http-endpoints-harness.test.mjs +35 -2
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +60 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +12 -12
- package/tests/mobile-phone-experience-static.test.mjs +2 -2
- package/tests/mobile-static.test.mjs +39 -20
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/rpc-supervisor-host.test.mjs +18 -1
- package/tests/rpc-supervisor-protocol.test.mjs +5 -0
- package/tests/search-match-highlighting-static.test.mjs +27 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/side-panel-section-reorder-static.test.mjs +23 -10
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/streaming-ui-coupling.test.mjs +8 -0
- package/tests/terminal-tab-workspace-static.test.mjs +15 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
|
@@ -304,6 +304,7 @@ test("server-owned layout survives stale reads, failed writes, localStorage clea
|
|
|
304
304
|
await expect(page.locator("#sidePanel")).toBeVisible();
|
|
305
305
|
await expect(page.locator('[data-composer-action-id="options"]')).toBeVisible();
|
|
306
306
|
|
|
307
|
+
await expect(page.locator("#sidePanelEditButton")).toBeHidden();
|
|
307
308
|
const controls = page.locator('[data-side-panel-section-toggle="controls"]');
|
|
308
309
|
await controls.focus();
|
|
309
310
|
await controls.press("Alt+ArrowDown");
|
|
@@ -547,6 +548,7 @@ test("conflict retry updates only the changed Control Deck subfield", async ({ b
|
|
|
547
548
|
await expect.poll(async () => (await sectionOrder(pageA)).slice(0, initialOrder.length)).toEqual(initialOrder);
|
|
548
549
|
await expect.poll(async () => (await sectionOrder(pageB)).slice(0, initialOrder.length)).toEqual(initialOrder);
|
|
549
550
|
|
|
551
|
+
await expect(pageA.locator("#sidePanelEditButton")).toBeHidden();
|
|
550
552
|
const controlsA = pageA.locator('[data-side-panel-section-toggle="controls"]');
|
|
551
553
|
await controlsA.focus();
|
|
552
554
|
await controlsA.press("Alt+ArrowDown");
|
|
@@ -0,0 +1,104 @@
|
|
|
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 { 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-search-highlights-"));
|
|
31
|
+
await writeFile(join(tempRoot, "search-sample.txt"), "Alpha beta alpha\nplain text\nALPHA final\n");
|
|
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
|
+
// Poll only until the package server and fake Pi fixture are ready.
|
|
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
|
+
if (child?.exitCode === null) {
|
|
59
|
+
await fetch(`${baseURL}/api/shutdown`, { method: "POST", signal: AbortSignal.timeout(1_000) }).catch(() => undefined);
|
|
60
|
+
await new Promise((resolve) => child.once("exit", resolve));
|
|
61
|
+
}
|
|
62
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("highlights every transcript and source-file match while retaining current-match navigation", async ({ page }) => {
|
|
66
|
+
await page.setViewportSize({ width: 1440, height: 900 });
|
|
67
|
+
await page.goto(baseURL);
|
|
68
|
+
await expect(page.locator("#chat .message")).toHaveCount(3);
|
|
69
|
+
|
|
70
|
+
await page.keyboard.press("Control+F");
|
|
71
|
+
await page.locator("#chatSearchInput").fill("fake");
|
|
72
|
+
await expect(page.locator("#chatSearchCount")).toHaveText("3/3");
|
|
73
|
+
const transcriptHighlightSizes = await page.evaluate(() => ({
|
|
74
|
+
all: CSS.highlights.get("chat-search-match")?.size || 0,
|
|
75
|
+
current: CSS.highlights.get("chat-search-current")?.size || 0,
|
|
76
|
+
}));
|
|
77
|
+
assert.deepEqual(transcriptHighlightSizes, { all: 3, current: 1 });
|
|
78
|
+
|
|
79
|
+
await page.keyboard.press("Escape");
|
|
80
|
+
await page.locator("#sidePanelSectionToggleFiles").click();
|
|
81
|
+
await page.locator("#fileTreeSearchInput").fill("search-sample.txt");
|
|
82
|
+
const fileResult = page.locator(".file-tree-search-item", { hasText: "search-sample.txt" });
|
|
83
|
+
await expect(fileResult).toBeVisible();
|
|
84
|
+
await fileResult.click();
|
|
85
|
+
await expect(page.locator("#fileViewerPane")).toBeVisible();
|
|
86
|
+
|
|
87
|
+
const editor = page.locator("#fileViewerEditor");
|
|
88
|
+
await editor.focus();
|
|
89
|
+
await page.keyboard.press("Control+F");
|
|
90
|
+
await page.locator("#fileViewerSearchInput").fill("alpha");
|
|
91
|
+
await expect(page.locator("#fileViewerSearchCount")).toHaveText("1/3");
|
|
92
|
+
await expect(page.locator("#fileViewerSearchOverlay .file-viewer-search-match")).toHaveCount(3);
|
|
93
|
+
await expect(page.locator("#fileViewerSearchOverlay .file-viewer-search-match.current")).toHaveCount(1);
|
|
94
|
+
|
|
95
|
+
const synchronizedScroll = await editor.evaluate((node) => {
|
|
96
|
+
node.scrollTop = 12;
|
|
97
|
+
node.dispatchEvent(new Event("scroll"));
|
|
98
|
+
return {
|
|
99
|
+
editor: node.scrollTop,
|
|
100
|
+
overlay: document.querySelector("#fileViewerSearchOverlay")?.scrollTop || 0,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
assert.equal(synchronizedScroll.overlay, synchronizedScroll.editor);
|
|
104
|
+
});
|
|
@@ -64,15 +64,27 @@ async function sectionOrder(page) {
|
|
|
64
64
|
));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
test("Control Deck
|
|
67
|
+
test("desktop Control Deck always enables and persists pointer and keyboard reordering", async ({ page }) => {
|
|
68
68
|
await page.setViewportSize({ width: 1440, height: 900 });
|
|
69
69
|
await page.goto(baseURL);
|
|
70
70
|
await expect(page.locator("#sidePanel")).toBeVisible();
|
|
71
71
|
|
|
72
72
|
const initialOrder = await sectionOrder(page);
|
|
73
73
|
expect(initialOrder.slice(0, 3)).toEqual(["controls", "files", "git"]);
|
|
74
|
+
await expect(page.locator("#sidePanelEditButton")).toBeHidden();
|
|
75
|
+
await expect(page.locator("#sidePanel")).toHaveClass(/section-edit-mode/);
|
|
74
76
|
|
|
75
77
|
const controls = page.locator('[data-side-panel-section-toggle="controls"]');
|
|
78
|
+
await expect(controls).toHaveAttribute("title", /drag to reorder/);
|
|
79
|
+
await expect(controls).toHaveCSS("cursor", "grab");
|
|
80
|
+
const desktopReorderVisuals = await controls.evaluate((button) => ({
|
|
81
|
+
borderColor: getComputedStyle(button).borderColor,
|
|
82
|
+
boxShadow: getComputedStyle(button).boxShadow,
|
|
83
|
+
labelMarker: getComputedStyle(button.querySelector(".side-panel-section-label"), "::before").content,
|
|
84
|
+
}));
|
|
85
|
+
expect(desktopReorderVisuals.borderColor).not.toContain("148, 226, 213");
|
|
86
|
+
expect(desktopReorderVisuals.boxShadow).not.toContain("148, 226, 213");
|
|
87
|
+
expect(desktopReorderVisuals.labelMarker).toBe("none");
|
|
76
88
|
const git = page.locator('[data-side-panel-section-toggle="git"]');
|
|
77
89
|
const controlsBox = await controls.boundingBox();
|
|
78
90
|
const gitBox = await git.boundingBox();
|
|
@@ -81,6 +93,7 @@ test("Control Deck sections persist pointer and keyboard reordering", async ({ p
|
|
|
81
93
|
await page.mouse.move(controlsBox.x + controlsBox.width / 2, controlsBox.y + controlsBox.height / 2);
|
|
82
94
|
await page.mouse.down();
|
|
83
95
|
await page.mouse.move(controlsBox.x + controlsBox.width / 2, controlsBox.y + controlsBox.height / 2 + 12, { steps: 2 });
|
|
96
|
+
await expect(controls.locator("xpath=../..")).toHaveClass(/dragging/);
|
|
84
97
|
await page.mouse.move(gitBox.x + gitBox.width / 2, gitBox.y + gitBox.height - 4, { steps: 6 });
|
|
85
98
|
await page.mouse.up();
|
|
86
99
|
|
|
@@ -89,6 +102,7 @@ test("Control Deck sections persist pointer and keyboard reordering", async ({ p
|
|
|
89
102
|
|
|
90
103
|
await page.reload();
|
|
91
104
|
await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "git", "controls"]);
|
|
105
|
+
await expect(page.locator("#sidePanelEditButton")).toBeHidden();
|
|
92
106
|
|
|
93
107
|
const movedControls = page.locator('[data-side-panel-section-toggle="controls"]');
|
|
94
108
|
await movedControls.focus();
|
|
@@ -98,4 +112,5 @@ test("Control Deck sections persist pointer and keyboard reordering", async ({ p
|
|
|
98
112
|
|
|
99
113
|
await page.reload();
|
|
100
114
|
await expect.poll(async () => (await sectionOrder(page)).slice(0, 3)).toEqual(["files", "controls", "git"]);
|
|
115
|
+
await expect(page.locator("#sidePanelEditButton")).toBeHidden();
|
|
101
116
|
});
|
|
@@ -54,7 +54,7 @@ assert.match(app, /statusKey === CODEX_FAST_MODE_STATUS_KEY[\s\S]*?applyCodexFas
|
|
|
54
54
|
assert.match(readme, /### Compact live output mode[\s\S]*?select \*\*Compact\*\*[\s\S]*?`compact-v1`/, "README should document Compact mode with the stable wire identifier");
|
|
55
55
|
assert.match(readme, /### Codex subscription Fast mode[\s\S]*?service_tier: "priority"[\s\S]*?1\.5× faster[\s\S]*?2× Standard credits[\s\S]*?2\.5×/, "README should separately document subscription Fast mode and its cost semantics");
|
|
56
56
|
// Intent preserved: browser-asset changes must advance the coherent cache tuple.
|
|
57
|
-
assert.match(serviceWorker, /pi-webui-pwa-
|
|
58
|
-
assert.match(html, /data-app-src="\/app\.js\?v=
|
|
57
|
+
assert.match(serviceWorker, /pi-webui-pwa-v84/, "PWA cache identity should be bumped for changed browser assets");
|
|
58
|
+
assert.match(html, /data-app-src="\/app\.js\?v=121"/, "browser module URL should be cache-busted for Fast-mode wiring");
|
|
59
59
|
|
|
60
60
|
console.log("codex-fast-mode-static.test.mjs passed");
|
|
@@ -56,8 +56,8 @@ assert.match(app, /function initializeComposerActionOrdering\(\)[\s\S]*MutationO
|
|
|
56
56
|
assert.match(app, /event\.key === COMPOSER_ACTION_ORDER_STORAGE_KEY\) restoreComposerActionOrder\(\)[\s\S]*event\.key === COMPOSER_ACTION_LAYOUT_STORAGE_KEY\) restoreComposerActionSlotLayout\(\)/, "other tabs should apply persisted composer order and sparse-layout changes");
|
|
57
57
|
assert.match(app, /initializeComposerActionOrdering\(\);[\s\S]*restoreSidePanelSectionOrder\(\);/, "composer ordering should initialize during guarded app startup");
|
|
58
58
|
|
|
59
|
-
assert.match(html, /styles\.css\?v=
|
|
60
|
-
assert.match(html, /app\.js\?v=
|
|
61
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
59
|
+
assert.match(html, /styles\.css\?v=107/, "changed composer styles should advance the stylesheet revision");
|
|
60
|
+
assert.match(html, /app\.js\?v=121/, "changed composer behavior should advance the app revision");
|
|
61
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v84"/, "changed browser assets should advance the PWA cache identity");
|
|
62
62
|
|
|
63
63
|
console.log("composer-action-grid-reorder-static.test.mjs passed");
|
|
@@ -156,7 +156,7 @@ assert.match(worker, /pi-webui-pwa-v\d+[\s\S]*?"\/fast-output-live\.mjs"/, "PWA
|
|
|
156
156
|
assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>/, "the sidebar should mark compact mode as experimental");
|
|
157
157
|
assert.match(html, /Lightweight browser rendering; Markdown final output; live thinking expanded; stored thinking grouped and collapsed/, "the sidebar should distinguish compact rendering from model inference");
|
|
158
158
|
// Intent preserved: the guarded PWA entry point must advance whenever app wiring changes.
|
|
159
|
-
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=
|
|
159
|
+
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=121"/, "the guarded PWA entry point should cache-bust browser wiring");
|
|
160
160
|
assert.match(JSON.parse(packageRaw).scripts.check, /node --check public\/fast-output-live\.mjs/, "package checks should parse the compact helper");
|
|
161
161
|
|
|
162
162
|
const events = createFastModeOutputEvents();
|
|
@@ -166,7 +166,7 @@ assert.match(functionSource("closeTerminalTabs"), /clearFeatureDecisionStateForT
|
|
|
166
166
|
assert.match(app, /case "webui_connected":[\s\S]*clearFeatureDecisionStateForTab\(connectedTabId, \{ render: true \}\)[\s\S]*scheduleForegroundReconcile\("event stream reconnect", 0\)/, "reconnect should clear local state before authoritative replay");
|
|
167
167
|
assert.match(app, /statusKey === FEATURE_DECISION_OUTPUT_STATUS_KEY[\s\S]*handleFeatureDecisionOutputStatus[\s\S]*return;[\s\S]*statusKey === FEATURE_CATEGORY_STATUS_KEY[\s\S]*return;[\s\S]*statusEntries\.set/, "both feature statuses should be intercepted before generic footer storage while preserving category handling");
|
|
168
168
|
|
|
169
|
-
assert.match(html, /\/styles\.css\?v=
|
|
170
|
-
assert.match(html, /\/app\.js\?v=
|
|
169
|
+
assert.match(html, /\/styles\.css\?v=107/, "integrated stylesheet changes should advance the cache query");
|
|
170
|
+
assert.match(html, /\/app\.js\?v=121/, "integrated app changes should advance the cache query");
|
|
171
171
|
|
|
172
172
|
console.log("feature decision-output popup static checks passed");
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const [app, css] = await Promise.all([
|
|
9
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
function sourceBetween(source, startMarker, endMarker, label) {
|
|
14
|
+
const start = source.indexOf(startMarker);
|
|
15
|
+
const end = source.indexOf(endMarker, start + startMarker.length);
|
|
16
|
+
assert.ok(start >= 0 && end > start, `${label} source should be present`);
|
|
17
|
+
return source.slice(start, end);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const searchEntry = sourceBetween(app, "function appendFileSearchEntry(", "\nasync function revealFileTreeEntry(", "file search entry renderer");
|
|
21
|
+
const revealSearchEntry = sourceBetween(app, "async function revealFileTreeEntry(", "\nfunction appendFileTreeEntry(", "file search reveal behavior");
|
|
22
|
+
const clearSearch = sourceBetween(app, "function focusVisibleFileTreeSelection(", "\nasync function runFileTreeSearch(", "file search clear behavior");
|
|
23
|
+
const searchLabelCss = sourceBetween(css, ".file-tree-search-label {", "\n.file-tree-kind {", "file search row styles");
|
|
24
|
+
|
|
25
|
+
assert.match(
|
|
26
|
+
searchEntry,
|
|
27
|
+
/const contextPath = fileParentPath\(path\) \|\| "\.";[\s\S]*make\("span", "file-tree-name"[\s\S]*make\("span", "file-tree-search-path", contextPath\)/,
|
|
28
|
+
"search results should pair the prominent match name with compact parent-path context",
|
|
29
|
+
);
|
|
30
|
+
assert.doesNotMatch(searchEntry, /clearFileTreeSearch\(/, "opening a file or directory search result should not clear the active query");
|
|
31
|
+
assert.match(
|
|
32
|
+
searchEntry,
|
|
33
|
+
/const expanded = isDirectory && fileTreeState\.expanded\.has\(path\);[\s\S]*aria-expanded[\s\S]*fileTreeExpander\(expanded\)[\s\S]*toggleFileTreeDirectory\(path\)/,
|
|
34
|
+
"directory search results should expose and toggle their live expansion state without leaving search",
|
|
35
|
+
);
|
|
36
|
+
assert.match(
|
|
37
|
+
searchEntry,
|
|
38
|
+
/if \(isDirectory && expanded\)[\s\S]*entriesByPath\.get\(path\)[\s\S]*appendFileTreeEntry\(childList, child, 1\)/,
|
|
39
|
+
"expanded search directories should render their loaded children as a nested tree",
|
|
40
|
+
);
|
|
41
|
+
assert.doesNotMatch(revealSearchEntry, /clearFileTreeSearch\(/, "revealing a directory should preserve search while preparing the underlying tree state");
|
|
42
|
+
assert.match(
|
|
43
|
+
revealSearchEntry,
|
|
44
|
+
/fileTreeState\.selectedPath = targetPath;[\s\S]*loadFileTreeDirectory\(FILE_TREE_ROOT_PATH\)[\s\S]*fileTreeState\.expanded\.add/,
|
|
45
|
+
"context-menu reveal should still select, load, and expand the target behind the active search",
|
|
46
|
+
);
|
|
47
|
+
assert.match(
|
|
48
|
+
clearSearch,
|
|
49
|
+
/const selectedPath = normalizeFileTreePath[\s\S]*const selectedEntry = fileTreeState\.searchEntries\.find[\s\S]*const commitClear = \(\) => \{[\s\S]*fileTreeState\.searchQuery = "";[\s\S]*renderFileTree\(\);[\s\S]*focusVisibleFileTreeSelection\(selectedPath\)[\s\S]*revealFileTreeEntry\(selectedEntry, \{ expandTarget: selectedDirectoryExpanded \}\)\.then\(commitClear\)/,
|
|
50
|
+
"clearing search should prepare the selected branch before atomically restoring and focusing the normal tree",
|
|
51
|
+
);
|
|
52
|
+
assert.match(
|
|
53
|
+
searchLabelCss,
|
|
54
|
+
/\.file-tree-search-label \{[\s\S]*display: flex;[\s\S]*align-items: baseline;[\s\S]*white-space: nowrap;/,
|
|
55
|
+
"search result labels should remain on one compact line",
|
|
56
|
+
);
|
|
57
|
+
assert.match(
|
|
58
|
+
searchLabelCss,
|
|
59
|
+
/\.file-tree-search-item \{\s*grid-template-columns: auto auto minmax\(0, 1fr\) auto auto;/,
|
|
60
|
+
"search rows should preserve the normal tree column order for expander, icon, label, Git badge, and kind",
|
|
61
|
+
);
|
|
62
|
+
assert.doesNotMatch(searchLabelCss, /\.file-tree-search-label \{[\s\S]*?display: grid;/, "search labels should not return to the former two-line grid layout");
|
|
63
|
+
|
|
64
|
+
function fakeNode(tag, className = "", text = "") {
|
|
65
|
+
return {
|
|
66
|
+
tag,
|
|
67
|
+
className,
|
|
68
|
+
textContent: text,
|
|
69
|
+
children: [],
|
|
70
|
+
attributes: new Map(),
|
|
71
|
+
listeners: {},
|
|
72
|
+
dataset: {},
|
|
73
|
+
style: { setProperty() {} },
|
|
74
|
+
append(...children) { this.children.push(...children); },
|
|
75
|
+
setAttribute(name, value) { this.attributes.set(name, String(value)); },
|
|
76
|
+
addEventListener(name, listener) { this.listeners[name] = listener; },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const toggledPaths = [];
|
|
81
|
+
const renderedChildren = [];
|
|
82
|
+
const fileTreeState = {
|
|
83
|
+
expanded: new Set(),
|
|
84
|
+
loading: new Set(),
|
|
85
|
+
selectedPath: "",
|
|
86
|
+
searchQuery: "webui",
|
|
87
|
+
entriesByPath: new Map([["packages", [{ name: "child.js", path: "packages/child.js", type: "file" }]]]),
|
|
88
|
+
};
|
|
89
|
+
const runtime = {
|
|
90
|
+
fileTreeState,
|
|
91
|
+
normalizeFileTreePath: (value) => String(value || "").replace(/^\/+|\/+$/g, ""),
|
|
92
|
+
fileTreeGitStatusForEntry: () => null,
|
|
93
|
+
fileTreeGitStatusClasses: () => "",
|
|
94
|
+
fileTreeGitStatusTitle: () => "",
|
|
95
|
+
fileParentPath: (value) => String(value || "").split("/").slice(0, -1).join("/"),
|
|
96
|
+
fileDisplayName: (value) => String(value || "").split("/").pop() || ".",
|
|
97
|
+
make: fakeNode,
|
|
98
|
+
fileTreeExpander: (expanded) => fakeNode("span", "file-tree-expander", expanded ? "▾" : "▸"),
|
|
99
|
+
fileEntryIcon: () => "DIR",
|
|
100
|
+
fileTreeGitStatusBadge: () => null,
|
|
101
|
+
openFileInViewer: () => {},
|
|
102
|
+
toggleFileTreeDirectory: async (path) => { toggledPaths.push(path); },
|
|
103
|
+
addEvent: () => {},
|
|
104
|
+
showFileContextMenu: () => {},
|
|
105
|
+
bindFileTreeDragAndDrop: () => {},
|
|
106
|
+
fileTreeOverflowButton: () => fakeNode("button", "file-tree-overflow-button", "⋯"),
|
|
107
|
+
appendFileTreeEntry: (parent, child, depth) => { renderedChildren.push({ child, depth }); parent.append(fakeNode("li", "file-tree-node", child.name)); },
|
|
108
|
+
};
|
|
109
|
+
vm.runInNewContext(`${searchEntry}\nthis.renderSearchEntry = appendFileSearchEntry;`, runtime);
|
|
110
|
+
|
|
111
|
+
const directory = { name: "packages", path: "packages", type: "directory", directory: true };
|
|
112
|
+
const collapsedParent = fakeNode("ul");
|
|
113
|
+
runtime.renderSearchEntry(collapsedParent, directory);
|
|
114
|
+
const collapsedButton = collapsedParent.children[0].children[0];
|
|
115
|
+
assert.equal(collapsedButton.attributes.get("aria-expanded"), "false", "search directories should initially report their collapsed state");
|
|
116
|
+
collapsedButton.listeners.click();
|
|
117
|
+
await Promise.resolve();
|
|
118
|
+
assert.deepEqual(toggledPaths, ["packages"], "clicking a search directory should toggle that directory in place");
|
|
119
|
+
assert.equal(fileTreeState.searchQuery, "webui", "clicking a search directory should preserve the active query");
|
|
120
|
+
|
|
121
|
+
fileTreeState.expanded.add("packages");
|
|
122
|
+
const expandedParent = fakeNode("ul");
|
|
123
|
+
runtime.renderSearchEntry(expandedParent, directory);
|
|
124
|
+
const expandedItem = expandedParent.children[0];
|
|
125
|
+
assert.equal(expandedItem.children[0].attributes.get("aria-expanded"), "true", "expanded search directories should expose their state");
|
|
126
|
+
assert.equal(expandedItem.children[2].className, "file-tree-list", "expanded search directories should append a nested child list");
|
|
127
|
+
assert.deepEqual(renderedChildren, [{ child: fileTreeState.entriesByPath.get("packages")[0], depth: 1 }], "expanded search directories should render cached children one level deeper");
|
|
128
|
+
|
|
129
|
+
function focusableTreeItem(path) {
|
|
130
|
+
return {
|
|
131
|
+
dataset: { path },
|
|
132
|
+
focusCalls: 0,
|
|
133
|
+
scrollCalls: 0,
|
|
134
|
+
focus() { this.focusCalls += 1; },
|
|
135
|
+
scrollIntoView() { this.scrollCalls += 1; },
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const nestedFile = { name: "child.js", path: "packages/child.js", type: "file" };
|
|
140
|
+
const clearState = {
|
|
141
|
+
selectedPath: nestedFile.path,
|
|
142
|
+
searchQuery: "child",
|
|
143
|
+
searchEntries: [nestedFile],
|
|
144
|
+
searchLoading: false,
|
|
145
|
+
searchTruncated: false,
|
|
146
|
+
searchTotal: 1,
|
|
147
|
+
expanded: new Set(["packages"]),
|
|
148
|
+
entriesByPath: new Map([["", [{ name: "packages", path: "packages", type: "directory", directory: true }]]]),
|
|
149
|
+
};
|
|
150
|
+
const selectedRow = focusableTreeItem(nestedFile.path);
|
|
151
|
+
let visibleRows = [];
|
|
152
|
+
let revealCall = null;
|
|
153
|
+
let resolveReveal;
|
|
154
|
+
let renderCalls = 0;
|
|
155
|
+
const revealReady = new Promise((resolve) => { resolveReveal = resolve; });
|
|
156
|
+
const searchInput = { value: "child", focusCalls: 0, focus() { this.focusCalls += 1; } };
|
|
157
|
+
const clearRuntime = {
|
|
158
|
+
fileTreeState: clearState,
|
|
159
|
+
fileTreeSearchTimer: null,
|
|
160
|
+
fileTreeSearchRequestSerial: 0,
|
|
161
|
+
FILE_TREE_ROOT_PATH: "",
|
|
162
|
+
elements: { fileTreeSearchInput: searchInput },
|
|
163
|
+
clearTimeout: () => {},
|
|
164
|
+
normalizeFileTreePath: runtime.normalizeFileTreePath,
|
|
165
|
+
fileTreeSearchQueryText: () => searchInput.value.trim(),
|
|
166
|
+
fileEntryByPath: () => nestedFile,
|
|
167
|
+
updateFileTreeSearchControls: () => {},
|
|
168
|
+
fileTreeEntriesStatus: () => "1 item.",
|
|
169
|
+
setFileTreeStatus: () => {},
|
|
170
|
+
renderFileTree: () => { renderCalls += 1; },
|
|
171
|
+
visibleFileTreeItems: () => visibleRows,
|
|
172
|
+
revealFileTreeEntry: (entry, options) => { revealCall = { entry, options }; return revealReady; },
|
|
173
|
+
addEvent: () => {},
|
|
174
|
+
};
|
|
175
|
+
vm.runInNewContext(`${clearSearch}\nthis.clearSearch = clearFileTreeSearch;`, clearRuntime);
|
|
176
|
+
clearRuntime.clearSearch({ focus: true });
|
|
177
|
+
assert.equal(searchInput.value, "", "clearing search should empty the field immediately");
|
|
178
|
+
assert.equal(clearState.searchQuery, "child", "the search result tree should remain rendered while the selected branch is prepared");
|
|
179
|
+
assert.equal(renderCalls, 0, "clearing should not flash a fully collapsed root tree before reveal completes");
|
|
180
|
+
assert.equal(revealCall?.entry, nestedFile, "the selected nested entry should be prepared before clearing search state");
|
|
181
|
+
assert.equal(revealCall?.options?.expandTarget, false, "revealing a selected file should not treat it as an expandable directory");
|
|
182
|
+
|
|
183
|
+
visibleRows = [selectedRow];
|
|
184
|
+
resolveReveal();
|
|
185
|
+
await revealReady;
|
|
186
|
+
await Promise.resolve();
|
|
187
|
+
assert.equal(clearState.searchQuery, "", "search state should clear after the selected branch is ready");
|
|
188
|
+
assert.equal(clearState.searchEntries.length, 0, "search matches should clear only during the final tree transition");
|
|
189
|
+
assert.equal(renderCalls, 1, "the prepared normal tree should render in one committed transition");
|
|
190
|
+
assert.equal(selectedRow.focusCalls, 1, "the selected row should receive focus after its ancestors are ready");
|
|
191
|
+
assert.equal(selectedRow.scrollCalls, 1, "the selected row should be scrolled into view after the transition");
|
|
192
|
+
assert.equal(searchInput.focusCalls, 0, "the search input should not steal focus back from the selected row");
|
|
193
|
+
|
|
194
|
+
const packageDirectory = { name: "package", path: "package", type: "directory", directory: true };
|
|
195
|
+
const libDirectory = { name: "lib", path: "package/lib", type: "directory", directory: true };
|
|
196
|
+
const integrationFile = { name: "remote-core.mjs", path: "package/lib/remote-core.mjs", type: "file" };
|
|
197
|
+
const integrationRow = focusableTreeItem(integrationFile.path);
|
|
198
|
+
const integrationState = {
|
|
199
|
+
selectedPath: integrationFile.path,
|
|
200
|
+
searchQuery: "webui",
|
|
201
|
+
searchEntries: [libDirectory],
|
|
202
|
+
searchLoading: false,
|
|
203
|
+
searchTruncated: false,
|
|
204
|
+
searchTotal: 1,
|
|
205
|
+
expanded: new Set([libDirectory.path]),
|
|
206
|
+
entriesByPath: new Map([
|
|
207
|
+
["", [packageDirectory]],
|
|
208
|
+
[libDirectory.path, [integrationFile]],
|
|
209
|
+
]),
|
|
210
|
+
};
|
|
211
|
+
const integrationInput = { value: "webui", focusCalls: 0, focus() { this.focusCalls += 1; } };
|
|
212
|
+
const integrationRenderModes = [];
|
|
213
|
+
const integrationLoadCalls = [];
|
|
214
|
+
let integrationVisibleRows = [];
|
|
215
|
+
const integrationRuntime = {
|
|
216
|
+
fileTreeState: integrationState,
|
|
217
|
+
fileTreeSearchTimer: null,
|
|
218
|
+
fileTreeSearchRequestSerial: 0,
|
|
219
|
+
FILE_TREE_ROOT_PATH: "",
|
|
220
|
+
elements: { fileTreeSearchInput: integrationInput },
|
|
221
|
+
clearTimeout: () => {},
|
|
222
|
+
normalizeFileTreePath: runtime.normalizeFileTreePath,
|
|
223
|
+
fileParentPath: runtime.fileParentPath,
|
|
224
|
+
fileTreeSearchQueryText: () => integrationInput.value.trim(),
|
|
225
|
+
fileEntryByPath: (path) => {
|
|
226
|
+
for (const entries of integrationState.entriesByPath.values()) {
|
|
227
|
+
const entry = entries.find((candidate) => candidate.path === path);
|
|
228
|
+
if (entry) return entry;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
},
|
|
232
|
+
updateFileTreeSearchControls: () => {},
|
|
233
|
+
fileTreeEntriesStatus: () => "1 item.",
|
|
234
|
+
setFileTreeStatus: () => {},
|
|
235
|
+
visibleFileTreeItems: () => integrationVisibleRows,
|
|
236
|
+
loadFileTreeDirectory: async (path) => {
|
|
237
|
+
integrationLoadCalls.push(path);
|
|
238
|
+
if (path === packageDirectory.path) integrationState.entriesByPath.set(path, [libDirectory]);
|
|
239
|
+
return integrationState.entriesByPath.get(path) || [];
|
|
240
|
+
},
|
|
241
|
+
renderFileTree: () => {
|
|
242
|
+
const mode = integrationState.searchQuery ? "search" : "tree";
|
|
243
|
+
integrationRenderModes.push(mode);
|
|
244
|
+
if (mode === "tree" && integrationState.expanded.has(packageDirectory.path) && integrationState.expanded.has(libDirectory.path)) {
|
|
245
|
+
integrationVisibleRows = [integrationRow];
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
addEvent: () => {},
|
|
249
|
+
};
|
|
250
|
+
vm.runInNewContext(`${revealSearchEntry}\n${clearSearch}\nthis.clearSearch = clearFileTreeSearch;`, integrationRuntime);
|
|
251
|
+
integrationRuntime.clearSearch({ focus: true });
|
|
252
|
+
for (let index = 0; index < 12; index += 1) await Promise.resolve();
|
|
253
|
+
assert.deepEqual(integrationLoadCalls, ["", packageDirectory.path, libDirectory.path], "clearing should load the selected file's complete ancestor chain");
|
|
254
|
+
assert.equal(integrationState.expanded.has(packageDirectory.path), true, "the selected file's top-level directory should remain expanded");
|
|
255
|
+
assert.equal(integrationState.expanded.has(libDirectory.path), true, "the directory opened during search should remain expanded");
|
|
256
|
+
assert.equal(integrationRenderModes.at(-1), "tree", "the final render should restore the normal tree");
|
|
257
|
+
assert.equal(integrationRenderModes.slice(0, -1).every((mode) => mode === "search"), true, "ancestor preparation should retain the search results until the normal tree is ready");
|
|
258
|
+
assert.equal(integrationRow.focusCalls, 1, "the selected file should receive focus in the restored normal tree");
|
|
259
|
+
assert.equal(integrationRow.scrollCalls, 1, "the restored normal tree should scroll to the selected file");
|
|
260
|
+
|
|
261
|
+
console.log("file-tree-search-layout-static.test.mjs passed");
|
|
@@ -17,7 +17,9 @@ assert.match(
|
|
|
17
17
|
"the file viewer should expose an accessible in-file search bar with match navigation",
|
|
18
18
|
);
|
|
19
19
|
assert.match(html, /id="fileViewerSearchInput"[^>]*aria-controls="fileViewerEditor"/, "the in-file search input should identify the source editor it searches");
|
|
20
|
+
assert.match(html, /id="fileViewerSearchOverlay"[^>]*aria-hidden="true"[^>]*hidden/, "source search should provide a non-interactive highlight overlay");
|
|
20
21
|
assert.match(app, /fileViewerSearchInput: \$\("#fileViewerSearchInput"\)/, "file search controls should be registered in the element map");
|
|
22
|
+
assert.match(app, /fileViewerSearchOverlay: \$\("#fileViewerSearchOverlay"\)/, "the source highlight overlay should be registered in the element map");
|
|
21
23
|
assert.match(app, /const FILE_VIEWER_SEARCH_MATCH_LIMIT = 10_000;/, "in-file search should bound match collection for large files");
|
|
22
24
|
assert.match(app, /function collectFileViewerSearchMatches\([\s\S]*fileViewerSearchText\(\)\.toLowerCase\(\)[\s\S]*haystack\.indexOf\(needle, offset\)/, "in-file search should collect case-insensitive matches from the active viewer surface");
|
|
23
25
|
|
|
@@ -45,7 +47,9 @@ const truncatedMatches = JSON.parse(vm.runInNewContext(`${helperSource}\nJSON.st
|
|
|
45
47
|
assert.equal(truncatedMatches.matches.length, 10_000, "large-file match collection should stop at the declared bound");
|
|
46
48
|
assert.equal(truncatedMatches.truncated, true, "large-file match collection should disclose additional matches beyond the bound");
|
|
47
49
|
assert.match(app, /function fileViewerSearchSurface\(\)[\s\S]*mode === "preview"[\s\S]*mode === "changes"[\s\S]*fileViewerEditor/, "search should stay scoped to the current Source, Preview, or Changes surface");
|
|
48
|
-
assert.match(app, /function
|
|
50
|
+
assert.match(app, /function renderFileViewerSourceSearchHighlights\(\)[\s\S]*fileViewerSearchMatches\.forEach[\s\S]*make\("mark", `file-viewer-search-match/, "source search should render every collected match into the synchronized overlay");
|
|
51
|
+
assert.match(app, /function renderFileViewerSearchHighlights\(\)[\s\S]*new HighlightConstructor\(\.\.\.ranges\)[\s\S]*file-viewer-search-match[\s\S]*file-viewer-search-current/, "rendered file surfaces should highlight all exact ranges and distinguish the current range");
|
|
52
|
+
assert.match(app, /function focusFileViewerSearchMatch\(\)[\s\S]*setSelectionRange\(match\.start, match\.end\)[\s\S]*syncFileViewerSearchOverlayScroll\(\)[\s\S]*textOffsetPosition\(surface, match\.start\)[\s\S]*scrollIntoView/, "match navigation should select and center source or rendered matches without mutating document selection");
|
|
49
53
|
assert.doesNotMatch(app.slice(app.indexOf("function focusFileViewerSearchMatch("), app.indexOf("\nfunction runFileViewerSearch(", app.indexOf("function focusFileViewerSearchMatch("))), /getSelection|addRange|removeAllRanges/, "rendered file search must not overwrite selections used by the Send to Pi workflow");
|
|
50
54
|
assert.match(app, /function runFileViewerSearch\([\s\S]*setAttribute\("aria-controls", surface\.id\)/, "the search input should identify the active Source, Preview, or Changes surface");
|
|
51
55
|
assert.match(app, /function setFileViewerMode\([\s\S]*updateFileViewerUi\(\);[\s\S]*runFileViewerSearch\(\{ navigate: true \}\)/, "an explicit mode switch should reveal the first match on the new surface");
|
|
@@ -60,6 +64,7 @@ assert.match(
|
|
|
60
64
|
assert.match(app, /function openChatSearch\(\)[\s\S]*closeFileViewerSearch\(\{ restoreFocus: false \}\)/, "opening transcript search should close any stale in-file search bar");
|
|
61
65
|
assert.match(css, /\.chat-search-bar,\s*\.file-viewer-search-bar \{/, "file search should reuse the transcript search layout conventions");
|
|
62
66
|
assert.match(css, /\.file-viewer-search-bar\[hidden\] \{ display: none; \}/, "the hidden file search bar should not consume viewer space");
|
|
63
|
-
assert.match(css,
|
|
67
|
+
assert.match(css, /\.file-viewer-search-overlay[\s\S]*\.file-viewer-content\.search-highlights-source[\s\S]*\.file-viewer-search-match\.current/, "source matches should use a scroll-synchronized visual overlay with a distinct current match");
|
|
68
|
+
assert.match(css, /::highlight\(file-viewer-search-match\)[\s\S]*::highlight\(file-viewer-search-current\)[\s\S]*\.file-viewer-search-match-fallback/, "rendered matches should highlight all exact ranges with a non-destructive fallback affordance");
|
|
64
69
|
|
|
65
70
|
console.log("file viewer focused search static tests passed");
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
// isStreaming=true while a scripted flow runs.
|
|
18
18
|
// - FAKE_PI_STATS_PROMPT_CONTEXT=1: advertise /stats-webui and publish deterministic
|
|
19
19
|
// structured or malformed-subsection Prompt/context dashboard payloads.
|
|
20
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
20
21
|
import { createInterface } from "node:readline";
|
|
21
|
-
import { randomUUID } from "node:crypto";
|
|
22
22
|
import { appendFileSync } from "node:fs";
|
|
23
23
|
import {
|
|
24
24
|
BUILTIN_SAMPLING_APIS,
|
|
@@ -216,6 +216,9 @@ logJsonLine({
|
|
|
216
216
|
cwd: process.cwd(),
|
|
217
217
|
recoveryUrl: String(process.env.PI_WEBUI_RECOVERY_URL || ""),
|
|
218
218
|
recoveryTokenConfigured: Boolean(process.env.PI_WEBUI_RECOVERY_TOKEN),
|
|
219
|
+
recoveryTokenDigest: process.env.PI_WEBUI_RECOVERY_TOKEN
|
|
220
|
+
? createHash("sha256").update(process.env.PI_WEBUI_RECOVERY_TOKEN).digest("hex")
|
|
221
|
+
: "",
|
|
219
222
|
...(continuityModeEnabled ? { pid: process.pid, continuityMode: true } : {}),
|
|
220
223
|
});
|
|
221
224
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
8
|
+
|
|
9
|
+
function functionBody(source, name) {
|
|
10
|
+
const match = new RegExp(`function\\s+${name}\\s*\\(`).exec(source);
|
|
11
|
+
assert.ok(match, `${name} should be defined`);
|
|
12
|
+
let parens = 0;
|
|
13
|
+
let open = -1;
|
|
14
|
+
for (let index = match.index + match[0].length - 1; index < source.length; index += 1) {
|
|
15
|
+
if (source[index] === "(") parens += 1;
|
|
16
|
+
else if (source[index] === ")") parens -= 1;
|
|
17
|
+
else if (source[index] === "{" && parens === 0) {
|
|
18
|
+
open = index;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
assert.notEqual(open, -1, `${name} should open`);
|
|
23
|
+
let depth = 0;
|
|
24
|
+
for (let index = open; index < source.length; index += 1) {
|
|
25
|
+
if (source[index] === "{") depth += 1;
|
|
26
|
+
else if (source[index] === "}" && --depth === 0) return source.slice(open + 1, index);
|
|
27
|
+
}
|
|
28
|
+
assert.fail(`${name} should close`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
assert.match(app, /import \{ classifyTranscriptStreamEvent, createStreamOutputController \} from "\.\/stream-output-controller\.mjs";/);
|
|
32
|
+
assert.match(app, /let foregroundTranscriptCatchUpRequired = document\.visibilityState === "hidden";/);
|
|
33
|
+
|
|
34
|
+
const beginCatchUp = functionBody(app, "beginForegroundTranscriptCatchUp");
|
|
35
|
+
assert.match(beginCatchUp, /foregroundTranscriptCatchUpRequired = true/);
|
|
36
|
+
assert.match(beginCatchUp, /streamOutputController\.cancel\(\)/, "backgrounding should discard pending frame work rather than replaying it later");
|
|
37
|
+
assert.match(beginCatchUp, /eventStreamPausedForBackground = true[\s\S]*?eventSource = null[\s\S]*?source\.close\(\)/, "backgrounding should close the EventSource so Chromium cannot retain and replay an SSE backlog");
|
|
38
|
+
|
|
39
|
+
const dispatch = functionBody(app, "dispatchTranscriptStreamEvent");
|
|
40
|
+
assert.match(dispatch, /classifyTranscriptStreamEvent\(event\)/);
|
|
41
|
+
assert.match(dispatch, /document\.visibilityState === "hidden" \|\| foregroundTranscriptCatchUpRequired/);
|
|
42
|
+
assert.ok(
|
|
43
|
+
dispatch.indexOf("return true;") < dispatch.indexOf("streamOutputController.dispatch(event"),
|
|
44
|
+
"hidden transcript updates should be consumed without entering DOM render queues",
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const reconcile = functionBody(app, "reconcileForegroundState");
|
|
48
|
+
const authoritativeRefresh = reconcile.indexOf("refreshMessages(tabContext, { authoritative: true })");
|
|
49
|
+
const resumeLiveRendering = reconcile.indexOf("foregroundTranscriptCatchUpRequired = false");
|
|
50
|
+
const resumeEventStream = reconcile.indexOf("ensureActiveEventStream(tabContext)");
|
|
51
|
+
const supplementalRefresh = reconcile.indexOf("scheduleForegroundSupplementalRefresh(tabContext)");
|
|
52
|
+
assert.ok(authoritativeRefresh >= 0, "foreground catch-up should fetch one authoritative transcript snapshot");
|
|
53
|
+
assert.ok(authoritativeRefresh < resumeLiveRendering, "live transcript rendering must resume only after the authoritative snapshot settles");
|
|
54
|
+
assert.ok(resumeLiveRendering < resumeEventStream, "the event stream must reconnect only after authoritative transcript rendering resumes");
|
|
55
|
+
assert.ok(resumeEventStream < supplementalRefresh, "nonessential refresh work should be staged after transcript catch-up");
|
|
56
|
+
assert.match(reconcile, /backgroundReconnectSnapshotFresh = !\[\.\.\.tabResult, \.\.\.criticalResults\]\.some/, "a failed snapshot must not suppress reconnect recovery");
|
|
57
|
+
|
|
58
|
+
const supplemental = functionBody(app, "scheduleForegroundSupplementalRefresh");
|
|
59
|
+
assert.match(supplemental, /requestIdleCallback\(run, \{ timeout: 1_200 \}\)/, "supplemental panels should refresh during idle time when supported");
|
|
60
|
+
assert.match(supplemental, /setTimeout\(run, 250\)/, "browsers without idle callbacks should still yield before supplemental refreshes");
|
|
61
|
+
|
|
62
|
+
assert.doesNotMatch(app, /window\.addEventListener\("blur", beginForegroundTranscriptCatchUp\)/, "a visible but unfocused window must keep live streaming");
|
|
63
|
+
assert.match(
|
|
64
|
+
app,
|
|
65
|
+
/document\.addEventListener\("visibilitychange"[\s\S]*?beginForegroundTranscriptCatchUp\(\)[\s\S]*?mobileConnectionState = "away"/,
|
|
66
|
+
"the hidden transition should enter catch-up mode before background state rendering",
|
|
67
|
+
);
|
|
68
|
+
assert.match(app, /case "webui_connected":[\s\S]*?resumedWithFreshSnapshot[\s\S]*?if \(!resumedWithFreshSnapshot\) scheduleForegroundReconcile/, "the deliberate reconnect must not immediately trigger a second full refresh");
|
|
69
|
+
assert.match(app, /case "webui_supervisor_reconnected":[\s\S]*?foregroundReconnectSnapshotFreshUntil/, "initial supervisor replay must reuse the fresh foreground snapshot");
|
|
70
|
+
|
|
71
|
+
const executeBeginCatchUp = new Function("eventSource", "streamOutputController", `
|
|
72
|
+
let foregroundTranscriptCatchUpRequired = false;
|
|
73
|
+
let backgroundReconnectSnapshotFresh = true;
|
|
74
|
+
let eventStreamPausedForBackground = false;
|
|
75
|
+
${beginCatchUp}
|
|
76
|
+
return { foregroundTranscriptCatchUpRequired, backgroundReconnectSnapshotFresh, eventStreamPausedForBackground, eventSource };
|
|
77
|
+
`);
|
|
78
|
+
let closeCount = 0;
|
|
79
|
+
let cancelCount = 0;
|
|
80
|
+
const pausedState = executeBeginCatchUp(
|
|
81
|
+
{ close() { closeCount += 1; } },
|
|
82
|
+
{ cancel() { cancelCount += 1; } },
|
|
83
|
+
);
|
|
84
|
+
assert.equal(cancelCount, 1, "backgrounding should cancel pending transcript work exactly once");
|
|
85
|
+
assert.equal(closeCount, 1, "backgrounding should close the active EventSource exactly once");
|
|
86
|
+
assert.equal(pausedState.eventSource, null, "the closed EventSource must be detached so no queued message handler remains current");
|
|
87
|
+
assert.equal(pausedState.eventStreamPausedForBackground, true);
|
|
88
|
+
assert.equal(pausedState.backgroundReconnectSnapshotFresh, false);
|
|
89
|
+
assert.equal(pausedState.foregroundTranscriptCatchUpRequired, true);
|
|
90
|
+
|
|
91
|
+
console.log("foreground-transcript-catch-up-static.test.mjs passed");
|