TypeScript
refactor(web): remove obsolete changed-files preview helpers (#9956)
Julius Marmingeeae770b12555
diff --git a/apps/web/src/components/chat/changedFilesPresentation.test.ts b/apps/web/src/components/chat/changedFilesPresentation.test.tsdeleted file mode 100644index d13445b0226..00000000000--- a/apps/web/src/components/chat/changedFilesPresentation.test.ts+++ /dev/null@@ -1,69 +0,0 @@-import { describe, expect, it } from "vite-plus/test";--import {- changedFileName,- selectChangedFilePreview,- shouldAutoExpandChangedFiles,- summarizeChangedFileScopes,-} from "./changedFilesPresentation";--describe("changed-files presentation", () => {- it("auto-expands only small, low-churn latest changes", () => {- const smallFiles = [- { path: "src/a.ts", kind: "modified", additions: 80, deletions: 20 },- { path: "src/b.ts", kind: "modified", additions: 60, deletions: 20 },- ];-- expect(shouldAutoExpandChangedFiles(smallFiles, true)).toBe(true);- expect(shouldAutoExpandChangedFiles(smallFiles, false)).toBe(false);- expect(- shouldAutoExpandChangedFiles(- [{ path: "src/a.ts", kind: "modified", additions: 201, deletions: 0 }],- true,- ),- ).toBe(false);- expect(- shouldAutoExpandChangedFiles(- Array.from({ length: 6 }, (_, index) => ({- path: `src/${index}.ts`,- kind: "modified",- additions: 1,- deletions: 0,- })),- true,- ),- ).toBe(false);- });-- it("summarizes the most prominent top-level scopes", () => {- const files = [- { path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },- { path: "README.md", kind: "modified", additions: 1, deletions: 0 },- { path: "apps/server/src/index.ts", kind: "modified", additions: 1, deletions: 0 },- { path: "packages/shared/src/git.ts", kind: "modified", additions: 1, deletions: 0 },- { path: "apps\\mobile\\App.tsx", kind: "modified", additions: 1, deletions: 0 },- ];-- expect(summarizeChangedFileScopes(files)).toEqual([- { label: "apps", fileCount: 3 },- { label: "root", fileCount: 1 },- { label: "packages", fileCount: 1 },- ]);- });-- it("previews files across different scopes before filling from one scope", () => {- const files = [- { path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },- { path: "apps/web/src/App.test.tsx", kind: "modified", additions: 1, deletions: 0 },- { path: "packages/shared/src/git.ts", kind: "modified", additions: 1, deletions: 0 },- { path: "README.md", kind: "modified", additions: 1, deletions: 0 },- ];-- expect(selectChangedFilePreview(files).map((file) => file.path)).toEqual([- "apps/web/src/App.tsx",- "packages/shared/src/git.ts",- "README.md",- ]);- expect(changedFileName("apps\\web\\src\\App.tsx")).toBe("App.tsx");- });-});diff --git a/apps/web/src/components/chat/changedFilesPresentation.ts b/apps/web/src/components/chat/changedFilesPresentation.tsdeleted file mode 100644index bb3cac6c4b1..00000000000--- a/apps/web/src/components/chat/changedFilesPresentation.ts+++ /dev/null@@ -1,102 +0,0 @@-import { type TurnDiffFileChange } from "../../types";-import { summarizeTurnDiffStats } from "../../lib/turnDiffTree";--export const CHANGED_FILES_AUTO_EXPAND_FILE_LIMIT = 5;-export const CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT = 200;-export const CHANGED_FILES_PREVIEW_FILE_LIMIT = 3;-export const CHANGED_FILES_PREVIEW_SCOPE_LIMIT = 4;--export interface ChangedFilesScopeSummary {- readonly label: string;- readonly fileCount: number;-}--function pathSegments(pathValue: string): string[] {- return pathValue- .replaceAll("\\", "/")- .split("/")- .filter((segment) => segment.length > 0);-}--export function changedFileName(pathValue: string): string {- return pathSegments(pathValue).at(-1) ?? pathValue;-}--function changedFileScope(pathValue: string): string {- const segments = pathSegments(pathValue);- return segments.length > 1 ? (segments[0] ?? "root") : "root";-}--export function shouldAutoExpandChangedFiles(- files: ReadonlyArray<TurnDiffFileChange>,- isLatestTurn: boolean,-): boolean {- if (!isLatestTurn || files.length > CHANGED_FILES_AUTO_EXPAND_FILE_LIMIT) {- return false;- }- const stat = summarizeTurnDiffStats(files);- return stat.additions + stat.deletions <= CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT;-}--export function summarizeChangedFileScopes(- files: ReadonlyArray<TurnDiffFileChange>,- limit = CHANGED_FILES_PREVIEW_SCOPE_LIMIT,-): ChangedFilesScopeSummary[] {- const scopes = new Map<string, { fileCount: number; firstIndex: number }>();- files.forEach((file, index) => {- const label = changedFileScope(file.path);- const current = scopes.get(label);- scopes.set(label, {- fileCount: (current?.fileCount ?? 0) + 1,- firstIndex: current?.firstIndex ?? index,- });- });-- return Array.from(scopes, ([label, scope]) => ({- label,- fileCount: scope.fileCount,- firstIndex: scope.firstIndex,- }))- .toSorted(- (left, right) =>- right.fileCount - left.fileCount ||- left.firstIndex - right.firstIndex ||- left.label.localeCompare(right.label),- )- .slice(0, limit)- .map(({ label, fileCount }) => ({ label, fileCount }));-}--export function selectChangedFilePreview(- files: ReadonlyArray<TurnDiffFileChange>,- limit = CHANGED_FILES_PREVIEW_FILE_LIMIT,-): TurnDiffFileChange[] {- const selected: TurnDiffFileChange[] = [];- const selectedPaths = new Set<string>();- const selectedScopes = new Set<string>();-- for (const file of files) {- const scope = changedFileScope(file.path);- if (selectedScopes.has(scope)) {- continue;- }- selected.push(file);- selectedPaths.add(file.path);- selectedScopes.add(scope);- if (selected.length === limit) {- return selected;- }- }-- for (const file of files) {- if (selectedPaths.has(file.path)) {- continue;- }- selected.push(file);- if (selected.length === limit) {- break;- }- }-- return selected;-}