Avoid duplicate workspace diff warnings

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-05-15 14:14:08 -05:00
1 parent da7c584b8a
commit 142cc5d3c0
2 files changed
+29 -8

No files matched your search

@@ -92,7 +92,6 @@ export function isLongDiffFile(file: Pick<DiffFileViewModel, "lineCount">) {
export function toFileViewModels(diff: WorkspaceDiffResponse | null | undefined): DiffFileViewModel[] {
return (diff?.files ?? []).map((file) => {
const patchWarnings = file.patches.flatMap((patch) => patch.warnings);
const patches = buildFilePatches(file);
const lineCount = patches.reduce((count, patch) => count + patch.lineCount, 0);
return {
@@ -104,7 +103,7 @@ export function toFileViewModels(diff: WorkspaceDiffResponse | null | undefined)
binary: file.binary,
oversized: file.oversized,
truncated: file.truncated,
warnings: [...file.warnings, ...patchWarnings],
warnings: file.warnings,
patchKinds: file.patches.map((patch) => patch.kind),
patches,
patch: patches.find((patch) => patch.patch)?.patch ?? null,
@@ -119,10 +118,7 @@ export function diffSummary(diff: WorkspaceDiffResponse | null | undefined): Dif
const fileCount = stats?.fileCount ?? 0;
const additions = stats?.additions ?? 0;
const deletions = stats?.deletions ?? 0;
const warningCount = (diff?.warnings.length ?? 0)
+ (diff?.files ?? []).reduce((count, file) => {
return count + file.warnings.length + file.patches.reduce((patchCount, patch) => patchCount + patch.warnings.length, 0);
}, 0);
const warningCount = diff?.warnings.length ?? 0;
return {
changedLabel: `${fileCount} ${fileCount === 1 ? "file" : "files"}`,
@@ -38,20 +38,45 @@ describe("workspace diff UI model", () => {
});
it("surfaces truncation and file warnings", () => {
const warning = { code: "patch_truncated" as const, message: "Patch was truncated.", path: "src/app.ts" };
const file = changedFile({
truncated: true,
warnings: [{ code: "patch_truncated", message: "Patch was truncated.", path: "src/app.ts" }],
warnings: [warning],
patches: [],
});
const diff = diffResponse({ files: [file], truncated: true });
const diff = diffResponse({ files: [file], truncated: true, warnings: [warning] });
expect(buildFilePatch(file)).toBeNull();
expect(toFileViewModels(diff)[0]?.warnings).toEqual([warning]);
expect(diffSummary(diff)).toMatchObject({
warningCount: 1,
truncated: true,
});
});
it("does not duplicate aggregated patch warnings", () => {
const warning = { code: "patch_truncated" as const, message: "Patch was truncated.", path: "src/app.ts" };
const file = changedFile({
warnings: [warning],
patches: [
{
kind: "unstaged",
patch: null,
additions: 0,
deletions: 0,
binary: false,
oversized: false,
truncated: true,
warnings: [warning],
},
],
});
const diff = diffResponse({ files: [file], warnings: [warning] });
expect(toFileViewModels(diff)[0]?.warnings).toEqual([warning]);
expect(diffSummary(diff).warningCount).toBe(1);
});
it("keeps staged and unstaged patches renderable as separate single-file diffs", () => {
const stagedPatch = [
"diff --git a/src/app.ts b/src/app.ts",