Skip to content

Commit a037368

Browse files
committed
fix(web): resolve nested diff files without a remote
1 parent 59e4b3f commit a037368

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

‎apps/web/src/components/DiffPanel.browser.test.tsx‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ vi.mock("./DiffFilePathCopyButton", () => ({ DiffFilePathCopyButton: () => null
9191

9292
import DiffPanel from "./DiffPanel";
9393
import { useDiffPanelSessionStore, useDiffPanelStore } from "~/diffPanelStore";
94+
import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore";
9495

9596
const cwd = "/project-worktree";
9697
const errorMessage = "Could not find a common commit between 'origin/orphan' and HEAD.";
@@ -124,6 +125,7 @@ function setup(failedBaseRef: string | null) {
124125
keepSelectionOnOpenThreadKey: null,
125126
});
126127
useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
128+
useRightPanelStore.setState({ byThreadKey: {}, threadPanelVisibilityByThreadKey: {} });
127129
};
128130
reset();
129131
state.diffFilesCollapsed = false;
@@ -229,6 +231,36 @@ it.each([
229231
},
230232
);
231233

234+
it("opens a repository-relative file from a nested project without a remote", async () => {
235+
using context = setup("origin/orphan");
236+
state.thread = { ...state.thread!, worktreePath: null };
237+
const path = "project/back\\slash.txt";
238+
const metadata = preview();
239+
const source = {
240+
...metadata.sources[0]!,
241+
files: [{ path, previousPath: null, additions: 1, deletions: 0 }],
242+
};
243+
state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
244+
state.status = Atom.make(
245+
AsyncResult.success({
246+
...AsyncResult.getOrElse(context.registry.get(state.status), () => {
247+
throw new Error("Missing status");
248+
}),
249+
workingTree: { rootPath: "/", files: [], insertions: 0, deletions: 0 },
250+
}),
251+
);
252+
useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
253+
await using screen = await render(
254+
<RegistryContext.Provider value={context.registry}>
255+
<DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
256+
</RegistryContext.Provider>,
257+
);
258+
await userEvent.click(screen.getByText(path, { exact: true }));
259+
expect(
260+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, context.threadRef),
261+
).toMatchObject({ activeSurfaceId: "file:back\\slash.txt" });
262+
});
263+
232264
it.each([false, true])(
233265
"expands an unloaded file on the first click with default collapse %s",
234266
async (collapsed) => {

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ export default function DiffPanel({
257257
: null,
258258
);
259259
const activeCwd = activeThread?.worktreePath ?? activeProject?.workspaceRoot;
260-
const activeRepositoryRoot = activeThread?.worktreePath
261-
? undefined
262-
: activeProject?.repositoryIdentity?.rootPath;
263260
const serverConfig = useAtomValue(
264261
serverEnvironment.configValueAtom(activeThread?.environmentId ?? null),
265262
);
@@ -277,6 +274,9 @@ export default function DiffPanel({
277274
})
278275
: null,
279276
);
277+
const activeRepositoryRoot =
278+
gitStatusQuery.data?.workingTree.rootPath ??
279+
(activeThread?.worktreePath ? undefined : activeProject?.repositoryIdentity?.rootPath);
280280
const diffSelection = useDiffPanelStore((state) =>
281281
selectThreadDiffPanelSelection(state.byThreadKey, routeThreadRef),
282282
);

‎apps/web/src/components/chat/TimelineAssistantRows.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../times
2323
import { useV2ItemSupport } from "../../state/v2ItemSupport";
2424
import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
2525
import { MESSAGE_HEADING_LEVEL, MessageAuthorHeading } from "./TimelineRowParts";
26+
import { useAtomValue } from "@effect/atom-react";
27+
import { AsyncResult, Atom } from "effect/reactivity";
28+
import { vcsEnvironment } from "../../state/vcs";
29+
30+
const NO_VCS_STATUS = Atom.make(AsyncResult.initial());
2631

2732
export function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
2833
const ctx = use(TimelineRowCtx);
@@ -349,6 +354,15 @@ function AssistantChangedFilesSectionInner({
349354
: null,
350355
);
351356
const onFileContextMenu = useFileContextMenuHandler(ctx.activeThreadEnvironmentId);
357+
const repositoryRoot = useAtomValue(
358+
ctx.workspaceRoot
359+
? vcsEnvironment.status({
360+
environmentId: ctx.activeThreadEnvironmentId,
361+
input: { cwd: ctx.workspaceRoot },
362+
})
363+
: NO_VCS_STATUS,
364+
(status) => AsyncResult.getOrElse(status, () => null)?.workingTree.rootPath,
365+
);
352366

353367
return (
354368
<ChangedFilesCard
@@ -368,9 +382,10 @@ function AssistantChangedFilesSectionInner({
368382
filePath,
369383
workspaceRoot: ctx.workspaceRoot,
370384
repositoryRoot:
371-
thread?.worktreePath == null
385+
repositoryRoot ??
386+
(thread?.worktreePath == null
372387
? activeProject?.repositoryIdentity?.rootPath
373-
: undefined,
388+
: undefined),
374389
},
375390
event,
376391
)

0 commit comments

Comments
 (0)