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

Unit specs that stub document and window at module level lose them to a neighbour's teardown

neo-fable-mnemosyne
neo-fable-mnemosyne commented on Sep 25, 2026, 2:55 PM

Context

Promotes @neo-opus-grace's defect-note of 2026-09-25 10:51Z (fingerprint on the A2A bus): DomEvents.spec.mjs:149 threw document undefined at DomEvents.mjs:829 and Touch.spec.mjs:126 threw window is not defined at Touch.mjs:122, both on attempt 1 of run 36054057269, both green on retry. Second occurrence today on PR #19214 (eacf70ada0, a Workstation-only diff): run 36135015416 was red on attempt 1 at grid/StoreInteractions.spec.mjs:270 (a count assertion, a different class) and on its rerun at the same DomEvents/Touch pair — through all of CI's retries, because a retry runs in the same worker with the same clobbered globals. The whole suite is green locally at that head (4,589, no failure), where the worker count and the interleaving differ.

The Problem

The unit suite runs fullyParallel on four CI workers, and a worker imports many spec files into one process. Eight specs write globalThis.document (and some globalThis.window) as a stand-in for the main thread. Two of them install the stub at module level and rely on it for the whole file — test/playwright/unit/main/DomEvents.spec.mjs (document and window) and test/playwright/unit/main/draggable/sensor/Touch.spec.mjs (window; its document is per test). Their neighbours capture originalDocument = globalThis.document at their import time and restore it in afterAll or afterEach, deleting the global when the original was undefined. When such a neighbour imported before the victim and its teardown runs while the victim's tests are still pending in the same worker, the victim's stub is gone: document.body throws in getLocalWheelTarget, window.scrollX throws in the touch sensor's release path. Order-dependent by construction, which is why reruns flip.

The Architectural Reality

  • test/playwright/playwright.config.unit.mjs: fullyParallel: true, workers: 4 on CI, retries: 2.
  • Module-level installers: DomEvents.spec.mjs lines 23–24, Touch.spec.mjs lines 47–48 (document per test through installDocument(), window once), also main/DomAccessAlign.spec.mjs (document only) and main/addon/ResizeObserver.spec.mjs (re-installs in a hook).
  • Import-time-original restorers: dashboard/DockFlip.spec.mjs, main/addon/InputModality.spec.mjs, main/addon/GoogleMapsReadiness.spec.mjs, worker/ManagerReplySettlement.spec.mjs, and Touch.spec.mjs itself.

The Fix

The victims own their stubs per test: DomEvents.spec.mjs and Touch.spec.mjs re-install their own document and window references in test.beforeEach (idempotent, the same objects the module-level code created, so the sensor's import-time listener registration stays valid). The teardowns keep restoring. No production code changes.

Acceptance Criteria

  • AC-1 Both specs re-install their document and window stubs in beforeEach; deleting the globals between two of their tests no longer fails the next test (a red-first arm in each spec deletes both globals in a preceding test).
  • AC-2 The unit suite is green on CI at the PR head, and PR #19214's rerun on a dev that carries this fix is green.

Out of Scope

The grid/StoreInteractions.spec.mjs:270 count assertion (a separate timing class, defect-note e01b99180c6d70fe); DomAccessAlign.spec.mjs, which installs at module level but has not been observed failing — the same hook is a one-line follow-up if it does.

Related

PR #19214 (blocked by this), #19198 (the first occurrence's head), #19213

Live latest-open sweep: checked the latest 20 open issues at 2026-09-25T12:54:33Z; no equivalent (#19215 is about specs executed by nothing, not this). A2A in-flight sweep: Grace's defect-note is the capture, not a claim; no [lane-claim] on this surface. Own-assignment sweep: #19186, #19213, #19101, #15252 — none covers it.

Origin Session ID: 4c0a5550-17ba-4752-9852-846afa537c86 Retrieval Hint: query_raw_memories("unit spec module-level document window stub lost to neighbour teardown fullyParallel worker")

🪢 Mnemosyne (Claude Fable 5.1 · Claude Code)

tobiu referenced in commit 863a812 - "test(unit): the document and window stubs are re-installed per test where a neighbour's teardown can strip them (#19217) (#19218)" on Sep 25, 2026, 3:09 PM
tobiu closed this issue on Sep 25, 2026, 3:09 PM