@firstpick/pi-package-webui 0.7.8 → 0.8.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 +10 -4
- package/bin/pi-webui.mjs +696 -69
- package/lib/git-workflow-preferences.mjs +16 -0
- package/lib/git-worktrees.mjs +43 -4
- package/lib/queue-mutation.mjs +109 -0
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +4 -2
- package/public/app.js +2074 -188
- package/public/index.html +105 -4
- package/public/service-worker.js +1 -1
- package/public/styles.css +618 -73
- package/public/voice-conversation.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +2 -2
- package/tests/codex-fast-mode-static.test.mjs +56 -0
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/composer-skill-tag-layout.test.mjs +70 -0
- package/tests/cwd-footer-reliability-static.test.mjs +5 -0
- package/tests/fast-mode-client-static.test.mjs +8 -8
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/fake-pi.mjs +216 -43
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/git-workflow-preferences.test.mjs +8 -0
- package/tests/guided-git-publication-backend-static.test.mjs +40 -0
- package/tests/http-endpoints-harness.test.mjs +422 -2
- package/tests/mobile-static.test.mjs +111 -42
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/side-panel-resize-static.test.mjs +8 -1
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +4 -2
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
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
|
+
const fixtureRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-workspaces-harness-"));
|
|
15
|
+
const cwd = path.join(fixtureRoot, "cwd");
|
|
16
|
+
const missingCwd = path.join(fixtureRoot, "missing-cwd");
|
|
17
|
+
const missingSession = path.join(fixtureRoot, "missing-session.jsonl");
|
|
18
|
+
const workspacesFile = path.join(fixtureRoot, "workspaces.json");
|
|
19
|
+
|
|
20
|
+
async function portForHarness() {
|
|
21
|
+
const probe = createServer();
|
|
22
|
+
await new Promise((resolve) => probe.listen(0, "127.0.0.1", resolve));
|
|
23
|
+
const { port } = probe.address();
|
|
24
|
+
await new Promise((resolve) => probe.close(resolve));
|
|
25
|
+
return port;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function request(port, pathname, { method = "GET", body } = {}) {
|
|
29
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
30
|
+
method,
|
|
31
|
+
headers: body === undefined ? undefined : { "content-type": "application/json" },
|
|
32
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
33
|
+
signal: AbortSignal.timeout(5_000),
|
|
34
|
+
});
|
|
35
|
+
return { status: response.status, body: await response.json().catch(() => undefined) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function startServer(port, { initialCwd } = {}) {
|
|
39
|
+
const args = [serverScript, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi];
|
|
40
|
+
if (initialCwd) args.push("--cwd", initialCwd);
|
|
41
|
+
const child = spawn(process.execPath, args, {
|
|
42
|
+
cwd: root,
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
44
|
+
env: { ...process.env, PI_WEBUI_WORKSPACES_FILE: workspacesFile, PI_WEBUI_RPC_SUPERVISOR: "0" },
|
|
45
|
+
});
|
|
46
|
+
let output = "";
|
|
47
|
+
child.stdout.on("data", (chunk) => { output += String(chunk); });
|
|
48
|
+
child.stderr.on("data", (chunk) => { output += String(chunk); });
|
|
49
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
50
|
+
if (child.exitCode !== null) break;
|
|
51
|
+
try {
|
|
52
|
+
const health = await request(port, "/api/health");
|
|
53
|
+
if (health.status === 200) return { child, output: () => output };
|
|
54
|
+
} catch {
|
|
55
|
+
// Server is still booting.
|
|
56
|
+
}
|
|
57
|
+
await delay(50);
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`workspace harness server did not start:\n${output}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function stopServer(child) {
|
|
63
|
+
if (!child || child.exitCode !== null) return;
|
|
64
|
+
const exited = new Promise((resolve) => child.once("exit", resolve));
|
|
65
|
+
child.kill("SIGINT");
|
|
66
|
+
await Promise.race([exited, delay(5_000)]);
|
|
67
|
+
if (child.exitCode === null) {
|
|
68
|
+
child.kill("SIGKILL");
|
|
69
|
+
await exited;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let firstServer;
|
|
74
|
+
let secondServer;
|
|
75
|
+
try {
|
|
76
|
+
await chmod(fakePi, 0o755);
|
|
77
|
+
await mkdir(cwd, { recursive: true });
|
|
78
|
+
const port = await portForHarness();
|
|
79
|
+
|
|
80
|
+
firstServer = await startServer(port, { initialCwd: cwd });
|
|
81
|
+
const initialTabs = await request(port, "/api/tabs");
|
|
82
|
+
assert.equal(initialTabs.status, 200);
|
|
83
|
+
const firstTab = initialTabs.body.data.tabs[0];
|
|
84
|
+
assert.ok(firstTab?.id, "the explicit cwd must create one live tab");
|
|
85
|
+
const created = await request(port, "/api/tabs", { method: "POST", body: { cwd, title: "Second saved tab" } });
|
|
86
|
+
assert.equal(created.status, 201);
|
|
87
|
+
const secondTab = created.body.data.tab;
|
|
88
|
+
|
|
89
|
+
const saved = await request(port, "/api/workspaces", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
body: {
|
|
92
|
+
name: "Harness workspace",
|
|
93
|
+
activeTabId: secondTab.id,
|
|
94
|
+
groups: [{ title: "Saved group", tabIds: [firstTab.id, secondTab.id, "not-open"] }],
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
assert.equal(saved.status, 201, `save should work: ${saved.body?.error || ""}`);
|
|
98
|
+
assert.equal(saved.body.ok, true);
|
|
99
|
+
assert.equal(saved.body.data.workspace.name, "Harness workspace");
|
|
100
|
+
assert.equal(saved.body.data.workspace.tabCount, 2);
|
|
101
|
+
assert.deepEqual(saved.body.data.evicted, []);
|
|
102
|
+
const workspaceId = saved.body.data.workspace.id;
|
|
103
|
+
|
|
104
|
+
const listed = await request(port, "/api/workspaces");
|
|
105
|
+
assert.equal(listed.status, 200);
|
|
106
|
+
assert.deepEqual(listed.body.data.workspaces.map((workspace) => workspace.id), [workspaceId], "GET must return picker metadata only");
|
|
107
|
+
assert.equal(Object.hasOwn(listed.body.data.workspaces[0], "tabs"), false, "GET must not expose saved tab descriptors");
|
|
108
|
+
|
|
109
|
+
const duplicate = await request(port, "/api/workspaces", { method: "POST", body: { name: "Harness workspace" } });
|
|
110
|
+
assert.equal(duplicate.status, 409, "duplicate save must require overwrite");
|
|
111
|
+
const originalTabIds = [firstTab.id, secondTab.id].sort();
|
|
112
|
+
|
|
113
|
+
const loadWithoutDecision = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, { method: "POST" });
|
|
114
|
+
assert.equal(loadWithoutDecision.status, 400, "open tabs must reject a load without explicit replacement intent");
|
|
115
|
+
assert.deepEqual((await request(port, "/api/tabs")).body.data.tabs.map((tab) => tab.id).sort(), originalTabIds, "rejected loads must leave every open tab intact");
|
|
116
|
+
const ambiguousLoad = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
body: { replaceOpenTabs: true, discardCurrent: true, saveCurrent: { name: "Ambiguous workspace" } },
|
|
119
|
+
});
|
|
120
|
+
assert.equal(ambiguousLoad.status, 400, "open tabs must reject ambiguous save-and-discard replacement decisions");
|
|
121
|
+
assert.deepEqual((await request(port, "/api/tabs")).body.data.tabs.map((tab) => tab.id).sort(), originalTabIds, "ambiguous loads must leave every open tab intact");
|
|
122
|
+
|
|
123
|
+
const conflictingSaveAndLoad = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
body: {
|
|
126
|
+
replaceOpenTabs: true,
|
|
127
|
+
saveCurrent: {
|
|
128
|
+
name: "Harness workspace",
|
|
129
|
+
groups: [{ title: "Current group", tabIds: [firstTab.id, secondTab.id] }],
|
|
130
|
+
activeTabId: secondTab.id,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
assert.equal(conflictingSaveAndLoad.status, 409, "duplicate save-and-load names must conflict before tabs close");
|
|
135
|
+
assert.deepEqual((await request(port, "/api/tabs")).body.data.tabs.map((tab) => tab.id).sort(), originalTabIds, "duplicate save conflicts must leave every open tab intact");
|
|
136
|
+
|
|
137
|
+
const saveAndLoad = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
body: {
|
|
140
|
+
replaceOpenTabs: true,
|
|
141
|
+
saveCurrent: {
|
|
142
|
+
name: "Current workspace",
|
|
143
|
+
groups: [{ title: "Current group", tabIds: [firstTab.id, secondTab.id] }],
|
|
144
|
+
activeTabId: secondTab.id,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
assert.equal(saveAndLoad.status, 200, `save-and-load should succeed: ${saveAndLoad.body?.error || ""}`);
|
|
149
|
+
assert.deepEqual(saveAndLoad.body.data.closedIds.slice().sort(), originalTabIds, "save-and-load must report every tab it replaced");
|
|
150
|
+
assert.equal(saveAndLoad.body.data.savedCurrent.workspace.name, "Current workspace", "save-and-load must return saved-current metadata");
|
|
151
|
+
assert.equal(saveAndLoad.body.data.tabs.length, 2, "save-and-load must restore the target workspace after replacement");
|
|
152
|
+
const currentDocument = JSON.parse(await readFile(workspacesFile, "utf8"));
|
|
153
|
+
const savedCurrent = currentDocument.workspaces.find((workspace) => workspace.id === saveAndLoad.body.data.savedCurrent.workspace.id);
|
|
154
|
+
assert.deepEqual(savedCurrent?.groups, [{ title: "Current group", tabIds: [firstTab.id, secondTab.id] }], "save-and-load must persist current groups before replacement");
|
|
155
|
+
assert.equal(savedCurrent?.activeTabId, secondTab.id, "save-and-load must persist the current active tab before replacement");
|
|
156
|
+
|
|
157
|
+
const discardOnlyTab = await request(port, "/api/tabs", { method: "POST", body: { cwd, title: "Discard this tab" } });
|
|
158
|
+
assert.equal(discardOnlyTab.status, 201);
|
|
159
|
+
const tabsBeforeDiscard = (await request(port, "/api/tabs")).body.data.tabs.map((tab) => tab.id).sort();
|
|
160
|
+
const discardAndLoad = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
body: { replaceOpenTabs: true, discardCurrent: true },
|
|
163
|
+
});
|
|
164
|
+
assert.equal(discardAndLoad.status, 200, `discard-and-load should succeed: ${discardAndLoad.body?.error || ""}`);
|
|
165
|
+
assert.deepEqual(discardAndLoad.body.data.closedIds.slice().sort(), tabsBeforeDiscard, "discard-and-load must report every tab it replaced");
|
|
166
|
+
assert.equal(Object.hasOwn(discardAndLoad.body.data, "savedCurrent"), false, "discard-and-load must not report a saved current workspace");
|
|
167
|
+
assert.equal(discardAndLoad.body.data.tabs.length, 2, "discard-and-load must replace current tabs with the target workspace");
|
|
168
|
+
assert.equal(discardAndLoad.body.data.tabs.some((tab) => tab.id === discardOnlyTab.body.data.tab.id), false, "discard-and-load must remove tabs outside the target workspace");
|
|
169
|
+
|
|
170
|
+
const closedForLoad = await request(port, "/api/tabs/close", {
|
|
171
|
+
method: "POST",
|
|
172
|
+
body: { ids: (await request(port, "/api/tabs")).body.data.tabs.map((tab) => tab.id), allowEmpty: true },
|
|
173
|
+
});
|
|
174
|
+
assert.equal(closedForLoad.status, 200);
|
|
175
|
+
assert.deepEqual(closedForLoad.body.data.tabs, [], "explicit close-all must expose the planned zero-tab load state");
|
|
176
|
+
assert.equal(closedForLoad.body.data.activeTabId, null);
|
|
177
|
+
const loadedAfterCloseAll = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, { method: "POST" });
|
|
178
|
+
assert.equal(loadedAfterCloseAll.status, 200, "the existing zero-tab load journey must remain reachable");
|
|
179
|
+
assert.deepEqual(loadedAfterCloseAll.body.data.closedIds, [], "zero-tab loads must report no replacements");
|
|
180
|
+
assert.equal(loadedAfterCloseAll.body.data.tabs.length, 2);
|
|
181
|
+
|
|
182
|
+
await stopServer(firstServer.child);
|
|
183
|
+
firstServer = null;
|
|
184
|
+
|
|
185
|
+
const document = JSON.parse(await readFile(workspacesFile, "utf8"));
|
|
186
|
+
const storedWorkspace = document.workspaces.find((workspace) => workspace.id === workspaceId);
|
|
187
|
+
storedWorkspace.tabs[0].cwd = missingCwd;
|
|
188
|
+
storedWorkspace.tabs[0].sessionFile = missingSession;
|
|
189
|
+
await writeFile(workspacesFile, `${JSON.stringify(document, null, 2)}\n`, "utf8");
|
|
190
|
+
|
|
191
|
+
secondServer = await startServer(port);
|
|
192
|
+
const noTabs = await request(port, "/api/tabs");
|
|
193
|
+
assert.deepEqual(noTabs.body.data.tabs, [], "the no-cwd server must expose the planned zero-tab load state");
|
|
194
|
+
const saveWithoutTabs = await request(port, "/api/workspaces", { method: "POST", body: { name: "empty" } });
|
|
195
|
+
assert.equal(saveWithoutTabs.status, 400, "save requires live server-owned descriptors");
|
|
196
|
+
|
|
197
|
+
const loaded = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}/load`, { method: "POST" });
|
|
198
|
+
assert.equal(loaded.status, 200, `fail-soft load should succeed: ${loaded.body?.error || ""}`);
|
|
199
|
+
assert.equal(loaded.body.ok, true);
|
|
200
|
+
assert.equal(loaded.body.data.tabs.length, 2, "sequential load must recreate every saved tab");
|
|
201
|
+
assert.equal(loaded.body.data.idMap[firstTab.id], firstTab.id, "load must return saved-to-live tab id mappings");
|
|
202
|
+
assert.equal(loaded.body.data.idMap[secondTab.id], secondTab.id);
|
|
203
|
+
assert.deepEqual(loaded.body.data.groups, [{ title: "Saved group", tabIds: [firstTab.id, secondTab.id] }], "groups must remap only restored tab ids");
|
|
204
|
+
assert.equal(loaded.body.data.activeTabId, secondTab.id, "active tab must remap through the returned id map");
|
|
205
|
+
assert.ok(loaded.body.data.warnings.some((warning) => warning.savedTabId === firstTab.id && warning.code === "missing_session_file"));
|
|
206
|
+
assert.ok(loaded.body.data.warnings.some((warning) => warning.savedTabId === firstTab.id && warning.code === "missing_cwd"));
|
|
207
|
+
assert.equal(loaded.body.data.tabs.find((tab) => tab.id === firstTab.id).cwd, root, "missing cwd must fall back to the server default cwd");
|
|
208
|
+
|
|
209
|
+
const deleted = await request(port, `/api/workspaces/${encodeURIComponent(workspaceId)}`, { method: "DELETE" });
|
|
210
|
+
assert.equal(deleted.status, 200);
|
|
211
|
+
assert.equal(deleted.body.data.deletedId, workspaceId, "delete must return the removed target id");
|
|
212
|
+
assert.deepEqual(deleted.body.data.workspaces.map((workspace) => workspace.id), [saveAndLoad.body.data.savedCurrent.workspace.id], "delete must retain the workspace saved by save-and-load");
|
|
213
|
+
const deletedCurrent = await request(port, `/api/workspaces/${encodeURIComponent(saveAndLoad.body.data.savedCurrent.workspace.id)}`, { method: "DELETE" });
|
|
214
|
+
assert.equal(deletedCurrent.status, 200);
|
|
215
|
+
assert.deepEqual(deletedCurrent.body.data, { deletedId: saveAndLoad.body.data.savedCurrent.workspace.id, workspaces: [] }, "delete must use the frozen response envelope");
|
|
216
|
+
assert.deepEqual((await request(port, "/api/workspaces")).body.data.workspaces, []);
|
|
217
|
+
|
|
218
|
+
console.log("webui-workspaces-harness.test.mjs passed");
|
|
219
|
+
} finally {
|
|
220
|
+
await stopServer(firstServer?.child);
|
|
221
|
+
await stopServer(secondServer?.child);
|
|
222
|
+
await rm(fixtureRoot, { recursive: true, force: true });
|
|
223
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
WEBUI_WORKSPACE_LIMIT,
|
|
7
|
+
WEBUI_WORKSPACE_TAB_LIMIT,
|
|
8
|
+
deleteWebuiWorkspace,
|
|
9
|
+
getWebuiWorkspace,
|
|
10
|
+
listWebuiWorkspaces,
|
|
11
|
+
normalizeWebuiWorkspaces,
|
|
12
|
+
readWebuiWorkspaces,
|
|
13
|
+
saveWebuiWorkspace,
|
|
14
|
+
webuiWorkspacesFile,
|
|
15
|
+
} from "../lib/webui-workspaces.mjs";
|
|
16
|
+
|
|
17
|
+
function tab(id, cwd, index = 1) {
|
|
18
|
+
return {
|
|
19
|
+
id,
|
|
20
|
+
index,
|
|
21
|
+
title: `Tab ${index}`,
|
|
22
|
+
titleSource: "explicit",
|
|
23
|
+
conversationStarted: index % 2 === 0,
|
|
24
|
+
cwd,
|
|
25
|
+
sessionFile: path.join(cwd, `${id}.jsonl`),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-workspaces-"));
|
|
30
|
+
const storageFile = path.join(root, "nested", "workspaces.json");
|
|
31
|
+
const concurrentFile = path.join(root, "concurrent.json");
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
assert.equal(webuiWorkspacesFile({ PI_WEBUI_WORKSPACES_FILE: "~/workspace-file.json" }), path.resolve(homedir(), "workspace-file.json"));
|
|
35
|
+
assert.equal(webuiWorkspacesFile({ XDG_CONFIG_HOME: path.join(root, "xdg") }), path.join(root, "xdg", "pi-webui", "workspaces.json"));
|
|
36
|
+
|
|
37
|
+
const oversizedTabs = Array.from({ length: WEBUI_WORKSPACE_TAB_LIMIT + 3 }, (_, index) => tab(`tab-${index}`, root, index + 1));
|
|
38
|
+
const normalized = normalizeWebuiWorkspaces({
|
|
39
|
+
version: 1,
|
|
40
|
+
workspaces: [{
|
|
41
|
+
id: "ws-normalized",
|
|
42
|
+
name: ` ${"n".repeat(200)} `,
|
|
43
|
+
savedAt: new Date().toISOString(),
|
|
44
|
+
activeTabId: "tab-0",
|
|
45
|
+
tabs: oversizedTabs,
|
|
46
|
+
groups: [{ title: " Group ", tabIds: ["tab-0", "tab-0", "unknown"] }],
|
|
47
|
+
}],
|
|
48
|
+
});
|
|
49
|
+
assert.equal(normalized.version, 1);
|
|
50
|
+
assert.equal(normalized.workspaces[0].name.length, 160, "workspace names must be bounded");
|
|
51
|
+
assert.equal(normalized.workspaces[0].tabs.length, WEBUI_WORKSPACE_TAB_LIMIT, "workspace tabs must be bounded");
|
|
52
|
+
assert.deepEqual(normalized.workspaces[0].groups, [{ title: "Group", tabIds: ["tab-0"] }], "groups must only retain unique saved tab ids");
|
|
53
|
+
|
|
54
|
+
await mkdir(path.dirname(storageFile), { recursive: true });
|
|
55
|
+
await writeFile(storageFile, "{ malformed", "utf8");
|
|
56
|
+
const warnings = [];
|
|
57
|
+
assert.deepEqual(await readWebuiWorkspaces(storageFile, { onWarning: (message) => warnings.push(message) }), { version: 1, workspaces: [] });
|
|
58
|
+
assert.equal(warnings.length, 1, "malformed persisted files must fail soft with one warning");
|
|
59
|
+
assert.match(warnings[0], /treating it as empty/i);
|
|
60
|
+
|
|
61
|
+
for (let index = 0; index <= WEBUI_WORKSPACE_LIMIT; index += 1) {
|
|
62
|
+
await saveWebuiWorkspace({ name: `workspace-${index}`, tabs: [tab(`saved-${index}`, root)] }, storageFile);
|
|
63
|
+
}
|
|
64
|
+
const afterEviction = await listWebuiWorkspaces(storageFile);
|
|
65
|
+
assert.equal(afterEviction.length, WEBUI_WORKSPACE_LIMIT, "oldest workspace must be evicted at the configured bound");
|
|
66
|
+
assert.equal(afterEviction.some((workspace) => workspace.name === "workspace-0"), false);
|
|
67
|
+
assert.ok(afterEviction.some((workspace) => workspace.name === `workspace-${WEBUI_WORKSPACE_LIMIT}`));
|
|
68
|
+
|
|
69
|
+
const overwriteTarget = afterEviction.find((workspace) => workspace.name === "workspace-1");
|
|
70
|
+
await assert.rejects(
|
|
71
|
+
saveWebuiWorkspace({ name: "workspace-1", tabs: [tab("replacement", root)] }, storageFile),
|
|
72
|
+
(error) => error?.code === "WORKSPACE_NAME_CONFLICT",
|
|
73
|
+
"duplicate names must require explicit overwrite",
|
|
74
|
+
);
|
|
75
|
+
const overwritten = await saveWebuiWorkspace({
|
|
76
|
+
name: "workspace-1",
|
|
77
|
+
overwrite: true,
|
|
78
|
+
activeTabId: "replacement",
|
|
79
|
+
groups: [{ title: "Replacement", tabIds: ["replacement"] }],
|
|
80
|
+
tabs: [tab("replacement", root)],
|
|
81
|
+
}, storageFile);
|
|
82
|
+
assert.equal(overwritten.workspace.id, overwriteTarget.id, "overwrite must preserve the saved workspace identity");
|
|
83
|
+
const stored = await getWebuiWorkspace(overwritten.workspace.id, storageFile);
|
|
84
|
+
assert.equal(stored.activeTabId, "replacement");
|
|
85
|
+
assert.deepEqual(stored.groups, [{ title: "Replacement", tabIds: ["replacement"] }]);
|
|
86
|
+
|
|
87
|
+
const deleted = await deleteWebuiWorkspace(overwritten.workspace.id, storageFile);
|
|
88
|
+
assert.equal(deleted.deletedId, overwritten.workspace.id);
|
|
89
|
+
assert.equal(await getWebuiWorkspace(overwritten.workspace.id, storageFile), null);
|
|
90
|
+
if (process.platform !== "win32") assert.equal((await stat(storageFile)).mode & 0o777, 0o600, "atomic writes must be owner-only");
|
|
91
|
+
assert.equal((await readWebuiWorkspaces(storageFile)).version, 1, "atomic writes must leave valid JSON behind");
|
|
92
|
+
|
|
93
|
+
await Promise.all(Array.from({ length: 8 }, (_, index) => saveWebuiWorkspace({
|
|
94
|
+
name: `concurrent-${index}`,
|
|
95
|
+
tabs: [tab(`concurrent-tab-${index}`, root)],
|
|
96
|
+
}, concurrentFile)));
|
|
97
|
+
const concurrent = await listWebuiWorkspaces(concurrentFile);
|
|
98
|
+
assert.equal(concurrent.length, 8, "serialized writes must retain every concurrent save");
|
|
99
|
+
assert.deepEqual(new Set(concurrent.map((workspace) => workspace.name)), new Set(Array.from({ length: 8 }, (_, index) => `concurrent-${index}`)));
|
|
100
|
+
const concurrentDocument = JSON.parse(await readFile(concurrentFile, "utf8"));
|
|
101
|
+
assert.equal(concurrentDocument.version, 1, "serialized atomic writes must not leave partial JSON");
|
|
102
|
+
|
|
103
|
+
console.log("webui-workspaces.test.mjs passed");
|
|
104
|
+
} finally {
|
|
105
|
+
await rm(root, { recursive: true, force: true });
|
|
106
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const read = (relativePath) => readFile(path.join(root, relativePath), "utf8");
|
|
8
|
+
const [html, app, css] = await Promise.all([
|
|
9
|
+
read("public/index.html"),
|
|
10
|
+
read("public/app.js"),
|
|
11
|
+
read("public/styles.css"),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const actionStart = html.indexOf('<div class="terminal-sidebar-actions"');
|
|
15
|
+
const actionEnd = html.indexOf("</div>", actionStart);
|
|
16
|
+
const saveButton = html.indexOf('id="workspaceSaveButton"', actionStart);
|
|
17
|
+
assert.ok(actionStart >= 0 && saveButton > actionStart && saveButton < actionEnd, "Save workspace must be a header action");
|
|
18
|
+
assert.match(html, /workspaceSaveButton[\s\S]*?aria-label="Save workspace"/, "Save workspace must be labelled");
|
|
19
|
+
assert.match(app, /applyStyledTooltip\(elements\.workspaceSaveButton,[\s\S]*?floating: false/, "Save workspace must keep only its dedicated styled tooltip instead of also binding the shared floating tooltip");
|
|
20
|
+
|
|
21
|
+
assert.match(app, /function saveWebuiWorkspace[\s\S]*?api\("\/api\/workspaces", \{ method: "POST", body, scoped: false \}\)/, "Save must use an unscoped workspace API call");
|
|
22
|
+
assert.match(app, /function refreshSavedWorkspaces[\s\S]*?api\("\/api\/workspaces", \{ scoped: false \}\)/, "Workspace list must use an unscoped API call");
|
|
23
|
+
assert.match(app, /function deleteWebuiWorkspace[\s\S]*?method: "DELETE", scoped: false/, "Delete must use an unscoped API call");
|
|
24
|
+
assert.match(app, /function saveWebuiWorkspace[\s\S]*?appConfirm\(\{[\s\S]*?confirmLabel: "Overwrite"/, "Duplicate saves must use the existing confirmation modal");
|
|
25
|
+
|
|
26
|
+
const loadStart = app.indexOf("async function loadWebuiWorkspace");
|
|
27
|
+
const loadEnd = app.indexOf("async function deleteWebuiWorkspace", loadStart);
|
|
28
|
+
const loadFlow = app.slice(loadStart, loadEnd);
|
|
29
|
+
assert.ok(loadStart >= 0 && loadEnd > loadStart, "Load flow must be defined before delete flow");
|
|
30
|
+
assert.match(loadFlow, /\/api\/workspaces\/\$\{encodeURIComponent\(workspaceId\)\}\/load/, "Load must call the workspace load endpoint");
|
|
31
|
+
assert.match(loadFlow, /scoped: false/, "Load must be unscoped");
|
|
32
|
+
assert.ok(loadFlow.indexOf("await refreshTabs();") < loadFlow.indexOf("installLoadedWorkspaceGroups"), "Tabs must refresh before restored groups are installed");
|
|
33
|
+
assert.match(loadFlow, /await hydrateLoadedWorkspaceActiveTab\(data\.activeTabId\)/, "Load must hydrate the restored active tab even when refreshTabs selected it already");
|
|
34
|
+
assert.match(loadFlow, /settleUndoToast\(/, "Load must show a bounded restore summary");
|
|
35
|
+
assert.match(loadFlow, /addEvent\(/, "Load must record restore warnings/events");
|
|
36
|
+
|
|
37
|
+
assert.match(app, /function hydrateLoadedWorkspaceActiveTab[\s\S]*?connectEvents\(tabContext\);[\s\S]*?await refreshAll\(tabContext\)/, "A restored tab already selected by refreshTabs must still connect events and hydrate session state");
|
|
38
|
+
assert.match(app, /function installLoadedWorkspaceGroups[\s\S]*?terminalCustomGroups = new Map\(\);[\s\S]*?nextTerminalCustomGroupId\(\)[\s\S]*?persistTerminalCustomGroups\(\)/, "Restored groups must replace stale groups, use local ids, and persist");
|
|
39
|
+
assert.match(app, /const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1"/, "The existing custom-group storage key must remain unchanged");
|
|
40
|
+
assert.match(app, /const savedWorkspacePanel = !tabs\.length \? renderSavedWorkspacePicker\(\) : null/, "The saved-workspace picker must be dashboard-only at zero tabs");
|
|
41
|
+
assert.match(app, /label: "Workspace: Save"/, "The command palette must offer workspace save when tabs exist");
|
|
42
|
+
assert.match(app, /label: "Workspace: Load…"/, "The command palette must offer workspace load when no tabs exist");
|
|
43
|
+
assert.match(app, /function closeAllTerminalTabs[\s\S]*?allowEmpty: true/, "Close all must permit the planned zero-tab workspace-load state");
|
|
44
|
+
assert.match(app, /function closeTerminalTabs[\s\S]*?if \(!tabs\.length\) setWorkspaceDashboardCollapsed\(false, \{ persist: false \}\)/, "Closing all tabs must reveal the workspace picker dashboard");
|
|
45
|
+
assert.match(app, /function initializeTabs[\s\S]*?if \(!saved\.length\) await createFirstTerminalTabFromChosenDirectory\(\)/, "Fresh installs without saved workspaces must retain the first-terminal cwd prompt");
|
|
46
|
+
|
|
47
|
+
const emptyStart = app.slice(app.indexOf("function renderEmptyStartState"), app.indexOf("function userPromptTargets"));
|
|
48
|
+
assert.match(emptyStart, /title: "Load workspace"[\s\S]*?description: "Restore a saved tab constellation"[\s\S]*?openWorkspaceLoadPicker/, "The empty-start card must offer a labelled saved-workspace picker action");
|
|
49
|
+
assert.match(html, /id="workspaceLoadDialog"[\s\S]*?aria-labelledby="workspaceLoadDialogTitle"/, "The saved-workspace picker must use a labelled dialog");
|
|
50
|
+
assert.match(html, /id="workspaceReplaceDialog"[\s\S]*?workspaceReplaceCurrentTabsList[\s\S]*?workspaceReplaceSaveName[\s\S]*?Load without saving[\s\S]*?Save & load/, "The replacement dialog must expose current tabs, a save name, and explicit discard/save choices");
|
|
51
|
+
assert.match(app, /function renderWorkspaceLoadDialog[\s\S]*?Loading saved workspaces…[\s\S]*?workspace-load-dialog-retry[\s\S]*?No saved workspaces yet[\s\S]*?loadWebuiWorkspace[\s\S]*?workspace-load-dialog-item-delete danger[\s\S]*?deleteWebuiWorkspace[\s\S]*?workspaceLoadDialogCloseButton\?\.focus/, "The dialog picker must render loading, retry/error, empty, load, and destructive delete states while preserving focus after deletion");
|
|
52
|
+
assert.match(app, /const result = await loadWebuiWorkspace[\s\S]*?result === "cancelled"[\s\S]*?openWorkspaceLoadPicker[\s\S]*?result === "error"[\s\S]*?focusReturn\.focus/, "Cancelled and failed picker loads must restore a usable keyboard destination");
|
|
53
|
+
assert.match(app, /function workspaceReplacementTabRow[\s\S]*?tabIndicator\(tab\)[\s\S]*?tab\.id === activeTabId[\s\S]*?normalizeDisplayPath\(tab\.cwd/, "The replacement dialog must identify each current tab's activity, active state, and cwd");
|
|
54
|
+
assert.match(app, /function workspaceSaveCurrentDecision[\s\S]*?replaceOpenTabs: true[\s\S]*?groups: workspaceGroupsForSave\(\)[\s\S]*?activeTabId/, "Save-and-load must send only UI-owned group and active-tab metadata");
|
|
55
|
+
assert.match(app, /workspaceReplaceDiscardButton[\s\S]*?replaceOpenTabs: true, discardCurrent: true/, "Discard-and-load must require its own explicit dialog action");
|
|
56
|
+
assert.match(loadFlow, /const decision = await chooseWorkspaceReplacement[\s\S]*?Object\.keys\(decision\)\.length[\s\S]*?body: decision/, "Open-tab loading must send the WS1 decision body while zero-tab loading keeps an empty body");
|
|
57
|
+
assert.match(loadFlow, /workspace with that name already exists[\s\S]*?confirmLabel: "Overwrite & load"[\s\S]*?overwrite: true/, "Duplicate save-and-load names must confirm overwrite before retrying");
|
|
58
|
+
assert.match(loadFlow, /data\.closedIds[\s\S]*?retireClosedWorkspaceTabContexts\(closedIds\)[\s\S]*?data\.savedCurrent\?\.workspaces/, "The client must reconcile closed tabs and optional saved-current workspace metadata");
|
|
59
|
+
assert.match(app, /function retireClosedWorkspaceTabContexts[\s\S]*?tabDrafts\.delete[\s\S]*?clearAttachments[\s\S]*?fileViewersByTab\.delete[\s\S]*?removeSubagentTerminalViewsForParent/, "Workspace replacement must retire per-tab client state along with closed tabs");
|
|
60
|
+
|
|
61
|
+
assert.match(css, /body\.terminal-tabs-left \.terminal-sidebar-actions \{[\s\S]*?grid-template-columns: repeat\(4, minmax\(0, 1fr\)\)/, "The left tab layout must provide four action slots");
|
|
62
|
+
assert.match(css, /\.workspace-saved-workspaces/, "Saved-workspace picker styles must be scoped");
|
|
63
|
+
assert.match(css, /\.workspace-load-dialog,[\s\S]*?\.workspace-replace-dialog/, "Workspace loading and replacement dialogs must have scoped styles");
|
|
64
|
+
assert.match(css, /\.workspace-replace-current-tabs-list[\s\S]*?max-height:[\s\S]*?overflow: auto/, "The replacement tab disclosure must remain bounded and scrollable");
|
|
65
|
+
assert.match(css, /\.workspace-load-dialog-item-actions button \{ flex: 1 1 7rem; min-height: 44px; \}/, "Picker load and delete actions must remain touch-friendly on narrow layouts");
|
|
66
|
+
assert.match(css, /\.workspace-replace-dialog menu button \{ flex: 1 1 9rem; min-height: 44px; \}/, "Replacement decisions must remain touch-friendly on narrow layouts");
|
|
67
|
+
assert.match(css, /@media \(max-width: 720px\)[\s\S]*?\.workspace-saved-workspace-actions button \{ flex: 1 1 7rem; min-height: 44px; \}/, "Saved-workspace actions must stay touch-friendly on narrow layouts");
|
|
68
|
+
|
|
69
|
+
console.log("workspace-save-load-static.test.mjs passed");
|