Open History to see the last commit
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);
39}
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 store.navigateFolder(refA, "file:apps", "", "apps/web/src");
754 expect(state().surfaces.map((surface) => surface.id)).toEqual(["file:README.md", "files"]);
755 expect(state().surfaces[1]).toEqual({
756 id: "files",
757 kind: "files",
758 folderTrail: "apps/web/src",
759 });
760
761 store.navigateFolder(refA, "files", "apps/web/src", "apps/web/src");
762 expect(state().activeSurfaceId).toBe("file:apps/web/src");
763 expect(state().surfaces[1]).toEqual({
764 id: "file:apps/web/src",
765 kind: "file",
766 relativePath: "apps/web/src",
767 revealLine: null,
768 revealRequestId: 1,
769 });
770 });
771
772 it("switches to a tab that already shows the folder instead of replacing it", () => {
773 const store = useRightPanelStore.getState();
774 store.openFile(refA, "apps");
775 store.openFile(refA, "apps/web/src", 12);
776
777 store.navigateFolder(refA, "file:apps/web/src", "apps", "apps/web/src");
778 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
779 expect(state.activeSurfaceId).toBe("file:apps");
780 expect(state.surfaces).toEqual([
781 { id: "file:apps", kind: "file", relativePath: "apps", revealLine: null, revealRequestId: 1 },
782 ]);
783 });
784
785 it("keeps a file's tab when walking up from it, and comes back to it", () => {
786 const store = useRightPanelStore.getState();
787 const state = () =>
788 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
789 store.openFile(refA, "src/app.ts", 40);
790
791 store.navigateFolder(refA, "file:src/app.ts", "src", "src/app.ts", true);
792 expect(state().activeSurfaceId).toBe("file:src");
793 expect(state().surfaces).toEqual([
794 {
795 id: "file:src/app.ts",
796 kind: "file",
797 relativePath: "src/app.ts",
798 revealLine: 40,
799 revealRequestId: 1,
800 },
801 expect.objectContaining({ id: "file:src", folderTrail: "src/app.ts" }),
802 ]);
803
804 store.navigateFolder(refA, "file:src", "src/app.ts", "src/app.ts");
805 expect(state().activeSurfaceId).toBe("file:src/app.ts");
806 expect(state().surfaces).toEqual([
807 {
808 id: "file:src/app.ts",
809 kind: "file",
810 relativePath: "src/app.ts",
811 revealLine: 40,
812 revealRequestId: 1,
813 },
814 ]);
815 });
816
817 // regression: #15045 breadcrumb navigation from a closed tab must not resurrect it
818 it("ignores navigation from a tab that was closed", () => {
819 const store = useRightPanelStore.getState();
820 store.openFile(refA, "apps");
821 const before = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
822 store.navigateFolder(refA, "file:gone", "", "gone");
823 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toBe(
824 before,
825 );
826 });
827
828 it("replaces the standalone explorer with peer file surfaces", () => {
829 useRightPanelStore.getState().open(refA, "files");
830 useRightPanelStore.getState().openFile(refA, "src/index.ts");
831 useRightPanelStore.getState().openFile(refA, "src/index.ts");
832 useRightPanelStore.getState().openFile(refA, "README.md");
833
834 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
835 isOpen: true,
836 activeSurfaceId: "file:README.md",
837 surfaces: [
838 {
839 id: "file:src/index.ts",
840 kind: "file",
841 relativePath: "src/index.ts",
842 revealLine: null,
843 revealRequestId: 2,
844 },
845 {
846 id: "file:README.md",
847 kind: "file",
848 relativePath: "README.md",
849 revealLine: null,
850 revealRequestId: 1,
851 },
852 ],
853 });
854 });
855
856 it.each([
857 ["generated\\", "generated"],
858 ["notes/meeting ", "notes/meeting"],
859 [" notes/meeting", "notes/meeting"],
860 ])("keeps %j and %j in separate file tabs", (firstPath, secondPath) => {
861 useRightPanelStore.getState().openFile(refA, firstPath);
862 useRightPanelStore.getState().openFile(refA, secondPath);
863
864 expect(
865 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
866 ).toMatchObject([
867 { id: `file:${firstPath}`, relativePath: firstPath },
868 { id: `file:${secondPath}`, relativePath: secondPath },
869 ]);
870 });
871
872 it("keeps attachment and workspace file ids disjoint", () => {
873 useRightPanelStore.getState().openFile(refA, "attachment:shared-id");
874 useRightPanelStore.getState().openAttachment(refA, {
875 type: "file",
876 id: "shared-id",
877 name: "report.pdf",
878 mimeType: "application/pdf",
879 sizeBytes: 42,
880 });
881
882 expect(
883 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
884 (surface) => surface.id,
885 ),
886 ).toEqual(["file:attachment:shared-id", "attachment:shared-id"]);
887 });
888
889 it("updates line reveal requests when reopening a file surface", () => {
890 useRightPanelStore.getState().openFile(refA, "src/index.ts", 42);
891 useRightPanelStore.getState().openFile(refA, "src/index.ts", 87);
892
893 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
894 isOpen: true,
895 activeSurfaceId: "file:src/index.ts",
896 surfaces: [
897 {
898 id: "file:src/index.ts",
899 kind: "file",
900 relativePath: "src/index.ts",
901 revealLine: 87,
902 revealRequestId: 2,
903 },
904 ],
905 });
906
907 useRightPanelStore.getState().openFile(refA, "src/index.ts");
908
909 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
910 isOpen: true,
911 activeSurfaceId: "file:src/index.ts",
912 surfaces: [
913 {
914 id: "file:src/index.ts",
915 kind: "file",
916 relativePath: "src/index.ts",
917 revealLine: null,
918 revealRequestId: 3,
919 },
920 ],
921 });
922 });
923
924 it("removes persisted file surfaces when their workspace no longer exists", () => {
925 useRightPanelStore.getState().openFile(refA, "src/index.ts");
926 useRightPanelStore.getState().open(refA, "device");
927 useRightPanelStore.getState().openFile(refA, "README.md");
928
929 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
930
931 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
932 isOpen: true,
933 activeSurfaceId: "device",
934 surfaces: [{ id: "device", kind: "device" }],
935 });
936
937 useRightPanelStore.getState().openFile(refB, "conductor.json");
938 useRightPanelStore.getState().reconcileFileSurfaces(refB, false);
939 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refB)).toEqual({
940 isOpen: false,
941 activeSurfaceId: null,
942 surfaces: [],
943 });
944 });
945
946 it("keeps attachment previews when their workspace is unavailable", () => {
947 const attachment = {
948 type: "file" as const,
949 id: "thread-A-attachment-pdf",
950 name: "report.pdf",
951 mimeType: "application/pdf",
952 sizeBytes: 42,
953 };
954 useRightPanelStore.getState().openFile(refA, "README.md");
955 useRightPanelStore.getState().openAttachment(refA, attachment);
956
957 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
958
959 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
960 isOpen: true,
961 activeSurfaceId: "attachment:thread-A-attachment-pdf",
962 surfaces: [
963 {
964 id: "attachment:thread-A-attachment-pdf",
965 kind: "file",
966 relativePath: "report.pdf",
967 revealLine: null,
968 revealRequestId: 0,
969 attachment,
970 },
971 ],
972 });
973 });
974
975 it("tracks one surface per pull request", () => {
976 const first = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
977 const second = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4910 };
978 useRightPanelStore.getState().openPullRequest(refA, first);
979 useRightPanelStore.getState().openPullRequest(refA, second);
980 const url = "https://gitlab.example.com/pingdotgg/t3code/-/merge_requests/4909";
981 useRightPanelStore.getState().openPullRequest(refA, { ...first, url });
982 useRightPanelStore.getState().openPullRequest(refA, first);
983
984 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
985 expect(state.surfaces.map((surface) => surface.id)).toEqual([
986 pullRequestSurfaceId(first),
987 pullRequestSurfaceId(second),
988 ]);
989 expect(state.activeSurfaceId).toBe(pullRequestSurfaceId(first));
990 expect(
991 selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
992 ).toMatchObject({ url });
993 expect(state.surfaces[1]).not.toHaveProperty("url");
994 });
995
996 it("restores each environment, thread and PR surface's detail tab after reload and URL reopen", async () => {
997 const pr = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
998 const otherPr = { ...pr, projectId: "project-b" };
999 const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
1000 const selections = [
1001 [refA, pr, "code"],
1002 [refB, pr, "guide"],
1003 [otherEnvironment, pr, "timeline"],
1004 [refA, otherPr, "summary"],
1005 ] as const;
1006 const store = useRightPanelStore.getState();
1007 for (const [ref, reference, tab] of selections) {
1008 store.openPullRequest(ref, reference);
1009 store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), "guide");
1010 store.setPullRequestDetailTab(ref, pullRequestSurfaceId(reference), tab);
1011 }
1012
1013 store.openPullRequest(refA, pr);
1014 const revision = store.getUserActionRevision(refA);
1015 store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "timeline");
1016 expect(store.openProactive(refA, linkedPullRequest, revision)).toBe(true);
1017 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
1018 linkedPullRequest,
1019 );
1020 store.setPullRequestDetailTab(refA, pullRequestSurfaceId(pr), "code");
1021
1022 const { storage, name } = useRightPanelStore.persist.getOptions();
1023 const saved = await storage!.getItem(name!);
1024 expect(saved).not.toBeNull();
1025 useRightPanelStore.setState({ byThreadKey: {} });
1026 await storage!.setItem(name!, saved!);
1027 await useRightPanelStore.persist.rehydrate();
1028
1029 for (const [ref, reference, tab] of selections) {
1030 store.openPullRequest(ref, {
1031 ...reference,
1032 url: `https://github.com/${reference.repository}/pull/${reference.number}`,
1033 });
1034 const active = selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, ref);
1035 expect(active?.id).toBe(pullRequestSurfaceId(reference));
1036 expect(active?.kind === "pull-request" && (active.detailTab ?? "summary")).toBe(tab);
1037 store.closeSurface(ref, active!.id);
1038 await reopenClosedView(useClosedViewStore.getState().entries[0]!, {
1039 workspaceAvailable: true,
1040 openPreview: () => {
1041 throw new Error("A PR tab must not create a browser session");
1042 },
1043 });
1044 const reopened = selectActiveRightPanelSurface(
1045 useRightPanelStore.getState().byThreadKey,
1046 ref,
1047 );
1048 expect(reopened?.kind === "pull-request" && (reopened.detailTab ?? "summary")).toBe(tab);
1049 }
1050 });
1051
1052 it("keeps matching repository and number on different hosts as separate tabs", () => {
1053 const first = { projectId: "project-a", repository: "acme/api", number: 7, host: "github.com" };
1054 const second = { ...first, host: "github.example.com" };
1055 useRightPanelStore.getState().openPullRequest(refA, first);
1056 useRightPanelStore.getState().openPullRequest(refA, second);
1057 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
1058 expect(state.surfaces).toEqual([pullRequestSurface(first), pullRequestSurface(second)]);
1059 expect(pullRequestSurfaceId({ ...first, host: "GITHUB.COM" })).toBe(
1060 pullRequestSurfaceId(first),
1061 );
1062 });
1063
1064 it("keeps the page's panel tabs reachable when the set of connected servers changes", () => {
1065 const panelId = ThreadId.make("pull-requests-panel");
1066 const stableRef = scopeThreadRef("pull-requests-panel" as EnvironmentId, panelId);
1067 const fromServerA = {
1068 environmentId: "server-a",
1069 projectId: "project-a",
1070 repository: "pingdotgg/t3code",
1071 number: 1,
1072 };
1073 const fromServerB = {
1074 environmentId: "server-b",
1075 projectId: "project-b",
1076 repository: "pingdotgg/t3code",
1077 number: 2,
1078 };
1079
1080 useRightPanelStore.getState().openPullRequest(stableRef, fromServerA);
1081 useRightPanelStore.getState().openPullRequest(stableRef, fromServerB);
1082
1083 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, stableRef);
1084 expect(state.surfaces.map((surface) => surface.id)).toEqual([
1085 pullRequestSurfaceId(fromServerA),
1086 pullRequestSurfaceId(fromServerB),
1087 ]);
1088
1089 const refWhileBothConnected = scopeThreadRef("server-a" as EnvironmentId, panelId);
1090 const refAfterServerADisconnects = scopeThreadRef("server-b" as EnvironmentId, panelId);
1091 expect(refWhileBothConnected).not.toEqual(refAfterServerADisconnects);
1092 expect(
1093 selectThreadRightPanelState(
1094 useRightPanelStore.getState().byThreadKey,
1095 refAfterServerADisconnects,
1096 ).surfaces,
1097 ).toEqual([]);
1098 });
1099
1100 it("tracks split panes and the active pane within a terminal surface", () => {
1101 useRightPanelStore.getState().openTerminal(refA, "term-1");
1102 useRightPanelStore.getState().splitTerminal(refA, "terminal:term-1", "term-2");
1103
1104 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1105 id: "terminal:term-1",
1106 kind: "terminal",
1107 resourceId: "term-1",
1108 terminalIds: ["term-1", "term-2"],
1109 activeTerminalId: "term-2",
1110 });
1111
1112 useRightPanelStore.getState().activateTerminal(refA, "terminal:term-1", "term-1");
1113 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
1114 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1115 id: "terminal:term-1",
1116 kind: "terminal",
1117 resourceId: "term-1",
1118 terminalIds: ["term-2"],
1119 activeTerminalId: "term-2",
1120 });
1121 });
1122
1123 it("closing the final terminal pane removes its surface and closes the panel", () => {
1124 useRightPanelStore.getState().openTerminal(refA, "term-1");
1125 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
1126
1127 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1128 isOpen: false,
1129 activeSurfaceId: null,
1130 surfaces: [],
1131 });
1132 });
1133
1134 it("closing the active surface activates a neighboring surface", () => {
1135 useRightPanelStore.getState().openBrowser(refA, "tab-a");
1136 useRightPanelStore.getState().openTerminal(refA, "term-1");
1137 useRightPanelStore.getState().closeSurface(refA, "terminal:term-1");
1138
1139 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)?.id).toBe(
1140 "browser:tab-a",
1141 );
1142 });
1143
1144 it("closing surfaces to the right activates the selected surface when active was removed", () => {
1145 useRightPanelStore.getState().openBrowser(refA, "tab-a");
1146 useRightPanelStore.getState().openFile(refA, "src/index.ts");
1147 useRightPanelStore.getState().openTerminal(refA, "term-1");
1148
1149 useRightPanelStore.getState().closeSurfacesToRight(refA, "browser:tab-a");
1150
1151 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1152 isOpen: true,
1153 activeSurfaceId: "browser:tab-a",
1154 surfaces: [{ id: "browser:tab-a", kind: "preview", resourceId: "tab-a" }],
1155 });
1156 });
1157
1158 it("does not replace a stale surface with a hidden tab, but preserves explicit opens", () => {
1159 const store = useRightPanelStore.getState();
1160 store.openBrowser(refA, "stale-tab");
1161 store.reconcileBrowserSurfaces(refA, ["hidden-tab"], new Set(["hidden-tab"]));
1162 expect(
1163 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
1164 ).toMatchObject({
1165 activeSurfaceId: null,
1166 surfaces: [],
1167 });
1168
1169 store.openBrowser(refA, "hidden-tab");
1170 store.reconcileBrowserSurfaces(
1171 refA,
1172 ["hidden-tab", "other-tab"],
1173 new Set(["hidden-tab", "other-tab"]),
1174 );
1175 expect(
1176 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
1177 ).toMatchObject({
1178 isOpen: true,
1179 activeSurfaceId: "browser:hidden-tab",
1180 surfaces: [{ id: "browser:hidden-tab", kind: "preview", resourceId: "hidden-tab" }],
1181 });
1182 });
1183
1184 it("hides the panel when browser reconciliation removes its last session tab", () => {
1185 const store = useRightPanelStore.getState();
1186 store.openBrowser(refA, "tab-a");
1187 store.reconcileBrowserSurfaces(refA, []);
1188 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
1189 isOpen: false,
1190 activeSurfaceId: null,
1191 surfaces: [],
1192 });
1193
1194 store.openBrowser(refA, "tab-b");
1195 store.open(refA, "diff");
1196 store.reconcileBrowserSurfaces(refA, []);
1197 expect(
1198 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
1199 ).toMatchObject({ isOpen: true, activeSurfaceId: "diff" });
1200 });
1201
1202 it("moves a surface to a new index and keeps it there through browser reconciliation", () => {
1203 const store = useRightPanelStore.getState();
1204 store.openTerminal(refA, "term-1");
1205 store.openBrowser(refA, "tab-a");
1206 store.open(refA, "diff");
1207 const revision = store.getUserActionRevision(refA);
1208 const surfaceIds = () =>
1209 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
1210 (surface) => surface.id,
1211 );
1212
1213 store.moveSurface(refA, "browser:tab-a", 0);
1214 expect(surfaceIds()).toEqual(["browser:tab-a", "terminal:term-1", "diff"]);
1215 store.moveSurface(refA, "browser:tab-a", 2);
1216 expect(surfaceIds()).toEqual(["terminal:term-1", "diff", "browser:tab-a"]);
1217 store.moveSurface(refA, "browser:tab-a", 0);
1218
1219 store.reconcileBrowserSurfaces(refA, ["tab-a", "tab-b"]);
1220 expect(surfaceIds()).toEqual(["browser:tab-a", "terminal:term-1", "diff", "browser:tab-b"]);
1221 expect(store.getUserActionRevision(refA)).toBe(revision);
1222 });
1223});