@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.
Files changed (41) hide show
  1. package/README.md +10 -4
  2. package/bin/pi-webui.mjs +696 -69
  3. package/lib/git-workflow-preferences.mjs +16 -0
  4. package/lib/git-worktrees.mjs +43 -4
  5. package/lib/queue-mutation.mjs +109 -0
  6. package/lib/scoped-models.mjs +19 -0
  7. package/lib/webui-workspaces.mjs +265 -0
  8. package/package.json +4 -2
  9. package/public/app.js +2074 -188
  10. package/public/index.html +105 -4
  11. package/public/service-worker.js +1 -1
  12. package/public/styles.css +618 -73
  13. package/public/voice-conversation.mjs +1 -1
  14. package/tests/boot-failure-diagnostics.test.mjs +2 -2
  15. package/tests/codex-fast-mode-static.test.mjs +56 -0
  16. package/tests/compaction-mutation-contract.test.mjs +166 -0
  17. package/tests/compaction-resume-harness.test.mjs +113 -2
  18. package/tests/compaction-static.test.mjs +5 -0
  19. package/tests/composer-skill-tag-layout.test.mjs +70 -0
  20. package/tests/cwd-footer-reliability-static.test.mjs +5 -0
  21. package/tests/fast-mode-client-static.test.mjs +8 -8
  22. package/tests/file-selection-overlay-static.test.mjs +21 -0
  23. package/tests/file-viewer-search-static.test.mjs +65 -0
  24. package/tests/fixtures/fake-pi.mjs +216 -43
  25. package/tests/git-panel-file-preview-static.test.mjs +20 -5
  26. package/tests/git-workflow-preferences.test.mjs +8 -0
  27. package/tests/guided-git-publication-backend-static.test.mjs +40 -0
  28. package/tests/http-endpoints-harness.test.mjs +422 -2
  29. package/tests/mobile-static.test.mjs +111 -42
  30. package/tests/native-parity.test.mjs +1 -1
  31. package/tests/open-issue-wizard-static.test.mjs +1 -1
  32. package/tests/queue-edit-reorder-static.test.mjs +101 -0
  33. package/tests/queue-mutation-contract.test.mjs +143 -0
  34. package/tests/scoped-models.test.mjs +42 -0
  35. package/tests/side-panel-resize-static.test.mjs +8 -1
  36. package/tests/subagents-helper.test.mjs +216 -3
  37. package/tests/terminal-tab-workspace-static.test.mjs +4 -2
  38. package/tests/webui-workspaces-harness.test.mjs +223 -0
  39. package/tests/webui-workspaces.test.mjs +106 -0
  40. package/tests/workspace-save-load-static.test.mjs +69 -0
  41. package/webui-rpc-helper.mjs +300 -41
@@ -228,6 +228,26 @@ try {
228
228
  assert.equal(health.body.piRunning, true, "fake pi RPC process should be attached and running");
229
229
  assert.match(health.body.piVersion, /^\d+\.\d+\.\d+/, "health metadata should expose the installed Pi version");
230
230
 
231
+ const initialInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences");
232
+ assert.equal(initialInterfacePreferences.status, 200);
233
+ assert.equal(initialInterfacePreferences.body?.data?.preferences?.sidePanelWidth, null, "a user without a saved width should receive the default preference");
234
+ assert.equal(Object.hasOwn(initialInterfacePreferences.body?.data || {}, "path"), false, "preference responses must not disclose the user's settings-file path");
235
+ const savedInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences", {
236
+ method: "PUT",
237
+ body: { sidePanelWidth: 612.4 },
238
+ });
239
+ assert.equal(savedInterfacePreferences.status, 200);
240
+ assert.equal(savedInterfacePreferences.body?.data?.preferences?.sidePanelWidth, 612, "saved side-panel widths should be normalized to whole pixels");
241
+ assert.equal(JSON.parse(await readFile(settingsFile, "utf8")).interfacePreferences?.sidePanelWidth, 612, "the side-panel width should be saved in the private user settings file");
242
+ const reloadedInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences");
243
+ assert.equal(reloadedInterfacePreferences.body?.data?.preferences?.sidePanelWidth, 612, "the saved width should survive subsequent user preference reads");
244
+ const invalidInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences", {
245
+ method: "PUT",
246
+ body: { sidePanelWidth: 100 },
247
+ });
248
+ assert.equal(invalidInterfacePreferences.status, 400, "out-of-range side-panel widths should be rejected");
249
+ assert.equal((await request("127.0.0.1", "/api/interface-preferences")).body?.data?.preferences?.sidePanelWidth, 612, "invalid saves must preserve the last valid user width");
250
+
231
251
  // Workflow policy setup is server-scoped: missing policy reads as canonical
232
252
  // deny-default state without creating PI_CODING_AGENT_DIR or its policy file.
233
253
  const missingWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy");
