@firstpick/pi-package-webui 0.9.8 → 0.10.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.
Files changed (59) hide show
  1. package/DEVELOPMENT.md +911 -0
  2. package/README.md +8 -8
  3. package/TECHNICAL.md +415 -0
  4. package/bin/pi-webui.mjs +237 -64
  5. package/index.ts +23 -33
  6. package/lib/git-workflow-preferences.mjs +51 -12
  7. package/lib/tui-model-profile-selector.mjs +183 -0
  8. package/lib/tui-resource-selector.mjs +173 -0
  9. package/lib/windows-drive-roots.mjs +114 -0
  10. package/package.json +3 -1
  11. package/public/app.js +274 -90
  12. package/public/index.html +7 -3
  13. package/public/service-worker.js +1 -1
  14. package/public/styles.css +76 -16
  15. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  16. package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
  17. package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
  18. package/tests/browser/windows-drive-parent.spec.mjs +198 -0
  19. package/tests/codex-fast-mode-static.test.mjs +2 -2
  20. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  21. package/tests/control-visibility-static.test.mjs +3 -3
  22. package/tests/controls-layout-static.test.mjs +3 -3
  23. package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
  24. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  25. package/tests/fast-mode-client-static.test.mjs +1 -1
  26. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  27. package/tests/file-viewer-image-static.test.mjs +3 -3
  28. package/tests/fixtures/fake-pi.mjs +3 -3
  29. package/tests/guided-git-activation-static.test.mjs +24 -12
  30. package/tests/guided-git-fallback-runtime.test.mjs +209 -270
  31. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  32. package/tests/guided-git-message-reliability-static.test.mjs +2 -1
  33. package/tests/guided-git-optional-feature.test.mjs +8 -5
  34. package/tests/http-endpoints-harness.test.mjs +22 -4
  35. package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
  36. package/tests/intercom-tag-layout-static.test.mjs +35 -16
  37. package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
  38. package/tests/main-output-loading-static.test.mjs +3 -3
  39. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  40. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  41. package/tests/mobile-foundation-static.test.mjs +3 -3
  42. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  43. package/tests/mobile-static.test.mjs +11 -6
  44. package/tests/open-issue-wizard-static.test.mjs +1 -1
  45. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  46. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  47. package/tests/questionnaire-dialog.test.mjs +3 -3
  48. package/tests/remote-auth-settings-harness.test.mjs +18 -3
  49. package/tests/resource-tui-extension.test.mjs +2 -1
  50. package/tests/session-sampling-ui-static.test.mjs +3 -3
  51. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  52. package/tests/subagent-observability-static.test.mjs +2 -2
  53. package/tests/syntax-highlighting-static.test.mjs +3 -3
  54. package/tests/theme-customizer-static.test.mjs +1 -1
  55. package/tests/tui-model-profile-selector.test.mjs +102 -0
  56. package/tests/tui-resource-selector.test.mjs +74 -0
  57. package/tests/webui-settings-locking.test.mjs +32 -1
  58. package/tests/windows-drive-cwd-picker-static.test.mjs +81 -0
  59. package/tests/windows-drive-roots.test.mjs +130 -0
@@ -27,8 +27,8 @@ assert.doesNotMatch(layout, /sectionHeightMin|sectionHeightMax|validateSectionHe
27
27
  assert.match(app, /const UI_LAYOUT_SIDE_PANEL_FIELDS = \["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"\];/, "the browser durable layout field list should omit section heights");
28
28
  assert.match(app, /function clearRemovedSidePanelSectionHeightState\(\)[\s\S]*localStorage\.removeItem\(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY\)[\s\S]*record\.field === "sidePanel" && record\.subfield === "sectionHeights"/, "startup should remove the retired cache and pending mutations");
29
29
  assert.match(app, /clearRemovedSidePanelSectionHeightState\(\);\s*restoreDurableUiLayoutPendingJournal\(\);/, "retired height state should be cleared before pending layout restoration");
30
- assert.match(html, /styles\.css\?v=142/, "removing section resize styles should advance the stylesheet revision");
31
- assert.match(html, /app\.js\?v=172/, "removing section resize behavior should advance the app revision");
32
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "removing browser assets should advance the PWA cache identity");
30
+ assert.match(html, /styles\.css\?v=145/, "removing section resize styles should advance the stylesheet revision");
31
+ assert.match(html, /app\.js\?v=177/, "removing section resize behavior should advance the app revision");
32
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v145"/, "removing browser assets should advance the PWA cache identity");
33
33
 
34
34
  console.log("side-panel-section-height-removal-static.test.mjs passed");
