@firstpick/pi-package-webui 0.8.2 → 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 +9 -3
- package/bin/pi-webui.mjs +97 -12
- package/lib/git-workflow-preferences.mjs +246 -19
- package/lib/thinking-stream-recovery.mjs +156 -0
- package/lib/ui-layout-settings.mjs +254 -0
- package/package.json +5 -3
- package/public/app.js +1618 -41
- package/public/index.html +35 -14
- package/public/service-worker.js +1 -1
- package/public/styles.css +324 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
- package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
- package/tests/browser/interaction-continuity.spec.mjs +29 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +63 -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 +51 -1
- 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 +3 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +32 -15
- 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 +3 -3
- 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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
UI_LAYOUT_LIMITS,
|
|
4
|
+
defaultUiLayout,
|
|
5
|
+
mergeUiLayout,
|
|
6
|
+
normalizeUiLayout,
|
|
7
|
+
uiLayoutRevision,
|
|
8
|
+
validateUiLayoutPatch,
|
|
9
|
+
} from "../lib/ui-layout-settings.mjs";
|
|
10
|
+
|
|
11
|
+
const defaults = defaultUiLayout();
|
|
12
|
+
assert.deepEqual(normalizeUiLayout(undefined), defaults);
|
|
13
|
+
assert.deepEqual(normalizeUiLayout({ version: 99, sidePanel: { collapsed: true } }), defaults, "unknown layout versions must fail soft to nullable defaults");
|
|
14
|
+
|
|
15
|
+
const valid = normalizeUiLayout({
|
|
16
|
+
version: 1,
|
|
17
|
+
sidePanel: {
|
|
18
|
+
sectionOrder: ["files", "controls", "git"],
|
|
19
|
+
collapsedSectionIds: ["git"],
|
|
20
|
+
hiddenSectionIds: [],
|
|
21
|
+
collapsed: false,
|
|
22
|
+
},
|
|
23
|
+
composerActions: {
|
|
24
|
+
order: ["new", "git", "send"],
|
|
25
|
+
grid: { version: 2, columns: 12, positions: { new: 0, git: 1, send: 10 } },
|
|
26
|
+
},
|
|
27
|
+
footerScopedModelOrder: ["openai-codex/gpt-5.6-sol"],
|
|
28
|
+
terminalTabs: {
|
|
29
|
+
layout: "left",
|
|
30
|
+
customGroups: { version: 1, groups: [{ id: "group-1", title: "Group 1", tabIds: ["tab-a", "tab-b"] }] },
|
|
31
|
+
},
|
|
32
|
+
fileViewerWidth: 560.4,
|
|
33
|
+
});
|
|
34
|
+
assert.deepEqual(valid.sidePanel.sectionOrder, ["files", "controls", "git"]);
|
|
35
|
+
assert.equal(valid.fileViewerWidth, 560);
|
|
36
|
+
assert.equal(valid.terminalTabs.layout, "left");
|
|
37
|
+
|
|
38
|
+
const partiallyMalformed = normalizeUiLayout({
|
|
39
|
+
...valid,
|
|
40
|
+
sidePanel: { ...valid.sidePanel, sectionOrder: ["files", "files"], collapsed: true },
|
|
41
|
+
composerActions: { ...valid.composerActions, grid: { version: 2, columns: 999, positions: {} } },
|
|
42
|
+
terminalTabs: { layout: "bottom", customGroups: valid.terminalTabs.customGroups },
|
|
43
|
+
});
|
|
44
|
+
assert.equal(partiallyMalformed.sidePanel.sectionOrder, null, "a malformed disk field should fail soft independently");
|
|
45
|
+
assert.equal(partiallyMalformed.sidePanel.collapsed, true, "valid sibling disk fields should survive");
|
|
46
|
+
assert.equal(partiallyMalformed.composerActions.grid, null);
|
|
47
|
+
assert.equal(partiallyMalformed.terminalTabs.layout, null);
|
|
48
|
+
assert.deepEqual(partiallyMalformed.terminalTabs.customGroups, valid.terminalTabs.customGroups);
|
|
49
|
+
|
|
50
|
+
const merged = mergeUiLayout(valid, {
|
|
51
|
+
sidePanel: { collapsed: true, hiddenSectionIds: null },
|
|
52
|
+
footerScopedModelOrder: [],
|
|
53
|
+
fileViewerWidth: null,
|
|
54
|
+
});
|
|
55
|
+
assert.equal(merged.sidePanel.collapsed, true);
|
|
56
|
+
assert.deepEqual(merged.sidePanel.sectionOrder, valid.sidePanel.sectionOrder, "omitted fields must be preserved");
|
|
57
|
+
assert.equal(merged.sidePanel.hiddenSectionIds, null, "explicit null must clear only the named field");
|
|
58
|
+
assert.deepEqual(merged.footerScopedModelOrder, [], "explicit empty arrays are valid resets");
|
|
59
|
+
assert.equal(merged.fileViewerWidth, null);
|
|
60
|
+
|
|
61
|
+
const composerReset = mergeUiLayout(valid, { composerActions: { order: [], grid: null } });
|
|
62
|
+
assert.deepEqual(composerReset.composerActions, { order: [], grid: null });
|
|
63
|
+
const terminalReset = mergeUiLayout(valid, { terminalTabs: null });
|
|
64
|
+
assert.deepEqual(terminalReset.terminalTabs, defaults.terminalTabs);
|
|
65
|
+
|
|
66
|
+
assert.throws(() => validateUiLayoutPatch({}), /at least one mutable field/);
|
|
67
|
+
assert.throws(() => validateUiLayoutPatch({ unknown: true }), /unsupported field/);
|
|
68
|
+
assert.throws(() => validateUiLayoutPatch({ version: 2, fileViewerWidth: 500 }), /version must be 1/);
|
|
69
|
+
assert.throws(() => validateUiLayoutPatch({ composerActions: { order: ["send"] } }), /order and grid together/);
|
|
70
|
+
assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsed: "yes" } }), /boolean or null/);
|
|
71
|
+
assert.throws(() => validateUiLayoutPatch({ fileViewerWidth: UI_LAYOUT_LIMITS.fileViewerWidthMin - 1 }), /must be between/);
|
|
72
|
+
assert.throws(() => validateUiLayoutPatch({ footerScopedModelOrder: Array(UI_LAYOUT_LIMITS.listItems + 1).fill("model") }), /at most/);
|
|
73
|
+
assert.throws(() => validateUiLayoutPatch({
|
|
74
|
+
composerActions: { order: ["a", "b"], grid: { version: 2, columns: 2, positions: { a: 0, b: 0 } } },
|
|
75
|
+
}), /must not reuse a slot/);
|
|
76
|
+
assert.throws(() => validateUiLayoutPatch({
|
|
77
|
+
terminalTabs: {
|
|
78
|
+
customGroups: {
|
|
79
|
+
version: 1,
|
|
80
|
+
groups: [
|
|
81
|
+
{ id: "one", title: "One", tabIds: ["tab-a"] },
|
|
82
|
+
{ id: "two", title: "Two", tabIds: ["tab-a"] },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}), /only one group/);
|
|
87
|
+
|
|
88
|
+
assert.match(uiLayoutRevision(defaults), /^[a-f0-9]{64}$/);
|
|
89
|
+
assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 1 })), "equivalent normalized layouts need stable revisions");
|
|
90
|
+
assert.notEqual(uiLayoutRevision(defaults), uiLayoutRevision(merged), "layout changes must change the revision");
|
|
91
|
+
|
|
92
|
+
console.log("ui-layout-settings.test.mjs passed");
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFile, spawn } from "node:child_process";
|
|
3
|
+
import { once } from "node:events";
|
|
4
|
+
import { mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
+
import { homedir, tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import {
|
|
10
|
+
legacyWebuiSettingsFile,
|
|
11
|
+
migrateLegacyWebuiSettings,
|
|
12
|
+
readWebuiSettings,
|
|
13
|
+
updateWebuiSettings,
|
|
14
|
+
webuiSettingsFile,
|
|
15
|
+
withWebuiSettingsLock,
|
|
16
|
+
writeWebuiSettings,
|
|
17
|
+
} from "../lib/git-workflow-preferences.mjs";
|
|
18
|
+
|
|
19
|
+
const execFileAsync = promisify(execFile);
|
|
20
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-settings-locking-"));
|
|
21
|
+
const moduleUrl = pathToFileURL(path.join(import.meta.dirname, "..", "lib", "git-workflow-preferences.mjs")).href;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
assert.equal(webuiSettingsFile({}), path.join(homedir(), ".pi", "webui", "settings.json"));
|
|
25
|
+
assert.equal(webuiSettingsFile({ PI_WEBUI_SETTINGS_FILE: path.join(root, "override.json") }), path.join(root, "override.json"));
|
|
26
|
+
assert.equal(legacyWebuiSettingsFile({ XDG_CONFIG_HOME: path.join(root, "xdg") }), path.join(root, "xdg", "pi-webui", "settings.json"));
|
|
27
|
+
|
|
28
|
+
const legacyFile = path.join(root, "legacy", "settings.json");
|
|
29
|
+
const migratedFile = path.join(root, "new", "settings.json");
|
|
30
|
+
await writeFile(legacyFile, `${JSON.stringify({ version: 4, remoteAuthEnabled: true, retained: { value: 7 } })}\n`, { mode: 0o600, recursive: false }).catch(async (error) => {
|
|
31
|
+
if (error?.code !== "ENOENT") throw error;
|
|
32
|
+
const { mkdir } = await import("node:fs/promises");
|
|
33
|
+
await mkdir(path.dirname(legacyFile), { recursive: true });
|
|
34
|
+
await writeFile(legacyFile, `${JSON.stringify({ version: 4, remoteAuthEnabled: true, retained: { value: 7 } })}\n`, { mode: 0o600 });
|
|
35
|
+
});
|
|
36
|
+
assert.equal(await migrateLegacyWebuiSettings(migratedFile, legacyFile), true);
|
|
37
|
+
assert.equal(await migrateLegacyWebuiSettings(migratedFile, legacyFile), false, "an existing new target must always win");
|
|
38
|
+
const migrated = JSON.parse(await readFile(migratedFile, "utf8"));
|
|
39
|
+
assert.equal(migrated.version, 6);
|
|
40
|
+
assert.equal(migrated.remoteAuthEnabled, true);
|
|
41
|
+
assert.deepEqual(migrated.retained, { value: 7 }, "migration must preserve unrelated top-level settings");
|
|
42
|
+
assert.equal((await readFile(legacyFile, "utf8")).includes('"retained"'), true, "migration must leave the legacy file untouched");
|
|
43
|
+
if (process.platform !== "win32") {
|
|
44
|
+
assert.equal((await stat(migratedFile)).mode & 0o777, 0o600, "migrated settings must be private");
|
|
45
|
+
assert.equal((await stat(path.dirname(migratedFile))).mode & 0o777, 0o700, "new settings directory must be private");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const malformedTarget = path.join(root, "malformed-target.json");
|
|
49
|
+
const validLegacy = path.join(root, "valid-legacy.json");
|
|
50
|
+
await writeFile(malformedTarget, "{not-json", "utf8");
|
|
51
|
+
await writeFile(validLegacy, '{"remoteAuthEnabled":true}\n', "utf8");
|
|
52
|
+
assert.equal(await migrateLegacyWebuiSettings(malformedTarget, validLegacy), false, "an existing malformed new target must not fall back to legacy data");
|
|
53
|
+
await assert.rejects(readWebuiSettings(malformedTarget), /Cannot read Pi Web UI settings/);
|
|
54
|
+
assert.equal(await readFile(malformedTarget, "utf8"), "{not-json");
|
|
55
|
+
|
|
56
|
+
const malformedLegacy = path.join(root, "malformed-legacy.json");
|
|
57
|
+
const absentTarget = path.join(root, "absent-target.json");
|
|
58
|
+
await writeFile(malformedLegacy, "[]\n", "utf8");
|
|
59
|
+
assert.equal(await migrateLegacyWebuiSettings(absentTarget, malformedLegacy), false, "invalid legacy settings must not be imported");
|
|
60
|
+
await assert.rejects(readFile(absentTarget, "utf8"), { code: "ENOENT" });
|
|
61
|
+
|
|
62
|
+
const oldOverride = process.env.PI_WEBUI_SETTINGS_FILE;
|
|
63
|
+
const oldXdg = process.env.XDG_CONFIG_HOME;
|
|
64
|
+
const overrideFile = path.join(root, "isolated-override", "settings.json");
|
|
65
|
+
const overrideLegacy = path.join(root, "override-xdg", "pi-webui", "settings.json");
|
|
66
|
+
const { mkdir } = await import("node:fs/promises");
|
|
67
|
+
await mkdir(path.dirname(overrideLegacy), { recursive: true });
|
|
68
|
+
await writeFile(overrideLegacy, '{"remoteAuthEnabled":true}\n', "utf8");
|
|
69
|
+
process.env.PI_WEBUI_SETTINGS_FILE = overrideFile;
|
|
70
|
+
process.env.XDG_CONFIG_HOME = path.join(root, "override-xdg");
|
|
71
|
+
try {
|
|
72
|
+
const isolated = await readWebuiSettings();
|
|
73
|
+
assert.equal(isolated.remoteAuthEnabled, false, "an override must never import default-path legacy settings");
|
|
74
|
+
await assert.rejects(readFile(overrideFile, "utf8"), { code: "ENOENT" });
|
|
75
|
+
} finally {
|
|
76
|
+
if (oldOverride === undefined) delete process.env.PI_WEBUI_SETTINGS_FILE;
|
|
77
|
+
else process.env.PI_WEBUI_SETTINGS_FILE = oldOverride;
|
|
78
|
+
if (oldXdg === undefined) delete process.env.XDG_CONFIG_HOME;
|
|
79
|
+
else process.env.XDG_CONFIG_HOME = oldXdg;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const settingsFile = path.join(root, "concurrent", "settings.json");
|
|
83
|
+
await writeWebuiSettings({ remoteAuthEnabled: false, outputModeDefault: "normal", retained: "keep" }, settingsFile);
|
|
84
|
+
const childCode = (patch, holdMs) => `
|
|
85
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
86
|
+
import { updateWebuiSettings } from ${JSON.stringify(moduleUrl)};
|
|
87
|
+
await updateWebuiSettings(async () => {
|
|
88
|
+
await delay(${holdMs});
|
|
89
|
+
return ${JSON.stringify(patch)};
|
|
90
|
+
}, ${JSON.stringify(settingsFile)});
|
|
91
|
+
`;
|
|
92
|
+
await Promise.all([
|
|
93
|
+
execFileAsync(process.execPath, ["--input-type=module", "-e", childCode({ remoteAuthEnabled: true }, 120)]),
|
|
94
|
+
execFileAsync(process.execPath, ["--input-type=module", "-e", childCode({ outputModeDefault: "compact-v1" }, 0)]),
|
|
95
|
+
]);
|
|
96
|
+
const concurrent = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
97
|
+
assert.equal(concurrent.remoteAuthEnabled, true);
|
|
98
|
+
assert.equal(concurrent.outputModeDefault, "compact-v1", "cross-process updates must preserve unrelated concurrent patches");
|
|
99
|
+
assert.equal(concurrent.retained, "keep");
|
|
100
|
+
|
|
101
|
+
const incrementCode = (holdMs) => `
|
|
102
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
103
|
+
import { updateWebuiSettings } from ${JSON.stringify(moduleUrl)};
|
|
104
|
+
await updateWebuiSettings(async (current) => {
|
|
105
|
+
await delay(${holdMs});
|
|
106
|
+
return { stressCounter: Number(current.stressCounter || 0) + 1 };
|
|
107
|
+
}, ${JSON.stringify(settingsFile)});
|
|
108
|
+
`;
|
|
109
|
+
await Promise.all(Array.from({ length: 8 }, (_, index) => (
|
|
110
|
+
execFileAsync(process.execPath, ["--input-type=module", "-e", incrementCode((index % 3) * 10)])
|
|
111
|
+
)));
|
|
112
|
+
assert.equal(JSON.parse(await readFile(settingsFile, "utf8")).stressCounter, 8, "the same-host lock must serialize a burst of cross-process read/merge/write updates");
|
|
113
|
+
|
|
114
|
+
await Promise.all([
|
|
115
|
+
updateWebuiSettings(() => ({ interfacePreferences: { sidePanelWidth: 611 } }), settingsFile),
|
|
116
|
+
updateWebuiSettings(() => ({ gitWorkflow: { deliveryMode: "current" } }), settingsFile),
|
|
117
|
+
]);
|
|
118
|
+
const queued = await readWebuiSettings(settingsFile);
|
|
119
|
+
assert.equal(queued.interfacePreferences.sidePanelWidth, 611);
|
|
120
|
+
assert.equal(queued.gitWorkflow.deliveryMode, "current");
|
|
121
|
+
|
|
122
|
+
const futureLayout = { version: 2, futureSurface: { order: ["keep-this"] } };
|
|
123
|
+
const futureSettings = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
124
|
+
futureSettings.uiLayout = futureLayout;
|
|
125
|
+
await writeFile(settingsFile, `${JSON.stringify(futureSettings, null, 2)}\n`, "utf8");
|
|
126
|
+
await writeWebuiSettings({ remoteAuthEnabled: false }, settingsFile);
|
|
127
|
+
assert.deepEqual(JSON.parse(await readFile(settingsFile, "utf8")).uiLayout, futureLayout, "unrelated writes must preserve an unknown future layout envelope");
|
|
128
|
+
assert.deepEqual((await readWebuiSettings(settingsFile)).uiLayout.sidePanel.sectionOrder, null, "unknown layout versions must still read as safe nullable defaults");
|
|
129
|
+
|
|
130
|
+
const liveLockTarget = path.join(root, "live-lock", "settings.json");
|
|
131
|
+
const liveLockDirectory = `${liveLockTarget}.lock`;
|
|
132
|
+
const liveLockRecord = path.join(liveLockDirectory, "live.json");
|
|
133
|
+
await mkdir(liveLockDirectory, { recursive: true });
|
|
134
|
+
await writeFile(liveLockRecord, `${JSON.stringify({ pid: process.pid, token: "live", state: "active", createdAt: 0 })}\n`, "utf8");
|
|
135
|
+
await assert.rejects(
|
|
136
|
+
withWebuiSettingsLock(liveLockTarget, () => true, { timeoutMs: 35, retryMs: 5 }),
|
|
137
|
+
(error) => error?.code === "WEBUI_SETTINGS_LOCK_TIMEOUT",
|
|
138
|
+
"lock age alone must never permit reclaiming a live owner's lock",
|
|
139
|
+
);
|
|
140
|
+
assert.equal(JSON.parse(await readFile(liveLockRecord, "utf8")).token, "live");
|
|
141
|
+
await rm(liveLockRecord);
|
|
142
|
+
|
|
143
|
+
const exited = spawn(process.execPath, ["-e", "process.exit(0)"], { stdio: "ignore" });
|
|
144
|
+
const deadPid = exited.pid;
|
|
145
|
+
await once(exited, "exit");
|
|
146
|
+
const deadLockRecord = path.join(liveLockDirectory, "dead.json");
|
|
147
|
+
await writeFile(deadLockRecord, `${JSON.stringify({ pid: deadPid, token: "dead", state: "active" })}\n`, "utf8");
|
|
148
|
+
assert.equal(await withWebuiSettingsLock(liveLockTarget, () => "recovered", { timeoutMs: 250, retryMs: 5 }), "recovered");
|
|
149
|
+
await assert.rejects(readFile(deadLockRecord, "utf8"), { code: "ENOENT" });
|
|
150
|
+
await assert.rejects(readdir(liveLockDirectory), { code: "ENOENT" });
|
|
151
|
+
|
|
152
|
+
const artifacts = await readdir(path.dirname(settingsFile));
|
|
153
|
+
assert.equal(artifacts.some((name) => name.endsWith(".lock") || name.endsWith(".tmp")), false, "successful writes must clean lock and temp artifacts");
|
|
154
|
+
if (process.platform !== "win32") assert.equal((await stat(settingsFile)).mode & 0o777, 0o600);
|
|
155
|
+
|
|
156
|
+
console.log("webui-settings-locking.test.mjs passed");
|
|
157
|
+
} finally {
|
|
158
|
+
await rm(root, { recursive: true, force: true });
|
|
159
|
+
}
|