LearnNewsExamplesConnect
Frontmatter
assigneesneo-fable-mnemosyne
createdAtSep 2, 2026, 3:53 PM
updatedAtSep 2, 2026, 4:38 PM
githubUrlhttps://github.com/neomjs/neo/issues/18092
authorneo-fable-mnemosyne
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 2, 2026, 4:38 PM

A unit spec whose import chain reaches manager/Window at top level loads only after another spec ran in its worker: the setup installs Neo.currentWorker after the hoisted imports

neo-fable-mnemosyne
neo-fable-mnemosyne commented on Sep 2, 2026, 3:53 PM

Problem

test/playwright/setup.mjs installs the Neo.currentWorker mock inside setup(), which a spec calls in its module body — after every static import has been evaluated, because ES imports are hoisted. src/manager/Window.mjs creates its singleton at import time and its construct calls Neo.currentWorker.on(...). A spec whose static import chain reaches the window manager therefore throws at load, and Playwright reports the file as having no tests.

The chain exists on dev since 2026-08-30: examples/dashboard/crossWindow/DemoBWorkspace.mjs imports src/ai/client/InteractionService.mjs (since 08-23), which gained import WindowManager from '../../manager/Window.mjs' with the atomic drag transactions (#17862). test/playwright/unit/examples/dashboard/crossWindow/DemoBWorkspace.spec.mjs has not been runnable alone since.

CI does not see it because Playwright reuses a worker's Node process across spec files and globalThis.Neo survives that reuse: when another spec ran first in the same worker, its setup() already installed the mock, and the example spec loads and passes. With four CI workers and sixty-odd files that is nearly always the case. Alone, or first in its worker, it is dead. Measured: npx playwright test -c playwright.config.unit.mjs unit/examples/dashboard/crossWindow/DemoBWorkspace.spec.mjs → TypeError: Cannot read properties of undefined (reading 'on') at src/manager/Window.mjs:40, "No tests found", exit 1; the same file after unit/dashboard/DockActionTooltips.spec.mjs with --workers=1 → loads, 64 tests run. Same result with CI's invocation (NEO_TEST_SKIP_CI=true npm run test-unit -- <file>).

This class has been seen before from the other side: a local namespace collision killing every service-importing unit spec while CI stayed unaffected, and the theme-deferral gate reading a stale worker binding across worker reuse. The shared cause is state that lives on globalThis.Neo across files in one worker.

Evidence

  • test/playwright/setup.mjs: top level sets globalThis.Neo ??= {}, Neo.config and DOMRect; Neo.currentWorker ??= {...} sits inside setup().
  • src/manager/Window.mjs:40 (construct) and :230 (singleton at import).
  • src/ai/client/InteractionService.mjs:2 — the static import; examples/dashboard/crossWindow/DemoBWorkspace.mjs:17.
  • Only test/playwright/unit/data/PipelineRemoteExecution.spec.mjs assigns its own Neo.currentWorker, by plain assignment with restore — unaffected by an earlier default.

Proposed change

Move the Neo.currentWorker ??= {...} block to the module top level of setup.mjs, next to globalThis.Neo ??= {}: setup.mjs is every spec's first import, so its top level runs before any engine module evaluates. ??= keeps a spec's own later assignment authoritative and keeps setup()'s behaviour for every other spec identical. No change to the window manager: constructing its singleton at import is its production shape.

Acceptance Criteria

  • DemoBWorkspace.spec.mjs runs alone (npx playwright test -c playwright.config.unit.mjs <file>) and finds and passes its tests; it also passes first in a --workers=1 pair.
  • The full unit suite stays green; PipelineRemoteExecution.spec.mjs keeps its own worker seam.
  • The moved block's comment states why it lives at top level (hoisted imports evaluate before setup()).

Non-goals

  • Making the window manager tolerate a missing worker at import.
  • The worker-reuse class in general (a lint that spots globalThis.Neo state leaking across files) — a separate leaf if wanted.

Found while adding a unit arm to that spec for #18088; the arm is blocked on this. Sweep 13:50Z before filing: live latest-20 open (no match), A2A last-8 (no claim), Knowledge Base (#15364 and #16503 are the same class from other causes, neither this).

Authored by Mnemosyne (@neo-fable, Claude Fable 5.1, Claude Code) · session 37bbc610-f0cd-4abb-95c2-eb70336a86f3

tobiu referenced in commit 5a08fb9 - "fix(test): the unit setup installs the worker mock before the hoisted imports evaluate (#18092) (#18093) on Sep 2, 2026, 4:38 PM
tobiu closed this issue on Sep 2, 2026, 4:38 PM