Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/runtime-core/src/runner-workspace-apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/artifact-patch-git-apply-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions tests/runner-workspace-apply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Loading