Skip to content

Commit bb3091e

Browse files
Retain full local review patches
1 parent 3a5f83f commit bb3091e

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/adapter.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,16 @@ async function routeClaimedDelivery(
11671167
};
11681168
}
11691169

1170-
function runCommand(args: string[], cwd?: string, env?: NodeJS.ProcessEnv, timeoutSeconds = 300): CommandResult {
1170+
function runCommand(
1171+
args: string[],
1172+
cwd?: string,
1173+
env?: NodeJS.ProcessEnv,
1174+
timeoutSeconds = 300,
1175+
retainedOutputBytes = 8000,
1176+
): CommandResult {
11711177
const startedAt = Date.now();
11721178
const maxOutputBytes = 2 * 1024 * 1024;
1179+
const retainedBytes = Math.max(1, Math.min(retainedOutputBytes, maxOutputBytes));
11731180
const proc = spawnSync(args[0], args.slice(1), {
11741181
cwd,
11751182
env,
@@ -1183,10 +1190,10 @@ function runCommand(args: string[], cwd?: string, env?: NodeJS.ProcessEnv, timeo
11831190
return {
11841191
args,
11851192
returncode: proc.status ?? 125,
1186-
stdout: stdout.slice(-8000),
1187-
stderr: stderr.slice(-8000),
1188-
stdout_truncated: stdout.length > 8000,
1189-
stderr_truncated: stderr.length > 8000,
1193+
stdout: stdout.slice(-retainedBytes),
1194+
stderr: stderr.slice(-retainedBytes),
1195+
stdout_truncated: Buffer.byteLength(stdout, "utf8") > retainedBytes,
1196+
stderr_truncated: Buffer.byteLength(stderr, "utf8") > retainedBytes,
11901197
output_limit_bytes: maxOutputBytes,
11911198
duration_ms: Date.now() - startedAt,
11921199
signal: proc.signal || null,
@@ -2936,6 +2943,7 @@ async function prepareReviewContext(
29362943
workspace,
29372944
env,
29382945
180,
2946+
2 * 1024 * 1024,
29392947
);
29402948
localPatches.set(filename, diff);
29412949
localPatchEvidence.push({
@@ -2987,7 +2995,7 @@ export function summarizePrFiles(files: JsonObject[], localPatches?: ReadonlyMap
29872995
const filename = String(item.filename || "");
29882996
const localPatch = localPatches?.get(filename);
29892997
const localCaptureRequired = localPatches !== undefined;
2990-
const localCaptureSucceeded = localPatch?.returncode === 0;
2998+
const localCaptureSucceeded = localPatch?.returncode === 0 && localPatch.stdout_truncated !== true;
29912999
const patch = localCaptureSucceeded ? localPatch.stdout : String(item.patch || "");
29923000
const patchTruncated = patchEvidenceIncomplete(patch, Number(item.additions || 0), Number(item.deletions || 0));
29933001
const binaryPatch = patch.includes("GIT binary patch") || patch.includes("Binary files ");

tests/webhook-adapter.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,28 @@ test("fails closed when exact-base/head patch capture fails", () => {
20482048
assert.equal(summary.patch_truncated, true);
20492049
});
20502050

2051+
test("fails closed when the local exact-base/head command output was truncated", () => {
2052+
const completePatch = "@@ -1 +1 @@\n-old\n+new";
2053+
const files = [{filename: "src/a.ts", status: "modified", additions: 1, deletions: 1, changes: 2, patch: completePatch}];
2054+
const localPatches = new Map([[
2055+
"src/a.ts",
2056+
{
2057+
args: ["git", "diff"],
2058+
returncode: 0,
2059+
stdout: completePatch,
2060+
stderr: "",
2061+
signal: null,
2062+
timed_out: false,
2063+
spawn_error: "",
2064+
stdout_truncated: true,
2065+
},
2066+
]]);
2067+
2068+
const [summary] = summarizePrFiles(files, localPatches);
2069+
assert.equal(summary.patch_source, "github_files_api");
2070+
assert.equal(summary.patch_truncated, true);
2071+
});
2072+
20512073
test("rejects syntactically valid supporting paths that are missing from the checkout", () => {
20522074
const root = tempStateDir();
20532075
const task = reviewTask();

0 commit comments

Comments
 (0)