@firstpick/pi-package-webui 0.11.1 → 0.11.2

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 (309) hide show
  1. package/DEVELOPMENT.md +151 -12
  2. package/README.md +34 -6
  3. package/TECHNICAL.md +75 -8
  4. package/bin/pi-webui.mjs +5390 -11423
  5. package/index.ts +10 -3
  6. package/lib/component-update-state.mjs +2 -2
  7. package/lib/git-workflow-preference-values.mjs +122 -0
  8. package/lib/git-workflow-preferences.mjs +35 -563
  9. package/lib/package-updates.mjs +260 -0
  10. package/lib/rpc-supervisor-client.mjs +8 -4
  11. package/lib/server/app-runners.mjs +1667 -0
  12. package/lib/server/codex-fast-mode.mjs +161 -0
  13. package/lib/server/conversation-mode.mjs +218 -0
  14. package/lib/server/conversation-voice.mjs +318 -0
  15. package/lib/server/extension-ui-requests.mjs +114 -0
  16. package/lib/server/git-generation.mjs +459 -0
  17. package/lib/server/git-mutations.mjs +1827 -0
  18. package/lib/server/git-reads.mjs +608 -0
  19. package/lib/server/git-worktree-sessions.mjs +408 -0
  20. package/lib/server/helper-requests.mjs +82 -0
  21. package/lib/server/no-project-workspaces.mjs +103 -0
  22. package/lib/server/rpc-transports.mjs +394 -0
  23. package/lib/server/settings-store.mjs +544 -0
  24. package/lib/server/sse-delivery.mjs +138 -0
  25. package/lib/server/workspace-files.mjs +563 -0
  26. package/lib/update/supervisor.mjs +4 -0
  27. package/lib/webui-workspaces.mjs +2 -0
  28. package/package.json +4 -4
  29. package/public/activity-agents-controller.mjs +269 -0
  30. package/public/activity-events-controller.mjs +236 -0
  31. package/public/activity-intercom-controller.mjs +627 -0
  32. package/public/activity-queue-controller.mjs +534 -0
  33. package/public/activity-todo-view.mjs +89 -0
  34. package/public/activity-usage-controller.mjs +589 -0
  35. package/public/app.js +3761 -3886
  36. package/public/conversation-overview.css +84 -0
  37. package/public/conversation-overview.mjs +193 -0
  38. package/public/draft-conversations.mjs +135 -0
  39. package/public/focused-composer-controls.css +111 -0
  40. package/public/focused-composer-controls.mjs +143 -0
  41. package/public/focused-composer-disclosure.mjs +223 -0
  42. package/public/focused-shell-adapter.css +264 -0
  43. package/public/focused-shell-adapter.mjs +257 -0
  44. package/public/index.html +137 -80
  45. package/public/model-catalog-order.mjs +63 -0
  46. package/public/platform-event-stream.mjs +64 -0
  47. package/public/project-artifact-controller.mjs +218 -0
  48. package/public/project-file-viewer-controller.mjs +383 -0
  49. package/public/project-git-tools-controller.mjs +181 -0
  50. package/public/project-runners-controller.mjs +220 -0
  51. package/public/service-worker.js +52 -1
  52. package/public/session-attention-scheduler.mjs +182 -0
  53. package/public/session-composer-store.mjs +56 -0
  54. package/public/session-context.mjs +51 -0
  55. package/public/session-extension-requests.mjs +63 -0
  56. package/public/session-shelf-state.mjs +151 -0
  57. package/public/session-shelves.css +171 -0
  58. package/public/session-shelves.mjs +95 -0
  59. package/public/settings-navigation-controller.mjs +249 -0
  60. package/public/settings-navigation.css +61 -0
  61. package/public/settings-resource-controller.mjs +232 -0
  62. package/public/settings-workspace.css +19 -0
  63. package/public/settings-workspace.mjs +175 -0
  64. package/public/shell-actions.mjs +87 -0
  65. package/public/shell-attention-inbox.css +72 -0
  66. package/public/shell-attention-inbox.mjs +198 -0
  67. package/public/shell-context-actions.css +61 -0
  68. package/public/shell-context-actions.mjs +168 -0
  69. package/public/shell-inspector-resize.mjs +124 -0
  70. package/public/shell-navigation-resize.mjs +107 -0
  71. package/public/shell-navigation.mjs +127 -0
  72. package/public/shell-preferences.mjs +108 -0
  73. package/public/shell-surfaces.mjs +99 -0
  74. package/public/shell-tools-launcher.css +97 -0
  75. package/public/shell-tools-launcher.mjs +222 -0
  76. package/public/shell-view-host.mjs +115 -0
  77. package/public/shell-workspace.css +266 -0
  78. package/public/shell-workspace.mjs +402 -0
  79. package/public/sidebar-update-menu.css +190 -0
  80. package/public/sidebar-update-menu.mjs +512 -0
  81. package/public/styles.css +320 -169
  82. package/public/subagent-launch-slot-state.mjs +2 -2
  83. package/public/themed-selects.css +156 -0
  84. package/public/workspace-choices.mjs +104 -0
  85. package/tests/activity-agents-controller.test.mjs +652 -0
  86. package/tests/activity-events-controller.test.mjs +511 -0
  87. package/tests/app-runner-terminal-static.test.mjs +3 -3
  88. package/tests/append-system-http.test.mjs +7 -6
  89. package/tests/append-system-selector-static.test.mjs +6 -6
  90. package/tests/aur-review-widget-static.test.mjs +11 -3
  91. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  92. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  93. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  94. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  95. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  96. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  97. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  98. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  99. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  100. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  101. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  102. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  103. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  104. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  105. package/tests/browser/control-visibility.spec.mjs +5 -0
  106. package/tests/browser/controls-layout.spec.mjs +21 -2
  107. package/tests/browser/conversation-overview.spec.mjs +251 -0
  108. package/tests/browser/draft-conversations.spec.mjs +276 -0
  109. package/tests/browser/empty-startup-fixture.mjs +135 -0
  110. package/tests/browser/empty-startup.spec.mjs +282 -0
  111. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  112. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  113. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  114. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  115. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  116. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  117. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  118. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  119. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  120. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  121. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  122. package/tests/browser/inspector-header.spec.mjs +221 -0
  123. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  124. package/tests/browser/inspector-resize.spec.mjs +227 -0
  125. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  126. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  127. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  128. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  129. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  130. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  131. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  132. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  133. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  134. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  135. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  136. package/tests/browser/more-row-menus.spec.mjs +258 -0
  137. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  138. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  139. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  140. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  141. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  142. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  143. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  144. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  145. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  146. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  147. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  148. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  149. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  150. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  151. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  152. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  153. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  154. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  155. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  156. package/tests/browser/session-fixture.mjs +118 -0
  157. package/tests/browser/session-ownership.spec.mjs +175 -0
  158. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  159. package/tests/browser/session-shelves.spec.mjs +340 -0
  160. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  161. package/tests/browser/session-summary.spec.mjs +17 -12
  162. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  163. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  164. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  165. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  166. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  167. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  168. package/tests/browser/shell-ownership.spec.mjs +398 -0
  169. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  170. package/tests/browser/shell-rollout.spec.mjs +357 -0
  171. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  172. package/tests/browser/shell-workspace.spec.mjs +433 -0
  173. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  174. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  175. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  176. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  177. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  178. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  179. package/tests/browser/themed-selects.spec.mjs +297 -0
  180. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  181. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  182. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  183. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  184. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  185. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  186. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  187. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  188. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  189. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  190. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  191. package/tests/codex-fast-mode-static.test.mjs +16 -11
  192. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  193. package/tests/codex-usage-source.test.mjs +4 -3
  194. package/tests/component-update-api-static.test.mjs +2 -2
  195. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  196. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  197. package/tests/control-visibility-static.test.mjs +3 -3
  198. package/tests/controls-layout-static.test.mjs +5 -5
  199. package/tests/conversation-overview-adapter.test.mjs +100 -0
  200. package/tests/document-artifact-static.test.mjs +2 -1
  201. package/tests/draft-conversations.test.mjs +205 -0
  202. package/tests/empty-startup-launcher.test.mjs +197 -0
  203. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  204. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  205. package/tests/fast-mode-client-static.test.mjs +1 -1
  206. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  207. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  208. package/tests/file-viewer-image-static.test.mjs +15 -11
  209. package/tests/file-viewer-search-static.test.mjs +5 -5
  210. package/tests/fixtures/fake-pi.mjs +41 -9
  211. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  212. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  213. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  214. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  215. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  216. package/tests/git-workflow-dispatch.test.mjs +66 -0
  217. package/tests/git-workflow-preferences.test.mjs +9 -1
  218. package/tests/guided-git-activation-static.test.mjs +14 -11
  219. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  220. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  221. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  222. package/tests/http-endpoints-harness.test.mjs +21 -9
  223. package/tests/interaction-state-stability-static.test.mjs +4 -3
  224. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  225. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  226. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  227. package/tests/main-output-loading-static.test.mjs +4 -4
  228. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  229. package/tests/mobile-compact-layout.test.mjs +2 -2
  230. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  231. package/tests/mobile-foundation-static.test.mjs +10 -7
  232. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  233. package/tests/mobile-static.test.mjs +173 -135
  234. package/tests/model-catalog-order.test.mjs +103 -0
  235. package/tests/native-parity.test.mjs +6 -4
  236. package/tests/native-session-choice-owner.test.mjs +102 -0
  237. package/tests/native-update-lifecycle.test.mjs +10 -5
  238. package/tests/no-project-http-harness.test.mjs +328 -0
  239. package/tests/no-project-navigation.test.mjs +54 -0
  240. package/tests/no-project-workspaces.test.mjs +77 -0
  241. package/tests/open-issue-wizard-static.test.mjs +1 -1
  242. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  243. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  244. package/tests/package-updates.test.mjs +630 -0
  245. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  246. package/tests/platform-event-stream.test.mjs +253 -0
  247. package/tests/project-file-viewer-controller.test.mjs +652 -0
  248. package/tests/project-git-tools-adapter.test.mjs +103 -0
  249. package/tests/project-git-tools-controller.test.mjs +577 -0
  250. package/tests/project-runners-controller.test.mjs +453 -0
  251. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  252. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  253. package/tests/questionnaire-dialog.test.mjs +6 -6
  254. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  255. package/tests/rpc-supervisor-host.test.mjs +4 -1
  256. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  257. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  258. package/tests/server-app-runners.test.mjs +536 -0
  259. package/tests/server-codex-fast-mode.test.mjs +346 -0
  260. package/tests/server-conversation-mode.test.mjs +386 -0
  261. package/tests/server-conversation-voice.test.mjs +426 -0
  262. package/tests/server-extension-ui-requests.test.mjs +357 -0
  263. package/tests/server-git-generation.test.mjs +558 -0
  264. package/tests/server-git-mutations.test.mjs +729 -0
  265. package/tests/server-git-reads.test.mjs +381 -0
  266. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  267. package/tests/server-helper-requests.test.mjs +364 -0
  268. package/tests/server-rpc-transports.test.mjs +553 -0
  269. package/tests/server-settings-store.test.mjs +132 -0
  270. package/tests/server-shell-rollout.test.mjs +478 -0
  271. package/tests/server-sse-delivery.test.mjs +410 -0
  272. package/tests/server-workspace-files.test.mjs +546 -0
  273. package/tests/session-attention-scheduler.test.mjs +514 -0
  274. package/tests/session-composer-store.test.mjs +153 -0
  275. package/tests/session-context.test.mjs +134 -0
  276. package/tests/session-extension-requests.test.mjs +193 -0
  277. package/tests/session-ownership-adapter.test.mjs +130 -0
  278. package/tests/session-sampling-ui-static.test.mjs +10 -4
  279. package/tests/session-send-lifetime.test.mjs +140 -0
  280. package/tests/session-shelf-state.test.mjs +348 -0
  281. package/tests/session-shelves-adapter.test.mjs +79 -0
  282. package/tests/session-summary-lifetime.test.mjs +54 -0
  283. package/tests/settings-resource-controller.test.mjs +548 -0
  284. package/tests/shell-action-adapter.test.mjs +169 -0
  285. package/tests/shell-actions.test.mjs +182 -0
  286. package/tests/shell-navigation.test.mjs +348 -0
  287. package/tests/shell-preferences.test.mjs +367 -0
  288. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  289. package/tests/stream-output-isolation-static.test.mjs +1 -1
  290. package/tests/subagent-gate-visibility.test.mjs +1 -1
  291. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  292. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  293. package/tests/subagent-observability-static.test.mjs +2 -2
  294. package/tests/subagent-reliability-integration.test.mjs +13 -30
  295. package/tests/syntax-highlighting-static.test.mjs +3 -3
  296. package/tests/tab-close-continuity-static.test.mjs +1 -1
  297. package/tests/tab-metadata-ordering.test.mjs +99 -0
  298. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  299. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  300. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  301. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  302. package/tests/theme-customizer-static.test.mjs +1 -1
  303. package/tests/thread-display-title.test.mjs +44 -0
  304. package/tests/update-api-harness.test.mjs +15 -14
  305. package/tests/update-tab-restore-harness.test.mjs +3 -0
  306. package/tests/webui-settings-locking.test.mjs +2 -2
  307. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  308. package/tests/workspace-choices.test.mjs +114 -0
  309. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,348 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { createShellHistory } from "../public/shell-navigation.mjs";
