feat(web): add a file tree to the diff panel and pull request code tab (#9330)

Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Shpetim <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-09-02 20:58:10 -07:00
1 parent f5fbb1bcb0
commit 1aa44a071f
8 files changed
+686 -168

No files matched your search

@@ -0,0 +1,69 @@
import type { FileDiffMetadata } from "@pierre/diffs";
import { describe, expect, it } from "vite-plus/test";
import {
buildDiffFileTreeUpdates,
collectDirectoryPaths,
diffFileTreeEntries,
} from "./diffFileTree.logic";
function file(type: FileDiffMetadata["type"], name: string, prevName = name): FileDiffMetadata {
return { type, name: `b/${name}`, prevName: `a/${prevName}` } as FileDiffMetadata;
}
describe("diffFileTreeEntries", () => {
it("maps each change type to its git status under the file's current path", () => {
expect(
diffFileTreeEntries([
file("new", "src/a.ts"),
file("deleted", "src/b.ts"),
file("rename-pure", "src/c.ts", "src/old-c.ts"),
file("rename-changed", "src/d.ts", "src/old-d.ts"),
file("change", "README.md"),
]),
).toEqual([
{ path: "src/a.ts", status: "added" },
{ path: "src/b.ts", status: "deleted" },
{ path: "src/c.ts", status: "renamed" },
{ path: "src/d.ts", status: "renamed" },
{ path: "README.md", status: "modified" },
]);
});
});
describe("collectDirectoryPaths", () => {
it("lists every ancestor once, parents first, with Pierre's trailing slash", () => {
expect(collectDirectoryPaths(["apps/web/src/a.ts", "apps/web/b.ts", "README.md"])).toEqual([
"apps/",
"apps/web/",
"apps/web/src/",
]);
});
});
describe("buildDiffFileTreeUpdates", () => {
it("adds a new file's directories before the file", () => {
expect(buildDiffFileTreeUpdates(["README.md"], ["README.md", "src/lib/a.ts"])).toEqual([
{ type: "add", path: "src/" },
{ type: "add", path: "src/lib/" },
{ type: "add", path: "src/lib/a.ts" },
]);
});
it("removes files before their now-empty directories, deepest first", () => {
expect(buildDiffFileTreeUpdates(["src/lib/a.ts", "src/b.ts"], ["src/b.ts"])).toEqual([
{ type: "remove", path: "src/lib/a.ts" },
{ type: "remove", path: "src/lib/", recursive: true },
]);
});
it("keeps a directory that still holds a file", () => {
expect(buildDiffFileTreeUpdates(["src/a.ts", "src/b.ts"], ["src/b.ts"])).toEqual([
{ type: "remove", path: "src/a.ts" },
]);
});
it("produces nothing when the paths are unchanged", () => {
expect(buildDiffFileTreeUpdates(["src/a.ts"], ["src/a.ts"])).toEqual([]);
});
});