The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 12:00 UTC
fix(server): review guides keep excerpts in files with spaces or escaped names (#22053)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 30, 2026 at 15:31 UTC
33c6401bf4ae1d0d3d7402cbb80ffd8ad318ddae
2 files changed
+46
-2
apps/server/src/pullRequest/pullRequestReviewGuideNormalize.test.ts
+31
@@ -91,6 +91,37 @@ describe("parseReviewGuideChange", () => {
91
expect(change.hunks.get("src/gone.ts")).toEqual({ new: [], old: [{ start: 1, end: 20 }] });
92
expect(change.hunks.get("docs/readme.md")).toEqual({ new: [{ start: 3, end: 3 }], old: [] });
93
});
94
+
95
+ it("reads file names git quotes or ends with a tab", () => {
96
+ const unusual = [
97
+ "diff --git a/with space.txt b/with space.txt",
98
+ "--- a/with space.txt\t",
99
+ "+++ b/with space.txt\t",
100
+ "@@ -1,0 +2 @@",
101
+ 'diff --git "a/tab\\tname.txt" "b/tab\\tname.txt"',
102
+ '--- "a/tab\\tname.txt"',
103
+ '+++ "b/tab\\tname.txt"',
104
+ "@@ -1,0 +2 @@",
105
+ 'diff --git "a/back\\\\slash.txt" "b/back\\\\slash.txt"',
106
+ '--- "a/back\\\\slash.txt"',
107
+ '+++ "b/back\\\\slash.txt"',
108
+ "@@ -1,0 +2 @@",
109
+ 'diff --git "a/gone\\tfile.txt" "b/gone\\tfile.txt"',
110
+ '--- "a/gone\\tfile.txt"',
111
+ "+++ /dev/null",
112
+ "@@ -1 +0,0 @@",
113
+ "",
114
+ ].join("\n");
115
+ const names = ["with space.txt", "tab\tname.txt", "back\\slash.txt", "gone\tfile.txt"];
116
+ const parsed = parseReviewGuideChange(names.join("\0"), unusual);
117
+ expect([...parsed.hunks.keys()]).toEqual(names);
118
+ expect(parsed.hunks.get("gone\tfile.txt")).toEqual({ new: [], old: [{ start: 1, end: 1 }] });
119
+ const result = normalizeReviewGuide(
120
+ guide({ stops: [stop({ excerpts: names.slice(0, 3).map((path) => excerpt(path, 1, 5)) })] }),
121
+ parsed,
122
+ );
123
+ expect(result.stops[0]?.excerpts).toEqual(names.slice(0, 3).map((path) => excerpt(path, 2, 2)));
124
+ });
125
});
126
127
describe("normalizeReviewGuide", () => {
apps/server/src/pullRequest/pullRequestReviewGuideNormalize.ts
+15
-2
@@ -1,5 +1,6 @@
1
import type { PullRequestReviewGuideExcerpt, PullRequestReviewGuideStop } from "@t3tools/contracts";
2
import type { ReviewGuideGenerationResult } from "@t3tools/provider-core/server/textGeneration";
3
+import { unquoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
4
5
const MAX_EXCERPT_LINES = 25;
6
@@ -25,6 +26,18 @@ const hunkRange = (start: string, count: string | undefined): LineRange | null =
26
return lines === 0 ? null : { start: Number(start), end: Number(start) + lines - 1 };
27
};
28
29
+/**
30
+ * Git quotes a name holding a tab, quote or backslash, and ends an unquoted name holding a space
31
+ * with a tab, so the first literal tab is never part of what the file is called.
32
+ */
33
+function headerPath(line: string, prefix: string): string | null {
34
+ const rest = line.slice(4);
35
+ const tab = rest.indexOf("\t");
36
+ const token = tab === -1 ? rest : rest.slice(0, tab);
37
+ const path = token.startsWith('"') ? unquoteGitPatchPath(token) : token;
38
+ return path.startsWith(prefix) ? path.slice(prefix.length) : null;
39
+}
40
+
41
export function parseReviewGuideChange(nameOnly: string, patch: string): ReviewGuideChange {
42
const hunks = new Map<string, FileHunks>();
43
let oldPath: string | null = null;
@@ -37,9 +50,9 @@ export function parseReviewGuideChange(nameOnly: string, patch: string): ReviewG
50
current = null;
51
inHunks = false;
52
} else if (!inHunks && line.startsWith("--- ")) {
40
- oldPath = line.startsWith("--- a/") ? line.slice(6) : null;
53
+ oldPath = headerPath(line, "a/");
54
} else if (!inHunks && line.startsWith("+++ ")) {
42
- const path = line.startsWith("+++ b/") ? line.slice(6) : oldPath;
55
+ const path = headerPath(line, "b/") ?? oldPath;
56
if (path === null) continue;
57
current = hunks.get(path) ?? { new: [], old: [] };
58
hunks.set(path, current);