← Back to PRs

#9333: Tests: add test coverage for security/audit-fs.ts

by M00N7682 open 2026-02-05 03:57 View on GitHub →
stale
## Summary Adds comprehensive unit tests for the previously untested `src/security/audit-fs.ts` module. This module handles file permission inspection for security auditing, supporting both POSIX and Windows ACL systems. ## Tests Added (32 tests) - **modeBits**: permission bit extraction from file mode - **formatOctal**: formatting bits as 3-digit octal strings - **isWorldWritable/isGroupWritable**: write permission bit checks - **isWorldReadable/isGroupReadable**: read permission bit checks - **formatPermissionDetail**: human-readable permission formatting - **formatPermissionRemediation**: chmod/icacls command generation - **safeStat**: error-safe file stat wrapper with symlink detection - **inspectPathPermissions**: full permission inspection on POSIX/Windows ## Test plan - [x] All 32 tests passing - [x] Tests use temporary files for filesystem operations - [x] Tests clean up after themselves - [x] Covers edge cases (null inputs, non-existent paths, symlinks) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Adds a new Vitest suite (`src/security/audit-fs.test.ts`) covering the permission-auditing helpers in `src/security/audit-fs.ts` (POSIX mode bit handling, formatting, and higher-level permission inspection), including basic coverage of the Windows ACL branch via dependency injection. Most assertions are straightforward and exercise the key bitmask/formatting behavior. The main gap is that the Windows-branch test doesn’t assert observable behavior (e.g., `exec` invocation, `source/error` shape), so it can pass even if the Windows ACL inspection path regresses. <h3>Confidence Score: 4/5</h3> - This PR is mostly safe to merge; remaining issues are around test effectiveness rather than production behavior. - Only a new test file is added. However, a couple of Windows-related assertions are currently too weak and can allow regressions to slip through or produce brittle expectations depending on how the Windows command string is formatted. - src/security/audit-fs.test.ts <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs