@firstpick/pi-package-webui 0.7.8 → 0.7.9
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/bin/pi-webui.mjs +380 -56
- package/lib/queue-mutation.mjs +109 -0
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +1 -1
- package/public/app.js +1483 -112
- package/public/index.html +87 -0
- package/public/styles.css +592 -73
- package/public/voice-conversation.mjs +1 -1
- 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/cwd-footer-reliability-static.test.mjs +5 -0
- 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 +175 -43
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/http-endpoints-harness.test.mjs +160 -1
- package/tests/mobile-static.test.mjs +56 -38
- package/tests/native-parity.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/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
|
@@ -30,7 +30,12 @@ const extensionHandlers = new Map();
|
|
|
30
30
|
const registeredCommands = new Map();
|
|
31
31
|
const statuses = [];
|
|
32
32
|
const notifications = [];
|
|
33
|
+
const sentMessages = [];
|
|
34
|
+
const subagentRpcRequests = [];
|
|
35
|
+
let branchEntries = [];
|
|
36
|
+
let idle = true;
|
|
33
37
|
let subagentStatusRequestCount = 0;
|
|
38
|
+
let subagentRpcReplyHook = null;
|
|
34
39
|
const pi = {
|
|
35
40
|
events: bus,
|
|
36
41
|
on(name, handler) {
|
|
@@ -42,7 +47,8 @@ const pi = {
|
|
|
42
47
|
getAllTools() { return []; },
|
|
43
48
|
getActiveTools() { return []; },
|
|
44
49
|
setActiveTools() {},
|
|
45
|
-
appendEntry() {},
|
|
50
|
+
appendEntry(customType, data) { branchEntries.push({ type: "custom", customType, data }); },
|
|
51
|
+
sendMessage(message, options) { sentMessages.push({ message, options }); },
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
const ctx = {
|
|
@@ -50,8 +56,9 @@ const ctx = {
|
|
|
50
56
|
hasUI: true,
|
|
51
57
|
cwd: "/tmp/subagent-helper-test",
|
|
52
58
|
sessionManager: {
|
|
53
|
-
getBranch() { return
|
|
59
|
+
getBranch() { return branchEntries; },
|
|
54
60
|
},
|
|
61
|
+
isIdle() { return idle; },
|
|
55
62
|
getSystemPromptOptions() {
|
|
56
63
|
return {
|
|
57
64
|
skills: [
|
|
@@ -112,10 +119,12 @@ const statusText = `Active async runs: 2
|
|
|
112
119
|
|
|
113
120
|
webuiRpcHelper(pi);
|
|
114
121
|
const unsubscribeRpc = bus.on("subagents:rpc:v1:request", (request) => {
|
|
122
|
+
subagentRpcRequests.push(request);
|
|
115
123
|
subagentStatusRequestCount += 1;
|
|
116
124
|
const text = request.params?.id === "run-a"
|
|
117
125
|
? `Run: run-a\nState: running\nMode: parallel\nDir: ${asyncRunDir}`
|
|
118
126
|
: statusText;
|
|
127
|
+
subagentRpcReplyHook?.(request);
|
|
119
128
|
bus.emit(`subagents:rpc:v1:reply:${request.requestId}`, {
|
|
120
129
|
version: 1,
|
|
121
130
|
requestId: request.requestId,
|
|
@@ -164,6 +173,13 @@ function latestPayload() {
|
|
|
164
173
|
return JSON.parse(entry.text.slice("PI_WEBUI_SUBAGENTS_V1 ".length));
|
|
165
174
|
}
|
|
166
175
|
|
|
176
|
+
function helperResponse(requestId) {
|
|
177
|
+
const notice = notifications.findLast((entry) => entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")
|
|
178
|
+
&& JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === requestId);
|
|
179
|
+
assert.ok(notice, `helper action ${requestId} should return a response notification`);
|
|
180
|
+
return JSON.parse(notice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
181
|
+
}
|
|
182
|
+
|
|
167
183
|
let payload = latestPayload();
|
|
168
184
|
assert.equal(payload.available, true, "successful pi-subagents RPC should mark status available");
|
|
169
185
|
assert.deepEqual(payload.runs.map((run) => run.id), ["run-a", "run-b"]);
|
|
@@ -441,7 +457,17 @@ for (const handler of extensionHandlers.get("tool_execution_end") || []) {
|
|
|
441
457
|
handler({ type: "tool_execution_end", toolCallId: "foreground-call", toolName: "subagent" }, ctx);
|
|
442
458
|
}
|
|
443
459
|
payload = latestPayload();
|
|
444
|
-
|
|
460
|
+
foreground = payload.runs.find((run) => run.id === "foreground-call");
|
|
461
|
+
assert.deepEqual(foreground && {
|
|
462
|
+
status: foreground.status,
|
|
463
|
+
endedAt: typeof foreground.endedAt,
|
|
464
|
+
agents: foreground.agents.map((agent) => [agent.name, agent.status]),
|
|
465
|
+
}, {
|
|
466
|
+
status: "done",
|
|
467
|
+
endedAt: "number",
|
|
468
|
+
agents: [["reviewer", "done"], ["tester", "done"]],
|
|
469
|
+
}, "foreground children should remain viewable with final statuses when their tool finishes");
|
|
470
|
+
assert.equal(branchEntries.at(-1)?.customType, "webui-subagent-retained-runs-v1", "terminal runs should persist as parent-session custom snapshots");
|
|
445
471
|
|
|
446
472
|
const boundedWorkflowSnapshot = {
|
|
447
473
|
version: 1,
|
|
@@ -495,6 +521,193 @@ payload = latestPayload();
|
|
|
495
521
|
assert.equal(payload.runs.some((run) => run.source === "workflow"), false, "an empty workflow snapshot should clear only workflow rows");
|
|
496
522
|
assert.ok(payload.runs.some((run) => run.id === "run-a") && payload.runs.some((run) => run.id === "run-b"), "workflow cleanup must preserve ordinary async rows");
|
|
497
523
|
|
|
524
|
+
await helperCommand.handler(JSON.stringify({
|
|
525
|
+
requestId: "dismiss-finished-foreground",
|
|
526
|
+
action: "subagent-dismiss",
|
|
527
|
+
payload: { runId: "foreground-call" },
|
|
528
|
+
}), ctx);
|
|
529
|
+
assert.deepEqual(helperResponse("dismiss-finished-foreground"), {
|
|
530
|
+
requestId: "dismiss-finished-foreground",
|
|
531
|
+
ok: true,
|
|
532
|
+
data: { runId: "foreground-call", dismissed: true },
|
|
533
|
+
}, "dismiss should remove only a retained finished run");
|
|
534
|
+
payload = latestPayload();
|
|
535
|
+
assert.equal(payload.runs.some((run) => run.id === "foreground-call"), false, "a dismissed finished run should disappear from the published snapshot");
|
|
536
|
+
|
|
537
|
+
await helperCommand.handler(JSON.stringify({
|
|
538
|
+
requestId: "dismiss-running-async",
|
|
539
|
+
action: "subagent-dismiss",
|
|
540
|
+
payload: { runId: "run-a" },
|
|
541
|
+
}), ctx);
|
|
542
|
+
assert.equal(helperResponse("dismiss-running-async").ok, false, "dismiss should reject a still-running run");
|
|
543
|
+
|
|
544
|
+
for (const handler of extensionHandlers.get("tool_execution_start") || []) {
|
|
545
|
+
handler({
|
|
546
|
+
type: "tool_execution_start",
|
|
547
|
+
toolCallId: "foreground-cancel",
|
|
548
|
+
toolName: "subagent",
|
|
549
|
+
args: { agent: "tester", model: "openai-codex/gpt-5.6-terra:xhigh" },
|
|
550
|
+
}, ctx);
|
|
551
|
+
}
|
|
552
|
+
await helperCommand.handler(JSON.stringify({
|
|
553
|
+
requestId: "cancel-foreground-not-ready",
|
|
554
|
+
action: "subagent-cancel",
|
|
555
|
+
payload: { runId: "foreground-cancel" },
|
|
556
|
+
}), ctx);
|
|
557
|
+
assert.equal(helperResponse("cancel-foreground-not-ready").ok, false, "foreground cancellation should wait until pi-subagents publishes its control run id");
|
|
558
|
+
for (const handler of extensionHandlers.get("tool_execution_update") || []) {
|
|
559
|
+
handler({
|
|
560
|
+
type: "tool_execution_update",
|
|
561
|
+
toolCallId: "foreground-cancel",
|
|
562
|
+
toolName: "subagent",
|
|
563
|
+
partialResult: { details: { runId: "foreground-control", mode: "single", progress: [{ agent: "tester", status: "running", index: 0 }] } },
|
|
564
|
+
}, ctx);
|
|
565
|
+
}
|
|
566
|
+
const interruptRequestsBefore = subagentRpcRequests.length;
|
|
567
|
+
idle = true;
|
|
568
|
+
await helperCommand.handler(JSON.stringify({
|
|
569
|
+
requestId: "cancel-foreground",
|
|
570
|
+
action: "subagent-cancel",
|
|
571
|
+
payload: { runId: "foreground-control" },
|
|
572
|
+
}), ctx);
|
|
573
|
+
assert.deepEqual(helperResponse("cancel-foreground"), {
|
|
574
|
+
requestId: "cancel-foreground",
|
|
575
|
+
ok: true,
|
|
576
|
+
data: { runId: "foreground-control", state: "cancelled", delivery: "context", rpcMethod: "interrupt" },
|
|
577
|
+
}, "foreground cancellation should report a context delivery after an interrupt RPC");
|
|
578
|
+
assert.deepEqual(subagentRpcRequests.slice(interruptRequestsBefore).find((request) => request.method === "interrupt")?.params, { id: "foreground-control" }, "foreground cancellation should target pi-subagents' published control run id");
|
|
579
|
+
assert.equal(sentMessages.at(-1)?.message?.customType, "webui-subagent-cancelled");
|
|
580
|
+
assert.equal(sentMessages.at(-1)?.options, undefined, "idle parent sessions should receive cancellation notices as context");
|
|
581
|
+
|
|
582
|
+
const longReason = "R".repeat(125);
|
|
583
|
+
const longNote = "N".repeat(2_010);
|
|
584
|
+
const stopRequestsBefore = subagentRpcRequests.length;
|
|
585
|
+
idle = false;
|
|
586
|
+
await helperCommand.handler(JSON.stringify({
|
|
587
|
+
requestId: "cancel-async",
|
|
588
|
+
action: "subagent-cancel",
|
|
589
|
+
payload: { runId: "run-a", agentId: "run-a:step:0:reviewer", reason: longReason, note: longNote },
|
|
590
|
+
}), ctx);
|
|
591
|
+
const asyncCancel = helperResponse("cancel-async");
|
|
592
|
+
assert.deepEqual(asyncCancel, {
|
|
593
|
+
requestId: "cancel-async",
|
|
594
|
+
ok: true,
|
|
595
|
+
data: { runId: "run-a", state: "cancelled", delivery: "steer", rpcMethod: "stop" },
|
|
596
|
+
}, "async cancellation should report a steer delivery after a stop RPC");
|
|
597
|
+
assert.deepEqual(subagentRpcRequests.slice(stopRequestsBefore).find((request) => request.method === "stop")?.params, { id: "run-a" }, "async cancellation should target the tracked run with stop");
|
|
598
|
+
const asyncCancelMessage = sentMessages.at(-1);
|
|
599
|
+
assert.equal(asyncCancelMessage?.message?.customType, "webui-subagent-cancelled");
|
|
600
|
+
assert.deepEqual(asyncCancelMessage?.options, { deliverAs: "steer" }, "busy parent sessions should receive cancellation notices as steer messages");
|
|
601
|
+
assert.equal(asyncCancelMessage?.message?.display, true);
|
|
602
|
+
assert.equal(asyncCancelMessage?.message?.details?.runId, "run-a");
|
|
603
|
+
assert.deepEqual(asyncCancelMessage?.message?.details?.agentNames, ["reviewer", "reviewer"]);
|
|
604
|
+
assert.equal(asyncCancelMessage?.message?.details?.reason.length, 120, "cancel reasons should retain the documented 120-character bound");
|
|
605
|
+
assert.equal(asyncCancelMessage?.message?.details?.note.length, 2000, "cancel notes should retain the documented 2000-character bound");
|
|
606
|
+
assert.match(asyncCancelMessage?.message?.content || "", /should not be automatically retried without asking/, "parent cancellation notices should prevent silent retries");
|
|
607
|
+
payload = latestPayload();
|
|
608
|
+
const cancelledAsync = payload.runs.find((run) => run.id === "run-a");
|
|
609
|
+
assert.deepEqual(cancelledAsync && {
|
|
610
|
+
status: cancelledAsync.status,
|
|
611
|
+
cancelledBy: cancelledAsync.cancelledBy,
|
|
612
|
+
cancelReasonLength: cancelledAsync.cancelReason?.length,
|
|
613
|
+
cancelNoteLength: cancelledAsync.cancelNote?.length,
|
|
614
|
+
agentStatuses: cancelledAsync.agents.map((agent) => agent.status),
|
|
615
|
+
}, {
|
|
616
|
+
status: "cancelled",
|
|
617
|
+
cancelledBy: "user",
|
|
618
|
+
cancelReasonLength: 120,
|
|
619
|
+
cancelNoteLength: 2000,
|
|
620
|
+
agentStatuses: ["cancelled", "cancelled"],
|
|
621
|
+
}, "cancelled runs should remain published with bounded user cancellation metadata");
|
|
622
|
+
|
|
623
|
+
await helperCommand.handler(JSON.stringify({
|
|
624
|
+
requestId: "cancel-finished-async",
|
|
625
|
+
action: "subagent-cancel",
|
|
626
|
+
payload: { runId: "run-a" },
|
|
627
|
+
}), ctx);
|
|
628
|
+
assert.equal(helperResponse("cancel-finished-async").ok, false, "cancel should reject a retained terminal run");
|
|
629
|
+
|
|
630
|
+
bus.emit("subagent:async-started", { id: "run-race", mode: "single", agent: "tester" });
|
|
631
|
+
subagentRpcReplyHook = (request) => {
|
|
632
|
+
if (request.method !== "stop" || request.params?.id !== "run-race") return;
|
|
633
|
+
subagentRpcReplyHook = null;
|
|
634
|
+
bus.emit("subagent:async-complete", { id: "run-race" });
|
|
635
|
+
};
|
|
636
|
+
await helperCommand.handler(JSON.stringify({
|
|
637
|
+
requestId: "cancel-complete-race",
|
|
638
|
+
action: "subagent-cancel",
|
|
639
|
+
payload: { runId: "run-race", reason: "Stopped by the user" },
|
|
640
|
+
}), ctx);
|
|
641
|
+
assert.equal(helperResponse("cancel-complete-race").ok, true);
|
|
642
|
+
const racedCancel = latestPayload().runs.find((run) => run.id === "run-race");
|
|
643
|
+
assert.equal(racedCancel?.status, "cancelled", "a successful user cancel should remain authoritative when completion races the RPC reply");
|
|
644
|
+
assert.equal(racedCancel?.cancelledBy, "user");
|
|
645
|
+
assert.equal(racedCancel?.cancelReason, "Stopped by the user");
|
|
646
|
+
|
|
647
|
+
bus.emit("subagent:async-complete", { id: "run-b" });
|
|
648
|
+
payload = latestPayload();
|
|
649
|
+
const completedAsync = payload.runs.find((run) => run.id === "run-b");
|
|
650
|
+
assert.deepEqual(completedAsync && {
|
|
651
|
+
status: completedAsync.status,
|
|
652
|
+
endedAt: typeof completedAsync.endedAt,
|
|
653
|
+
agentStatuses: completedAsync.agents.map((agent) => agent.status),
|
|
654
|
+
}, {
|
|
655
|
+
status: "done",
|
|
656
|
+
endedAt: "number",
|
|
657
|
+
agentStatuses: ["done", "done"],
|
|
658
|
+
}, "async completion should retain a final run rather than deleting it");
|
|
659
|
+
|
|
660
|
+
const persistedSnapshot = branchEntries.at(-1);
|
|
661
|
+
assert.equal(persistedSnapshot?.customType, "webui-subagent-retained-runs-v1", "the latest parent-session custom entry should own retained run state");
|
|
662
|
+
assert.equal(persistedSnapshot?.data?.version, 1);
|
|
663
|
+
assert.equal(persistedSnapshot?.data?.runs?.find((run) => run.id === "run-a")?.agents?.[0]?.transcript, undefined, "retained snapshots should store output locators rather than redundant transcripts");
|
|
664
|
+
|
|
665
|
+
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "resume" }, ctx);
|
|
666
|
+
payload = latestPayload();
|
|
667
|
+
assert.equal(payload.runs.find((run) => run.id === "run-a")?.status, "cancelled", "resuming the same parent session should restore retained cancellation state");
|
|
668
|
+
assert.equal(payload.runs.find((run) => run.id === "run-b")?.status, "done", "resuming the same parent session should restore completed runs");
|
|
669
|
+
await helperCommand.handler(JSON.stringify({
|
|
670
|
+
requestId: "restored-async-output",
|
|
671
|
+
action: "subagent-output",
|
|
672
|
+
payload: { runId: "run-a", agentId: "run-a:step:0:reviewer" },
|
|
673
|
+
}), ctx);
|
|
674
|
+
const restoredOutput = helperResponse("restored-async-output");
|
|
675
|
+
assert.equal(restoredOutput.ok, true, "retained async output should remain accessible after a parent-session resume");
|
|
676
|
+
assert.equal(restoredOutput.data.agent.status, "cancelled");
|
|
677
|
+
|
|
678
|
+
const retainedParentBranch = branchEntries;
|
|
679
|
+
branchEntries = [];
|
|
680
|
+
for (const handler of extensionHandlers.get("session_tree") || []) await handler({ reason: "different-branch" }, ctx);
|
|
681
|
+
payload = latestPayload();
|
|
682
|
+
assert.equal(payload.runs.some((run) => ["run-a", "run-b", "foreground-cancel"].includes(run.id)), false, "a different parent branch must not inherit retained runs");
|
|
683
|
+
branchEntries = retainedParentBranch;
|
|
684
|
+
for (const handler of extensionHandlers.get("session_tree") || []) await handler({ reason: "return-to-parent-branch" }, ctx);
|
|
685
|
+
payload = latestPayload();
|
|
686
|
+
assert.equal(payload.runs.find((run) => run.id === "run-a")?.status, "cancelled", "returning to the parent branch should restore its retained runs");
|
|
687
|
+
|
|
688
|
+
await helperCommand.handler(JSON.stringify({
|
|
689
|
+
requestId: "dismiss-cancelled-async",
|
|
690
|
+
action: "subagent-dismiss",
|
|
691
|
+
payload: { runId: "run-a" },
|
|
692
|
+
}), ctx);
|
|
693
|
+
assert.equal(helperResponse("dismiss-cancelled-async").ok, true, "dismiss should accept a retained cancelled run");
|
|
694
|
+
assert.equal(branchEntries.at(-1)?.data?.runs?.some((run) => run.id === "run-a"), false, "dismiss should persist a tombstone snapshot without the removed run");
|
|
695
|
+
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "resume" }, ctx);
|
|
696
|
+
payload = latestPayload();
|
|
697
|
+
assert.equal(payload.runs.some((run) => run.id === "run-a"), false, "a dismissed run must remain absent after resume");
|
|
698
|
+
|
|
699
|
+
for (let index = 0; index < 17; index += 1) {
|
|
700
|
+
const runId = `retention-cap-${index}`;
|
|
701
|
+
for (const handler of extensionHandlers.get("tool_execution_start") || []) {
|
|
702
|
+
handler({ type: "tool_execution_start", toolCallId: runId, toolName: "subagent", args: { agent: "tester" } }, ctx);
|
|
703
|
+
}
|
|
704
|
+
for (const handler of extensionHandlers.get("tool_execution_end") || []) {
|
|
705
|
+
handler({ type: "tool_execution_end", toolCallId: runId, toolName: "subagent" }, ctx);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
payload = latestPayload();
|
|
709
|
+
assert.ok(payload.runs.filter((run) => run.source !== "workflow" && run.status !== "running").length <= 16, "ordinary retained runs should enforce the 16-run finished retention cap");
|
|
710
|
+
|
|
498
711
|
for (const handler of extensionHandlers.get("session_shutdown") || []) await handler({ reason: "quit" }, ctx);
|
|
499
712
|
unsubscribeRpc();
|
|
500
713
|
delete process.env.PI_WEBUI_SETTINGS_FILE;
|
|
@@ -88,12 +88,14 @@ assert.match(results.group, /^Tooltip group · 2 tabs\nWorkspaces: projects\/pi-
|
|
|
88
88
|
assert.match(results.group, /Click to switch · Drop tabs here to add$/, "group hover summary should preserve the drop-target affordance");
|
|
89
89
|
assert.doesNotMatch(terminalTabMetaSource, /\bpid\b/i, "compact tab metadata should not expose the process PID");
|
|
90
90
|
assert.equal(app.match(/applyStyledTooltip\(button, terminalTabTooltip\(tab\)/g)?.length, 2, "single and grouped-item tabs should share one tooltip formatter");
|
|
91
|
-
assert.match(renderTerminalTabGroupSource, /
|
|
91
|
+
assert.match(renderTerminalTabGroupSource, /applyStyledTooltip\(button, terminalTabGroupTooltip\(group, groupTitle\), \{ ariaLabel: false, description: true, placement: "right", variant: "workspace" \}\)/, "group hover disclosure should use the shared floating tooltip layer to the right of its trigger");
|
|
92
|
+
assert.doesNotMatch(renderTerminalTabGroupSource, /terminal-tab-group-summary|menu\.append\(summary\)/, "group hover disclosure should not render an in-flow summary that shifts group menu items");
|
|
92
93
|
assert.match(app, /footerTooltipNode\.setAttribute\("role", "tooltip"\)/, "the shared visual tooltip should expose tooltip semantics");
|
|
93
94
|
assert.match(app, /document\.addEventListener\("keydown", \(event\) => \{[\s\S]*event\.key === "Escape" && footerTooltipTarget[\s\S]*hideFooterTooltip\(footerTooltipTarget\)[\s\S]*\}, true\)/, "Escape should dismiss both hover- and focus-triggered tooltips from the document capture phase");
|
|
94
95
|
assert.match(app, /data-tooltip-variant"\) === "workspace" && !node\.matches\(":focus-visible"\)/, "touch focus should not flash the large workspace tooltip while keyboard focus remains supported");
|
|
95
96
|
assert.match(app, /styled-tooltip-description[\s\S]*aria-describedby/, "detailed tab tooltip text should be available as an accessible description");
|
|
96
97
|
assert.match(styles, /footer-floating-tooltip\[data-variant="workspace"\][\s\S]*line-height: 1\.52/, "workspace tooltips should use the readable visual variant");
|
|
97
|
-
assert.
|
|
98
|
+
assert.doesNotMatch(styles, /terminal-tab-group-summary/, "group tooltip styling should not reserve in-flow menu space");
|
|
99
|
+
assert.match(app, /placement === "right"[\s\S]*left = rect\.right \+ gap;[\s\S]*top = rect\.top;/, "right-placed tooltips should overlay beside and top-align with their trigger");
|
|
98
100
|
|
|
99
101
|
console.log("terminal tab workspace static tests passed");
|
|
@@ -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
|
+
}
|