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 21, 09:45 UTC
fix(contracts): preserve whitespace in diff file paths (#37835)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
안동민 committed
Nov 17, 2026 at 11:18 UTC
75683c8f9375bc66771aed60afa0af4acc928659
6 files changed
+127
-19
apps/web/src/lib/diffFileContents.test.ts
+51
@@ -87,6 +87,57 @@ describe("createGitDiffFileContentsLoader", () => {
87
await expect(loader(partialFileDiff())).rejects.toThrow("changed since the diff was loaded");
88
});
89
90
+ it.each([
91
+ {
92
+ name: "a renamed file",
93
+ patch: [
94
+ "diff --git a/ leading.txt b/renamed.txt ",
95
+ "similarity index 100%",
96
+ "rename from leading.txt",
97
+ "rename to renamed.txt ",
98
+ "",
99
+ ],
100
+ oldPath: " leading.txt",
101
+ newPath: "renamed.txt ",
102
+ },
103
+ {
104
+ name: "a modified file",
105
+ patch: [
106
+ "diff --git a/trailing.txt b/trailing.txt ",
107
+ "index 422c2b7..55dce13 100644",
108
+ "--- a/trailing.txt \t",
109
+ "+++ b/trailing.txt \t",
110
+ "@@ -1,2 +1,2 @@",
111
+ " a",
112
+ "-b",
113
+ "+B",
114
+ "",
115
+ ],
116
+ oldPath: "trailing.txt ",
117
+ newPath: "trailing.txt ",
118
+ },
119
+ ])("requests the exact whitespace-edged paths of $name", async ({ patch, oldPath, newPath }) => {
120
+ const requested: Array<{ oldPath: string; newPath: string }> = [];
121
+ const loader = createGitDiffFileContentsLoader(
122
+ async ({ input }) => {
123
+ requested.push({ oldPath: input.oldPath, newPath: input.newPath });
124
+ return AsyncResult.success({ oldContents: "a\nb\n", newContents: "a\nB\n" });
125
+ },
126
+ {
127
+ environmentId: EnvironmentId.make("environment-diff-contents-test"),
128
+ cwd: "/repo",
129
+ sourceKind: "working-tree",
130
+ baseRef: null,
131
+ headRef: null,
132
+ cacheKey: "diff-hash",
133
+ },
134
+ );
135
+
136
+ await loader(parsePartialFileDiff(patch.join("\n")));
137
+
138
+ expect(requested).toEqual([{ oldPath, newPath }]);
139
+ });
140
+
141
it("loads a whitespace-ignored patch whose context shows one side's whitespace", async () => {
142
const patch = [
143
"diff --git a/src/file01.ts b/src/file01.ts",
packages/contracts/src/git.test.ts
+54
-10
@@ -6,12 +6,23 @@ import {
6
GitPreparePullRequestThreadResult,
7
GitRunStackedActionInput,
8
} from "./git.ts";
9
+import { PullRequestDiffFileContentsInput } from "./pullRequest.ts";
10
+import { ReviewDiffFileContentsInput } from "./review.ts";
11
12
const decodeGitCommandError = Schema.decodeUnknownSync(Schema.toCodecJson(GitCommandError));
13
const decodePreparePullRequestThreadResult = Schema.decodeUnknownSync(
14
GitPreparePullRequestThreadResult,
15
);
16
const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
17
+const encodeRunStackedActionInput = Schema.encodeUnknownSync(GitRunStackedActionInput);
18
+const decodeReviewDiffFileContentsInput = Schema.decodeUnknownSync(ReviewDiffFileContentsInput);
19
+const encodeReviewDiffFileContentsInput = Schema.encodeUnknownSync(ReviewDiffFileContentsInput);
20
+const decodePullRequestDiffFileContentsInput = Schema.decodeUnknownSync(
21
+ PullRequestDiffFileContentsInput,
22
+);
23
+const encodePullRequestDiffFileContentsInput = Schema.encodeUnknownSync(
24
+ PullRequestDiffFileContentsInput,
25
+);
26
27
describe("GitCommandError", () => {
28
it("decodes an unknown failure reason as absent", () => {
@@ -50,15 +61,48 @@ describe("GitPreparePullRequestThreadResult", () => {
61
});
62
});
63
53
-describe("GitRunStackedActionInput", () => {
54
- it("preserves leading and trailing whitespace in file paths", () => {
55
- const parsed = decodeRunStackedActionInput({
56
- actionId: "action-1",
57
- cwd: "/repo",
58
- action: "commit",
59
- filePaths: [" leading.txt", "trailing.txt "],
60
- });
61
-
62
- expect(parsed.filePaths).toEqual([" leading.txt", "trailing.txt "]);
64
+describe("Git file paths", () => {
65
+ it.each([
66
+ {
67
+ operation: "commit",
68
+ decode: decodeRunStackedActionInput,
69
+ encode: encodeRunStackedActionInput,
70
+ input: {
71
+ actionId: "action-1",
72
+ cwd: "/repo",
73
+ action: "commit",
74
+ filePaths: [" leading.txt", "trailing.txt "],
75
+ },
76
+ },
77
+ {
78
+ operation: "local diff expansion",
79
+ decode: decodeReviewDiffFileContentsInput,
80
+ encode: encodeReviewDiffFileContentsInput,
81
+ input: {
82
+ cwd: "/repo",
83
+ sourceKind: "working-tree",
84
+ changeType: "rename-changed",
85
+ baseRef: "HEAD",
86
+ headRef: null,
87
+ oldPath: " leading.txt",
88
+ newPath: "trailing.txt ",
89
+ },
90
+ },
91
+ {
92
+ operation: "pull request diff expansion",
93
+ decode: decodePullRequestDiffFileContentsInput,
94
+ encode: encodePullRequestDiffFileContentsInput,
95
+ input: {
96
+ projectId: "project-1",
97
+ repository: "owner/repo",
98
+ number: 1,
99
+ changeType: "rename-changed",
100
+ oldPath: " leading.txt",
101
+ newPath: "trailing.txt ",
102
+ },
103
+ },
104
+ ])("preserves leading and trailing whitespace for $operation", ({ decode, encode, input }) => {
105
+ expect(decode(input)).toEqual(input);
106
+ expect(encode(input)).toEqual(input);
107
});
108
});
packages/contracts/src/pullRequest.ts
+2
-2
@@ -754,8 +754,8 @@ export const PullRequestDiffFileContentsInput = Schema.Struct({
754
...PullRequestRef.fields,
755
commit: Schema.optional(TrimmedNonEmptyString),
756
changeType: Schema.Literals(["change", "rename-pure", "rename-changed", "new", "deleted"]),
757
- oldPath: TrimmedNonEmptyString,
758
- newPath: TrimmedNonEmptyString,
757
+ oldPath: Schema.NonEmptyString,
758
+ newPath: Schema.NonEmptyString,
759
});
760
export type PullRequestDiffFileContentsInput = typeof PullRequestDiffFileContentsInput.Type;
761
packages/contracts/src/review.ts
+2
-2
@@ -86,8 +86,8 @@ export const ReviewDiffFileContentsInput = Schema.Struct({
86
changeType: ReviewDiffChangeType,
87
baseRef: Schema.NullOr(TrimmedNonEmptyString),
88
headRef: Schema.NullOr(TrimmedNonEmptyString),
89
- oldPath: TrimmedNonEmptyString,
90
- newPath: TrimmedNonEmptyString,
89
+ oldPath: Schema.NonEmptyString,
90
+ newPath: Schema.NonEmptyString,
91
});
92
export type ReviewDiffFileContentsInput = typeof ReviewDiffFileContentsInput.Type;
93
patches/@pierre__diffs@1.7.0-beta.4.patch
+13
@@ -134,6 +134,19 @@ index 96d4fb137ea683b66381b1ce6e47e8708a89366c..13f2564897a5bf53a8f311300003b3ea
134
}
135
/**
136
* Re-measure the '0' character width against the font that is loaded right
137
+diff --git a/dist/utils/parsePatchFiles.js b/dist/utils/parsePatchFiles.js
138
+index 48568bd..f27123f 100644
139
+--- a/dist/utils/parsePatchFiles.js
140
++++ b/dist/utils/parsePatchFiles.js
141
+@@ -339,7 +339,7 @@ function parsePatchFiles(data, options = {}) {
142
+ return patches;
143
+ }
144
+ function decodeDiffFileName(value, stripGitPrefix = false) {
145
+- const rawName = value.trim();
146
++ const rawName = value.replace(/[\t\r\n]+$/, "");
147
+ const name = rawName.startsWith("\"") ? parseQuotedDiffFileName(rawName)?.fileName ?? rawName : rawName;
148
+ return stripGitPrefix && (name.startsWith("a/") || name.startsWith("b/")) ? name.slice(2) : name;
149
+ }
150
diff --git a/package.json b/package.json
151
index d1fa4d5d79ba70b6cd990b0ac9df5206fe55b58d..8762624a075174f5d9f35224cf091596d951a1a7 100644
152
--- a/package.json
pnpm-lock.yaml
+5
-5
@@ -372,7 +372,7 @@ patchedDependencies:
372
'@ff-labs/fff-node@0.11.0': 93f62a76399b435a76588b2bef237db0a1e85880c1ac0d0759c416e9cc579252
373
'@legendapp/list@3.7.2': fc8470158c72676c35f43a0a84f90e53105c3eedd930e242534a37ff4159a3ef
374
'@muse-code/sdk@1.4.6': 7b495b607fc5d76b444c7c4d58821e839726a30e6f3c53564f0d59f2d5b42101
375
- '@pierre/diffs@1.7.0-beta.4': 241563d810c29250e0e92f3eda74214393726d46667fedbf1f91a5f5bea07d1e
375
+ '@pierre/diffs@1.7.0-beta.4': b24b206d14c79de95be10322b96490b82e41cc13c8a02c7378aaf8e03623431b
376
'@react-native-ai/apple@0.12.0': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
377
'@react-native-menu/menu@2.0.0': 6872ba71b9847c5a0210b1b896923dadc3860faedfe28d9f062bcedfe786ef1d
378
'@react-navigation/native-stack@7.21.0': 990d575444c4af2ce8218b3b7a8280fe244c03abbdb32b822a2e862f791dbf42
@@ -573,7 +573,7 @@ importers:
573
version: 0.3.0
574
'@pierre/diffs':
575
specifier: 1.7.0-beta.4
576
- version: 1.7.0-beta.4(patch_hash=241563d810c29250e0e92f3eda74214393726d46667fedbf1f91a5f5bea07d1e)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
576
+ version: 1.7.0-beta.4(patch_hash=b24b206d14c79de95be10322b96490b82e41cc13c8a02c7378aaf8e03623431b)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
577
'@pierre/highlights':
578
specifier: 'catalog:'
579
version: 0.5.0
@@ -1094,7 +1094,7 @@ importers:
1094
version: 1.8.0
1095
'@pierre/diffs':
1096
specifier: 1.7.0-beta.4
1097
- version: 1.7.0-beta.4(patch_hash=241563d810c29250e0e92f3eda74214393726d46667fedbf1f91a5f5bea07d1e)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
1097
+ version: 1.7.0-beta.4(patch_hash=b24b206d14c79de95be10322b96490b82e41cc13c8a02c7378aaf8e03623431b)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
1098
'@pierre/trees':
1099
specifier: 1.0.0-beta.6
1100
version: 1.0.0-beta.6(@pierre/theme@2.0.0)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)(shiki@4.2.0)
@@ -1510,7 +1510,7 @@ importers:
1510
dependencies:
1511
'@pierre/diffs':
1512
specifier: 1.7.0-beta.4
1513
- version: 1.7.0-beta.4(patch_hash=241563d810c29250e0e92f3eda74214393726d46667fedbf1f91a5f5bea07d1e)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
1513
+ version: 1.7.0-beta.4(patch_hash=b24b206d14c79de95be10322b96490b82e41cc13c8a02c7378aaf8e03623431b)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
1514
'@t3tools/contracts':
1515
specifier: workspace:*
1516
version: link:../contracts
@@ -16443,7 +16443,7 @@ snapshots:
16443
tslib: 2.8.1
16444
webcrypto-core: 1.9.2
16445
16446
- '@pierre/diffs@1.7.0-beta.4(patch_hash=241563d810c29250e0e92f3eda74214393726d46667fedbf1f91a5f5bea07d1e)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)':
16446
+ '@pierre/diffs@1.7.0-beta.4(patch_hash=b24b206d14c79de95be10322b96490b82e41cc13c8a02c7378aaf8e03623431b)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)':
16447
dependencies:
16448
'@pierre/highlights': 0.5.1
16449
'@pierre/patches': 0.0.1