Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: restore the trailing newline on materialized review patches so git apply accepts them

[._.]/ Adam Eivy48f53e9c313e
diff --git a/server/services/modelAbuseGuard.js b/server/services/modelAbuseGuard.js
index b7f23287af..d0dd0592d6 100644
--- a/server/services/modelAbuseGuard.js
+++ b/server/services/modelAbuseGuard.js
@@ -255,7 +255,11 @@ export async function materializePublicReviewPatches({ scanKey, workspacePath, a
const filename = `PR-${pullRequest.number}.patch`;
const relativePath = `${PUBLIC_REVIEW_PATCH_DIRNAME}/${filename}`;
const destination = join(patchDir, filename);
- await atomicWrite(destination, pullRequest.diff);
+ // The gh wrapper trims stdout, which drops the diff's final newline; git
+ // apply then rejects the file as "corrupt patch at line N". Restore it so
+ // the reviewer can apply the patch verbatim (the fingerprint is computed
+ // on the trimmed text upstream and is unaffected).
+ await atomicWrite(destination, pullRequest.diff.endsWith('\n') ? pullRequest.diff : `${pullRequest.diff}\n`);
const restricted = await chmod(destination, 0o444).then(() => true).catch(() => false);
if (!restricted) return false;
patches.push({
diff --git a/server/services/modelAbuseGuard.materialize.test.js b/server/services/modelAbuseGuard.materialize.test.js
index 6e63586da6..faac742be4 100644
--- a/server/services/modelAbuseGuard.materialize.test.js
+++ b/server/services/modelAbuseGuard.materialize.test.js
@@ -23,7 +23,8 @@ const pullRequests = [{
headSha,
title: 'docs: example change',
body: '',
- diff: 'diff --git a/README.md b/README.md\n+example\n',
+ // Trailing newline already stripped, as the gh wrapper's stdout trim leaves it.
+ diff: 'diff --git a/README.md b/README.md\n--- a/README.md\n+++ b/README.md\n@@ -1 +1 @@\n-old\n+example',
}];
let workspace;
@@ -45,7 +46,8 @@ describe('materializing the screened public-review snapshot', () => {
expect(await materializePublicReviewPatches({ scanKey, workspacePath: workspace, allowedPullRequestNumbers: [42] })).toBe(true);
const manifest = JSON.parse(await readFile(join(workspace, PUBLIC_REVIEW_PATCH_DIRNAME, PUBLIC_REVIEW_PATCH_MANIFEST_FILENAME), 'utf8'));
expect(manifest.patches).toEqual([expect.objectContaining({ number: 42, headSha, path: `${PUBLIC_REVIEW_PATCH_DIRNAME}/PR-42.patch` })]);
- expect(await readFile(join(workspace, PUBLIC_REVIEW_PATCH_DIRNAME, 'PR-42.patch'), 'utf8')).toBe(pullRequests[0].diff);
+ // git apply rejects a patch whose last line has no newline ("corrupt patch").
+ expect(await readFile(join(workspace, PUBLIC_REVIEW_PATCH_DIRNAME, 'PR-42.patch'), 'utf8')).toBe(`${pullRequests[0].diff}\n`);
expect((await stat(join(workspace, PUBLIC_REVIEW_PATCH_DIRNAME, 'PR-42.patch'))).mode & 0o222).toBe(0);
});
});