Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

rightPanelStore.test.ts

1,208 lines45.0 KB

1import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { type EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3import { beforeEach, describe, expect, it } from "vite-plus/test";
4​
5import { useClosedViewStore } from "./closedViewStore";
6import { reopenClosedView } from "./reopenClosedView";
7import {
8 migratePersistedRightPanelState,
9 pullRequestSurface,
10 pullRequestSurfaceId,
11 selectActiveRightPanel,
12 selectActiveRightPanelSurface,
13 selectThreadPanelVisibility,
14 selectThreadRightPanelState,
15 useRightPanelStore,
16} from "./rightPanelStore";
17​
18const refA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
19const refB = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-B"));
20​
21beforeEach(() => {
22 useClosedViewStore.setState({ entries: [] });
23 useRightPanelStore.setState({
24 byThreadKey: {},
25 threadPanelVisibilityByThreadKey: {},
26 userActionRevisionByThreadKey: {},
27 closeRevisionByThreadKey: {},
28 });
29});
30​
31async function reloadRightPanelStore() {
32 const { storage, name } = useRightPanelStore.persist.getOptions();
33 const persisted = await storage!.getItem(name!);
34 expect(persisted).not.toBeNull();
35 useRightPanelStore.setState(useRightPanelStore.getInitialState());
36 await storage!.setItem(name!, persisted!);
37 await useRightPanelStore.persist.rehydrate();
38 expect(useRightPanelStore.persist.hasHydrated()).toBe(true);
40​
41describe("rightPanelStore", () => {
42 it("records single and bulk tab closes, newest first", () => {
43 const store = useRightPanelStore.getState();
44 const pr = pullRequestSurface({
45 projectId: "project-a",
46 repository: "pingdotgg/t3code",
47 number: 42,
48 });
49 store.openFile(refA, "src/app.ts");
50 store.open(refA, "device");
51 store.openPullRequest(refA, pr);
52 store.open(refA, "diff");
53 store.closeSurface(refA, pr.id);
54 store.closeSurfacesToRight(refA, "device");
55 store.closeOtherSurfaces(refA, "file:src/app.ts");
56 expect(
57 useClosedViewStore
58 .getState()
59 .entries.map((entry) => (entry.kind === "panel-tab" ? entry.surface.id : null)),
60 ).toEqual(["device", "diff", pr.id]);
61 });
62​
63 it("reopens the active tab first after a bulk close", () => {
64 const store = useRightPanelStore.getState();
65 store.open(refA, "files");
66 store.open(refA, "diff");
67 store.open(refA, "device");
68 store.activateSurface(refA, "diff");
69 store.closeAllSurfaces(refA);
70​
71 expect(
72 useClosedViewStore
73 .getState()
74 .entries.map((entry) => entry.kind === "panel-tab" && entry.surface.id),
75 ).toEqual(["diff", "device", "files"]);
76 });
77​
78 it("does not save an incidental Files replacement when opening an existing file", () => {
79 const store = useRightPanelStore.getState();
80 store.openFile(refA, "src/app.ts");
81 store.open(refA, "files");
82 store.openFile(refA, "src/app.ts");
83​
84 expect(useClosedViewStore.getState().entries).toEqual([]);
85 });
86​
87 it("ignores session tabs without browser snapshots and records the empty browser tab", () => {
88 const store = useRightPanelStore.getState();
89 store.openBrowser(refA, "tab-1");
90 store.closeSurface(refA, "browser:tab-1");
91 expect(useClosedViewStore.getState().entries).toEqual([]);
92 store.openBrowser(refA, null);
93 store.closeSurface(refA, "browser:new");
94 expect(useClosedViewStore.getState().entries).toMatchObject([
95 { kind: "panel-tab", surface: { id: "browser:new", resourceId: null } },
96 ]);
97 });
98​
99 it("keeps a dismissed device hidden after another file opens", () => {
100 const store = useRightPanelStore.getState();
101 const device = {
102 hostId: "nucbox",
103 deviceId: "emulator-5580",
104 name: "Pixel",
105 platform: "android",
106 } as const;
107 store.openFile(refA, "src/app.ts");
108 store.closeSurface(refA, "file:src/app.ts");
109 store.openDevice(refA, device);
110 store.closeSurface(refA, "device:nucbox:emulator-5580");
111​
112 store.openFile(refA, "src/app.ts");
113 store.openDevice(refA, device, true);
114​
115 expect(
116 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
117 ).toEqual([expect.objectContaining({ id: "file:src/app.ts" })]);
118 });
119​
120 it("records only closed tabs when a panel is hidden or a terminal tab closes", () => {
121 const store = useRightPanelStore.getState();
122 store.open(refA, "diff");
123 store.openFile(refA, "src/app.ts");
124 store.closeSurface(refA, "file:src/app.ts");
125 store.close(refA);
126 expect(useClosedViewStore.getState().entries).toMatchObject([
127 { kind: "panel-tab", threadRef: refA, surface: { id: "file:src/app.ts" } },
128 ]);
129 store.toggleVisibility(refA);
130 store.toggle(refA, "diff");
131 store.openTerminal(refA, "term-1");
132 store.closeSurface(refA, "terminal:term-1");
133 expect(useClosedViewStore.getState().entries).toMatchObject([
134 { kind: "panel-tab", threadRef: refA, surface: { id: "file:src/app.ts" } },
135 ]);
136 expect(useClosedViewStore.getState().entries).toHaveLength(1);
137 });
138​
139 it("gives each host/device its own tab and preserves renamed tabs", () => {
140 const store = useRightPanelStore.getState();
141 const android = {
142 hostId: "nucbox",
143 deviceId: "emulator-5580",
144 name: "Pixel",
145 platform: "android",
146 } as const;
147 const ios = { hostId: "macmini", deviceId: "ios-1", name: "iPhone", platform: "ios" } as const;
148 store.open(refA, "device");
149 store.openDevice(refA, android);
150 store.open(refA, "device");
151 expect(
152 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
153 ).toHaveLength(2);
154 store.openDevice(refA, ios);
155 let state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
156 expect(state.surfaces.map((surface) => surface.id)).toEqual([
157 "device:nucbox:emulator-5580",
158 "device:macmini:ios-1",
159 ]);
160 store.renameDevice(refA, "device:nucbox:emulator-5580", "Android test");
161 store.openDevice(refA, android);
162 state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
163 expect(state.surfaces).toHaveLength(2);
164 expect(state.surfaces[0]).toMatchObject({ title: "Android test", target: android });
165 expect(state.activeSurfaceId).toBe("device:nucbox:emulator-5580");
166 store.closeSurface(refA, state.activeSurfaceId!);
167 expect(
168 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
169 ).toEqual([expect.objectContaining({ target: ios })]);
170 });
171​
172 it("does not collide when two hosts expose the same device id", () => {
173 const store = useRightPanelStore.getState();
174 const device = { deviceId: "emulator-5554", name: "Pixel", platform: "android" } as const;
175 store.openDevice(refA, { ...device, hostId: "a:b" });
176 store.openDevice(refA, { ...device, hostId: "a" });
177 expect(
178 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
179 ).toHaveLength(2);
180 expect(
181 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refB).surfaces,
182 ).toHaveLength(0);
183 });
184​
185 it.each(["one", "all", "others", "right"])(
186 "keeps device tabs dismissed across reload after closing %s",
187 (mode) => {
188 const store = useRightPanelStore.getState();
189 const target = {
190 hostId: "nucbox",
191 deviceId: "emulator-5580",
192 name: "Pixel",
193 platform: "android",
194 } as const;
195 store.open(refA, "files");
196 store.openDevice(refA, target);
197 if (mode === "one") store.closeSurface(refA, "device:nucbox:emulator-5580");
198 if (mode === "all") store.closeAllSurfaces(refA);
199 if (mode === "others") store.closeOtherSurfaces(refA, "files");
200 if (mode === "right") store.closeSurfacesToRight(refA, "files");
201 const persisted = JSON.parse(
202 JSON.stringify({ byThreadKey: useRightPanelStore.getState().byThreadKey }),
203 );
204 useRightPanelStore.setState(migratePersistedRightPanelState(persisted));
205 store.openDevice(refA, target, true);
206 expect(
207 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.some(
208 (surface) => surface.kind === "device",
209 ),
210 ).toBe(false);
211 store.openDevice(refA, target);
212 expect(
213 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.some(
214 (surface) => surface.kind === "device",
215 ),
216 ).toBe(true);
217 },
218 );
219​
220 const completedDiff = { kind: "diff", turnId: RunId.make("turn-1") } as const;
221 const linkedPullRequest = pullRequestSurface({
222 projectId: "project-a",
223 repository: "pingdotgg/t3code",
224 number: 42,
225 });
226​
227 it.each([
228 { order: "diff-first", surface: linkedPullRequest },
229 { order: "pull-request-first", surface: linkedPullRequest },
230 { order: "diff-first", surface: { id: "pull-requests", kind: "pull-requests" } as const },
231 {
232 order: "pull-request-first",
233 surface: { id: "pull-requests", kind: "pull-requests" } as const,
234 },
235 ])(
236 "prioritizes $surface.kind over browser and diff with $order delivery",
237 ({ order, surface }) => {
238 const store = useRightPanelStore.getState();
239 store.openBrowser(refA, "existing-browser");
240 const revision = store.getUserActionRevision(refA);
241 const requests = order === "diff-first" ? [completedDiff, surface] : [surface, completedDiff];
242 for (const surface of requests) store.openProactive(refA, surface, revision);
243 store.reconcileBrowserSurfaces(refA, ["existing-browser", "agent-browser"]);
244​
245 expect(
246 selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
247 ).toEqual(surface);
248​
249 store.open(refA, "diff");
250 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
251 },
252 );
253​
254 it.each([
255 { choice: "file", choose: () => useRightPanelStore.getState().openFile(refA, "src/app.ts") },
256 {
257 choice: "pull request",
258 choose: () =>
259 useRightPanelStore.getState().openPullRequest(refA, { ...linkedPullRequest, number: 41 }),
260 },
261 { choice: "browser", choose: () => useRightPanelStore.getState().openBrowser(refA, "tab-a") },
262 {
263 choice: "terminal",
264 choose: () => useRightPanelStore.getState().openTerminal(refA, "term-1"),
265 },
266 {
267 choice: "same tab",
268 choose: () => useRightPanelStore.getState().activateSurface(refA, "diff"),
269 },
270 { choice: "hide", choose: () => useRightPanelStore.getState().close(refA) },
271 { choice: "toggle", choose: () => useRightPanelStore.getState().toggle(refA, "diff") },
272 { choice: "close all", choose: () => useRightPanelStore.getState().closeAllSurfaces(refA) },
273 {
274 choice: "terminal close",
275 choose: () => {
276 const store = useRightPanelStore.getState();
277 store.openTerminal(refA, "term-1");
278 store.closeTerminal(refA, "terminal:term-1", "term-1");
279 },
280 },
281 ])("keeps a later $choice choice when automatic requests arrive", ({ choose }) => {
282 const store = useRightPanelStore.getState();
283 store.open(refA, "diff");
284 const revision = store.getUserActionRevision(refA);
285 choose();
286 const chosen = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
287​
288 expect(store.openProactive(refA, completedDiff, revision)).toBe(false);
289 expect(store.openProactive(refA, linkedPullRequest, revision)).toBe(false);
290 expect(
291 store.openProactive(refA, { id: "pull-requests", kind: "pull-requests" }, revision),
292 ).toBe(false);
293 const { isOpen, activeSurfaceId, surfaces } = selectThreadRightPanelState(
294 useRightPanelStore.getState().byThreadKey,
295 refA,
296 );
297 expect({ isOpen, activeSurfaceId, surfaces }).toEqual({
298 isOpen: chosen.isOpen,
299 activeSurfaceId: chosen.activeSurfaceId,
300 surfaces: chosen.surfaces,
301 });
302 });
303​
304 it.each([
305 {
306 surface: linkedPullRequest,
307 choose: () => useRightPanelStore.getState().openFile(refA, "notes.md"),
308 },
309 {
310 surface: { id: "pull-requests", kind: "pull-requests" } as const,
311 choose: () => useRightPanelStore.getState().openBrowser(refA, "tab-a"),
312 },
313 ])(
314 "preserves the selected tab and hidden panel when $surface.kind already exists",
315 ({ surface, choose }) => {
316 const store = useRightPanelStore.getState();
317 store.openProactive(refA, surface, store.getUserActionRevision(refA));
318 choose();
319 const chosen = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
320​
321 // Re-entry captures a fresh revision; the existing tab must still preserve the choice.
322 expect(store.openProactive(refA, surface, store.getUserActionRevision(refA))).toBe(false);
323 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
324 chosen,
325 );
326​
327 store.close(refA);
328 expect(store.openProactive(refA, surface, store.getUserActionRevision(refA))).toBe(false);
329 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
330 ...chosen,
331 isOpen: false,
332 });
333 },
334 );
335​
336 it("retargets an existing PR tab but respects a later manual choice", () => {
337 const store = useRightPanelStore.getState();
338 const relinkedPullRequest = pullRequestSurface({ ...linkedPullRequest, number: 43 });
339 store.openPullRequest(refA, relinkedPullRequest);
340 store.openPullRequest(refA, linkedPullRequest);
341 const revision = store.getUserActionRevision(refA);
342​
343 expect(store.openProactive(refA, relinkedPullRequest, revision, true)).toBe(true);
344 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
345 relinkedPullRequest,
346 );
347​
348 store.close(refA);
349 expect(store.openProactive(refA, linkedPullRequest, revision, true)).toBe(false);
350 expect(
351 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
352 ).toMatchObject({
353 activeSurfaceId: relinkedPullRequest.id,
354 isOpen: false,
355 });
356 });
357​
358 it("refocuses an existing diff for a later turn after a manual choice", () => {
359 const store = useRightPanelStore.getState();
360 store.openProactive(refA, completedDiff, store.getUserActionRevision(refA));
361 const firstTurnRevision = store.getUserActionRevision(refA);
362 store.openFile(refA, "src/app.ts");
363 expect(store.openProactive(refA, completedDiff, firstTurnRevision)).toBe(false);
364​
365 const nextTurnRevision = store.getUserActionRevision(refA);
366 expect(
367 store.openProactive(
368 refA,
369 { ...completedDiff, turnId: RunId.make("turn-2") },
370 nextTurnRevision,
371 ),
372 ).toBe(true);
373 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
374 });
375​
376 it("offers each completed diff once across dismissal, panel changes, and reload", async () => {
377 const store = useRightPanelStore.getState();
378 expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(true);
379 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
380​
381 store.close(refA);
382 await reloadRightPanelStore();
383 expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
384 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
385​
386 store.open(refA, "files");
387 store.openFile(refA, "src/app.ts");
388 await reloadRightPanelStore();
389 expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
390 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("file");
391​
392 store.closeAllSurfaces(refA);
393 await reloadRightPanelStore();
394 expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
395 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
396​
397 const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
398 for (const ref of [refB, otherEnvironment]) {
399 expect(store.openProactive(ref, completedDiff, store.getUserActionRevision(ref))).toBe(true);
400 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, ref)).toBe("diff");
401 }
402​
403 const nextTurn = { ...completedDiff, turnId: RunId.make("turn-2") };
404 expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(true);
405 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
406​
407 const completedWhileOpen = { ...completedDiff, turnId: RunId.make("turn-3") };
408 const existingDiff = selectActiveRightPanelSurface(
409 useRightPanelStore.getState().byThreadKey,
410 refA,
411 );
412 expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
413 false,
414 );
415 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
416 existingDiff,
417 );
418 store.closeSurface(refA, "diff");
419 await reloadRightPanelStore();
420 expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
421 false,
422 );
423 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
424​
425 // A later storage migration must preserve the dismissal, just like an ordinary reload.
426 const { storage, name, version } = useRightPanelStore.persist.getOptions();
427 const persisted = await storage!.getItem(name!);
428 await storage!.setItem(name!, { ...persisted!, version: version! - 1 });
429 await reloadRightPanelStore();
430 expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
431 false,
432 );
433 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
434​
435 expect(
436 store.openProactive(
437 refA,
438 { ...completedDiff, turnId: RunId.make("turn-4") },
439 store.getUserActionRevision(refA),
440 ),
441 ).toBe(true);
442 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
443 store.closeSurface(refA, "diff");
444 store.open(refA, "diff");
445 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
446 });
447​
448 it("keeps manual choices scoped to their thread and environment", () => {
449 const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
450 const store = useRightPanelStore.getState();
451 const revision = store.getUserActionRevision(refA);
452 store.openFile(refB, "src/app.ts");
453 store.openFile(otherEnvironment, "src/app.ts");
454​
455 expect(store.openProactive(refA, completedDiff, revision)).toBe(true);
456 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refB)).toBe("file");
457 expect(
458 selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, otherEnvironment),
459 ).toBe("file");
460 });
461​
462 it("does not treat resource reconciliation as a manual choice", () => {
463 const store = useRightPanelStore.getState();
464 store.openFile(refA, "src/app.ts");
465 const revision = store.getUserActionRevision(refA);
466 store.reconcileBrowserSurfaces(refA, ["agent-browser"]);
467 store.reconcileFileSurfaces(refA, false);
468​
469 expect(store.openProactive(refA, completedDiff, revision)).toBe(true);
470 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
471 });
472​
473 it("keeps a maximized panel per thread without counting it as a manual choice", () => {
474 const store = useRightPanelStore.getState();
475 store.open(refA, "preview");
476 store.open(refB, "diff");
477 const revision = store.getUserActionRevision(refA);
478 store.setMaximized(refA, true);
479 store.setMaximized(refB, true);
480 store.setMaximized(refB, false);
481​
482 const { byThreadKey } = useRightPanelStore.getState();
483 expect(selectThreadRightPanelState(byThreadKey, refA).maximized).toBe(true);
484 expect(selectThreadRightPanelState(byThreadKey, refB).maximized).toBeUndefined();
485 expect(store.getUserActionRevision(refA)).toBe(revision);
486 });
487​
488 it("restores a saved maximized panel during migration", () => {
489 const migrated = migratePersistedRightPanelState({
490 byThreadKey: {
491 "env-1:thread-A": {
492 isOpen: true,
493 activeSurfaceId: "browser:new",
494 surfaces: [{ id: "browser:new", kind: "preview", resourceId: null }],
495 maximized: true,
496 },
497 },
498 });
499 expect(selectThreadRightPanelState(migrated.byThreadKey, refA).maximized).toBe(true);
500 });
501​
502 it("drops the legacy singleton terminal surface during migration", () => {
503 expect(
504 migratePersistedRightPanelState({
505 byThreadKey: {
506 "env-1:thread-A": {
507 activeSurfaceId: "terminal",
508 surfaces: [
509 { id: "browser:tab-a", kind: "preview", resourceId: "tab-a" },
510 { id: "terminal", kind: "terminal" },
511 ],
512 },
513 },
514 }),
515 ).toEqual({
516 byThreadKey: {
517 "env-1:thread-A": {
518 isOpen: false,
519 activeSurfaceId: null,
520 surfaces: [{ id: "browser:tab-a", kind: "preview", resourceId: "tab-a" }],
521 },
522 },
523 threadPanelVisibilityByThreadKey: {},
524 });
525 });
526​
527 it("upgrades saved single-session terminal surfaces to split-capable surfaces", () => {
528 expect(
529 migratePersistedRightPanelState({
530 byThreadKey: {
531 "env-1:thread-A": {
532 isOpen: true,
533 activeSurfaceId: "terminal:term-1",
534 surfaces: [{ id: "terminal:term-1", kind: "terminal", resourceId: "term-1" }],
535 },
536 },
537 }),
538 ).toEqual({
539 byThreadKey: {
540 "env-1:thread-A": {
541 isOpen: true,
542 activeSurfaceId: "terminal:term-1",
543 surfaces: [
544 {
545 id: "terminal:term-1",
546 kind: "terminal",
547 resourceId: "term-1",
548 terminalIds: ["term-1"],
549 activeTerminalId: "term-1",
550 },
551 ],
552 },
553 },
554 threadPanelVisibilityByThreadKey: {},
555 });
556 });
557​
558 it("upgrades the legacy singleton pull request surface to a reference-keyed tab", () => {
559 const id = pullRequestSurfaceId({
560 projectId: "project-a",
561 repository: "pingdotgg/t3code",
562 number: 4909,
563 });
564 expect(
565 migratePersistedRightPanelState({
566 byThreadKey: {
567 "env-1:thread-A": {
568 isOpen: true,
569 activeSurfaceId: "pull-request",
570 surfaces: [
571 {
572 id: "pull-request",
573 kind: "pull-request",
574 projectId: "project-a",
575 repository: "pingdotgg/t3code",
576 number: 4909,
577 },
578 ],
579 },
580 },
581 }),
582 ).toEqual({
583 byThreadKey: {
584 "env-1:thread-A": {
585 isOpen: true,
586 activeSurfaceId: id,
587 surfaces: [
588 {
589 id,
590 kind: "pull-request",
591 projectId: "project-a",
592 repository: "pingdotgg/t3code",
593 number: 4909,
594 },
595 ],
596 },
597 },
598 threadPanelVisibilityByThreadKey: {},
599 });
600 });
601​
602 it("drops the pull-request list's shared panel so a restart opens the page fresh", () => {
603 const id = pullRequestSurfaceId({
604 projectId: "project-a",
605 repository: "pingdotgg/t3code",
606 number: 4909,
607 });
608 const panelState = {
609 isOpen: true,
610 activeSurfaceId: id,
611 surfaces: [
612 {
613 id,
614 kind: "pull-request" as const,
615 projectId: "project-a",
616 repository: "pingdotgg/t3code",
617 number: 4909,
618 },
619 ],
620 };
621 expect(
622 migratePersistedRightPanelState({
623 byThreadKey: {
624 "env-1:pull-requests-panel": panelState,
625 "env-1:thread-A": panelState,
626 },
627 }),
628 ).toEqual({
629 byThreadKey: { "env-1:thread-A": panelState },
630 threadPanelVisibilityByThreadKey: {},
631 });
632 });
633​
634 it.each([
635 { kind: "plan", isOpen: true },
636 { kind: "agents", isOpen: true },
637 { kind: "agents", isOpen: false },
638 ])("drops $kind with isOpen=$isOpen and falls back", ({ kind, isOpen }) => {
639 expect(
640 migratePersistedRightPanelState({
641 byThreadKey: {
642 "env-1:thread-A": {
643 isOpen,
644 activeSurfaceId: kind,
645 surfaces: [{ id: kind, kind }],
646 },
647 "env-1:thread-B": {
648 isOpen,
649 activeSurfaceId: kind,
650 surfaces: [
651 { id: kind, kind },
652 { id: "diff", kind: "diff" },
653 ],
654 },
655 },
656 }),
657 ).toEqual({
658 byThreadKey: {
659 "env-1:thread-A": {
660 isOpen: false,
661 activeSurfaceId: null,
662 surfaces: [],
663 },
664 "env-1:thread-B": {
665 isOpen,
666 activeSurfaceId: "diff",
667 surfaces: [{ id: "diff", kind: "diff" }],
668 },
669 },
670 threadPanelVisibilityByThreadKey: {},
671 });
672 });
673​
674 it("persists inline preference without restoring an open popover", () => {
675 expect(
676 migratePersistedRightPanelState({
677 threadPanelVisibilityByThreadKey: {
678 "env-1:thread-A": { inlineOpen: false, popoverOpen: true },
679 "env-1:thread-B": { inlineOpen: true, popoverOpen: true },
680 },
681 }),
682 ).toEqual({
683 byThreadKey: {},
684 threadPanelVisibilityByThreadKey: {
685 "env-1:thread-A": { inlineOpen: false, popoverOpen: false },
686 },
687 });
688 });
689​
690 it("closes the popover atomically when the real right panel opens", () => {
691 useRightPanelStore.getState().setThreadPanelOpen(refA, "popover", true);
692 useRightPanelStore.getState().open(refA, "diff");
693​
694 expect(
695 selectThreadPanelVisibility(
696 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
697 refA,
698 ),
699 ).toEqual({ inlineOpen: true, popoverOpen: false });
700 });
701​
702 it("keeps an open popover visible by promoting it to inline when the real panel closes", () => {
703 const store = useRightPanelStore.getState();
704 store.open(refA, "diff");
705 store.setThreadPanelOpen(refA, "inline", false);
706 store.setThreadPanelOpen(refA, "popover", true);
707 store.close(refA);
708​
709 expect(
710 selectThreadPanelVisibility(
711 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
712 refA,
713 ),
714 ).toEqual({ inlineOpen: true, popoverOpen: true });
715 });
716​
717 it("opens workspace-root links as the singleton files explorer", () => {
718 const store = useRightPanelStore.getState();
719 store.openFile(refA, "README.md");
720 store.openFile(refA, ".");
721 store.openFile(refA, ".");
722 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
723 expect(state.activeSurfaceId).toBe("files");
724 expect(state.surfaces.map((surface) => surface.id)).toEqual(["file:README.md", "files"]);
725 store.closeSurface(refA, "files");
726 expect(
727 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).activeSurfaceId,
728 ).toBe("file:README.md");
729 store.openFile(refA, ".");
730 expect(
731 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).activeSurfaceId,
732 ).toBe("files");
733 });
734​
735 it("walks a folder browser up and back down in one tab", () => {
736 const store = useRightPanelStore.getState();
737 const state = () =>
738 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
739 store.openFile(refA, "README.md");
740 store.openFile(refA, "apps/web/src");
741​
742 store.navigateFolder(refA, "file:apps/web/src", "apps", "apps/web/src");
743 expect(state().activeSurfaceId).toBe("file:apps");
744 expect(state().surfaces).toEqual([
745 expect.objectContaining({ id: "file:README.md" }),
746 expect.objectContaining({
747 id: "file:apps",
748 relativePath: "apps",
749 folderTrail: "apps/web/src",
750 }),
751 ]);
752​
753 // The workspace root is the files explorer, still holding the way back down.
754 store.navigateFolder(refA, "file:apps", "", "apps/web/src");
755 expect(state().surfaces.map((surface) => surface.id)).toEqual(["file:README.md", "files"]);
756 expect(state().surfaces[1]).toEqual({
757 id: "files",
758 kind: "files",
759 folderTrail: "apps/web/src",
760 });
761​
762 // Reaching the end of the trail leaves no trail behind.
763 store.navigateFolder(refA, "files", "apps/web/src", "apps/web/src");
764 expect(state().activeSurfaceId).toBe("file:apps/web/src");
765 expect(state().surfaces[1]).toEqual({
766 id: "file:apps/web/src",
767 kind: "file",
768 relativePath: "apps/web/src",
769 revealLine: null,
770 revealRequestId: 1,
771 });
772 });
773​
774 it("switches to a tab that already shows the folder instead of replacing it", () => {
775 const store = useRightPanelStore.getState();
776 store.openFile(refA, "apps");
777 store.openFile(refA, "apps/web/src", 12);
778​
779 store.navigateFolder(refA, "file:apps/web/src", "apps", "apps/web/src");
780 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
781 expect(state.activeSurfaceId).toBe("file:apps");
782 expect(state.surfaces).toEqual([
783 { id: "file:apps", kind: "file", relativePath: "apps", revealLine: null, revealRequestId: 1 },
784 ]);
785 });
786​
787 it("keeps a file's tab when walking up from it, and comes back to it", () => {
788 const store = useRightPanelStore.getState();
789 const state = () =>
790 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
791 store.openFile(refA, "src/app.ts", 40);
792​
793 store.navigateFolder(refA, "file:src/app.ts", "src", "src/app.ts", true);
794 expect(state().activeSurfaceId).toBe("file:src");
795 expect(state().surfaces).toEqual([
796 {
797 id: "file:src/app.ts",
798 kind: "file",
799 relativePath: "src/app.ts",
800 revealLine: 40,
801 revealRequestId: 1,
802 },
803 expect.objectContaining({ id: "file:src", folderTrail: "src/app.ts" }),
804 ]);
805​
806 // The trail's end is the file: its tab comes back as it was, the folder tab goes.
807 store.navigateFolder(refA, "file:src", "src/app.ts", "src/app.ts");
808 expect(state().activeSurfaceId).toBe("file:src/app.ts");
809 expect(state().surfaces).toEqual([
810 {
811 id: "file:src/app.ts",
812 kind: "file",
813 relativePath: "src/app.ts",
814 revealLine: 40,
815 revealRequestId: 1,
816 },
817 ]);
818 });
819​
820 // regression: #15045 breadcrumb navigation from a closed tab must not resurrect it
821 it("ignores navigation from a tab that was closed", () => {
822 const store = useRightPanelStore.getState();
823 store.openFile(refA, "apps");
824 const before = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
825 store.navigateFolder(refA, "file:gone", "", "gone");
826 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toBe(
827 before,
828 );
829 });
830​
831 it("replaces the standalone explorer with peer file surfaces", () => {
832 useRightPanelStore.getState().open(refA, "files");
833 useRightPanelStore.getState().openFile(refA, "src/index.ts");
834 useRightPanelStore.getState().openFile(refA, "src/index.ts");
835 useRightPanelStore.getState().openFile(refA, "README.md");
836​
837 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
838 isOpen: true,
839 activeSurfaceId: "file:README.md",
840 surfaces: [
841 {
842 id: "file:src/index.ts",
843 kind: "file",
844 relativePath: "src/index.ts",
845 revealLine: null,
846 revealRequestId: 2,
847 },
848 {
849 id: "file:README.md",
850 kind: "file",
851 relativePath: "README.md",
852 revealLine: null,
853 revealRequestId: 1,
854 },
855 ],
856 });
857 });
858​
859 it.each([
860 ["generated\\", "generated"],
861 ["notes/meeting ", "notes/meeting"],
862 [" notes/meeting", "notes/meeting"],
863 ])("keeps %j and %j in separate file tabs", (firstPath, secondPath) => {
864 useRightPanelStore.getState().openFile(refA, firstPath);
865 useRightPanelStore.getState().openFile(refA, secondPath);
866​
867 expect(
868 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
869 ).toMatchObject([
870 { id: `file:${firstPath}`, relativePath: firstPath },
871 { id: `file:${secondPath}`, relativePath: secondPath },
872 ]);
873 });
874​
875 it("keeps attachment and workspace file ids disjoint", () => {
876 useRightPanelStore.getState().openFile(refA, "attachment:shared-id");
877 useRightPanelStore.getState().openAttachment(refA, {
878 type: "file",
879 id: "shared-id",
880 name: "report.pdf",
881 mimeType: "application/pdf",
882 sizeBytes: 42,
883 });
884​
885 expect(
886 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
887 (surface) => surface.id,
888 ),
889 ).toEqual(["file:attachment:shared-id", "attachment:shared-id"]);
890 });
891​
892 it("updates line reveal requests when reopening a file surface", () => {
893 useRightPanelStore.getState().openFile(refA, "src/index.ts", 42);
894 useRightPanelStore.getState().openFile(refA, "src/index.ts", 87);
895​
896 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
897 isOpen: true,
898 activeSurfaceId: "file:src/index.ts",
899 surfaces: [
900 {
901 id: "file:src/index.ts",
902 kind: "file",
903 relativePath: "src/index.ts",
904 revealLine: 87,
905 revealRequestId: 2,
906 },
907 ],
908 });
909​
910 useRightPanelStore.getState().openFile(refA, "src/index.ts");
911​
912 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
913 isOpen: true,
914 activeSurfaceId: "file:src/index.ts",
915 surfaces: [
916 {
917 id: "file:src/index.ts",
918 kind: "file",
919 relativePath: "src/index.ts",
920 revealLine: null,
921 revealRequestId: 3,
922 },
923 ],
924 });
925 });
926​
927 it("removes persisted file surfaces when their workspace no longer exists", () => {
928 useRightPanelStore.getState().openFile(refA, "src/index.ts");
929 useRightPanelStore.getState().open(refA, "device");
930 useRightPanelStore.getState().openFile(refA, "README.md");
931​
932 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
933​
934 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
935 isOpen: true,
936 activeSurfaceId: "device",
937 surfaces: [{ id: "device", kind: "device" }],
938 });
939​
940 useRightPanelStore.getState().openFile(refB, "conductor.json");
941 useRightPanelStore.getState().reconcileFileSurfaces(refB, false);
942 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refB)).toEqual({
943 isOpen: false,
944 activeSurfaceId: null,
945 surfaces: [],
946 });
947 });
948​
949 it("keeps attachment previews when their workspace is unavailable", () => {
950 const attachment = {
951 type: "file" as const,
952 id: "thread-A-attachment-pdf",
953 name: "report.pdf",
954 mimeType: "application/pdf",
955 sizeBytes: 42,
956 };
957 useRightPanelStore.getState().openFile(refA, "README.md");
958 useRightPanelStore.getState().openAttachment(refA, attachment);
959​
960 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
961​
962 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
963 isOpen: true,
964 activeSurfaceId: "attachment:thread-A-attachment-pdf",
965 surfaces: [
966 {
967 id: "attachment:thread-A-attachment-pdf",
968 kind: "file",
969 relativePath: "report.pdf",
970 revealLine: null,
971 revealRequestId: 0,
972 attachment,
973 },
974 ],
975 });
976 });
977​
978 it("tracks one surface per pull request", () => {
979 const first = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
980 const second = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4910 };
981 useRightPanelStore.getState().openPullRequest(refA, first);
982 useRightPanelStore.getState().openPullRequest(refA, second);
983 const url = "https://gitlab.example.com/pingdotgg/t3code/-/merge_requests/4909";
984 useRightPanelStore.getState().openPullRequest(refA, { ...first, url });
985 useRightPanelStore.getState().openPullRequest(refA, first);
986​
987 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
988 expect(state.surfaces.map((surface) => surface.id)).toEqual([
989 pullRequestSurfaceId(first),
990 pullRequestSurfaceId(second),
991 ]);
992 expect(state.activeSurfaceId).toBe(pullRequestSurfaceId(first));
993 expect(
994 selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
995 ).toMatchObject({ url });
996 expect(state.surfaces[1]).not.toHaveProperty("url");
997 });
998​
999 it("restores each environment, thread and PR surface's detail tab after reload and URL reopen", async () => {
1000 const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
1001 const otherPr = { ...pr, projectId: "project-b" };
1002 const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
1003 const selections = [
1004 [refA, pr, "code"],
1005 [refB, pr, "guide"],
1006 [otherEnvironment, pr, "timeline"],
1007 [refA, otherPr, "summary"],
1008 ] as const;
1009 const store = useRightPanelStore.getState();
1010 for (const [ref, reference, tab] of selections) {
1011 store.openPullRequest(ref, reference);
1012 store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), "guide");
1013 store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), tab);
1015​
1016 store.openPullRequest(refA, pr);
1017 const revision = store.getUserActionRevision(refA);
1018 store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "timeline");
1019 expect(store.openProactive(refA, linkedPullRequest, revision)).toBe(true);
1020 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
1021 linkedPullRequest,
1022 );
1023 store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "code");
1024​
1025 const { storage, name } = useRightPanelStore.persist.getOptions();
1026 const saved = await storage!.getItem(name!);
1027 expect(saved).not.toBeNull();
1028 useRightPanelStore.setState({ byThreadKey: {} });
1029 await storage!.setItem(name!, saved!);
1030 await useRightPanelStore.persist.rehydrate();
1031​
1032 for (const [ref, reference, tab] of selections) {
1033 store.openPullRequest(ref, {
1034 ...reference,
1035 url: `https://github.com/${reference.repository}/pull/${reference.number}`,
1036 });
1037 const active = selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, ref);
1038 expect(active?.id).toBe(pullRequestSurfaceId(reference));
1039 expect(active?.kind === "pull-request" && (active.detailTab ?? "summary")).toBe(tab);
1040 store.closeSurface(ref, active!.id);
1041 await reopenClosedView(useClosedViewStore.getState().entries[0]!, {
1042 workspaceAvailable: true,
1043 openPreview: () => {
1044 throw new Error("A PR tab must not create a browser session");
1045 },
1046 });
1047 const reopened = selectActiveRightPanelSurface(
1048 useRightPanelStore.getState().byThreadKey,
1049 ref,
1050 );
1051 expect(reopened?.kind === "pull-request" && (reopened.detailTab ?? "summary")).toBe(tab);
1053 });
1054​
1055 it("keeps matching repository and number on different hosts as separate tabs", () => {
1056 const first = { projectId: "project-a", repository: "acme/api", number: 7, host: "github.com" };
1057 const second = { ...first, host: "github.example.com" };
1058 useRightPanelStore.getState().openPullRequest(refA, first);
1059 useRightPanelStore.getState().openPullRequest(refA, second);
1060 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
1061 expect(state.surfaces).toEqual([pullRequestSurface(first), pullRequestSurface(second)]);
1062 expect(pullRequestSurfaceId({ ...first, host: "GITHUB.COM" })).toBe(
1063 pullRequestSurfaceId(first),
1064 );
1065 });
1066​
1067 it("keeps the page's panel tabs reachable when the set of connected servers changes", () => {
1068 const panelId = ThreadId.make("pull-requests-panel");
1069 const stableRef = scopeThreadRef("pull-requests-panel" as EnvironmentId, panelId);
1070 const fromServerA = {
1071 environmentId: "server-a",
1072 projectId: "project-a",
1073 repository: "pingdotgg/t3code",
1074 number: 1,
1075 };
1076 const fromServerB = {
1077 environmentId: "server-b",
1078 projectId: "project-b",
1079 repository: "pingdotgg/t3code",
1080 number: 2,
1081 };
1082​
1083 useRightPanelStore.getState().openPullRequest(stableRef, fromServerA);
1084 useRightPanelStore.getState().openPullRequest(stableRef, fromServerB);
1085​
1086 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, stableRef);
1087 expect(state.surfaces.map((surface) => surface.id)).toEqual([
1088 pullRequestSurfaceId(fromServerA),
1089 pullRequestSurfaceId(fromServerB),
1090 ]);
1091​
1092 const refWhileBothConnected = scopeThreadRef("server-a" as EnvironmentId, panelId);
1093 const refAfterServerADisconnects = scopeThreadRef("server-b" as EnvironmentId, panelId);
1094 expect(refWhileBothConnected).not.toEqual(refAfterServerADisconnects);
1095 expect(
1096 selectThreadRightPanelState(
1097 useRightPanelStore.getState().byThreadKey,
1098 refAfterServerADisconnects,
1099 ).surfaces,
1100 ).toEqual([]);
1101 });
1102​
1103 it("tracks split panes and the active pane within a terminal surface", () => {
1104 useRightPanelStore.getState().openTerminal(refA, "term-1");
1105 useRightPanelStore.getState().splitTerminal(refA, "terminal:term-1", "term-2");
1106​
1107 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1108 id: "terminal:term-1",
1109 kind: "terminal",
1110 resourceId: "term-1",
1111 terminalIds: ["term-1", "term-2"],
1112 activeTerminalId: "term-2",
1113 });
1114​
1115 useRightPanelStore.getState().activateTerminal(refA, "terminal:term-1", "term-1");
1116 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
1117 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1118 id: "terminal:term-1",
1119 kind: "terminal",
1120 resourceId: "term-1",
1121 terminalIds: ["term-2"],
1122 activeTerminalId: "term-2",
1123 });
1124 });
1125​
1126 it("closing the final terminal pane removes its surface and closes the panel", () => {
1127 useRightPanelStore.getState().openTerminal(refA, "term-1");
1128 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
1129​
1130 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1131 isOpen: false,
1132 activeSurfaceId: null,
1133 surfaces: [],
1134 });
1135 });
1136​
1137 it("closing the active surface activates a neighboring surface", () => {
1138 useRightPanelStore.getState().openBrowser(refA, "tab-a");
1139 useRightPanelStore.getState().openTerminal(refA, "term-1");
1140 useRightPanelStore.getState().closeSurface(refA, "terminal:term-1");
1141​
1142 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)?.id).toBe(
1143 "browser:tab-a",
1144 );
1145 });
1146​
1147 it("closing surfaces to the right activates the selected surface when active was removed", () => {
1148 useRightPanelStore.getState().openBrowser(refA, "tab-a");
1149 useRightPanelStore.getState().openFile(refA, "src/index.ts");
1150 useRightPanelStore.getState().openTerminal(refA, "term-1");
1151​
1152 useRightPanelStore.getState().closeSurfacesToRight(refA, "browser:tab-a");
1153​
1154 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1155 isOpen: true,
1156 activeSurfaceId: "browser:tab-a",
1157 surfaces: [{ id: "browser:tab-a", kind: "preview", resourceId: "tab-a" }],
1158 });
1159 });
1160​
1161 it("does not replace a stale surface with a hidden tab, but preserves explicit opens", () => {
1162 const store = useRightPanelStore.getState();
1163 store.openBrowser(refA, "stale-tab");
1164 store.reconcileBrowserSurfaces(refA, ["hidden-tab"], new Set(["hidden-tab"]));
1165 expect(
1166 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
1167 ).toMatchObject({
1168 activeSurfaceId: null,
1169 surfaces: [],
1170 });
1171​
1172 store.openBrowser(refA, "hidden-tab");
1173 store.reconcileBrowserSurfaces(
1174 refA,
1175 ["hidden-tab", "other-tab"],
1176 new Set(["hidden-tab", "other-tab"]),
1177 );
1178 expect(
1179 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
1180 ).toMatchObject({
1181 isOpen: true,
1182 activeSurfaceId: "browser:hidden-tab",
1183 surfaces: [{ id: "browser:hidden-tab", kind: "preview", resourceId: "hidden-tab" }],
1184 });
1185 });
1186​
1187 it("moves a surface to a new index and keeps it there through browser reconciliation", () => {
1188 const store = useRightPanelStore.getState();
1189 store.openTerminal(refA, "term-1");
1190 store.openBrowser(refA, "tab-a");
1191 store.open(refA, "diff");
1192 const revision = store.getUserActionRevision(refA);
1193 const surfaceIds = () =>
1194 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
1195 (surface) => surface.id,
1196 );
1197​
1198 store.moveSurface(refA, "browser:tab-a", 0);
1199 expect(surfaceIds()).toEqual(["browser:tab-a", "terminal:term-1", "diff"]);
1200 store.moveSurface(refA, "browser:tab-a", 2);
1201 expect(surfaceIds()).toEqual(["terminal:term-1", "diff", "browser:tab-a"]);
1202 store.moveSurface(refA, "browser:tab-a", 0);
1203​
1204 store.reconcileBrowserSurfaces(refA, ["tab-a", "tab-b"]);
1205 expect(surfaceIds()).toEqual(["browser:tab-a", "terminal:term-1", "diff", "browser:tab-b"]);
1206 expect(store.getUserActionRevision(refA)).toBe(revision);
1207 });
1208});