@@ -28,7 +28,7 @@ assert.match(app, /const SUBAGENT_ASYNC_WIDGET_KEY = "subagent-async"[\s\S]*case
28
28
  assert.match(app, /for \(const \[key, value\] of widgets\)[\s\S]*if \(key === SUBAGENT_ASYNC_WIDGET_KEY\) continue;/, "stale cached async-status widgets should remain hidden defensively");
29
29
  assert.match(css, /\.subagent-source-badge[\s\S]*text-overflow: ellipsis[\s\S]*@media \(max-width: 720px\)/, "source badges should remain compact and responsive");
30
30
  assert.match(html, /Managed and registered Pi agent runs[\s\S]*External agents/, "help should explain managed, registered, and external groups");
31
- assert.match(html, /styles\.css\?v=142[\s\S]*app\.js\?v=172/, "browser assets should use the current subagent-observability revisions");
32
- assert.match(worker, /pi-webui-pwa-v139/, "PWA cache identity should advance with subagent widget suppression");
31
+ assert.match(html, /styles\.css\?v=145[\s\S]*app\.js\?v=177/, "browser assets should use the current subagent-observability revisions");
32
+ assert.match(worker, /pi-webui-pwa-v145/, "PWA cache identity should advance with subagent widget suppression");
33
33
 
34
34
  console.log("subagent-observability-static.test.mjs passed");
@@ -60,9 +60,9 @@ assert.match(css, /\.markdown-code \.syntax-comment \{[^}]*font-style: italic;/,
60
60
 
61
61
  // --- Offline/PWA startup closure and coherent revisions ---
62
62
  assert.match(serviceWorker, /"\/syntax-highlight\.mjs",/, "the eagerly imported tokenizer must be part of the offline app shell");
63
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "adding a startup module should advance the PWA cache identity");
64
- assert.match(html, /styles\.css\?v=142/, "new token styles should advance the stylesheet revision");
65
- assert.match(html, /data-app-src="\/app\.js\?v=172"/, "new renderer wiring should advance the app module revision");
63
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v145"/, "adding a startup module should advance the PWA cache identity");
64
+ assert.match(html, /styles\.css\?v=145/, "new token styles should advance the stylesheet revision");
65
+ assert.match(html, /data-app-src="\/app\.js\?v=177"/, "new renderer wiring should advance the app module revision");
66
66
  assert.match(pkg, /node --check public\/syntax-highlight\.mjs/, "the package check should syntax-check the startup-critical tokenizer");
67
67
 
68
68
  const appShell = serviceWorker.slice(serviceWorker.indexOf("const APP_SHELL"), serviceWorker.indexOf("];", serviceWorker.indexOf("const APP_SHELL")));
@@ -34,7 +34,7 @@ assert.match(html, /role="alert" hidden>[\s\S]*Replace this exact target\?/, "ov
34
34
 
35
35
  assert.match(app, /from "\.\/theme-contract\.mjs"/, "frontend should consume the shared browser-safe theme contract");
36
36
  assert.match(serviceWorker, /"\/theme-contract\.mjs"/, "the PWA app shell should cache the startup-critical theme contract");
37
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
37
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v145"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
38
38
  assert.match(pkg, /node --check public\/theme-contract\.mjs/, "the package check should syntax-check the startup-critical theme contract");
39
39
  assert.match(app, /function themeDraftFromCatalog\(theme, name = theme\?\.name\)[\s\S]*colors: cloneThemeDraft\(theme\?\.colors \|\| \{\}\)/, "catalog metadata should be projected into a schema-only editable draft");
40
40
  assert.match(app, /for \(const \{ name, label \} of group\.tokens\)/, "visual controls should render from the exact shared token inventory");
@@ -0,0 +1,102 @@
1
+ import assert from "node:assert/strict";
2
+ import { KeybindingsManager, setKeybindings, TUI_KEYBINDINGS } from "@earendil-works/pi-tui";
3
+ import { TuiModelProfileSelectorComponent } from "../lib/tui-model-profile-selector.mjs";
4
+
5
+ const theme = {
6
+ fg: (_color, text) => text,
7
+ bold: (text) => text,
8
+ };
9
+
10
+ function createSelector(config) {
11
+ const selected = [];
12
+ let cancelled = 0;
13
+ const selector = new TuiModelProfileSelectorComponent(
14
+ {
15
+ title: "Tools Model Profile",
16
+ subtitle: "Choose a profile to edit. This does not switch the active model.",
17
+ configuredModelKeys: [],
18
+ ...config,
19
+ },
20
+ theme,
21
+ {
22
+ onSelect: (model) => selected.push(model),
23
+ onCancel: () => cancelled++,
24
+ },
25
+ );
26
+ return { selector, selected, cancelled: () => cancelled };
27
+ }
28
+
29
+ setKeybindings(new KeybindingsManager(TUI_KEYBINDINGS));
30
+
31
+ {
32
+ const models = Array.from({ length: 15 }, (_, index) => ({
33
+ provider: index % 2 === 0 ? "alpha" : "beta",
34
+ id: `model-${String(index).padStart(2, "0")}`,
35
+ name: `Model ${index}`,
36
+ }));
37
+ const active = models[12];
38
+ const { selector, selected } = createSelector({
39
+ models,
40
+ activeModelKey: `${active.provider}\0${active.id}`,
41
+ configuredModelKeys: [`${active.provider}\0${active.id}`],
42
+ });
43
+ const rendered = selector.render(120).join("\n");
44
+ assert.match(rendered, /model-12 \[alpha\] \[active\] \[profile\]/, "the picker should open around the active model and mark configured profiles");
45
+ assert.match(rendered, /Model Name: Model 12 · Profile: configured/);
46
+
47
+ selector.handleInput("\x1b[B");
48
+ selector.handleInput("\r");
49
+ assert.equal(selected[0], models[13], "selection should return the exact model object rather than decoding its label");
50
+ }
51
+
52
+ {
53
+ const models = Array.from({ length: 15 }, (_, index) => ({
54
+ provider: "alpha",
55
+ id: `model-${String(index).padStart(2, "0")}`,
56
+ name: `Model ${index}`,
57
+ }));
58
+ const active = models[12];
59
+ const { selector, selected } = createSelector({ models, activeModelKey: `${active.provider}\0${active.id}` });
60
+ for (const character of "model-00") selector.handleInput(character);
61
+ selector.handleInput("\r");
62
+ assert.equal(selected[0], models[0], "a narrowing search should select its first match instead of retaining a stale list index");
63
+ }
64
+
65
+ {
66
+ const models = [
67
+ { provider: "alpha", id: "shared-a", name: "Shared Model" },
68
+ { provider: "beta", id: "shared-b", name: "Shared Model" },
69
+ { provider: "gamma", id: "other", name: "Other" },
70
+ ];
71
+ const { selector, selected } = createSelector({ models, activeModelKey: "" });
72
+ for (const character of "beta") selector.handleInput(character);
73
+ assert.equal(selector.getSearchInput().getValue(), "beta");
74
+ assert.doesNotMatch(selector.render(100).join("\n"), /\[alpha\]/);
75
+ selector.handleInput("\r");
76
+ assert.equal(selected[0], models[1], "provider search should disambiguate models with the same display name");
77
+ }
78
+
79
+ {
80
+ const { selector, cancelled } = createSelector({
81
+ models: [{ provider: "alpha", id: "one", name: "One" }],
82
+ activeModelKey: "",
83
+ });
84
+ for (const character of "missing") selector.handleInput(character);
85
+ assert.match(selector.render(100).join("\n"), /No matching models/);
86
+ selector.handleInput("\x03");
87
+ assert.equal(selector.getSearchInput().getValue(), "", "Ctrl+C should clear search before cancelling");
88
+ assert.equal(cancelled(), 0);
89
+ selector.handleInput("\x03");
90
+ assert.equal(cancelled(), 1);
91
+ }
92
+
93
+ {
94
+ const { selector, cancelled } = createSelector({
95
+ models: [{ provider: "alpha", id: "one", name: "One" }],
96
+ activeModelKey: "",
97
+ });
98
+ selector.handleInput("\x1b");
99
+ assert.equal(cancelled(), 1, "Escape should cancel model profile selection");
100
+ }
101
+
102
+ console.log("tui-model-profile-selector.test.mjs passed");
@@ -0,0 +1,74 @@
1
+ import assert from "node:assert/strict";
2
+ import { KeybindingsManager, setKeybindings, TUI_KEYBINDINGS } from "@earendil-works/pi-tui";
3
+ import { TuiResourceSelectorComponent } from "../lib/tui-resource-selector.mjs";
4
+
5
+ const theme = {
6
+ fg: (_color, text) => text,
7
+ bold: (text) => text,
8
+ };
9
+
10
+ function createSelector(enabledResourceNames = ["alpha", "gamma"]) {
11
+ const saved = [];
12
+ let cancelled = 0;
13
+ const selector = new TuiResourceSelectorComponent(
14
+ {
15
+ title: "Tools Configuration",
16
+ subtitle: "Session only. Changes apply only after Ctrl+S.",
17
+ resources: ["alpha", "beta", "gamma"],
18
+ enabledResourceNames,
19
+ },
20
+ theme,
21
+ {
22
+ onSave: (selection) => saved.push(selection),
23
+ onCancel: () => cancelled++,
24
+ },
25
+ );
26
+ return { selector, saved, cancelled: () => cancelled };
27
+ }
28
+
29
+ setKeybindings(new KeybindingsManager(TUI_KEYBINDINGS));
30
+
31
+ {
32
+ const { selector, saved } = createSelector();
33
+ selector.handleInput("\x1b[B");
34
+ selector.handleInput("\r");
35
+ assert.match(selector.render(100).join("\n"), /3\/3 enabled.*\(unsaved\)/);
36
+ selector.handleInput("\x13");
37
+ assert.deepEqual(saved, [["alpha", "beta", "gamma"]], "Ctrl+S should save the current explicit selection");
38
+ }
39
+
40
+ {
41
+ const { selector, saved } = createSelector();
42
+ selector.handleInput("b");
43
+ selector.handleInput("e");
44
+ assert.equal(selector.getSearchInput().getValue(), "be");
45
+ assert.doesNotMatch(selector.render(100).join("\n"), /alpha/);
46
+
47
+ selector.handleInput("\x18");
48
+ selector.handleInput("\x13");
49
+ assert.deepEqual(saved.at(-1), ["alpha", "gamma"], "Ctrl+X should clear only resources matching the active search");
50
+
51
+ selector.handleInput("\x01");
52
+ selector.handleInput("\x13");
53
+ assert.deepEqual(saved.at(-1), ["alpha", "beta", "gamma"], "Ctrl+A should enable only resources matching the active search");
54
+ }
55
+
56
+ {
57
+ const { selector, cancelled } = createSelector();
58
+ selector.handleInput("z");
59
+ selector.handleInput("z");
60
+ assert.match(selector.render(100).join("\n"), /No matching resources/);
61
+ selector.handleInput("\x03");
62
+ assert.equal(selector.getSearchInput().getValue(), "", "Ctrl+C should clear a non-empty search before cancelling");
63
+ assert.equal(cancelled(), 0);
64
+ selector.handleInput("\x03");
65
+ assert.equal(cancelled(), 1, "Ctrl+C on an empty search should cancel");
66
+ }
67
+
68
+ {
69
+ const { selector, cancelled } = createSelector();
70
+ selector.handleInput("\x1b");
71
+ assert.equal(cancelled(), 1, "Escape should cancel without saving");
72
+ }
73
+
74
+ console.log("tui-resource-selector.test.mjs passed");
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { execFile, spawn } from "node:child_process";
3
3
  import { once } from "node:events";
4
- import { mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
4
+ import { mkdtemp, readFile, readdir, rm, stat, utimes, writeFile } from "node:fs/promises";
5
5
  import { homedir, tmpdir } from "node:os";
6
6
  import path from "node:path";
7
7
  import { promisify } from "node:util";
@@ -170,9 +170,40 @@ try {
170
170
  assert.equal(JSON.parse(await readFile(liveLockRecord, "utf8")).token, "live");
171
171
  await rm(liveLockRecord);
172
172
 
173
+ const liveIncompleteRecord = path.join(liveLockDirectory, `${process.pid}-${Date.now() - 100}-incomplete.json`);
174
+ await writeFile(liveIncompleteRecord, "", "utf8");
175
+ await assert.rejects(
176
+ withWebuiSettingsLock(liveLockTarget, () => true, { timeoutMs: 35, retryMs: 5 }),
177
+ (error) => error?.code === "WEBUI_SETTINGS_LOCK_TIMEOUT",
178
+ "a newly created incomplete record from a live owner must retain a short write grace period",
179
+ );
180
+ await rm(liveIncompleteRecord);
181
+
173
182
  const exited = spawn(process.execPath, ["-e", "process.exit(0)"], { stdio: "ignore" });
174
183
  const deadPid = exited.pid;
175
184
  await once(exited, "exit");
185
+ const deadIncompleteRecord = path.join(liveLockDirectory, `${deadPid}-${Date.now()}-incomplete.json`);
186
+ await writeFile(deadIncompleteRecord, "", "utf8");
187
+ assert.equal(
188
+ await withWebuiSettingsLock(liveLockTarget, () => "recovered incomplete", { timeoutMs: 250, retryMs: 5 }),
189
+ "recovered incomplete",
190
+ "an incomplete record from a dead owner must not block future saves",
191
+ );
192
+ await assert.rejects(readFile(deadIncompleteRecord, "utf8"), { code: "ENOENT" });
193
+
194
+ await mkdir(liveLockDirectory, { recursive: true });
195
+ const malformedLockRecord = path.join(liveLockDirectory, "malformed.json");
196
+ await writeFile(malformedLockRecord, "{", "utf8");
197
+ const staleTime = new Date(Date.now() - 5_000);
198
+ await utimes(malformedLockRecord, staleTime, staleTime);
199
+ assert.equal(
200
+ await withWebuiSettingsLock(liveLockTarget, () => "recovered malformed", { timeoutMs: 250, retryMs: 5 }),
201
+ "recovered malformed",
202
+ "an old malformed record without owner metadata must not block future saves",
203
+ );
204
+ await assert.rejects(readFile(malformedLockRecord, "utf8"), { code: "ENOENT" });
205
+
206
+ await mkdir(liveLockDirectory, { recursive: true });
176
207
  const deadLockRecord = path.join(liveLockDirectory, "dead.json");
177
208
  await writeFile(deadLockRecord, `${JSON.stringify({ pid: deadPid, token: "dead", state: "active" })}\n`, "utf8");
178
209
  assert.equal(await withWebuiSettingsLock(liveLockTarget, () => "recovered", { timeoutMs: 250, retryMs: 5 }), "recovered");
@@ -0,0 +1,81 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import { dirname, join, win32 } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
+ const [app, html, styles, readme, technical, development, serviceWorker, server, packageJsonText] = await Promise.all([
8
+ readFile(join(root, "public", "app.js"), "utf8"),
9
+ readFile(join(root, "public", "index.html"), "utf8"),
10
+ readFile(join(root, "public", "styles.css"), "utf8"),
11
+ readFile(join(root, "README.md"), "utf8"),
12
+ readFile(join(root, "TECHNICAL.md"), "utf8"),
13
+ readFile(join(root, "DEVELOPMENT.md"), "utf8"),
14
+ readFile(join(root, "public", "service-worker.js"), "utf8"),
15
+ readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
16
+ readFile(join(root, "package.json"), "utf8"),
17
+ ]);
18
+ const packageJson = JSON.parse(packageJsonText);
19
+
20
+ function sourceBetween(source, start, end) {
21
+ const startIndex = source.indexOf(start);
22
+ const endIndex = source.indexOf(end, startIndex + start.length);
23
+ assert.ok(startIndex >= 0 && endIndex > startIndex, `expected source block from ${start} to ${end}`);
24
+ return source.slice(startIndex, endIndex);
25
+ }
26
+
27
+ assert.equal(win32.resolve("C:\\repo", "D:/"), "D:\\", "Node should treat a slash-form drive root as an absolute Windows cwd");
28
+ assert.match(html, /id="pathPickerPathInput"[^>]*placeholder="Path, e\.g\. C:\/ or D:\/project"[^>]*aria-label="Directory path"/, "the cwd picker should expose an accessible direct-path field with Windows drive examples");
29
+ assert.match(html, /id="pathPickerPathButton"[^>]*>Go<\/button>/, "the direct-path field should have an explicit Go action");
30
+ assert.match(app, /pathPickerPathInput: \$\("#pathPickerPathInput"\)[\s\S]*pathPickerPathButton: \$\("#pathPickerPathButton"\)/, "the browser should bind both direct-path controls");
31
+
32
+ const openEnteredPath = sourceBetween(app, "async function openPathPickerEnteredPath()", "function pathPickerCreateName()");
33
+ assert.match(openEnteredPath, /const cwd = pathPickerEnteredPath\(\)[\s\S]*await loadPathPickerDirectory\(cwd\)/, "direct paths should use the existing validated directory loader without rewriting drive-qualified input");
34
+ const renderPicker = sourceBetween(app, "function renderPathPicker(data)", "async function loadPathPickerDirectory(cwd, { focusAfterLoad = false } = {})");
35
+ assert.match(renderPicker, /pathPickerState\.selectable = data\.selectable !== false/, "the browser should default ordinary directories to selectable while honoring the virtual view contract");
36
+ assert.match(renderPicker, /pathPickerState\.displayCwd = data\.displayCwd \|\| pathPickerState\.cwd/, "the virtual This PC label should be retained independently of its empty cwd");
37
+ assert.match(renderPicker, /pathPickerChooseButton\.disabled = !pathPickerState\.selectable \|\| !pathPickerState\.cwd/, "Use this directory should stay disabled for the virtual view");
38
+ const searchControls = sourceBetween(app, "function updatePathPickerSearchControls()", "function pathPickerDirectoryMatchesSearch");
39
+ assert.match(searchControls, /pathPickerState\.selectable === false \|\| !!pathPickerState\.cwd/, "search should remain available in the non-selectable This PC view");
40
+ const createControls = sourceBetween(app, "function updateCreateDirectoryControls()", "function pathPickerSearchQuery()");
41
+ assert.match(createControls, /pathPickerState\.selectable !== false/, "directory creation should be gated by virtual-view selectability");
42
+ const currentFastPickBlock = sourceBetween(app, "function currentFastPick()", "function updateAddFastPickButton()");
43
+ assert.match(currentFastPickBlock, /pathPickerState\.selectable === false/, "the virtual view should not be pinnable");
44
+ const directoryList = sourceBetween(app, "function renderPathPickerDirectoryList()", "function clearPathPickerSearch");
45
+ assert.match(directoryList, /loadPathPickerDirectory\(directory\.cwd, \{ focusAfterLoad: true \}\)/, "clicking a listed drive should use the existing directory loader and restore stable focus");
46
+ assert.match(renderPicker, /loadPathPickerDirectory\(data\.parent, \{ focusAfterLoad: true \}\)/, "Parent navigation should restore focus after replacing its button");
47
+ const fastPicks = sourceBetween(app, "function renderFastPicks()", "async function addCurrentFastPick()");
48
+ assert.match(fastPicks, /loadPathPickerDirectory\(pick\.cwd, \{ focusAfterLoad: true \}\)/, "fast-pick navigation should restore focus after rerendering");
49
+
50
+ const loadDirectory = sourceBetween(app, "async function loadPathPickerDirectory(cwd, { focusAfterLoad = false } = {})", "async function createPathPickerDirectory()");
51
+ assert.match(loadDirectory, /encodeURIComponent\(cwd\)/, "drive-qualified paths and the internal Parent destination should be URL-encoded before the directory request");
52
+ assert.doesNotMatch(loadDirectory.slice(loadDirectory.indexOf("} catch (error)")), /pathPickerPathInput\.value\s*=/, "failed drive lookups should keep the entered path editable");
53
+ assert.match(loadDirectory, /pathPickerCurrent\.textContent = pathPickerState\.displayCwd \|\| pathPickerState\.cwd \|\| "Unable to load directory"/, "a failed drive load from This PC should restore the virtual display label");
54
+ assert.match(loadDirectory, /if \(focusAfterLoad\) elements\.pathPickerSearchInput\.focus\(\{ preventScroll: true \}\)/, "navigation-originated loads should restore focus to the stable search control");
55
+ assert.match(html, /id="pathPickerError"[^>]*role="alert"[^>]*hidden/, "directory load failures should be exposed through one dedicated live alert");
56
+ assert.match(app, /pathPickerPathInput\.addEventListener\("keydown"[\s\S]*event\.key !== "Enter"[\s\S]*openPathPickerEnteredPath\(\)/, "Enter should open the entered path");
57
+ assert.match(app, /pathPickerPathButton\.addEventListener\("click"[\s\S]*openPathPickerEnteredPath\(\)/, "the Go button should open the entered path");
58
+ assert.match(server, /platform\(\) === "win32" && isWindowsDriveRoot\(cwd\)[\s\S]*WINDOWS_DRIVES_PICKER_PATH/, "Parent from a Windows drive root should target the virtual This PC destination");
59
+ assert.match(server, /platform\(\) === "win32" && viewPath === WINDOWS_DRIVES_PICKER_PATH[\s\S]*getWindowsDrivesPickerData\(activeCwd\)/, "the virtual Parent destination should be intercepted only on Windows");
60
+
61
+ const splitFlow = sourceBetween(app, "async function splitTerminalTab", "async function createTerminalTabFromChosenDirectory");
62
+ assert.match(splitFlow, /pickCwd\([\s\S]*body: \{ cwd: resolvedCwd \}/, "split terminals without a cwd should use the shared drive-aware picker");
63
+ const newTabFlow = sourceBetween(app, "async function createTerminalTabFromChosenDirectory", "async function createFirstTerminalTabFromChosenDirectory");
64
+ assert.match(newTabFlow, /pickCwd\([\s\S]*createTerminalTab\(cwd/, "new terminal tabs should use the shared drive-aware picker");
65
+ const firstTabFlow = sourceBetween(app, "async function createFirstTerminalTabFromChosenDirectory", "function tabHasActiveAgent");
66
+ assert.match(firstTabFlow, /pickCwd\([\s\S]*createTerminalTab\(cwd/, "the first terminal should use the shared drive-aware picker");
67
+ const cwdChangeFlow = sourceBetween(app, "async function changeActiveTabCwd()", "function footerControlKey(node)");
68
+ assert.match(cwdChangeFlow, /await pickCwd\([\s\S]*method: "PATCH", body: \{ cwd \}/, "cwd changes should use the shared picker and pass its selected drive-qualified path to the existing tab route");
69
+
70
+ assert.match(styles, /\.path-picker-path-row[\s\S]*grid-template-columns: minmax\(0, 1fr\) auto/, "the direct-path controls should use the picker row layout");
71
+ assert.match(styles, /\.path-picker-current-row,[\s\S]*\.path-picker-path-row,[\s\S]*grid-template-columns: 1fr/, "the direct-path controls should stack on narrow screens");
72
+ assert.match(readme, /Windows[\s\S]*`C:\/`[\s\S]*`D:\/project`[\s\S]*\*\*Parent\*\*[\s\S]*\*\*This PC\*\*/, "the README should explain both typed paths and Parent-based Windows drive switching");
73
+ assert.match(technical, /working-directory picker accepts a direct path[\s\S]*\*\*Parent\*\* opens a \*\*This PC\*\*[\s\S]*navigation-only/i, "the technical reference should document the virtual drive view and its control limits");
74
+ assert.match(development, /virtual \*\*This PC\*\* response with an empty cwd and `selectable: false`/i, "the contributor guide should record the server/browser virtual-view contract");
75
+ assert.ok(packageJson.files.includes("TECHNICAL.md"), "the published package should include its advanced user reference");
76
+ assert.ok(packageJson.files.includes("DEVELOPMENT.md"), "the published package should include its contributor guide");
77
+ assert.match(html, /styles\.css\?v=145/, "the existing picker layout should retain its stylesheet revision");
78
+ assert.match(html, /app\.js\?v=177/, "the changed picker behavior should advance the app revision");
79
+ assert.match(serviceWorker, /pi-webui-pwa-v145/, "the changed browser assets should advance the PWA cache identity");
80
+
81
+ console.log("windows-drive-cwd-picker-static.test.mjs passed");
@@ -0,0 +1,130 @@
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
+ import {
6
+ WINDOWS_DRIVES_PICKER_PATH,
7
+ WINDOWS_DRIVE_DISCOVERY_MAX_OUTPUT,
8
+ WINDOWS_DRIVE_DISCOVERY_TIMEOUT_MS,
9
+ createWindowsDriveRootDiscovery,
10
+ isWindowsDriveRoot,
11
+ mergeWindowsDriveRoots,
12
+ normalizeWindowsDriveRoot,
13
+ parseWindowsDriveRoots,
14
+ windowsDriveRootsFromKnownPaths,
15
+ windowsDrivesPickerData,
16
+ } from "../lib/windows-drive-roots.mjs";
17
+
18
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
19
+
20
+ assert.equal(normalizeWindowsDriveRoot("c:\\"), "C:\\");
21
+ assert.equal(normalizeWindowsDriveRoot("d:/"), "D:\\");
22
+ assert.equal(isWindowsDriveRoot("Z:\\"), true);
23
+ for (const invalid of ["C:", "C:project", "C:\\project", " C:\\", "C:\\\\", "\\\\server\\share\\", "/"] ) {
24
+ assert.equal(normalizeWindowsDriveRoot(invalid), null, `${JSON.stringify(invalid)} must not be accepted as a drive root`);
25
+ }
26
+
27
+ assert.deepEqual(
28
+ parseWindowsDriveRoots("D:\\\r\nc:/\r\ninvalid\r\nd:\\\r\n Z:\\\r\n"),
29
+ ["C:\\", "D:\\"],
30
+ "PowerShell output should be parsed strictly, normalized, deduplicated, and sorted",
31
+ );
32
+ assert.deepEqual(
33
+ windowsDriveRootsFromKnownPaths(["d:\\project", "C:/Users/test", "e:", "e:relative", "/home/test", null]),
34
+ ["C:\\", "D:\\", "E:\\"],
35
+ "known absolute paths and system drive designators should provide fallback roots",
36
+ );
37
+ assert.deepEqual(mergeWindowsDriveRoots(["z:/", "C:\\"], ["c:/", "D:\\"]), ["C:\\", "D:\\", "Z:\\"]);
38
+
39
+ const virtualData = windowsDrivesPickerData(["D:\\", "c:/", "bad"], [{ label: "Tab", cwd: "C:\\repo" }]);
40
+ assert.deepEqual(virtualData, {
41
+ cwd: "",
42
+ displayCwd: "This PC",
43
+ parent: null,
44
+ roots: [{ label: "Tab", cwd: "C:\\repo" }],
45
+ directories: [
46
+ { name: "C:\\", cwd: "C:\\", displayCwd: "C:\\", hidden: false },
47
+ { name: "D:\\", cwd: "D:\\", displayCwd: "D:\\", hidden: false },
48
+ ],
49
+ truncated: false,
50
+ selectable: false,
51
+ });
52
+ assert.equal(WINDOWS_DRIVES_PICKER_PATH, "::pi-webui-windows-drives::");
53
+
54
+ let currentTime = 1_000;
55
+ const commandCalls = [];
56
+ const discover = createWindowsDriveRootDiscovery({
57
+ now: () => currentTime,
58
+ cacheTtlMs: 100,
59
+ runCommand: async (...args) => {
60
+ commandCalls.push(args);
61
+ return { exitCode: 0, timedOut: false, stdoutTruncated: false, stdout: "D:\\\r\nC:/\r\nmalformed\r\n" };
62
+ },
63
+ });
64
+
65
+ assert.deepEqual(await discover({ cwd: "C:\\repo", knownPaths: ["E:\\work"] }), ["C:\\", "D:\\", "E:\\"]);
66
+ assert.equal(commandCalls.length, 1);
67
+ assert.equal(commandCalls[0][0], "powershell.exe");
68
+ assert.deepEqual(commandCalls[0][1].slice(0, 4), ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command"]);
69
+ assert.match(commandCalls[0][1][4], /\[System\.IO\.DriveInfo\]::GetDrives\(\)/);
70
+ assert.match(commandCalls[0][1][4], /\.IsReady/);
71
+ assert.deepEqual(commandCalls[0][2], {
72
+ cwd: "C:\\repo",
73
+ timeoutMs: WINDOWS_DRIVE_DISCOVERY_TIMEOUT_MS,
74
+ maxOutputLength: WINDOWS_DRIVE_DISCOVERY_MAX_OUTPUT,
75
+ utf8Output: true,
76
+ });
77
+
78
+ assert.deepEqual(
79
+ await discover({ cwd: "C:\\other", knownPaths: ["F:"] }),
80
+ ["C:\\", "D:\\", "F:\\"],
81
+ "cached discovery should merge fresh known roots without rerunning PowerShell",
82
+ );
83
+ assert.equal(commandCalls.length, 1);
84
+ currentTime += 101;
85
+ await discover({ cwd: "C:\\other" });
86
+ assert.equal(commandCalls.length, 2, "expired discovery should rerun PowerShell");
87
+
88
+ let releaseConcurrent;
89
+ let concurrentCalls = 0;
90
+ const concurrent = createWindowsDriveRootDiscovery({
91
+ runCommand: async () => {
92
+ concurrentCalls += 1;
93
+ await new Promise((resolve) => { releaseConcurrent = resolve; });
94
+ return { exitCode: 0, timedOut: false, stdoutTruncated: false, stdout: "G:\\\n" };
95
+ },
96
+ });
97
+ const firstConcurrent = concurrent({ knownPaths: ["C:\\repo"] });
98
+ const secondConcurrent = concurrent({ knownPaths: ["D:\\repo"] });
99
+ releaseConcurrent();
100
+ assert.deepEqual(await firstConcurrent, ["C:\\", "G:\\"]);
101
+ assert.deepEqual(await secondConcurrent, ["D:\\", "G:\\"]);
102
+ assert.equal(concurrentCalls, 1, "concurrent picker requests should share one PowerShell process");
103
+
104
+ for (const failedResult of [
105
+ { exitCode: 1, timedOut: false, stdout: "Z:\\\n" },
106
+ { exitCode: undefined, timedOut: true, stdout: "Z:\\\n" },
107
+ { exitCode: 0, timedOut: false, stdoutTruncated: true, stdout: "Z:\\\n" },
108
+ ]) {
109
+ const failedDiscovery = createWindowsDriveRootDiscovery({ runCommand: async () => failedResult });
110
+ assert.deepEqual(await failedDiscovery({ knownPaths: ["C:\\repo", "D:"] }), ["C:\\", "D:\\"]);
111
+ }
112
+ const throwingDiscovery = createWindowsDriveRootDiscovery({ runCommand: async () => { throw new Error("unavailable"); } });
113
+ assert.deepEqual(await throwingDiscovery({ knownPaths: ["C:\\repo"] }), ["C:\\"]);
114
+
115
+ const serverSource = await readFile(join(root, "bin", "pi-webui.mjs"), "utf8");
116
+ assert.match(serverSource, /platform\(\) === "win32" && viewPath === WINDOWS_DRIVES_PICKER_PATH[\s\S]*return getWindowsDrivesPickerData\(activeCwd\)/, "the sentinel must be intercepted only on Windows before cwd resolution");
117
+ assert.match(serverSource, /platform\(\) === "win32" && isWindowsDriveRoot\(cwd\)[\s\S]*\? WINDOWS_DRIVES_PICKER_PATH/, "Windows drive roots should route Parent to the virtual picker");
118
+ assert.match(serverSource, /windowsDrivesPickerData\(driveRoots, pathPickerRoots\(activeCwd, activeCwd\)\)/, "the server should return the tested non-selectable virtual payload");
119
+ assert.match(
120
+ serverSource,
121
+ /function windowsDriveDiscoveryCwd\(\) \{[\s\S]*process\.env\.SystemRoot \|\| process\.env\.WINDIR \|\| path\.dirname\(process\.execPath\)[\s\S]*cwd: windowsDriveDiscoveryCwd\(\)/,
122
+ "drive discovery should launch from a stable Windows system or executable directory rather than the active drive",
123
+ );
124
+ assert.doesNotMatch(
125
+ serverSource,
126
+ /discoverWindowsDriveRoots\(\{\s*cwd: activeCwd/,
127
+ "a removable active cwd must not be used as the PowerShell process cwd",
128
+ );
129
+
130
+ console.log("windows-drive-roots.test.mjs passed");