@@ -391,6 +411,63 @@ try {
391
411
  const tabId = tabList[0].id;
392
412
  assert.ok(tabId, "tab should have an id");
393
413
 
414
+ const runtimeQueueBefore = { steering: ["runtime steering"], followUp: ["runtime first", "runtime second", "runtime third"] };
415
+ const runtimeQueueEdit = await waitForSseEvent(
416
+ tabId,
417
+ (event) => event.type === "queue_update" && event.source === "pi-runtime" && event.followUp?.[0] === "runtime edited",
418
+ () => request("127.0.0.1", "/api/queue/mutate", {
419
+ method: "POST",
420
+ body: {
421
+ tab: tabId,
422
+ source: "pi-runtime",
423
+ kind: "followUp",
424
+ expected: runtimeQueueBefore,
425
+ operation: { type: "edit", index: 0, expectedText: "runtime first", text: " runtime edited " },
426
+ },
427
+ }),
428
+ );
429
+ assert.equal(runtimeQueueEdit.triggerResult.status, 200, `runtime queue edit should succeed: ${runtimeQueueEdit.triggerResult.body?.error || ""}`);
430
+ assert.deepEqual(runtimeQueueEdit.triggerResult.body?.data, {
431
+ mutated: true,
432
+ source: "pi-runtime",
433
+ queue: { source: "pi-runtime", steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
434
+ }, "queue mutation should return the authoritative normalized runtime snapshot");
435
+ assert.equal(runtimeQueueEdit.event.source, "pi-runtime", "runtime queue events must retain their source");
436
+
437
+ const staleRuntimeQueueEdit = await request("127.0.0.1", "/api/queue/mutate", {
438
+ method: "POST",
439
+ body: {
440
+ tab: tabId,
441
+ source: "pi-runtime",
442
+ kind: "followUp",
443
+ expected: runtimeQueueBefore,
444
+ operation: { type: "move", from: 0, to: 2, expectedText: "runtime first" },
445
+ },
446
+ });
447
+ assert.equal(staleRuntimeQueueEdit.status, 409, "stale runtime queue snapshots must conflict");
448
+ assert.equal(staleRuntimeQueueEdit.body?.ok, false);
449
+ assert.equal(staleRuntimeQueueEdit.body?.data?.reason, "queue-changed");
450
+ assert.deepEqual(staleRuntimeQueueEdit.body?.data?.queue?.followUp, ["runtime edited", "runtime second", "runtime third"], "conflicts return the authoritative runtime queue");
451
+
452
+ const runtimeQueueMove = await request("127.0.0.1", "/api/queue/mutate", {
453
+ method: "POST",
454
+ body: {
455
+ tab: tabId,
456
+ source: "pi-runtime",
457
+ kind: "followUp",
458
+ expected: { steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
459
+ operation: { type: "move", from: 0, to: 2, expectedText: "runtime edited" },
460
+ },
461
+ });
462
+ assert.equal(runtimeQueueMove.status, 200, "runtime queue moves should use final zero-based indices");
463
+ assert.deepEqual(runtimeQueueMove.body?.data?.queue?.followUp, ["runtime second", "runtime third", "runtime edited"]);
464
+
465
+ const invalidRuntimeQueueMutation = await request("127.0.0.1", "/api/queue/mutate", {
466
+ method: "POST",
467
+ body: { tab: tabId, source: "pi-runtime", kind: "steering", expected: { steering: [], followUp: [] }, operation: { type: "edit", index: 0, expectedText: "x", text: "y" } },
468
+ });
469
+ assert.equal(invalidRuntimeQueueMutation.status, 400, "queue mutation must stay follow-up-only and reject malformed source contracts");
470
+
394
471
  const extensionResponseId = `fixture-extension-response-${Date.now()}`;
395
472
  const extensionResponseStartedAt = Date.now();
396
473
  const extensionResponse = await request("127.0.0.1", "/api/extension-ui-response", {
@@ -626,6 +703,10 @@ try {
626
703
  }
627
704
  assert.equal(subagentsResponse?.status, 200, "subagent overview endpoint should respond");
628
705
  assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "subagent overview should count all running agents");
706
+ assert.equal(subagentsResponse.body?.data?.runningRuns, 1, "subagent overview should expose running run counts separately from retained totals");
707
+ assert.equal(subagentsResponse.body?.data?.runningAgents, 2, "subagent overview should expose running agent counts separately from retained totals");
708
+ assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningRuns, 1);
709
+ assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningAgents, 2);
629
710
  assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.tabId, tabId, "subagent overview should group agents under their terminal tab");
630
711
  assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.source, "async", "ordinary async overview rows should retain their source");
631
712
  assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.agents?.map((agent) => agent.name), ["reviewer", "scout"], "subagent overview should preserve agent order within the session run");
@@ -662,6 +743,104 @@ try {
662
743
  ], "subagent output endpoint should preserve normalized structured transcript roles, order, IDs, and tool metadata");
