diff --git a/packages/runtime-core/src/runner-workspace-apply.ts b/packages/runtime-core/src/runner-workspace-apply.ts index 4594160a..a2dd4cdc 100644 --- a/packages/runtime-core/src/runner-workspace-apply.ts +++ b/packages/runtime-core/src/runner-workspace-apply.ts @@ -116,9 +116,12 @@ export async function applyRunnerWorkspacePatch(request: RunnerWorkspaceApplyReq if (!patch.trim()) throw new Error("Canonical changed-files declares changes but patch is empty.") validatePatchPaths(patch, changed) + // Apply the sandbox patch byte-for-byte. Whitespace style belongs to the + // target repository's own verification, not the transport; `nowarn` also + // overrides any host `apply.whitespace=fix` config that would rewrite it. try { - await execGit(workspaceRoot, ["apply", "--check", "--whitespace=error", "--", patchPath]) - await execGit(workspaceRoot, ["apply", "--whitespace=error", "--", patchPath]) + await execGit(workspaceRoot, ["apply", "--check", "--whitespace=nowarn", "--", patchPath]) + await execGit(workspaceRoot, ["apply", "--whitespace=nowarn", "--", patchPath]) } catch (error) { throw applyFailure(error instanceof Error ? error.message : String(error), failureEvidence) } diff --git a/scripts/artifact-patch-git-apply-smoke.ts b/scripts/artifact-patch-git-apply-smoke.ts index 40c5b242..17e271c3 100644 --- a/scripts/artifact-patch-git-apply-smoke.ts +++ b/scripts/artifact-patch-git-apply-smoke.ts @@ -99,8 +99,8 @@ async function assertPatchRoundTrip(directory: string, patch: string, baseline: await execFileAsync("git", ["init", "--quiet"], { cwd: directory }) const patchPath = join(root, `${basename(directory)}.diff`) await writeFile(patchPath, patch) - await execFileAsync("git", ["apply", "--check", "--whitespace=error", "--", patchPath], { cwd: directory }) - await execFileAsync("git", ["apply", "--whitespace=error", "--", patchPath], { cwd: directory }) + await execFileAsync("git", ["apply", "--check", "--whitespace=nowarn", "--", patchPath], { cwd: directory }) + await execFileAsync("git", ["apply", "--whitespace=nowarn", "--", patchPath], { cwd: directory }) for (const [path, contents] of Object.entries(expected)) { assert.deepEqual(await readFile(join(directory, path)), Buffer.from(contents)) diff --git a/tests/runner-workspace-apply.test.ts b/tests/runner-workspace-apply.test.ts index 4ec95220..329a25a9 100644 --- a/tests/runner-workspace-apply.test.ts +++ b/tests/runner-workspace-apply.test.ts @@ -229,6 +229,18 @@ const files = [{ path: "/workspace/README.md", relativePath: "README.md", status assert.equal(result.declaredChanges, 0) } +{ + // Whitespace in agent content (issue #2636): trailing spaces and a new blank + // line at EOF apply byte-for-byte, even when host config asks git to fix them. + const whitespacePatch = "--- a/README.md\n+++ b/README.md\n@@ -1 +1,3 @@\n-before\n+after \n+tail\t\n+\n" + const input = await fixture(whitespacePatch, files) + await exec("git", ["config", "apply.whitespace", "fix"], { cwd: input.workspace }) + const result = await applyRunnerWorkspacePatch({ artifactRoot: input.artifacts, artifactRefs: input.refs, workspaceRoot: input.workspace, writablePaths: ["README.md"] }) + assert.equal(result.status, "applied") + assert.equal(await readFile(join(input.workspace, "README.md"), "utf8"), "after \ntail\t\n\n") + await verifyRunnerWorkspaceIntegrity(result.integrity!) +} + // Host writable-path matching mirrors the sandbox workspace tools. for (const [path, pattern, expected] of [ ["plugins/extrachill-shop/docs/user/a.md", "plugins/extrachill-shop/docs/user/**", true],