Skip to content

test(write): add umask tests for deterministic file permissions#593

Open
HaleTom wants to merge 3 commits into
XiaomiMiMo:mainfrom
HaleTom:write-test-umask
Open

test(write): add umask tests for deterministic file permissions#593
HaleTom wants to merge 3 commits into
XiaomiMiMo:mainfrom
HaleTom:write-test-umask

Conversation

@HaleTom

@HaleTom HaleTom commented Jun 14, 2026

Copy link
Copy Markdown

Ported from anomalyco/opencode#21233

Issue for this PR

Fixes tool.write should enforce 0644 file mode despite umask #19076

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This keeps the PR surgical and limited to packages/opencode/test/tool/write.test.ts.

It updates the write-permission tests to reflect the actual contract: the write path respects the process umask instead of forcing a fixed 0644 file mode.

The permission coverage now models the real base mode and masking behavior directly:

  • 0o000 confirms the unmasked base mode is 0o666
  • 0o022 confirms the common masked result is 0o644
  • 0o027 covers the corner case where the masked result is 0o640
  • 0o077 confirms a restrictive mask produces 0o600
  • 0o777 is kept as a math-only assertion so the suite documents the full masking boundary without creating an unreadable file in-process

This also avoids the competing approach in fix(write): enforce explicit file mode despite umask #19077, which forces 0644 after write and would loosen a user's explicit umask-based security boundary.

How did you verify your code works?

  • Verified the PR diff is a single-file change with no unrelated files included.
  • Confirmed packages/opencode/test/tool/write.test.ts is clean under LSP diagnostics.
  • Ran bun install to bootstrap the worktree-local dependencies.
  • Ran bun test test/tool/write.test.ts → 17 pass, 0 fail.
  • Ran bun typecheck in packages/opencode → pass.

Screenshots / recordings

N/A — non-UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

HaleTom added 3 commits June 14, 2026 01:59
Port umask test coverage from upstream PR #21233, adapted to MiMo-Code
Effect-based test patterns. Tests verify base mode 0o666 and various
umask values (0o000, 0o022, 0o027, 0o077, 0o777).
Address review feedback:
- Check typeof process.umask before calling for runtime compatibility
- Make 0o777 test actually write a file instead of just bitwise assertion
@HaleTom

HaleTom commented Jun 14, 2026

Copy link
Copy Markdown
Author

Review Transparency

This code has been reviewed by two passes of gemini-code-assist and Cubic.

Full review history, discussion, and resolved threads: HaleTom/MiMo-Code#2

@qiaozongming qiaozongming force-pushed the main branch 4 times, most recently from 97aefc0 to ab53d06 Compare June 15, 2026 14:00
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.

tool.write should enforce 0644 file mode despite umask

1 participant