663
744
  const unknownSubagentOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=missing&agent=missing`);
664
745
  assert.equal(unknownSubagentOutput.status, 404, "subagent output endpoint should reject untracked selections");
746
+
747
+ const dismissRunningSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
748
+ method: "POST",
749
+ body: { tab: tabId, runId: "fixture-run" },
750
+ });
751
+ assert.equal(dismissRunningSubagent.status, 400, "dismiss endpoint should reject running runs through the helper");
752
+ const cancelUnknownSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
753
+ method: "POST",
754
+ body: { tab: tabId, runId: "missing" },
755
+ });
756
+ assert.equal(cancelUnknownSubagent.status, 400, "cancel endpoint should return helper errors for unknown runs");
757
+
758
+ const cancelledSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
759
+ method: "POST",
760
+ body: { tab: tabId, runId: "fixture-run", reason: "Taking too long", note: "Use the existing result instead." },
761
+ });
762
+ assert.equal(cancelledSubagent.status, 200, `cancel endpoint should relay helper cancellation: ${cancelledSubagent.body?.error || ""}`);
763
+ assert.deepEqual(cancelledSubagent.body?.data, {
764
+ runId: "fixture-run",
765
+ state: "cancelled",
766
+ delivery: "context",
767
+ rpcMethod: "stop",
768
+ }, "cancel endpoint should preserve the helper cancellation response contract");
769
+ for (let attempt = 0; attempt < 20; attempt++) {
770
+ subagentsResponse = await request("127.0.0.1", "/api/subagents");
771
+ if (subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.status === "cancelled") break;
772
+ await delay(50);
773
+ }
774
+ const cancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-run");
775
+ assert.deepEqual(cancelledRun && {
776
+ status: cancelledRun.status,
777
+ endedAt: typeof cancelledRun.endedAt,
778
+ cancelledBy: cancelledRun.cancelledBy,
779
+ cancelReason: cancelledRun.cancelReason,
780
+ cancelNote: cancelledRun.cancelNote,
781
+ agentStatuses: cancelledRun.agents.map((agent) => agent.status),
782
+ }, {
783
+ status: "cancelled",
784
+ endedAt: "number",
785
+ cancelledBy: "user",
786
+ cancelReason: "Taking too long",
787
+ cancelNote: "Use the existing result instead.",
788
+ agentStatuses: ["cancelled", "cancelled"],
789
+ }, "subagent normalization should retain cancelled run and agent metadata");
790
+ assert.equal(subagentsResponse.body?.data?.totalRuns, 1, "retained runs should remain included in total counts");
791
+ assert.equal(subagentsResponse.body?.data?.runningRuns, 0, "retained cancelled runs should not count as running");
792
+ assert.equal(subagentsResponse.body?.data?.runningAgents, 0, "retained cancelled agents should not count as running");
793
+ const retainedCancelledOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-run&agent=fixture-run%3A0`);
794
+ assert.equal(retainedCancelledOutput.status, 200, "subagent output should remain accessible for retained cancelled runs");
795
+ assert.equal(retainedCancelledOutput.body?.data?.agent?.status, "cancelled");
796
+ const duplicateCancel = await request("127.0.0.1", "/api/subagents/cancel", {
797
+ method: "POST",
798
+ body: { tab: tabId, runId: "fixture-run" },
799
+ });
800
+ assert.equal(duplicateCancel.status, 400, "cancel endpoint should reject an already-finished run");
801
+
802
+ const dismissedSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
803
+ method: "POST",
804
+ body: { tab: tabId, runId: "fixture-run" },
805
+ });
806
+ assert.equal(dismissedSubagent.status, 200, `dismiss endpoint should relay helper dismissal: ${dismissedSubagent.body?.error || ""}`);
807
+ assert.deepEqual(dismissedSubagent.body?.data, { runId: "fixture-run", dismissed: true });
808
+ subagentsResponse = await request("127.0.0.1", "/api/subagents");
809
+ assert.equal(subagentsResponse.body?.data?.totalRuns, 0, "dismissed runs should be removed from the overview");
810
+
811
+ const retainedFixture = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents retained" } });
812
+ assert.equal(retainedFixture.status, 200, "retained subagent fixture should be accepted");
813
+ for (let attempt = 0; attempt < 20; attempt++) {
814
+ subagentsResponse = await request("127.0.0.1", "/api/subagents");
815
+ if (subagentsResponse.body?.data?.totalRuns === 2) break;
816
+ await delay(50);
817
+ }
818
+ assert.equal(subagentsResponse.body?.data?.totalRuns, 2, "finished runs should survive payload normalization");
819
+ assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "finished agents should remain represented in retained totals");
820
+ assert.equal(subagentsResponse.body?.data?.runningRuns, 0);
821
+ assert.equal(subagentsResponse.body?.data?.runningAgents, 0);
822
+ const normalizedDoneRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-done");
823
+ const normalizedCancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-cancelled");
824
+ assert.deepEqual(normalizedDoneRun && { status: normalizedDoneRun.status, endedAt: typeof normalizedDoneRun.endedAt, agentStatus: normalizedDoneRun.agents[0]?.status }, {
825
+ status: "done", endedAt: "number", agentStatus: "done",
826
+ }, "normalization should retain completed run state and final agent status");
827
+ assert.deepEqual(normalizedCancelledRun && {
828
+ status: normalizedCancelledRun.status,
829
+ cancelledBy: normalizedCancelledRun.cancelledBy,
830
+ cancelReason: normalizedCancelledRun.cancelReason,
831
+ cancelNote: normalizedCancelledRun.cancelNote,
832
+ agentStatus: normalizedCancelledRun.agents[0]?.status,
833
+ }, {
834
+ status: "cancelled",
835
+ cancelledBy: "user",
836
+ cancelReason: "Taking too long",
837
+ cancelNote: "Use the existing result instead.",
838
+ agentStatus: "cancelled",
839
+ }, "normalization should retain bounded user cancellation metadata");
840
+ const retainedDoneOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-done&agent=fixture-done%3A0`);
841
+ assert.equal(retainedDoneOutput.status, 200, "subagent output should remain accessible for retained completed runs");
842
+ assert.equal(retainedDoneOutput.body?.data?.agent?.status, "done");
843
+
665
844
  const subagentFixtureClear = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents clear" } });
666
845
  assert.equal(subagentFixtureClear.status, 200, "subagent fixture clear should be accepted");
667
846
  for (let attempt = 0; attempt < 20; attempt++) {
@@ -669,7 +848,7 @@ try {
669
848
  if (subagentsResponse.body?.data?.totalAgents === 0) break;
670
849
  await delay(50);
671
850
  }
672
- assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "completed subagents should disappear from the running overview");
851
+ assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "an empty helper snapshot should clear retained subagent rows");
673
852
  assert.equal(subagentsResponse.body?.data?.totalGates, 0, "cleared retry gates should disappear from the overview");
674
853
 
675
854
  const state = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(tabId)}`);
