From c240af40fe3e4d370d4670fd4a8a7b140f5fced5 Mon Sep 17 00:00:00 2001 From: mohammed ahmed Date: Mon, 6 Apr 2026 10:34:04 +0000 Subject: [PATCH] fix: Skip test_returns_none_for_unreadable_file when running as root **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 --- tests/code_utils/test_config_js.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/code_utils/test_config_js.py b/tests/code_utils/test_config_js.py index a533b8124..d2a116562 100644 --- a/tests/code_utils/test_config_js.py +++ b/tests/code_utils/test_config_js.py @@ -3,6 +3,7 @@ from __future__ import annotations import json +import os import sys from pathlib import Path @@ -73,7 +74,10 @@ def test_returns_none_for_nonexistent_file(self, tmp_path: Path) -> None: assert result is None - @pytest.mark.skipif(sys.platform == "win32", reason="chmod doesn't restrict read access on Windows") + @pytest.mark.skipif( + sys.platform == "win32" or os.getuid() == 0, + reason="chmod doesn't restrict read access on Windows or when running as root" + ) def test_returns_none_for_unreadable_file(self, tmp_path: Path) -> None: """Should return None if file cannot be read.""" package_json = tmp_path / "package.json"