fix: Skip test_returns_none_for_unreadable_file when running as root#2001
fix: Skip test_returns_none_for_unreadable_file when running as root#2001mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
**Problem:**
Test `test_returns_none_for_unreadable_file` fails when running as root
because the root user can read files regardless of `chmod` permissions.
**Root Cause:**
On Linux, root (uid=0) bypasses file permission checks. When the test
creates a file with `chmod(0o000)` to make it unreadable, root can still
open and read it, causing no `PermissionError` to be raised.
**Evidence:**
- Test expects `get_package_json_data()` to return `None` for unreadable file
- When running as root, file is successfully read and returns `{}`
- Running `python3 -m pytest tests/code_utils/test_config_js.py` as root fails
**Impact:**
- Severity: LOW (test-only bug, doesn't affect production code)
- Affects CI/Docker environments running as root
- Test already skips on Windows for similar reason
**Fix:**
Added `os.getuid() == 0` check to the `@pytest.mark.skipif` decorator.
Test now skips on both Windows and when running as root.
**Testing:**
- When running as root: Test skips (expected)
- When running as non-root: Test should pass (verifies permission handling)
- All 80 other tests in the file pass
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @mohammedahmed18's task in 1m 23s —— View job PR Review SummaryPrek ChecksAll checks pass — ruff lint and format both clean. Code ReviewSize: SMALL (1 test file, +5/-1 lines) The fix is correct. On Linux, the root user bypasses DAC (discretionary access control), so Windows safety: No bugs, no security issues, no breaking changes. Duplicate DetectionNo duplicates detected. This pattern (skipping on Windows) already existed; the PR consistently extends it. Test CoverageN/A — only test code changed. Verdict: LGTM. The fix is minimal, correct, and follows the same pattern already used in the Last updated: 2026-04-06T10:35Z |
Problem
Test
test_returns_none_for_unreadable_fileintests/code_utils/test_config_js.pyfails when running as root because the root user can read files regardless ofchmodpermissions.Root Cause
On Linux, the root user (uid=0) bypasses file permission checks. When the test creates a file with
chmod(0o000)to make it unreadable, root can still open and read it, causing noPermissionErrorto be raised.Evidence:
Impact
Fix
Added
os.getuid() == 0check to the@pytest.mark.skipifdecorator:Testing
uv run prek)Trace ID
Discovered during autoresearch:debug iteration 4/20 while investigating failing test suite.