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

DiffPanel.browser.test.tsx

609 lines23.6 KB

1import { RegistryContext } from "@effect/atom-react";
2import { scopedThreadKey } from "@t3tools/client-runtime/environment";
3import {
4 DEFAULT_CLIENT_SETTINGS,
5 EnvironmentId,
6 CheckpointRef,
7 CheckpointScopeId,
8 ProjectId,
9 RunId,
10 ThreadId,
11 TurnItemId,
12 type ClientSettings,
13 type OrchestrationGetTurnDiffResult,
14 type ReviewBranchCommitsResult,
15 type ReviewDiffPreviewResult,
16 type ReviewDiffPreviewSource,
17 type ScopedThreadRef,
18 type VcsListRefsResult,
19 type VcsStatusResult,
20} from "@t3tools/contracts";
21import * as DateTime from "effect/DateTime";
22import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
23import { expect, it, vi } from "vite-plus/test";
24import { page, userEvent } from "vite-plus/test/browser";
25​
26import "~/index.css";
27import { act, render } from "../../test/render";
28import { makeThreadFixture } from "~/test-fixtures";
29​
30type ResultAtom<A> = Atom.Atom<AsyncResult.AsyncResult<A, Error>>;
31​
32const state = vi.hoisted(() => ({
33 thread: null as ReturnType<typeof makeThreadFixture> | null,
34 threadRef: null as ScopedThreadRef | null,
35 previews: new Map<string | null, ResultAtom<ReviewDiffPreviewResult>>(),
36 patch: null as unknown as ResultAtom<ReviewDiffPreviewSource>,
37 diffFilesCollapsed: false,
38 project: {
39 workspaceRoot: "/project",
40 repositoryIdentity: null as { rootPath: string } | null,
41 },
42 toolCallItem: null as unknown,
43 config: null as unknown as Atom.Atom<null>,
44 status: null as unknown as ResultAtom<VcsStatusResult>,
45 localRefs: null as unknown as ResultAtom<VcsListRefsResult>,
46 remoteRefs: null as unknown as ResultAtom<VcsListRefsResult>,
47 commits: null as unknown as ResultAtom<ReviewBranchCommitsResult>,
48 checkpoints: [] as unknown[],
49 checkpointDiff: null as Partial<OrchestrationGetTurnDiffResult> | null,
50}));
51​
52vi.mock("~/state/server", () => ({
53 serverEnvironment: { configValueAtom: () => state.config },
54}));
55vi.mock("~/state/review", () => ({
56 reviewEnvironment: {
57 diffPreview: ({ input }: { input: { baseRef?: string } }) =>
58 state.previews.get(input.baseRef ?? null)!,
59 branchCommits: () => state.commits,
60 diffFilePatch: () => state.patch,
61 diffFileContents: {},
62 },
63}));
64vi.mock("~/state/vcs", () => ({
65 vcsEnvironment: {
66 status: () => state.status,
67 listRefs: ({ input }: { input: { refKind: "local" | "remote" } }) =>
68 input.refKind === "local" ? state.localRefs : state.remoteRefs,
69 },
70}));
71vi.mock("~/state/entities", () => ({
72 useQuietThreadShell: () => state.thread,
73 useProject: () => state.project,
74 useThreadCheckpointSummaries: () => state.checkpoints,
75 useQuietThreadVisibleTurnItems: () => [],
76 useQuietThreadProjection: () => null,
77}));
78vi.mock("~/state/filesystem", () => ({
79 useFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false, error: null }),
80 filesystemEnvironment: {},
81}));
82vi.mock("~/hooks/useThreadRouteTarget", () => ({ useThreadRouteRef: () => state.threadRef }));
83vi.mock("~/hooks/useSettings", () => ({
84 useClientSettings: (select: (settings: ClientSettings) => unknown) =>
85 select({ ...DEFAULT_CLIENT_SETTINGS, diffFilesCollapsed: state.diffFilesCollapsed }),
86 updateClientSettings: async () => {},
87}));
88vi.mock("~/hooks/useTheme", () => ({
89 useRenderedAppearance: () => "dark",
90 getRenderedAppearance: () => "dark",
91 subscribeRenderedAppearance: () => () => {},
92}));
93vi.mock("~/state/queries", () => ({
94 useCheckpointDiff: () => ({ data: state.checkpointDiff, error: null, isPending: false }),
95 useTurnItemDetail: () => ({
96 data: state.toolCallItem ? { item: state.toolCallItem } : null,
97 error: null,
98 isPending: false,
99 }),
100 useDebouncedValue: <A,>(value: A) => value,
101}));
102vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => async () => {} }));
103vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => async () => {} }));
104vi.mock("~/fileContextMenu", () => ({ useFileContextMenuHandler: () => () => {} }));
105vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => async () => {} }));
106vi.mock("./diffs/DiffCommentAnnotation", () => ({ DiffCommentAnnotation: () => null }));
107vi.mock(import("~/assets/assetUrls"), async (original) => ({
108 ...(await original()),
109 useAssetUrlState: () => ({
110 _tag: "Success",
111 url: "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
112 expiresAt: Number.MAX_SAFE_INTEGER,
113 }),
114}));
115vi.mock("./diffs/DiffFileTree", () => ({ DiffFileTree: () => null }));
116vi.mock("./DiffFilePathCopyButton", () => ({ DiffFilePathCopyButton: () => null }));
117​
118import DiffPanel from "./DiffPanel";
119import { useDiffPanelSessionStore, useDiffPanelStore } from "~/diffPanelStore";
120import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore";
121​
122const cwd = "/project-worktree";
123const errorMessage = "Could not find a common commit between 'origin/orphan' and HEAD.";
124​
125function preview(): ReviewDiffPreviewResult {
126 return {
127 cwd,
128 generatedAt: DateTime.makeUnsafe("2026-10-30T00:00:00Z"),
129 sources: [
130 {
131 id: "branch",
132 kind: "branch-range",
133 title: "Changes",
134 baseRef: "main",
135 headRef: "dev",
136 diff: "",
137 diffHash: "empty",
138 truncated: false,
139 patchesDeferred: true,
140 files: [],
141 },
142 ],
143 };
145​
146function setup(failedBaseRef: string | null) {
147 const reset = () => {
148 useDiffPanelStore.setState({
149 byThreadKey: {},
150 branchBaseRefByThreadKey: {},
151 });
152 useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
153 useRightPanelStore.setState({ byThreadKey: {}, threadPanelVisibilityByThreadKey: {} });
154 };
155 reset();
156 state.diffFilesCollapsed = false;
157 state.project = { workspaceRoot: "/project", repositoryIdentity: null };
158 state.toolCallItem = null;
159 state.checkpoints = [];
160 state.checkpointDiff = null;
161 const patch = Atom.make<AsyncResult.AsyncResult<ReviewDiffPreviewSource, Error>>(
162 AsyncResult.initial(),
163 );
164 state.patch = patch;
165 state.threadRef = {
166 environmentId: EnvironmentId.make("environment"),
167 threadId: ThreadId.make("thread"),
168 };
169 state.thread = makeThreadFixture({
170 ...state.threadRef,
171 id: state.threadRef.threadId,
172 projectId: ProjectId.make("project"),
173 branch: "dev",
174 worktreePath: cwd,
175 });
176 state.previews.clear();
177 state.previews.set(null, Atom.make(AsyncResult.success(preview())));
178 state.previews.set("main", Atom.make(AsyncResult.success(preview())));
179 state.previews.set(failedBaseRef, Atom.make(AsyncResult.fail(new Error(errorMessage))));
180 state.config = Atom.make(null);
181 state.status = Atom.make(
182 AsyncResult.success({
183 isRepo: true,
184 hasPrimaryRemote: true,
185 isDefaultRef: false,
186 refName: "dev",
187 hasWorkingTreeChanges: false,
188 workingTree: { rootPath: cwd, files: [], insertions: 0, deletions: 0 },
189 hasUpstream: true,
190 aheadCount: 0,
191 behindCount: 0,
192 pr: null,
193 }),
194 );
195 const refs = (names: string[], isRemote: boolean): VcsListRefsResult => ({
196 isRepo: true,
197 hasPrimaryRemote: true,
198 nextCursor: null,
199 totalCount: names.length,
200 refs: names.map((name) => ({
201 name,
202 isRemote,
203 ...(isRemote ? { remoteName: "origin" } : {}),
204 current: name === "dev",
205 isDefault: name === "main",
206 worktreePath: null,
207 })),
208 });
209 state.localRefs = Atom.make(AsyncResult.success(refs(["dev", "main"], false)));
210 state.remoteRefs = Atom.make(AsyncResult.success(refs(["origin/orphan"], true)));
211 state.commits = Atom.make(AsyncResult.success({ commits: [], truncated: false }));
212 useDiffPanelStore.getState().selectBranchBaseRef(state.threadRef, failedBaseRef);
213 const registry = AtomRegistry.make();
214 return {
215 registry,
216 patch,
217 threadRef: state.threadRef,
218 [Symbol.dispose]() {
219 registry.dispose();
220 reset();
221 },
222 };
224​
225it.each([
226 {
227 name: "a saved unrelated branch",
228 failedBaseRef: "origin/orphan",
229 recovery: "Automatic",
230 baseRef: null,
231 },
232 {
233 name: "an automatic base with unrelated history",
234 failedBaseRef: null,
235 recovery: "main",
236 baseRef: "main",
237 },
238])(
239 "recovers from $name without leaving the diff panel",
240 async ({ failedBaseRef, recovery, baseRef }) => {
241 using context = setup(failedBaseRef);
242 await using screen = await render(
243 <RegistryContext.Provider value={context.registry}>
244 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
245 </RegistryContext.Provider>,
246 );
247 await expect.element(screen.getByText(errorMessage, { exact: true })).toBeVisible();
248 const selector = screen.getByRole("combobox", { name: /Change comparison target/ });
249 await vi.waitFor(() => expect(selector.query()).not.toBeNull());
250 await userEvent.click(selector);
251 await expect.element(page.getByRole("option", { name: "main", exact: true })).toBeVisible();
252 await userEvent.click(page.getByRole("option", { name: recovery, exact: true }));
253 await expect.element(screen.getByText("No net changes in this selection.")).toBeVisible();
254 await expect.element(screen.getByText(errorMessage, { exact: true })).not.toBeInTheDocument();
255 const key = scopedThreadKey(context.threadRef);
256 await vi.waitFor(() => {
257 expect(useDiffPanelStore.getState().byThreadKey[key]).toEqual({ kind: "branch", baseRef });
258 expect(useDiffPanelStore.getState().branchBaseRefByThreadKey[key]).toBe(baseRef);
259 });
260 },
261);
262​
263it("opens a repository-relative file from a nested project without a remote", async () => {
264 using context = setup("origin/orphan");
265 state.thread = { ...state.thread!, worktreePath: null };
266 const path = "project/back\\slash.txt";
267 const metadata = preview();
268 const source = {
269 ...metadata.sources[0]!,
270 files: [{ path, previousPath: null, additions: 1, deletions: 0 }],
271 };
272 state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
273 state.status = Atom.make(
274 AsyncResult.success({
275 ...AsyncResult.getOrElse(context.registry.get(state.status), () => {
276 throw new Error("Missing status");
277 }),
278 workingTree: { rootPath: "/", files: [], insertions: 0, deletions: 0 },
279 }),
280 );
281 useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
282 await using screen = await render(
283 <RegistryContext.Provider value={context.registry}>
284 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
285 </RegistryContext.Provider>,
286 );
287 await userEvent.click(screen.getByText(path, { exact: true }));
288 expect(
289 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, context.threadRef),
290 ).toMatchObject({ activeSurfaceId: "file:back\\slash.txt" });
291});
292​
293it("explains a branch diff whose only changes are hidden test files", async () => {
294 using context = setup("origin/orphan");
295 using _hideTestFiles = {
296 [Symbol.dispose]() {
297 window.localStorage.removeItem("t3code.diffHideTestFiles");
298 },
299 };
300 const path = "math.test.ts";
301 const metadata = preview();
302 const source = {
303 ...metadata.sources[0]!,
304 files: [{ path, previousPath: null, additions: 1, deletions: 0 }],
305 };
306 state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
307 useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
308 await using screen = await render(
309 <RegistryContext.Provider value={context.registry}>
310 <div style={{ height: 600, display: "flex", flexDirection: "column" }}>
311 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
312 </div>
313 </RegistryContext.Provider>,
314 );
315 await expect.element(screen.getByText(path, { exact: true })).toBeVisible();
316 await userEvent.click(screen.getByRole("button", { name: "Hide test files", exact: true }));
317 await expect.element(screen.getByText(path, { exact: true })).not.toBeInTheDocument();
318 await expect.element(screen.getByText("1 test file hidden", { exact: true })).toBeVisible();
319 await userEvent.click(screen.getByRole("button", { name: "Show test files", exact: true }));
320 await expect.element(screen.getByText(path, { exact: true })).toBeVisible();
321});
322​
323it.each([false, true])(
324 "expands an unloaded file on the first click with default collapse %s",
325 async (collapsed) => {
326 using context = setup("origin/orphan");
327 state.diffFilesCollapsed = collapsed;
328 const path = `pending-${collapsed}.txt`;
329 const metadata = preview();
330 const source = {
331 ...metadata.sources[0]!,
332 files: [{ path, previousPath: null, additions: 1, deletions: 1 }],
333 };
334 state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
335 useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
336 await using screen = await render(
337 <RegistryContext.Provider value={context.registry}>
338 <div style={{ height: 600, display: "flex", flexDirection: "column" }}>
339 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
340 </div>
341 </RegistryContext.Provider>,
342 );
343 const toggle = screen.getByRole("button", { name: `Expand ${path}`, exact: true });
344 await expect.element(toggle).toHaveAttribute("aria-expanded", "false");
345 await userEvent.click(toggle);
346 await act(() =>
347 context.registry.set(
348 context.patch,
349 AsyncResult.success({
350 ...source,
351 diff: `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1 +1 @@\n-before\n+after\n`,
352 }),
353 ),
354 );
355 const loadedToggle = screen.getByRole("button", { name: `Collapse ${path}`, exact: true });
356 await expect.element(loadedToggle).toHaveAttribute("aria-expanded", "true");
357 await expect.element(screen.getByText("after", { exact: true })).toBeVisible();
358 await userEvent.click(loadedToggle);
359 await expect.element(toggle).toHaveAttribute("aria-expanded", "false");
360 },
361);
362​
363it("previews a changed image when its file row is expanded", async () => {
364 using context = setup("origin/orphan");
365 const path = "changed.png";
366 const metadata = preview();
367 const source = {
368 ...metadata.sources[0]!,
369 files: [{ path, previousPath: null, additions: 0, deletions: 0 }],
370 };
371 state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
372 useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
373 await using screen = await render(
374 <RegistryContext.Provider value={context.registry}>
375 <div style={{ height: 600, display: "flex", flexDirection: "column" }}>
376 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
377 </div>
378 </RegistryContext.Provider>,
379 );
380 await userEvent.click(screen.getByRole("button", { name: `Expand ${path}`, exact: true }));
381 await act(() =>
382 context.registry.set(
383 context.patch,
384 AsyncResult.success({
385 ...source,
386 diff: `diff --git a/${path} b/${path}\nindex 19fc4a5..fd0af9e 100644\nBinary files a/${path} and b/${path} differ\n`,
387 }),
388 ),
389 );
390 await expect
391 .element(screen.getByRole("button", { name: `Collapse ${path}`, exact: true }))
392 .toHaveAttribute("aria-expanded", "true");
393 await expect.element(screen.getByRole("img", { name: path })).toBeVisible();
394});
395​
396it("says a turn diff cut off at the server's size limit is incomplete", async () => {
397 using context = setup("origin/orphan");
398 state.checkpoints = [
399 {
400 runId: "run",
401 checkpointTurnCount: 1,
402 checkpointRef: "ref",
403 status: "ready",
404 files: [],
405 assistantMessageId: null,
406 completedAt: "2026-01-01T00:00:00Z",
407 },
408 ];
409 state.checkpointDiff = {
410 diff: "diff --git a/first.txt b/first.txt\n--- a/first.txt\n+++ b/first.txt\n@@ -0,0 +1 @@\n+visible\n\n[truncated]",
411 };
412 useDiffPanelStore.getState().selectTurn(context.threadRef, RunId.make("run"));
413 await using screen = await render(
414 <RegistryContext.Provider value={context.registry}>
415 <div style={{ height: 600, display: "flex", flexDirection: "column" }}>
416 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
417 </div>
418 </RegistryContext.Provider>,
419 );
420 await expect.element(screen.getByText("first.txt", { exact: true }).first()).toBeVisible();
421 await expect
422 .element(screen.getByText("This preview exceeds the size limit. Changes shown are incomplete."))
423 .toBeVisible();
424});
425​
426it("shows a turn's repositories in a folder that is not a Git repository", async () => {
427 using context = setup("origin/orphan");
428 state.status = Atom.make(
429 AsyncResult.success({
430 isRepo: false,
431 hasPrimaryRemote: false,
432 isDefaultRef: false,
433 refName: null,
434 hasWorkingTreeChanges: false,
435 workingTree: { files: [], insertions: 0, deletions: 0 },
436 hasUpstream: false,
437 aheadCount: 0,
438 behindCount: 0,
439 pr: null,
440 }),
441 );
442 const patch = (path: string) =>
443 `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1 +1 @@\n-before\n+after\n`;
444 const repository = (name: string) => ({
445 scopeId: CheckpointScopeId.make(`scope-${name}`),
446 name,
447 repositoryPath: `${cwd}/${name}`,
448 cwd: `${cwd}/${name}`,
449 relativePath: name,
450 files: [{ path: "README.md", kind: "modified", additions: 1, deletions: 1 }],
451 baselineMissing: false,
452 });
453 state.checkpoints = [
454 {
455 runId: RunId.make("run-1"),
456 checkpointTurnCount: 1,
457 checkpointRef: CheckpointRef.make("refs/t3/root-1"),
458 status: "missing",
459 files: [],
460 repositories: [repository("api"), repository("web")],
461 assistantMessageId: null,
462 completedAt: "2026-11-10T00:00:00.000Z",
463 },
464 ];
465 state.checkpointDiff = {
466 threadId: context.threadRef.threadId,
467 fromTurnCount: 0,
468 toTurnCount: 1,
469 diff: "",
470 repositories: ["api", "web"].map((name) => ({
471 name,
472 repositoryPath: `${cwd}/${name}`,
473 relativePath: name,
474 diff: patch("README.md"),
475 })),
476 };
477 await using screen = await render(
478 <RegistryContext.Provider value={context.registry}>
479 <div style={{ height: 600, width: 390, display: "flex", flexDirection: "column" }}>
480 <DiffPanel
481 mode="embedded"
482 composerDraftTarget={context.threadRef}
483 workspaceMutationId={null}
484 visible
485 />
486 </div>
487 </RegistryContext.Provider>,
488 );
489 const api = screen.getByRole("button", { name: "Collapse api/README.md", exact: true });
490 const web = screen.getByRole("button", { name: "Collapse web/README.md", exact: true });
491 await expect.element(api).toBeVisible();
492 await expect.element(web).toBeVisible();
493 // Both pickers keep their labels in a phone-width panel.
494 await expect.element(screen.getByText("Latest turn", { exact: true })).toBeVisible();
495 const picker = screen.getByRole("button", { name: "Repository: All repositories" });
496 await expect.element(picker.getByText("All repositories")).toBeVisible();
497 await userEvent.click(picker);
498 await userEvent.click(page.getByRole("menuitemradio", { name: "web" }));
499 await expect.element(web).toBeVisible();
500 await expect.element(api).not.toBeInTheDocument();
501});
502​
503// Paths as git's numstat reports them; the parsed patch keeps their edge whitespace.
504it.each([
505 { path: " leading.ts", name: " leading.ts" },
506 { path: "src/trailing.ts ", name: "src/trailing.ts " },
507])("reveals the turn file $path picked from the changed files", async ({ path, name }) => {
508 using context = setup("origin/orphan");
509 state.diffFilesCollapsed = true;
510 state.checkpoints = [
511 {
512 runId: "run",
513 checkpointTurnCount: 1,
514 checkpointRef: "ref",
515 status: "ready",
516 files: [],
517 assistantMessageId: null,
518 completedAt: "2026-01-01T00:00:00Z",
519 },
520 ];
521 state.checkpointDiff = {
522 diff: `diff --git a/${path} b/${path}\nnew file mode 100644\n--- /dev/null\n+++ b/${path}\t\n@@ -0,0 +1 @@\n+revealed\n`,
523 };
524 useDiffPanelStore.getState().selectTurn(context.threadRef, RunId.make("run"), path);
525 await using screen = await render(
526 <RegistryContext.Provider value={context.registry}>
527 <div style={{ height: 600, display: "flex", flexDirection: "column" }}>
528 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
529 </div>
530 </RegistryContext.Provider>,
531 );
532 await expect
533 .element(screen.getByRole("button", { name: `Collapse ${name}`, exact: true }))
534 .toHaveAttribute("aria-expanded", "true");
535});
536​
537it("opens a tool call diff expanded and uses the path its agent recorded", async () => {
538 using context = setup("origin/orphan");
539 state.diffFilesCollapsed = true;
540 // A local thread in a project that is the repository's apps/web folder.
541 state.thread = { ...state.thread!, worktreePath: null };
542 state.project = { workspaceRoot: "/repo/apps/web", repositoryIdentity: { rootPath: "/repo" } };
543 const status = AsyncResult.getOrThrow(context.registry.get(state.status));
544 state.status = Atom.make(
545 AsyncResult.success({ ...status, workingTree: { ...status.workingTree, rootPath: "/repo" } }),
546 );
547 // Claude's Edit can record a path relative to the workspace, unlike the repository's diffs.
548 state.toolCallItem = {
549 type: "file_change",
550 fileName: "src/a.ts",
551 diffStr: "--- src/a.ts\n+++ src/a.ts\n@@ -1 +1 @@\n-before\n+after\n",
552 };
553 useDiffPanelStore.getState().selectToolCall(context.threadRef, {
554 threadId: context.threadRef.threadId,
555 itemId: TurnItemId.make("edit"),
556 revision: "1",
557 });
558 await using screen = await render(
559 <RegistryContext.Provider value={context.registry}>
560 <div className="flex h-[600px] flex-col">
561 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
562 </div>
563 </RegistryContext.Provider>,
564 );
565 await expect
566 .element(screen.getByRole("button", { name: "Collapse src/a.ts", exact: true }))
567 .toHaveAttribute("aria-expanded", "true");
568 await userEvent.click(screen.getByText("src/a.ts", { exact: true }));
569 await vi.waitFor(() =>
570 expect(
571 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, context.threadRef),
572 ).toMatchObject({ activeSurfaceId: "file:src/a.ts" }),
573 );
574});
575​
576it("filters base-ref dropdown rows against the search query", async () => {
577 using context = setup("origin/orphan");
578 useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
579 await using screen = await render(
580 <RegistryContext.Provider value={context.registry}>
581 <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
582 </RegistryContext.Provider>,
583 );
584 await userEvent.click(screen.getByRole("combobox", { name: /Change comparison target/ }));
585 const searchInput = page.getByPlaceholder("Search refs...");
586 const automaticOption = page.getByRole("option", { name: "Automatic", exact: true });
587 const mainOption = page.getByRole("option", { name: "main", exact: true });
588 const remoteOption = page.getByRole("option", { name: /origin\/orphan/ });
589​
590 await expect.element(automaticOption).toBeVisible();
591 await expect.element(mainOption).toBeVisible();
592 await expect.element(remoteOption).toBeVisible();
593​
594 await userEvent.fill(searchInput, "zzz-no-match");
595 await expect.element(page.getByText("No matching refs.", { exact: true })).toBeVisible();
596 await expect.element(automaticOption).not.toBeInTheDocument();
597 await expect.element(mainOption).not.toBeInTheDocument();
598 await expect.element(remoteOption).not.toBeInTheDocument();
599​
600 await userEvent.fill(searchInput, "main");
601 await expect.element(mainOption).toBeVisible();
602 await expect.element(automaticOption).not.toBeInTheDocument();
603 await expect.element(remoteOption).not.toBeInTheDocument();
604​
605 await userEvent.clear(searchInput);
606 await expect.element(automaticOption).toBeVisible();
607 await expect.element(mainOption).toBeVisible();
608 await expect.element(remoteOption).toBeVisible();
609});