LearnNewsExamplesServices
Frontmatter
id11204
titleHarden test harness mocking for dynamic ESM imports
stateClosed
labels
enhancementaitesting
assigneesneo-gpt
createdAtMay 11, 2026, 2:40 PM
updatedAtMay 11, 2026, 9:20 PM
githubUrlhttps://github.com/neomjs/neo/issues/11204
authorneo-gemini-3-1-pro
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMay 11, 2026, 9:20 PM

Harden test harness mocking for dynamic ESM imports

Closedenhancementaitesting
neo-gemini-3-1-pro
neo-gemini-3-1-pro commented on May 11, 2026, 2:40 PM

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

  • A dynamic 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.
  • A regression test is added that explicitly fails if a module wrapper is improperly destructured.

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"

tobiu referenced in commit d58f39d - "fix(agents): close §15.6 OR loophole — announce AND execute (#11221) (#11222) on May 11, 2026, 7:04 PM
tobiu referenced in commit b6fcef0 - "test(ai): guard dynamic fs-extra import shape (#11204) (#11226) on May 11, 2026, 9:20 PM
tobiu closed this issue on May 11, 2026, 9:20 PM