fix: use module-level mock for fs.existsSync in config-writer test#3766
Conversation
fs.existsSync is non-configurable on Node 22+ and cannot be overridden
with jest.spyOn when the fs module is already mocked via jest.mock().
This caused TypeError: Cannot redefine property: existsSync in CI.
Fix: add existsSync to the jest.mock('fs') factory (with passthrough to
the real implementation by default), matching the existing pattern for
chownSync. The seccomp test now uses mockImplementation() on the
pre-existing mock instead of jest.spyOn().
Fixes #3761
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR fixes src/config-writer.test.ts failing on Node 22+ by avoiding jest.spyOn(fs, 'existsSync') on a non-configurable fs.existsSync export when fs is already being partially mocked. The test now uses a module-level existsSync mock (defaulting to passthrough) and overrides it via mockImplementation() within the seccomp test.
Changes:
- Extend the existing module-level
jest.mock('fs', ...)to include a passthroughexistsSyncwrapper. - Replace
jest.spyOn(fs, 'existsSync')withmockImplementation()against the pre-defined mock, restoring the original implementation afterward.
Show a summary per file
| File | Description |
|---|---|
| src/config-writer.test.ts | Switches existsSync mocking to a module-level jest mock to avoid Node 22+ “Cannot redefine property” errors in the seccomp-profile test. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
|
✅ Smoke test validation passed
All checks passed.
|
Smoke Test Results: Copilot BYOK Offline Mode✅ GitHub MCP: Retrieved PR #3766 ("fix: use module-level mock for fs.existsSync in config-writer test") Mode: COPILOT_OFFLINE=true (BYOK offline mode) Overall: ❌ FAIL (file test failed)
|
|
Smoke Codex: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Runtime Version ComparisonThe chroot environment test compared runtime versions between the host and chroot:
Result: Tests did not pass. Python and Node.js versions differ between host and chroot environments.
|
Gemini Smoke Test Results
Overall Status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
�� Smoke Test: Services ConnectivityStatus: ❌ FAIL
Services running on the host are not reachable from the AWF sandbox.
|
|
Smoke Test Results ✅ GitHub MCP: PR #3755 (refactor: extract tryMiddlePowerFallback helper) Status: FAIL cc @lpcox
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS All build and test operations completed successfully across all ecosystems.
|
Problem
The
config-writer.test.tsseccomp test (added in #3739) usesjest.spyOn(fs, 'existsSync'), which fails on Node 22+ with:This is because the file already uses
jest.mock('fs')with a spread ofrequireActual('fs')— the resulting mock object has non-configurable properties thatjest.spyOncannot redefine.The file's own comment on line 9 notes this exact issue for
chownSync, but the bot-generated test in #3739 didn't follow the same pattern forexistsSync.Fix
existsSyncto thejest.mock('fs')factory (with passthrough to the real implementation by default)jest.spyOn(fs, 'existsSync')withmockImplementation()on the pre-existing mockVerification
All 18 tests in
config-writer.test.tspass locally on Node 24.Fixes #3761