From b41c6357749736adea0c3effdab2db3449f65710 Mon Sep 17 00:00:00 2001 From: Greg Grace <77203234+ggrace519@users.noreply.github.com> Date: Sat, 19 Sep 2026 12:46:01 -0400 Subject: [PATCH] test(opencode): make write-tool permission test umask-independent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "sets file permissions when writing sensitive data" test asserted a fixed 0644 mode, but the write tool never chmods — a written file's mode is the OS default (0666) filtered by the process umask. The test only passed under a 0022 umask (CI's default); under a stricter local umask (0002 → 0664, 0077 → 0600) it failed, even though the tool behaved correctly. Enforcing 0644 in the tool was proposed and rejected upstream (#19076, #19077) as a security regression: programmatically loosening a umask-077 user's boundary would make agent-written files (incl. .env, keys) world-readable. The recommended direction was a test-side fix. Pin process.umask(0o022) around the write so the expected mode is deterministic regardless of the developer's environment, and restore it afterwards. Verified: passes under umask 0002, 0022, and 0077; full packages/opencode test/tool suite (341) green; typecheck clean. Co-Authored-By: Claude Opus 4.8 --- packages/opencode/test/tool/write.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/opencode/test/tool/write.test.ts b/packages/opencode/test/tool/write.test.ts index 4f897dc87591..33191acf24da 100644 --- a/packages/opencode/test/tool/write.test.ts +++ b/packages/opencode/test/tool/write.test.ts @@ -173,11 +173,22 @@ describe("tool.write", () => { }) describe("file permissions", () => { - it.instance("sets file permissions when writing sensitive data", () => + it.instance("writes files with the default 0644 mode under a standard umask", () => Effect.gen(function* () { const test = yield* TestInstance const filepath = path.join(test.directory, "sensitive.json") - yield* run({ filePath: filepath, content: JSON.stringify({ secret: "data" }) }) + + // The write tool doesn't chmod; a written file's mode is the OS default + // (0666) filtered by the process umask. Pin a standard 0022 umask so the + // expected mode is deterministic regardless of the developer's umask + // (CI runs at 0022; a stricter local umask like 0002/0077 otherwise makes + // this assert 0664/0600 and fail). Restore the umask afterwards. + const previousUmask = process.umask(0o022) + try { + yield* run({ filePath: filepath, content: JSON.stringify({ secret: "data" }) }) + } finally { + process.umask(previousUmask) + } if (process.platform !== "win32") { const stats = yield* Effect.promise(() => fs.stat(filepath))