Skip to content

test(opencode): make write-tool permission test umask-independent - #1

Merged
ggrace519 merged 1 commit into
devfrom
write-tool-permissions
Sep 19, 2026
Merged

ggrace519 merged 1 commit into
devfrom
write-tool-permissions

Conversation

@ggrace519

Copy link
Copy Markdown
Collaborator

What

The tool.write "sets file permissions" test asserted a fixed 0644 mode, but the write tool never chmods — a written file's mode is the OS default (0666) minus the process umask. So it passed only under a 0022 umask (CI's default) and failed on a stricter local umask (0002 → 0664, 0077 → 0600), even though the tool was behaving correctly.

Enforcing 0644 in the tool was proposed and rejected upstream (anomalyco#19076 / anomalyco#19077) as a security regression — it would loosen a umask 077 user's boundary. The recommended direction was a test-side fix, which this is: pin process.umask(0o022) around the write and restore it after.

Verified

Passes under umask 0002, 0022, and 0077; full packages/opencode test/tool suite (341) green; typecheck clean.

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 (anomalyco#19076,
anomalyco#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 <noreply@anthropic.com>
@ggrace519
ggrace519 merged commit 0b0532e into dev Sep 19, 2026
@ggrace519
ggrace519 deleted the write-tool-permissions branch September 19, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant