Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(durability): gate installHelper's exec-bit chmod on dryRun (#3736) (#3759)
Masafa313f29696e
diff --git a/src/core/brain-repo-durability.ts b/src/core/brain-repo-durability.tsindex 8ac06df218..746cb243e8 100644--- a/src/core/brain-repo-durability.ts+++ b/src/core/brain-repo-durability.ts@@ -394,8 +394,9 @@ function installHelper(repoPath: string, dryRun: boolean): { status: StepStatus;const helperPath = join(repoPath, HELPER_REL);const script = renderCommitPushHelper();if (existsSync(helperPath) && readFileSync(helperPath, 'utf-8') === script) {- // Ensure exec bit even when content is current.- try { chmodSync(helperPath, 0o755); } catch { /* */ }+ // Ensure exec bit even when content is current — but not in dry-run: a+ // preview must not mutate permissions (#3736).+ if (!dryRun) { try { chmodSync(helperPath, 0o755); } catch { /* */ } }return { status: 'ok', detail: `${HELPER_REL} already current` };}if (dryRun) return { status: 'fixed', detail: `would write ${HELPER_REL} (dry-run)` };diff --git a/test/brain-repo-durability.serial.test.ts b/test/brain-repo-durability.serial.test.tsindex d381e492bd..1768cc3f22 100644--- a/test/brain-repo-durability.serial.test.ts+++ b/test/brain-repo-durability.serial.test.ts@@ -169,6 +169,22 @@ describe('hardenBrainRepo', () => {expect(commitCount(work)).toBe(before);expect(existsSync(join(work, 'scripts', 'brain-commit-push.sh'))).toBe(false);});++ test('dry-run does not chmod an already-current helper (#3736)', async () => {+ await harden(); // real run installs scripts/brain-commit-push.sh at 0o755+ const helperPath = join(work, 'scripts', 'brain-commit-push.sh');+ chmodSync(helperPath, 0o644); // simulate perms drifting away from +x, content unchanged+ await harden({ dryRun: true });+ expect(statSync(helperPath).mode & 0o777).toBe(0o644); // untouched — preview must not mutate+ });++ test('non-dry-run restores the exec bit on an already-current helper', async () => {+ await harden();+ const helperPath = join(work, 'scripts', 'brain-commit-push.sh');+ chmodSync(helperPath, 0o644);+ await harden();+ expect(statSync(helperPath).mode & 0o111).toBeTruthy(); // exec bit restored+ });});describe('unhardenBrainRepo', () => {