Skip to content

test: refuse to test fs_errors on root environments#364

Merged
KSXGitHub merged 11 commits into
masterfrom
claude/debug-fs-errors-tests-ZosXe
Mar 22, 2026
Merged

test: refuse to test fs_errors on root environments#364
KSXGitHub merged 11 commits into
masterfrom
claude/debug-fs-errors-tests-ZosXe

Conversation

@KSXGitHub

Copy link
Copy Markdown
Owner

Summary

Add a root environment check to the fs_errors test to prevent it from running with elevated privileges, which would compromise test accuracy. The test now panics with helpful guidance if executed as root, and can be skipped via a configuration flag.

Changes

  • Added a root privilege check at the start of the fs_errors test using libc::geteuid()
  • If running as root (uid == 0), the test panics with an informative error message directing users to either run as non-root or set RUSTFLAGS='--cfg pdu_test_skip_fs_errors' to skip the test
  • Added #[cfg(not(pdu_test_skip_fs_errors))] attribute to allow conditional compilation of the test
  • Added libc as a dev dependency to access the geteuid() function

Implementation Details

The test requires non-root execution because filesystem permission errors behave differently when running with elevated privileges, which would invalidate the test's assertions about permission-denied scenarios.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the fs_errors integration test safer and more reliable by refusing to run under root privileges (where permission errors behave differently), and adds an opt-out compile-time flag to skip the test entirely.

Changes:

  • Add an effective-UID check (libc::geteuid() == 0) to fail fast with guidance when the test is run as root.
  • Add #[cfg(not(pdu_test_skip_fs_errors))] to allow skipping the test via RUSTFLAGS='--cfg pdu_test_skip_fs_errors'.
  • Add libc as a dev-dependency to support the Unix UID check.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/cli_errors.rs Adds root-environment guard + optional cfg-based skip for fs_errors.
Cargo.toml Adds libc under dev-dependencies for UID detection.
Cargo.lock Locks the new libc dependency.

Comment thread tests/cli_errors.rs
Comment thread tests/cli_errors.rs Outdated
@github-actions

github-actions Bot commented Mar 22, 2026

Copy link
Copy Markdown

Performance Regression Reports

commit: 67c2b72

There are no regressions.

claude and others added 8 commits March 22, 2026 22:00
Root (uid=0) bypasses Unix discretionary access controls, so removing
read permissions with chmod has no effect. This causes the fs_errors
test to fail because read_dir() succeeds instead of returning
Permission denied. Skip the test with an explanatory message when
euid is 0.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
Replace the `unsafe { libc::geteuid() }` check with a direct probe:
after chmod -r, try read_dir and skip if it still succeeds. This
removes the `unsafe` block and the `libc` dev-dependency while being
more semantically correct — it tests the actual condition we care
about rather than a proxy.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
Instead of silently skipping, panic with an actionable error message
when running as root. The test can be excluded entirely via
`RUSTFLAGS='--cfg pdu_test_skip_fs_errors'` for environments like
Claude Code Web where root is unavoidable.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Suppress the -D unexpected-cfgs error by adding #[allow(unexpected_cfgs)]
before the custom cfg gate.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
The #[allow(unexpected_cfgs)] approach doesn't override -D warnings
used in CI release builds. Register the custom cfg in Cargo.toml's
[lints.rust] section instead, which properly declares it as a known
cfg to the compiler.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
@KSXGitHub KSXGitHub force-pushed the claude/debug-fs-errors-tests-ZosXe branch from 837f345 to 0de4461 Compare March 22, 2026 22:00
claude added 2 commits March 22, 2026 22:06
…rors

Gate the Unix-specific imports and fs_permission helper with
cfg(all(unix, not(pdu_test_skip_fs_errors))) so they don't produce
dead code warnings when the test is skipped.

https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread Cargo.toml Outdated
@KSXGitHub KSXGitHub marked this pull request as ready for review March 22, 2026 22:19
@KSXGitHub KSXGitHub merged commit b2d64ec into master Mar 22, 2026
13 checks passed
@KSXGitHub KSXGitHub deleted the claude/debug-fs-errors-tests-ZosXe branch March 22, 2026 22:34
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.

3 participants