fix(codex): restore trust config permissions on rollback

This commit is contained in:
Brennan Benson
2026-07-15 13:52:46 -07:00
parent d4f549364b
commit 8f9da3ed4c
2 changed files with 28 additions and 1 deletions
@@ -51,4 +51,20 @@ describe('Codex trust config rollback', () => {
expect(statSync(configPath).mode & 0o777).toBe(0o640)
}
})
it.skipIf(process.platform === 'win32')(
'restores the captured mode when the contents already match',
() => {
const configPath = tempConfigPath()
writeFileSync(configPath, '[hooks]\n')
chmodSync(configPath, 0o640)
const snapshot = captureCodexTrustConfig(configPath)
chmodSync(configPath, 0o600)
restoreCodexTrustConfig(configPath, snapshot)
expect(readFileSync(configPath, 'utf8')).toBe('[hooks]\n')
expect(statSync(configPath).mode & 0o777).toBe(0o640)
}
)
})
+12 -1
View File
@@ -1,4 +1,12 @@
import { closeSync, fstatSync, openSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
import {
chmodSync,
closeSync,
fstatSync,
openSync,
readFileSync,
unlinkSync,
writeFileSync
} from 'node:fs'
import { randomUUID } from 'node:crypto'
import { renameFileWithWindowsRetry } from '../codex-accounts/fs-utils'
@@ -45,6 +53,9 @@ export function restoreCodexTrustConfig(
}
try {
if (readFileSync(tomlPath).equals(snapshot.contents)) {
// Why: the RPC may change permissions without changing bytes; rollback
// restores the complete captured file state, not only its contents.
chmodSync(tomlPath, snapshot.mode)
return
}
} catch (error) {