4
+ import { mobileNavigationTargetFromSearch } from "../public/mobile-shell-state.mjs";
5
+
6
+ function navigation(overrides = {}) {
7
+ return {
8
+ piMobileShellV2: true,
9
+ mobileShellState: { route: "chat", surface: "none", surfacePage: "root", routeHistory: [], ...overrides },
10
+ };
11
+ }
12
+
13
+ function fakeWindow({ state = { otherFeature: { selected: 3 } }, href = "https://pi.example/?embed=split&tab=tab_12345678&mobileShell=v2#chat" } = {}) {
14
+ const listeners = new Map();
15
+ const calls = [];
16
+ const entries = [{ state: structuredClone(state), href }];
17
+ let index = 0;
18
+ const window = {
19
+ location: { href },
20
+ addEventListener(type, listener) {
21
+ if (!listeners.has(type)) listeners.set(type, new Set());
22
+ listeners.get(type).add(listener);
23
+ },
24
+ removeEventListener(type, listener) {
25
+ calls.push({ method: "removeEventListener", type, listener });
26
+ listeners.get(type)?.delete(listener);
27
+ },
28
+ dispatch(type, event) {
29
+ for (const listener of listeners.get(type) || []) listener(event);
30
+ },
31
+ };
32
+ function write(method, args) {
33
+ const [nextState, , url] = args;
34
+ const entry = { state: structuredClone(nextState), href: url === undefined ? window.location.href : new URL(url, window.location.href).href };
35
+ calls.push({ method, args });
36
+ if (method === "pushState") {
37
+ entries.splice(index + 1);
38
+ entries.push(entry);
39
+ index++;
40
+ } else entries[index] = entry;
41
+ window.location.href = entry.href;
42
+ }
43
+ window.history = {
44
+ get state() { return entries[index].state; },
45
+ pushState(...args) { write("pushState", args); },
46
+ replaceState(...args) { write("replaceState", args); },
47
+ back() {
48
+ calls.push({ method: "back" });
49
+ if (index === 0) return;
50
+ index--;
51
+ window.location.href = entries[index].href;
52
+ window.dispatch("popstate", { type: "popstate", state: window.history.state });
53
+ },
54
+ };
55
+ return { window, listeners, calls, entries };
56
+ }
57
+
58
+ test("construction owns one popstate listener and leaves history and URL untouched", () => {
59
+ const { window, listeners, calls, entries } = fakeWindow();
60
+ const history = createShellHistory({ window, onPopState() {} });
61
+ assert.deepEqual([...listeners.keys()], ["popstate"]);
62
+ assert.equal(listeners.get("popstate").size, 1);
63
+ assert.equal(calls.length, 0);
64
+ assert.equal(entries.length, 1);
65
+ assert.deepEqual(window.history.state, { otherFeature: { selected: 3 } });
66
+ history.dispose();
67
+ });
68
+
69
+ test("push and explicit replace merge current unrelated fields and preserve omitted URL", () => {
70
+ const { window, calls, entries } = fakeWindow();
71
+ const history = createShellHistory({ window, onPopState() {} });
72
+ const originalUrl = window.location.href;
73
+ const state = navigation({ route: "sessions", routeHistory: ["chat"] });
74
+ history.write({ state });
75
+ state.mobileShellState.routeHistory.push("project");
76
+ assert.equal(entries.length, 2);
77
+ assert.deepEqual(window.history.state, {
78
+ otherFeature: { selected: 3 }, ...navigation({ route: "sessions", routeHistory: ["chat"] }),
79
+ });
80
+ assert.equal(calls[0].method, "pushState");
81
+ assert.equal(calls[0].args.length, 2, "omitted URL is omitted from the native call");
82
+ assert.equal(window.location.href, originalUrl);
83
+ window.history.state.laterFeature = "retained";
84
+ history.write({ state: { mobileShellState: navigation({ surface: "more", surfacePage: "settings" }).mobileShellState }, replace: true });
85
+ assert.equal(entries.length, 2);
86
+ assert.equal(calls[1].method, "replaceState");
87
+ assert.equal(window.history.state.piMobileShellV2, true);
88
+ assert.equal(window.history.state.laterFeature, "retained");
89
+ assert.equal(window.history.state.mobileShellState.surfacePage, "settings");
90
+ history.dispose();
91
+ });
92
+
93
+ test("back delegates once and forwards the actual event for caller restoration", () => {
94
+ const { window, calls } = fakeWindow();
95
+ const received = [];
96
+ const history = createShellHistory({ window, onPopState: (event) => received.push(event) });
97
+ history.write({ state: navigation(), replace: true });
98
+ history.write({ state: navigation({ route: "activity", routeHistory: ["chat"] }) });
99
+ history.back();
100
+ assert.equal(calls.filter((call) => call.method === "back").length, 1);
101
+ assert.equal(received.length, 1);
102
+ assert.equal(received[0].state.mobileShellState.route, "chat");
103
+ const event = { state: { legacyOrInvalid: true }, marker: Symbol("original event") };
104
+ window.dispatch("popstate", event);
105
+ assert.equal(received[1], event, "the adapter does not normalize or filter incoming events");
106
+ assert.equal(calls.filter((call) => call.method === "pushState").length, 1);
107
+ history.dispose();
108
+ });
109
+
110
+ test("dispose removes only its own listener, is repeatable, and forbids later history calls", () => {
111
+ const { window, calls, listeners } = fakeWindow();
112
+ let otherCalls = 0;
113
+ let ownCalls = 0;
114
+ const unrelated = () => otherCalls++;
115
+ window.addEventListener("popstate", unrelated);
116
+ for (let cycle = 0; cycle < 3; cycle++) {
117
+ const history = createShellHistory({ window, onPopState: () => ownCalls++ });
118
+ assert.equal(listeners.get("popstate").size, 2);
119
+ const ownedListener = [...listeners.get("popstate")].find((listener) => listener !== unrelated);
120
+ window.dispatch("popstate", {});
121
+ history.dispose();
122
+ history.dispose();
123
+ ownedListener({});
124
+ assert.equal(listeners.get("popstate").size, 1);
125
+ assert.throws(() => history.write({ state: navigation() }), /disposed/);
126
+ assert.throws(() => history.back(), /disposed/);
127
+ }
128
+ window.dispatch("popstate", {});
129
+ assert.equal(ownCalls, 3);
130
+ assert.equal(otherCalls, 4);
131
+ assert.equal(calls.filter((call) => call.method === "removeEventListener").length, 3);
132
+ assert.equal(calls.some((call) => ["pushState", "replaceState", "back"].includes(call.method)), false);
133
+ });
134
+
135
+ test("explicit same-origin URLs preserve existing deep-link and rollout query semantics", () => {
136
+ const { window } = fakeWindow();
137
+ const history = createShellHistory({ window, onPopState() {} });
138
+ const search = "?mobileRoute=activity&tab=tab_12345678&run=run_12345678&blocker=blocker_12345678&embed=split&mobileShell=legacy&tabletShell=v2&shell=classic&custom=a%20b";
139
+ history.write({ state: navigation(), url: `/${search}#details` });
140
+ assert.equal(window.location.href, `https://pi.example/${search}#details`);
141
+ assert.deepEqual(mobileNavigationTargetFromSearch(new URL(window.location.href).search), {
142
+ v: 1, route: "activity", tabId: "tab_12345678", runId: "run_12345678", blockerId: "blocker_12345678",
143
+ });
144
+ history.write({ state: navigation(), replace: true, url: new URL("https://pi.example/?embed=split&tab=tab_87654321") });
145
+ assert.equal(new URL(window.location.href).searchParams.get("tab"), "tab_87654321");
146
+ history.dispose();
147
+ });
148
+
149
+ test("foreign URLs and malformed navigation identifiers fail before a history write", () => {
150
+ const { window, calls } = fakeWindow();
151
+ const history = createShellHistory({ window, onPopState() {} });
152
+ for (const url of [
153
+ "https://elsewhere.example/", "//elsewhere.example/", "http://pi.example/", "javascript:alert(1)",
154
+ "data:text/html,hello", "https://pi.example:444/", "/?tab=private%20title", "/?run=short", "/?blocker=",
155
+ "/?tab=tab_12345678&tab=bad", "/?mobileRoute=unknown", "/?mobileRoute=chat&mobileRoute=unknown", null, {},
156
+ ]) assert.throws(() => history.write({ state: navigation(), url }), TypeError, String(url));
157
+ assert.equal(calls.length, 0);
158
+ history.dispose();
159
+ });
160
+
161
+ test("only serializable navigation fields are accepted, without silently fixing invalid state", () => {
162
+ const { window, calls } = fakeWindow();
163
+ const history = createShellHistory({ window, onPopState() {} });
164
+ const sparseRoutes = Array(1);
165
+ const invalidStates = [
166
+ undefined, null, [], "chat", { draft: "private prompt" }, { piMobileShellV2: false },
167
+ { ...navigation(), [Symbol("extra")]: true },
168
+ ...[
169
+ { route: "settings" }, { surface: "unknown" }, { surfacePage: "" }, { surfacePage: {} },
170
+ { routeHistory: "chat" }, { routeHistory: ["invalid"] }, { routeHistory: sparseRoutes },
171
+ { routeHistory: Array(17).fill("chat") }, { draft: "private prompt" },
172
+ ].map((overrides) => navigation(overrides)),
173
+ { mobileShellState: { route: "chat" } },
174
+ ];
175
+ for (const state of invalidStates) assert.throws(() => history.write({ state }), TypeError);
176
+ assert.throws(() => history.write({ state: navigation(), replace: "yes" }), TypeError);
177
+ assert.equal(calls.length, 0);
178
+ history.dispose();
179
+ });
180
+
181
+ test("all existing route/surface values and the reducer's sixteen-route bound remain usable", () => {
182
+ const { window } = fakeWindow({ state: null });
183
+ const history = createShellHistory({ window, onPopState() {} });
184
+ for (const route of ["chat", "sessions", "activity", "project"]) {
185
+ for (const surface of ["none", "more", "actionSheet", "file", "dialog"]) {
186
+ const state = navigation({ route, surface, routeHistory: Array(16).fill("chat") });
187
+ history.write({ state });
188
+ assert.deepEqual(window.history.state, state);
189
+ }
190
+ }
191
+ history.dispose();
192
+ });
193
+
194
+ test("native history failures propagate without synthetic callbacks or retries", () => {
195
+ const { window } = fakeWindow();
196
+ const failure = new Error("browser denied history write");
197
+ let attempts = 0;
198
+ window.history.pushState = () => { attempts++; throw failure; };
199
+ const history = createShellHistory({ window, onPopState() { assert.fail("unexpected synthetic event"); } });
200
+ assert.throws(() => history.write({ state: navigation() }), (error) => error === failure);
201
+ assert.equal(attempts, 1);
202
+ history.dispose();
203
+ });
204
+
205
+ test("invalid construction fails before installing a listener", () => {
206
+ const { window, listeners } = fakeWindow();
207
+ assert.throws(() => createShellHistory(), TypeError);
208
+ assert.throws(() => createShellHistory({ window }), TypeError);
209
+ assert.equal(listeners.size, 0);
210
+ });
211
+
212
+ test("focused patches merge with mobile and third-party state without retaining caller objects", () => {
213
+ const { window, listeners, entries } = fakeWindow();
214
+ const history = createShellHistory({ window, onPopState() {} });
215
+ history.write({ state: navigation(), replace: true });
216
+ for (const destination of ["conversation", "home", "project", "activity", "settings"]) {
217
+ for (const inspector of [null, "a", "Project:files_1-2", `z${"_".repeat(119)}`]) {
218
+ const focusedShellState = { destination, inspector };
219
+ history.write({ state: { focusedShellState } });
220
+ focusedShellState.destination = "home";
221
+ assert.deepEqual(window.history.state, {
222
+ otherFeature: { selected: 3 }, ...navigation(), focusedShellState: { destination, inspector },
223
+ });
224
+ }
225
+ }
226
+ const focused = { ...window.history.state.focusedShellState };
227
+ const entryCount = entries.length;
228
+ history.write({ state: navigation({ route: "sessions" }), replace: true });
229
+ assert.equal(entries.length, entryCount);
230
+ assert.deepEqual(window.history.state.focusedShellState, focused, "mobile writes retain focused state");
231
+ assert.equal(window.history.state.mobileShellState.route, "sessions");
232
+ assert.deepEqual([...listeners.keys()], ["popstate"]);
233
+ assert.equal(listeners.get("popstate").size, 1);
234
+ history.dispose();
235
+ });
236
+
237
+ test("focused history back forwards the original saved state and URL, then disposal is terminal", () => {
238
+ const { window, listeners, calls } = fakeWindow();
239
+ const received = [];
240
+ const history = createShellHistory({ window, onPopState: (event) => received.push(event) });
241
+ const focusedShellState = { destination: "conversation", inspector: null };
242
+ history.write({ state: { ...navigation(), focusedShellState }, replace: true });
243
+ const originalUrl = window.location.href;
244
+ history.write({ state: { focusedShellState: { destination: "project", inspector: "files" } },
245
+ url: "/?view=project&inspector=files&tab=tab_12345678" });
246
+ history.back();
247
+ assert.equal(received.length, 1);
248
+ assert.equal(received[0].state, window.history.state);
249
+ assert.deepEqual(received[0].state, { otherFeature: { selected: 3 }, ...navigation(), focusedShellState });
250
+ assert.equal(window.location.href, originalUrl);
251
+ assert.equal(calls.filter((call) => call.method === "back").length, 1);
252
+ const listener = [...listeners.get("popstate")][0];
253
+ history.dispose();
254
+ history.dispose();
255
+ listener({ state: { focusedShellState } });
256
+ assert.equal(received.length, 1, "already queued callback is suppressed after disposal");
257
+ assert.equal(listeners.get("popstate").size, 0);
258
+ assert.throws(() => history.write({ state: { focusedShellState } }), /disposed/);
259
+ assert.throws(() => history.back(), /disposed/);
260
+ });
261
+
262
+ test("focused deep links preserve mobile identifiers, rollout flags, unknown queries and fragments", () => {
263
+ const { window } = fakeWindow();
264
+ const history = createShellHistory({ window, onPopState() {} });
265
+ const identity = "tab=tab_12345678&run=run_12345678&blocker=blocker_12345678";
266
+ for (const destination of ["conversation", "home", "project", "activity", "settings"]) {
267
+ const search = `?view=${destination}&inspector=Project%3Afiles_1-2&mobileRoute=activity&${identity}&embed=split&mobileShell=legacy&tabletShell=v2&shell=classic&custom=a%20b&custom=c`;
268
+ history.write({ state: { focusedShellState: { destination, inspector: "Project:files_1-2" } },
269
+ url: `${search}#details` });
270
+ assert.equal(window.location.href, `https://pi.example/${search}#details`);
271
+ assert.deepEqual(mobileNavigationTargetFromSearch(new URL(window.location.href).search), {
272
+ v: 1, route: "activity", tabId: "tab_12345678", runId: "run_12345678", blockerId: "blocker_12345678",
273
+ });
274
+ history.write({ state: {}, url: new URL(window.location.href), replace: true });
275
+ assert.equal(window.location.href, `https://pi.example/${search}#details`);
276
+ }
277
+ history.dispose();
278
+ });
279
+
280
+ test("malformed focused state and queries fail atomically before push or replace", () => {
281
+ const { window, calls, entries } = fakeWindow();
282
+ const history = createShellHistory({ window, onPopState() {} });
283
+ const focused = { destination: "project", inspector: "files" };
284
+ const invalidFocused = [
285
+ undefined, null, [], "project", {}, { destination: "project" }, { inspector: null },
286
+ { ...focused, destination: "chat" }, { ...focused, destination: "sessions" },
287
+ { ...focused, destination: "Settings" }, { ...focused, destination: null },
288
+ { ...focused, inspector: undefined }, { ...focused, inspector: "" },
289
+ { ...focused, inspector: 1 }, { ...focused, inspector: {} },
290
+ { ...focused, inspector: "a\n" }, { ...focused, inspector: "private title" },
291
+ { ...focused, inspector: `a${"b".repeat(120)}` },
292
+ { ...focused, extra: true }, { ...focused, [Symbol("extra")]: true },
293
+ Object.assign(Object.create({ destination: "project" }), { inspector: null }),
294
+ ];
295
+ const invalidUrls = [
296
+ "/?view=", "/?view=chat", "/?view=sessions", "/?view=Project", "/?view=project&view=invalid",
297
+ "/?inspector=", "/?inspector=1files", "/?inspector=private%20title", "/?inspector=files%0A",
298
+ "/?inspector=%C3%A9", "/?inspector=files&inspector=bad.value", `/?inspector=a${"b".repeat(120)}`,
299
+ "/?view=project&inspector=files&tab=bad", "/?view=project&mobileRoute=unknown",
300
+ ];
301
+ for (const replace of [false, true]) {
302
+ for (const focusedShellState of invalidFocused) {
303
+ assert.throws(() => history.write({ state: { ...navigation(), focusedShellState }, replace }), TypeError);
304
+ }
305
+ for (const url of invalidUrls) {
306
+ assert.throws(() => history.write({ state: { focusedShellState: focused }, replace, url }), TypeError, url);
307
+ }
308
+ assert.throws(() => history.write({ state: { focusedShellState: focused, session: "private" }, replace }), TypeError);
309
+ }
310
+ assert.deepEqual(calls, []);
311
+ assert.equal(entries.length, 1);
312
+ assert.deepEqual(window.history.state, { otherFeature: { selected: 3 } });
313
+ assert.equal(window.location.href, entries[0].href);
314
+ history.dispose();
315
+ });
316
+
317
+
318
+ test("Settings anchors share the existing writer and restore with unrelated history and URL fields", () => {
319
+ const { window } = fakeWindow();
320
+ const received = [];
321
+ const history = createShellHistory({ window, onPopState: event => received.push(event.state) });
322
+ const initial = { destination: "settings", inspector: "settings:appearance", setting: "theme" };
323
+ const url = new URL(window.location.href);
324
+ url.searchParams.set("view", "settings");
325
+ url.searchParams.set("inspector", initial.inspector);
326
+ url.searchParams.set("setting", initial.setting);
327
+ history.write({ state: { focusedShellState: initial }, replace: true, url });
328
+ history.write({ state: { focusedShellState: { destination: "settings", inspector: "settings:resources", setting: "tools" } } });
329
+ history.back();
330
+ assert.deepEqual(received[0].focusedShellState, initial);
331
+ assert.deepEqual(received[0].otherFeature, { selected: 3 });
332
+ assert.equal(new URL(window.location.href).searchParams.get("embed"), "split");
333
+ assert.equal(new URL(window.location.href).searchParams.get("setting"), "theme");
334
+ assert.equal(new URL(window.location.href).hash, "#chat");
335
+ });
336
+
337
+ test("Settings anchors reject malformed identifiers and non-Settings state before writing", () => {
338
+ const { window, calls } = fakeWindow();
339
+ const history = createShellHistory({ window, onPopState() {} });
340
+ for (const setting of ["", " bad", "a/b", "a".repeat(121), 1, {}, undefined]) {
341
+ assert.throws(() => history.write({ state: { focusedShellState: { destination: "settings", inspector: "settings:appearance", setting } } }), TypeError);
342
+ }
343
+ assert.throws(() => history.write({ state: { focusedShellState: { destination: "conversation", inspector: null, setting: "theme" } } }), TypeError);
344
+ assert.throws(() => history.write({ state: { focusedShellState: { destination: "settings", inspector: null } }, url: "?view=settings&setting=theme&setting=a%2Fb" }), TypeError);
345
+ assert.equal(calls.length, 0);
346
+ history.write({ state: { focusedShellState: { destination: "settings", inspector: "settings:appearance", setting: null } } });
347
+ assert.equal(calls.length, 1);
348
+ });