@@ -762,6 +941,39 @@ try {
762
941
  assert.equal(gitMain.status, 200);
763
942
  assert.equal(gitMain.body?.ok, true, "main branch endpoint should rename the branch");
764
943
 
944
+ const bypassPublish = await request("127.0.0.1", `/api/git-workflow/publish?tab=${encodeURIComponent(tabId)}`);
945
+ assert.equal(bypassPublish.status, 405, "GET /api/git-workflow/publish should be refused with 405");
946
+
947
+ const pushWithoutRemote = await request("127.0.0.1", "/api/git-workflow/push", { method: "POST", body: { tab: tabId } });
948
+ assert.equal(pushWithoutRemote.status, 200);
949
+ assert.equal(pushWithoutRemote.body?.ok, false, "push without a configured destination should fail closed");
950
+ assert.equal(pushWithoutRemote.body?.code, "NO_REMOTE", "remote-less push should have a stable recovery code");
951
+ assert.match(String(pushWithoutRemote.body?.hint || ""), /publish this repository|add a Git remote/i);
952
+ assert.match(String(pushWithoutRemote.body?.data?.stderr || ""), /No configured push destination/i, "classified failures should preserve process output");
953
+
954
+ const unconfirmedPublish = await request("127.0.0.1", "/api/git-workflow/publish", {
955
+ method: "POST",
956
+ body: { tab: tabId, repoName: "pi-webui-http-harness", visibility: "private" },
957
+ });
958
+ assert.equal(unconfirmedPublish.status, 200);
959
+ assert.equal(unconfirmedPublish.body?.ok, false, "publication should require exact server-side confirmation");
960
+ assert.match(String(unconfirmedPublish.body?.error || ""), /confirmed: true/);
961
+
962
+ const invalidVisibilityPublish = await request("127.0.0.1", "/api/git-workflow/publish", {
963
+ method: "POST",
964
+ body: { tab: tabId, repoName: "pi-webui-http-harness", visibility: "internal", confirmed: true },
965
+ });
966
+ assert.equal(invalidVisibilityPublish.body?.ok, false, "publication should reject visibility outside public/private");
967
+ assert.match(String(invalidVisibilityPublish.body?.error || ""), /visibility must be 'public' or 'private'/);
968
+
969
+ const invalidNamePublish = await request("127.0.0.1", "/api/git-workflow/publish", {
970
+ method: "POST",
971
+ body: { tab: tabId, repoName: "invalid repository name", visibility: "public", confirmed: true },
972
+ });
973
+ assert.equal(invalidNamePublish.body?.ok, false, "publication should reuse GitHub repository-name validation");
974
+ assert.match(String(invalidNamePublish.body?.error || ""), /Invalid GitHub repository name/);
975
+ assert.equal(runGitFixture(["remote"], cwd, "guarded publication requests must not configure a remote"), "");
976
+
765
977
  const initialWorktrees = await request("127.0.0.1", `/api/git-worktrees?tab=${encodeURIComponent(tabId)}`);
766
978
  assert.equal(initialWorktrees.status, 200);
767
979
  assert.equal(initialWorktrees.body?.ok, true, "worktree list endpoint should return data for a git repository");
@@ -936,12 +1148,156 @@ try {
936
1148
  await writeFile(path.join(remoteWork, "incoming.txt"), "base\nremote one\nremote two\n");
937
1149
  runGitFixture(["commit", "-am", "remote two"], remoteWork, "remote worktree should commit second incoming change");
938
1150
  runGitFixture(["push", "origin", "main"], remoteWork, "remote worktree should push incoming commits");
939
- runGitFixture(["fetch", "origin"], localRepo, "local repo should fetch incoming commits");
1151
+
1152
+ const remoteOnlySwitchBranch = "feature/remote-only-switch";
1153
+ runGitFixture(["switch", "-c", remoteOnlySwitchBranch], remoteWork, "remote worktree should create the switch fixture branch");
1154
+ await writeFile(path.join(remoteWork, "remote-switch.txt"), "switch fixture\n");
1155
+ runGitFixture(["add", "remote-switch.txt"], remoteWork, "remote switch fixture should stage its marker");
1156
+ runGitFixture(["commit", "-m", "remote switch fixture"], remoteWork, "remote switch fixture should commit its marker");
1157
+ runGitFixture(["push", "-u", "origin", remoteOnlySwitchBranch], remoteWork, "remote switch fixture should push its branch");
1158
+ runGitFixture(["switch", "main"], remoteWork, "remote worktree should return to main after the switch fixture");
1159
+
1160
+ const remoteOnlyWorktreeBranch = "feature/remote-only-worktree";
1161
+ runGitFixture(["switch", "-c", remoteOnlyWorktreeBranch], remoteWork, "remote worktree should create the worktree fixture branch");
1162
+ await writeFile(path.join(remoteWork, "remote-worktree.txt"), "worktree fixture\n");
1163
+ runGitFixture(["add", "remote-worktree.txt"], remoteWork, "remote worktree fixture should stage its marker");
1164
+ runGitFixture(["commit", "-m", "remote worktree fixture"], remoteWork, "remote worktree fixture should commit its marker");
1165
+ runGitFixture(["push", "-u", "origin", remoteOnlyWorktreeBranch], remoteWork, "remote worktree fixture should push its branch");
1166
+ runGitFixture(["switch", "main"], remoteWork, "remote worktree should return to main after the worktree fixture");
1167
+
1168
+ const remoteOnlyCreateBranch = "feature/remote-only-create";
1169
+ runGitFixture(["branch", remoteOnlyCreateBranch], remoteWork, "remote worktree should create the local-create compatibility fixture branch");
1170
+ runGitFixture(["push", "origin", remoteOnlyCreateBranch], remoteWork, "remote create fixture should push its branch");
1171
+ const staleRemoteBranch = "feature/remote-only-stale";
1172
+ runGitFixture(["branch", staleRemoteBranch], remoteWork, "remote worktree should create the stale fixture branch");
1173
+ runGitFixture(["push", "origin", staleRemoteBranch], remoteWork, "remote stale fixture should push its branch");
1174
+
1175
+ runGitFixture(["remote", "add", "mirror", remoteBare], localRepo, "local repo should add a second configured remote for exact-ref coverage");
1176
+ runGitFixture(["remote", "add", "team/mirror", remoteBare], localRepo, "local repo should add a slash-named remote for exact local-name derivation coverage");
940
1177
 
941
1178
  const remoteTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: localRepo, title: "remote-behind-fixture" } });
