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
54 changes: 38 additions & 16 deletions apps/web/src/diffFileActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,45 @@ describe("openDiffFilePrimaryAction", () => {
).toBe("index.ts");
});

it.each(["backend/server.ts", "frontend2/app.ts", "frontend/../secret.ts", "C:secret.ts"])(
"does not open an out-of-project diff path: %s",
(filePath) => {
const openInEditor = vi.fn();

openDiffFilePrimaryAction({
threadRef: THREAD_REF,
filePath,
activeCwd: "/repo/frontend",
repositoryRoot: "/repo",
openInEditor,
});

it.each([
{
filePath: "/repo/frontend/src/index.ts",
workspaceRoot: "/repo/frontend",
expected: "src/index.ts",
},
{ filePath: "c:\\Repo\\src\\index.ts", workspaceRoot: "C:\\repo", expected: "src/index.ts" },
])(
"opens absolute diff paths inside the workspace: $filePath",
({ filePath, workspaceRoot, expected }) => {
expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
).toMatchObject({ isOpen: false });
expect(openInEditor).not.toHaveBeenCalled();
resolveDiffPathForWorkspace({ filePath, workspaceRoot, repositoryRoot: workspaceRoot }),
).toBe(expected);
},
);

it.each([
"backend/server.ts",
"frontend2/app.ts",
"frontend/../secret.ts",
"C:secret.ts",
"/repo/backend/server.ts",
"/repo/frontend/../backend/server.ts",
"/repo/frontend",
"/etc/passwd",
])("does not open an out-of-project diff path: %s", (filePath) => {
const openInEditor = vi.fn();

openDiffFilePrimaryAction({
threadRef: THREAD_REF,
filePath,
activeCwd: "/repo/frontend",
repositoryRoot: "/repo",
openInEditor,
});

expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
).toMatchObject({ isOpen: false });
expect(openInEditor).not.toHaveBeenCalled();
});
});
14 changes: 13 additions & 1 deletion apps/web/src/diffFileActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { ScopedThreadRef } from "@t3tools/contracts";
import { isWindowsAbsolutePath, normalizeProjectPathForComparison } from "@t3tools/shared/path";
import {
isAbsolutePath,
isWindowsAbsolutePath,
normalizeProjectPathForComparison,
workspaceRelativeFilePath,
} from "@t3tools/shared/path";

import { useRightPanelStore } from "./rightPanelStore";
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
Expand Down Expand Up @@ -52,6 +57,13 @@ export function resolveDiffPathForWorkspace(input: {
readonly workspaceRoot: string | undefined;
readonly repositoryRoot: string | undefined;
}): string | null {
// Claude and ACP tool-call diffs name files by absolute path.
if (isAbsolutePath(input.filePath)) {
const relativePath = workspaceRelativeFilePath(input.filePath, input.workspaceRoot);
const segments = relativePath === null ? null : normalizedRelativePathSegments(relativePath);
return segments ? segments.join("/") : null;
}

const fileSegments = normalizedRelativePathSegments(input.filePath);
if (!fileSegments) return null;

Expand Down
Loading