Context
During the review of PR #11203, which resolved a runtime TypeError in HealthService caused by an incorrect fs-extra namespace import inside a dynamic await import(), it was noted that the HealthService.spec.mjs unit tests passed completely despite this broken import.
The Problem
The current test harness mock setup for HealthService correctly isolates internal logic, but dynamic imports (await import(...)) escape our standard static module boundary mocking. Because the test environment did not throw on the dynamic import resolving to a namespace wrapper instead of the actual API object, the observable runtime regression shipped silently.
The Architectural Reality
Node.js ESM dynamic imports evaluate differently than statically bound imports, and our Playwright/Node test harness does not currently enforce strict shape-checking on mocked or partially resolved dynamic imports for filesystem dependencies like fs-extra.
The Fix
- Implement a harness-level proxy or test-side mock that forces dynamic imports of core Node libraries (like
fs-extra) to return shapes identical to their runtime namespace resolution.
- Apply this mock boundary uniformly to all services executing dynamic imports.
Acceptance Criteria
Out of Scope
- Rewriting all existing dynamic imports across the framework to static imports (that is handled on a case-by-case basis like #11201).
Avoided Traps / Gold Standards Rejected
- Avoiding global
require rewrites since we run pure Node ESM and Playwright unit tests. The solution must be native to the current execution context.
Related
Origin Session ID
Origin Session ID: 57502eb2-7f7b-4b9b-a849-49f016b08c95
Handoff Retrieval Hints
Retrieval Hint: "dynamic import fs-extra mock gap"
Context During the review of PR #11203, which resolved a runtime
TypeErrorinHealthServicecaused by an incorrectfs-extranamespace import inside a dynamicawait import(), it was noted that theHealthService.spec.mjsunit tests passed completely despite this broken import.The Problem The current test harness mock setup for
HealthServicecorrectly isolates internal logic, but dynamic imports (await import(...)) escape our standard static module boundary mocking. Because the test environment did not throw on the dynamic import resolving to a namespace wrapper instead of the actual API object, the observable runtime regression shipped silently.The Architectural Reality Node.js ESM dynamic imports evaluate differently than statically bound imports, and our Playwright/Node test harness does not currently enforce strict shape-checking on mocked or partially resolved dynamic imports for filesystem dependencies like
fs-extra.The Fix
fs-extra) to return shapes identical to their runtime namespace resolution.Acceptance Criteria
await import('fs-extra')inside a test throws or returns a namespace wrapper (mimicking Node ESM), rather than returning the raw object directly, OR our mock explicitly enforces the strict default export boundary.Out of Scope
Avoided Traps / Gold Standards Rejected
requirerewrites since we run pure Node ESM and Playwright unit tests. The solution must be native to the current execution context.Related
Origin Session ID Origin Session ID: 57502eb2-7f7b-4b9b-a849-49f016b08c95
Handoff Retrieval Hints Retrieval Hint: "dynamic import fs-extra mock gap"