942
1179
  assert.equal(remoteTab.status, 201);
943
1180
  const remoteTabId = remoteTab.body?.data?.tab?.id;
944
1181
  assert.ok(remoteTabId, "remote fixture tab should have an id");
1182
+
1183
+ const fetchedRemoteBranches = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 20_000 });
1184
+ assert.equal(fetchedRemoteBranches.status, 200);
1185
+ assert.equal(fetchedRemoteBranches.body?.ok, true, `git fetch --prune should reveal remote-only branches: ${fetchedRemoteBranches.body?.error || ""}`);
1186
+ runGitFixture(["fetch", "mirror"], localRepo, "remote fixture should fetch the second remote for exact-ref collision coverage");
1187
+ runGitFixture(["fetch", "team/mirror"], localRepo, "remote fixture should fetch the slash-named remote for prefix matching coverage");
1188
+ runGitFixture(["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"], localRepo, "remote fixture should create a symbolic remote HEAD alias");
1189
+ runGitFixture(["branch", "origin/main", "main"], localRepo, "remote fixture should create a local ref that makes refname:short ambiguous");
1190
+
1191
+ const listedRemoteBranches = await request("127.0.0.1", `/api/git-branches?tab=${encodeURIComponent(remoteTabId)}`);
1192
+ assert.equal(listedRemoteBranches.status, 200);
1193
+ assert.equal(listedRemoteBranches.body?.ok, true, "branch listing should include fetched remote-only branches");
1194
+ const branchRecords = listedRemoteBranches.body?.data?.branches || [];
1195
+ const originRemoteSwitch = branchRecords.find((branch) => branch.remote === true && branch.remoteRef === `origin/${remoteOnlySwitchBranch}`);
1196
+ assert.deepEqual(originRemoteSwitch, {
1197
+ name: remoteOnlySwitchBranch,
1198
+ current: false,
1199
+ remote: true,
1200
+ remoteRef: `origin/${remoteOnlySwitchBranch}`,
1201
+ remoteName: "origin",
1202
+ displayName: `origin/${remoteOnlySwitchBranch}`,
1203
+ }, "remote-only rows should carry explicit local and exact remote metadata");
1204
+ const sameNameRemoteRefs = branchRecords
1205
+ .filter((branch) => branch.remote === true && branch.name === remoteOnlySwitchBranch)
1206
+ .map((branch) => branch.remoteRef)
1207
+ .sort();
1208
+ assert.deepEqual(sameNameRemoteRefs, [`mirror/${remoteOnlySwitchBranch}`, `origin/${remoteOnlySwitchBranch}`, `team/mirror/${remoteOnlySwitchBranch}`], "same-name remote-only branches should remain distinct by exact ref even when a remote name contains a slash");
1209
+ assert.equal(branchRecords.some((branch) => branch.remote === true && branch.remoteRef === "origin/HEAD"), false, "symbolic remote HEAD aliases must not be listed");
1210
+ assert.equal(branchRecords.some((branch) => branch.remote === true && branch.name === "main"), false, "a local branch should hide same-named remote rows");
1211
+ assert.ok(branchRecords.some((branch) => branch.remote !== true && branch.name === "origin/main"), "local branch names must not change when refname shortening would be ambiguous");
1212
+ assert.equal(listedRemoteBranches.body?.data?.remoteBranchesTruncated, false, "complete remote branch output should not be marked truncated");
1213
+
1214
+ const implicitRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
1215
+ method: "POST",
1216
+ body: { tab: remoteTabId, branch: remoteOnlySwitchBranch },
1217
+ });
1218
+ assert.equal(implicitRemoteSwitch.body?.ok, false, "remote-only names without an exact remoteRef must not trigger Git DWIM tracking creation");
1219
+ assert.match(String(implicitRemoteSwitch.body?.error || ""), /Unknown local git branch/, "implicit remote selection should retain the local-only API guard");
1220
+ assert.equal(runGitFixture(["branch", "--list", remoteOnlySwitchBranch], localRepo, "implicit remote switch should not create a local branch"), "");
1221
+
1222
+ const localCreateOverRemote = await request("127.0.0.1", "/api/git-branch", {
1223
+ method: "POST",
1224
+ body: { tab: remoteTabId, branch: remoteOnlyCreateBranch, create: true },
1225
+ timeoutMs: 20_000,
1226
+ });
1227
+ assert.equal(localCreateOverRemote.body?.ok, true, "explicit local branch creation should remain available when a same-named remote-only branch exists");
1228
+ assert.equal(runGitFixture(["branch", "--show-current"], localRepo, "local create compatibility path should switch to its new branch"), remoteOnlyCreateBranch);
1229
+ const createdUpstream = spawnSync("git", ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], { cwd: localRepo, encoding: "utf8" });
1230
+ assert.notEqual(createdUpstream.status, 0, "explicit local creation should not silently track the same-named remote branch");
1231
+ runGitFixture(["switch", "main"], localRepo, "local repo should return to main after local-create compatibility coverage");
1232
+
1233
+ runGitFixture(["push", "origin", "--delete", staleRemoteBranch], remoteWork, "remote fixture should delete the stale branch upstream");
1234
+ const prunedRemoteBranches = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 20_000 });
1235
+ assert.equal(prunedRemoteBranches.body?.ok, true, "git fetch --prune should remove the deleted origin tracking ref");
1236
+ const staleRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
1237
+ method: "POST",
1238
+ body: { tab: remoteTabId, branch: staleRemoteBranch, remoteRef: `origin/${staleRemoteBranch}` },
1239
+ });
1240
+ assert.equal(staleRemoteSwitch.body?.ok, false, "acting on a remote ref removed by prune must fail closed");
1241
+ assert.match(String(staleRemoteSwitch.body?.error || ""), /Unknown remote git branch/, "stale remote actions should explain that the advertised ref no longer exists");
1242
+ assert.equal(runGitFixture(["branch", "--list", staleRemoteBranch], localRepo, "stale remote action should not create a local branch"), "");
1243
+
1244
+ const mismatchedRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
1245
+ method: "POST",
1246
+ body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `origin/${remoteOnlyWorktreeBranch}` },
1247
+ });
1248
+ assert.equal(mismatchedRemoteSwitch.status, 200);
1249
+ assert.equal(mismatchedRemoteSwitch.body?.ok, false, "a remote ref must match its submitted local branch name");
1250
+ assert.equal(runGitFixture(["branch", "--list", remoteOnlySwitchBranch], localRepo, "mismatched remote switch should not create a local branch"), "");
1251
+
1252
+ const switchedRemoteBranch = await request("127.0.0.1", "/api/git-branch", {
1253
+ method: "POST",
1254
+ body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `origin/${remoteOnlySwitchBranch}` },
1255
+ timeoutMs: 20_000,
1256
+ });
1257
+ assert.equal(switchedRemoteBranch.status, 200);
1258
+ assert.equal(switchedRemoteBranch.body?.ok, true, `remote-only switch should create a tracking branch: ${switchedRemoteBranch.body?.error || ""}`);
1259
+ assert.equal(runGitFixture(["branch", "--show-current"], localRepo, "remote-only switch should remain attached"), remoteOnlySwitchBranch);
1260
+ assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], localRepo, "remote-only switch should configure its upstream"), `origin/${remoteOnlySwitchBranch}`);
1261
+
1262
+ const collisionRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
1263
+ method: "POST",
1264
+ body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `mirror/${remoteOnlySwitchBranch}` },
1265
+ });
1266
+ assert.equal(collisionRemoteSwitch.status, 200);
1267
+ assert.equal(collisionRemoteSwitch.body?.ok, false, "a newly materialized local branch should reject a same-name remote selection");
1268
+ assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], localRepo, "collision rejection must preserve the original upstream"), `origin/${remoteOnlySwitchBranch}`);
1269
+
1270
+ const switchedBackToMain = await request("127.0.0.1", "/api/git-branch", { method: "POST", body: { tab: remoteTabId, branch: "main" }, timeoutMs: 20_000 });
1271
+ assert.equal(switchedBackToMain.status, 200);
1272
+ assert.equal(switchedBackToMain.body?.ok, true, "local branch switching should remain unchanged after remote switching");
1273
+
1274
+ const mismatchedRemoteWorktree = await request("127.0.0.1", "/api/git-worktrees", {
1275
+ method: "POST",
1276
+ body: { tab: remoteTabId, branchName: remoteOnlyWorktreeBranch, remoteRef: `origin/${remoteOnlySwitchBranch}`, sessionMode: "empty", openTab: true },
1277
+ timeoutMs: 20_000,
1278
+ });
1279
+ assert.equal(mismatchedRemoteWorktree.status, 200);
1280
+ assert.equal(mismatchedRemoteWorktree.body?.ok, false, "a worktree remote ref must match its submitted local branch name");
1281
+ assert.equal(runGitFixture(["branch", "--list", remoteOnlyWorktreeBranch], localRepo, "mismatched remote worktree should not create a local branch"), "");
1282
+
1283
+ const remoteTrackingWorktree = await request("127.0.0.1", "/api/git-worktrees", {
1284
+ method: "POST",
1285
+ body: { tab: remoteTabId, branchName: remoteOnlyWorktreeBranch, remoteRef: `team/mirror/${remoteOnlyWorktreeBranch}`, sessionMode: "empty", openTab: true },
1286
+ timeoutMs: 20_000,
1287
+ });
1288
+ assert.equal(remoteTrackingWorktree.status, 200);
1289
+ assert.equal(remoteTrackingWorktree.body?.ok, true, `remote-only worktree should create a tracking branch: ${remoteTrackingWorktree.body?.error || ""}`);
1290
+ const remoteTrackingWorktreePath = remoteTrackingWorktree.body?.data?.worktree?.path || remoteTrackingWorktree.body?.data?.path;
1291
+ const remoteTrackingWorktreeTabId = remoteTrackingWorktree.body?.data?.tab?.id;
1292
+ assert.ok(remoteTrackingWorktreePath, "remote-only worktree response should include its path");
1293
+ assert.ok(remoteTrackingWorktreeTabId, "remote-only worktree should open a tab");
1294
+ assert.equal(runGitFixture(["branch", "--show-current"], remoteTrackingWorktreePath, "remote-only worktree should remain attached"), remoteOnlyWorktreeBranch);
1295
+ assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], remoteTrackingWorktreePath, "remote-only worktree should configure its upstream"), `team/mirror/${remoteOnlyWorktreeBranch}`);
1296
+ const closeRemoteTrackingWorktreeTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [remoteTrackingWorktreeTabId] }, timeoutMs: 10_000 });
1297
+ assert.equal(closeRemoteTrackingWorktreeTab.body?.ok, true, "remote-only worktree tab should close before cleanup");
1298
+ const removeRemoteTrackingWorktree = await request("127.0.0.1", "/api/git-worktrees", { method: "DELETE", body: { tab: remoteTabId, path: remoteTrackingWorktreePath, confirmed: true }, timeoutMs: 20_000 });
1299
+ assert.equal(removeRemoteTrackingWorktree.body?.ok, true, "remote-only tracking worktree should be removable after the tab closes");
1300
+
945
1301
  const incomingChanges = await request("127.0.0.1", `/api/git-changes?tab=${encodeURIComponent(remoteTabId)}`);
