Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/web/src/components/ChatMarkdown.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ vi.mock(import("../state/filesystem"), async (original) => {
: actual.useFilesystemReadAccess(environmentId)) as never,
};
});
const threadWorktrees = vi.hoisted(() => new Map<string, string>());
vi.mock(import("../state/entities"), async (original) => {
const actual = await original();
return {
...actual,
readThreadShell: ((ref: { threadId: string }) => {
const worktreePath = threadWorktrees.get(ref.threadId);
return worktreePath === undefined ? actual.readThreadShell(ref as never) : { worktreePath };
}) as never,
};
});
vi.mock(import("../remoteOpen"), async (original) => ({
...(await original()),
useRemoteOpenResolution: () => ({ state: { mode: "local-exec" }, isResolved: true }) as never,
Expand Down Expand Up @@ -170,6 +181,7 @@ function setup() {
parsedSources.length = 0;
settingsOverrides.mathRenderingEnabled = false;
renderDiagram.mockReset();
threadWorktrees.clear();
workspaceSearch.mockReset().mockResolvedValue(AsyncResult.success({ entries: [] }));
filesystemMetadata.mockReset().mockResolvedValue(AsyncResult.success({ entries: [null] }));
}
Expand Down Expand Up @@ -559,6 +571,27 @@ describe("ChatMarkdown workspace file opens", () => {
expect(workspaceSearch).toHaveBeenCalledOnce();
});

it("opens a path from markdown rendered in another checkout under that checkout", async () => {
setup();
const scratchThread = { ...threadRef, threadId: ThreadId.make("scratch-thread") };
threadWorktrees.set(scratchThread.threadId, "/scratch/thread");
filesystemMetadata.mockResolvedValue(AsyncResult.success({ entries: [{ kind: "file" }] }));
using openFile = vi.spyOn(useRightPanelStore.getState(), "openFile");
await using screen = await renderText("[State](packages/state/filesystem.ts)", {
cwd: "/repo-a",
threadRef: scratchThread,
});
await act(async () => screen.container.querySelector("a")!.click());

await vi.waitFor(() =>
expect(openFile).toHaveBeenCalledExactlyOnceWith(
scratchThread,
"/repo-a/packages/state/filesystem.ts",
undefined,
),
);
});

it.each([
["its own panel", "thread-own-panel", false],
["its parent's panel from a side chat", "thread-side-chat", true],
Expand Down
18 changes: 17 additions & 1 deletion apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,24 @@ function useChatMarkdownState(
};
const openFileInPanel = (fileLinkMeta: MarkdownFileLinkMeta, panelPath: string) => {
if (!threadRef) return;
// The panel reads relative paths from the thread's folder. A pull request body's `cwd` is the
// checkout of its repository, which can be another folder.
const shell = readThreadShell(threadRef);
const panelRoot =
shell?.worktreePath ??
projects.find(
(project) => project.environmentId === environmentId && project.id === shell?.projectId,
)?.workspaceRoot;
const openAt = (path: string) =>
useRightPanelStore.getState().openFile(threadRef, path, fileLinkMeta.line);
useRightPanelStore
.getState()
.openFile(
threadRef,
cwd && panelRoot !== undefined && cwd !== panelRoot
? resolveWorkspaceFilePath(path, cwd)
: path,
fileLinkMeta.line,
);
if (
fileLinkMeta.workspaceLookupPath === null ||
!cwd ||
Expand Down
Loading