946
1302
  assert.equal(incomingChanges.status, 200);
947
1303
  assert.equal(incomingChanges.body?.ok, true, "git changes endpoint should load a fetched-behind repo");
@@ -2186,6 +2542,70 @@ try {
2186
2542
  const closeFilesTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [filesTabId] }, timeoutMs: 10_000 });
2187
2543
  assert.equal(closeFilesTab.status, 200, "file fixture tab should close after scoped file checks");
2188
2544
 
2545
+ // Codex subscription Fast mode: exact status is extension-owned and every mutation must be
2546
+ // idle, explicit, tab-scoped, and confirmed by the extension status event.
2547
+ const initialCodexFastMode = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
2548
+ assert.equal(initialCodexFastMode.status, 200);
2549
+ assert.equal(initialCodexFastMode.body?.data?.available, true, "fake /fast-mode command should make Codex Fast mode available");
2550
+ assert.equal(initialCodexFastMode.body?.data?.statusKnown, false, "server must not infer Fast mode before the extension publishes status");
2551
+
2552
+ const invalidCodexFastMode = await request("127.0.0.1", "/api/codex-fast-mode", {
2553
+ method: "PUT",
2554
+ body: { enabled: "yes", tab: tabId },
2555
+ });
2556
+ assert.equal(invalidCodexFastMode.status, 400, "Codex Fast mode should require an explicit boolean");
2557
+
2558
+ const codexFastModeOn = await request("127.0.0.1", "/api/codex-fast-mode", {
2559
+ method: "PUT",
2560
+ body: { enabled: true, tab: tabId },
2561
+ });
2562
+ assert.equal(codexFastModeOn.status, 200, `Codex Fast mode on should succeed: ${codexFastModeOn.body?.error || ""}`);
2563
+ assert.equal(codexFastModeOn.body?.data?.statusKnown, true);
2564
+ assert.equal(codexFastModeOn.body?.data?.enabled, true, "PUT should return only extension-confirmed on state");
2565
+
2566
+ const rejectNextCodexFastMode = await request("127.0.0.1", "/api/prompt", {
2567
+ method: "POST",
2568
+ body: { message: "fixture reject next codex fast mode mutation", tab: tabId },
2569
+ });
2570
+ assert.equal(rejectNextCodexFastMode.status, 200);
2571
+ const rejectedCodexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
2572
+ method: "PUT",
2573
+ body: { enabled: false, tab: tabId },
2574
+ timeoutMs: 5_000,
2575
+ });
2576
+ assert.equal(rejectedCodexFastModeOff.status, 409, "RPC success without matching extension status should fail closed");
2577
+ assert.match(String(rejectedCodexFastModeOff.body?.error || ""), /did not confirm off/i);
2578
+ const codexFastModeStillOn = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
2579
+ assert.equal(codexFastModeStillOn.body?.data?.enabled, true, "a rejected mutation must not become optimistic off state");
2580
+
2581
+ const busyFixturePrompt = await request("127.0.0.1", "/api/prompt", {
2582
+ method: "POST",
2583
+ body: { message: "voice test slow", tab: tabId },
2584
+ });
2585
+ assert.equal(busyFixturePrompt.status, 200);
2586
+ await delay(80);
2587
+ const busyCodexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
2588
+ method: "PUT",
2589
+ body: { enabled: false, tab: tabId },
2590
+ });
2591
+ assert.equal(busyCodexFastModeOff.status, 409, "Codex Fast mode changes should be rejected during a running turn");
2592
+ assert.match(String(busyCodexFastModeOff.body?.error || ""), /busy|running turn/i);
2593
+ let settledCodexFastMode;
2594
+ for (let attempt = 0; attempt < 40; attempt += 1) {
2595
+ settledCodexFastMode = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
2596
+ if (settledCodexFastMode.body?.data?.busy === false) break;
2597
+ await delay(150);
2598
+ }
2599
+ assert.equal(settledCodexFastMode?.body?.data?.busy, false, "fake running turn should settle before the retry");
2600
+
2601
+ const codexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
2602
+ method: "PUT",
2603
+ body: { enabled: false, tab: tabId },
2604
+ });
2605
+ assert.equal(codexFastModeOff.status, 200, `Codex Fast mode off should succeed after the tab settles: ${codexFastModeOff.body?.error || ""}`);
2606
+ assert.equal(codexFastModeOff.body?.data?.enabled, false);
2607
+ assert.equal(codexFastModeOff.body?.data?.statusKnown, true, "off response should be extension-confirmed");
2608
+
2189
2609
  // Natural Conversation shell: /talk availability drives per-tab status and safety guards.
2190
2610
  const conversationFeature = await request("127.0.0.1", `/api/features/natural-conversation?tab=${encodeURIComponent(tabId)}`);
2191
2611
  assert.equal(conversationFeature.status, 200);