Skip to content

fix(ui): prevent mock Gateway tests from leaking into routing tests - #131052

Merged
steipete merged 3 commits into
mainfrom
codex/qa-mock-gateway-fixture-lifetime-20260827
Aug 27, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/qa-mock-gateway-fixture-lifetime-20260827

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where Control UI routing tests fail depending on which mock-Gateway tests ran first. Running the serialized deferral tests before the browser routing tests on current main reliably leaves an empty base-path override behind, causing the two routing tests to return the wrong path.

Why This Change Was Made

The serialized Gateway fixture installs browser globals, listeners, storage, and timers. Restoring only WebSocket or clearing storage cannot retire that page lifetime. Both serialized transport suites now execute the unchanged initialization script in a fresh JSDOM VM realm supplied by a shared Vitest fixture. A finally block closes that realm, including on assertion failure. Per-test partial cleanup and implied-eval suppressions are removed.

Production routing, the shared Vitest isolation setting, ordinary socket disconnect semantics, and Vite passthrough are unchanged. The fix uses the existing jsdom dependency and its documented outside-only VM/close lifecycle, rather than introducing a production teardown API or compensating in routing consumers. It adds pinned dev-only @types/jsdom declarations; no runtime dependency changes.

User Impact

No user-visible product change. Developers get order-independent Control UI checks and deterministic retirement of queued mock-Gateway work. No changelog or screenshots are applicable to this test-only repair.

Evidence

  • On baseline aa0647d06d27e1a9abd0a607abfc3c85649f710d, the original single-worker order (deferral suite, then browser routing suite) reproduces two routing failures; the deferral tests themselves pass.
  • With the fix, the same ordered owner/sibling run plus the serialized config/session suite and new lifetime regressions passes all 19 tests across four files.
  • Temporarily disabling page cleanup makes the lifetime regression fail: a queued config write survives teardown. Cleanup was restored before the final passing run. The final regression also directly observes the mock socket for late responses, independently of storage teardown.
  • Coverage retains config round trips, held and one-shot deferred requests, session creation/adoption, archive filtering, unsubscribe, offline replacement sockets, and Vite passthrough. New checks verify host globals/storage are untouched and page closure retires queued work and listeners.
  • Independent owner review accepted the realm boundary; its test-strengthening feedback was applied. Structured Codex autoreview reports no blocking findings.
  • Full shared UI suite: 10,916 tests passed, 66 skipped; 744 files passed and 18 skipped. Run used one worker and disabled file parallelism and cache so shared-state ordering remained in scope.
  • The first changed gate caught missing jsdom declarations. After adding the dev-only types, a fresh UI type check and then the normal incremental UI type checks pass. Focused lint and the final 19-test owner/sibling rerun pass. Structured Codex review covers the complete six-file patch and the later lint-only follow-up, with no blocking findings.
  • Complete six-file changed gate passed: all 95 npm package-lock targets, dependency/ownership guards, core/UI/test/plugin/script type checks, full lint, and zero runtime import cycles.
  • Final-head stress: all ten shuffled seeds (11, 29, 47, 83, 101, 137, 173, 211, 257, 307) passed all 19 tests, for 190 passing executions across 40 file runs.
  • Hosted CI caught a suppression-inventory failure; the fixture now uses Vitest's built-in task context to name generated scripts, removing the exception entirely. Authentic local RED became GREEN: all 23 relevant tests, types, focused lint, review and the final changed-file gate pass.
  • A separate startup-memory gate failed at 401.7 MiB against a 401 MiB ceiling. The exact main baseline independently failed the same check at 402.02 MiB (run 33094744720); no runtime/build/startup code or runtime resolution changed here, and the ceiling is unchanged.
  • Hosted CI on 4689d81a2947e01174f58232837bb53cd11c1dcb is green: run 33099198074, attempt 2. Both initially failed jobs passed the single failed-jobs retry on the unchanged head. Build, including the unchanged startup-memory gate, passed; the required openclaw/ci-gate succeeded. No threshold, assertion, or test environment was weakened.
  • The latest ClawSweeper review reports no correctness finding; its sole rank-up move was waiting for exact-head CI, now satisfied. Its attached execution also passed all 19 focused owner/sibling tests.

Named follow-up — Gateway place-label ownership, now repaired separately in draft #131118: the failed browser shard reported Gateway · local instead of the advertised machine name. All affected product, existing E2E, and browser-fixture paths are byte-identical to this PR's baseline, and this new JSDOM unit fixture is not loaded by Chromium E2E. The original six-test suite passed three focused repetitions, but two controlled Chromium orderings reproduced real baseline defects: recovery-scope initialization can clear a completed name without changing the discovery Task's arguments, and Browse captures an old label before discovery completes. The Task dependency contract was inspected directly. The separate fix makes that Task the canonical name owner and renders the open browser's current label; retries do not fix these races. The hosted log cannot identify which ordering produced its symptom.

The other failed job exceeded the pinned old-reader test's 300-second budget after 355 seconds. Its synchronous body returned normally after pinned-reader and reopened-candidate assertions; Vitest's elapsed-time check then rejected it. No SQLite assertion failed. The test is byte-identical to baseline/current main, and the log lacks stage timings to distinguish fetch, worktree, or TypeScript child startup cost. No timeout, test environment, storage, or assertion was changed here. Named follow-up: the hosted Node-shard raw-tsx entry path bypasses the canonical tooling registration, so the later tooling-cache repair does not cover that path; this is a verified bootstrap coverage gap, not proof of the 355-second cause.

Production LOC: +0/-0. Tests/test support: +251/-174. Dev manifest: +1; lockfile: +23. No application code changed.

Provenance: the shared-window installation pattern is present in #107458 (d6fc3d34e2010997d4f67807b30c336347808f31, July 14), authored and merged by @steipete; #130468 (fc6cf5e6907dd9fde31fcb454002cffcf5d465d4, August 27 UTC), also authored and merged by @steipete, carried it into the deferral suite that reproduces the routing failure. This is a fixture-lifetime defect, not evidence of a production routing regression.

Related but distinct: #120554 improves reconnect/catalog E2E deferrals and remains owned by its author. This repair does not copy or replace that work.

@steipete
steipete requested a review from a team as a code owner August 27, 2026 17:17
@steipete steipete added the app: web-ui App: web-ui label Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete steipete self-assigned this Aug 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Aug 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • package.json
  • pnpm-lock.yaml

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfiles or workspace dependency policy changes are present.
  • Treat pnpm-lock.yaml and package-lock.json diffs as dependency security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of @openclaw/openclaw-secops, or an OpenClaw organization member with Maintain or Admin repository access.

  • Current SHA: 4689d81a2947e01174f58232837bb53cd11c1dcb
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Security review is still recommended before merge when the dependency graph change is intentional.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 2:13 PM ET / 18:13 UTC.

ClawSweeper review

What this changes

The PR runs serialized mock-Gateway tests in a fresh JSDOM page realm per test and closes that realm to prevent globals, storage, listeners, and queued work from leaking into routing tests.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking correctness finding. This focused test-isolation repair targets the fixture that writes the shared base-path global; keep the maintainer-owned PR open until its remaining exact-head CI completes.

Priority: P2
Reviewed head: 4689d81a2947e01174f58232837bb53cd11c1dcb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful regression coverage; independent execution is unavailable in this node_modules-less checkout and exact-head CI is still running.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored test-only repair makes no user-visible runtime change; its supplied evidence is focused ordered and shuffled Vitest coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored test-only repair makes no user-visible runtime change; its supplied evidence is focused ordered and shuffled Vitest coverage.
Evidence reviewed 6 items Leaking producer and routing consumer: The mock initializer assigns the base-path override on its executing window, and Control UI routing reads that override before path inference. The patch moves execution into a separate window rather than adding a routing-side workaround.
Introduced lifetime owner: The new fixture executes generated scripts in JSDOM's VM context and closes the JSDOM window in a finally block, including assertion failures.
Regression coverage: New tests independently assert that generated Gateway globals and storage stay out of the host realm and that closing the page cancels queued work and listeners.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs ui/src/test-helpers/mock-gateway-page.test.ts ui/src/test-helpers/control-ui-e2e.deferral.test.ts ui/src/test-helpers/control-ui-e2e.mock-gateway.test.ts ui/src/app/browser.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.ui.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-131052-2C0KOk/target

 ✓  ui  ui/src/test-helpers/mock-gateway-page.test.ts (2 tests) 52ms
 ✓  ui  ui/src/test-helpers/control-ui-e2e.deferral.test.ts (2 tests) 55ms
 ✓  ui  ui/src/app/browser.test.ts (2 tests) 3ms
 ✓  ui  ui/src/test-helpers/control-ui-e2e.mock-gateway.test.ts (13 tests) 1475ms
     ✓ cycles subscription-scoped session events and stops after unsubscribe  1219ms

 Test Files  4 passed (4)
      Tests  19 passed (19)
   Start at  18:14:30
   Duration  3.31s (transform 1.73s, setup 474ms, import 701ms, tests 1.58s, environment 3.59s)

[test] passed 1 Vitest shard in 3.88s

Assertions:

  • PASS expect_output: Test Files

How this fits together

Control UI test helpers serialize a mock Gateway script into a browser-like page, where it installs WebSocket behavior and a base-path override. Routing reads that override when choosing resource paths, so the fixture’s page lifetime must end before later tests use Vitest’s shared browser realm.

flowchart LR
  A[Mock Gateway init script] --> B[JSDOM page realm]
  B --> C[Page globals and storage]
  C --> D[Mock Gateway tests]
  B --> E[Fixture teardown]
  E --> F[Shared routing-test realm remains clean]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still incomplete; wait for the remaining relevant job before merging. The read-only checkout lacks node_modules, so the supplied focused test evidence was not independently re-executed here.
Agent review details

Security

None.

PR surface

Source +30, Tests +47, Config +1, Other +23. Total +101 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 1 30 0 +30
Tests 3 221 174 +47
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 1 23 0 +23
Total 6 275 174 +101

Review metrics

Metric Value Why it matters
Production vs. test LOC production +0/-0; test/test-support +251/-174; dev manifest +1; lockfile +23 The production runtime is unchanged; added surface is the isolated test fixture, regression tests, and typings for an existing dev dependency.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one fixture-owned JSDOM realm per serialized mock-Gateway test, always close it, and merge after the exact-head CI result confirms the supplied focused regression coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one fixture-owned JSDOM realm per serialized mock-Gateway test, always close it, and merge after the exact-head CI result confirms the supplied focused regression coverage.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: the old tests execute the initializer in Vitest’s shared window, and that initializer writes the value routing reads. The checkout has no node_modules, so this review did not independently rerun the ordered failure.

Is this the best way to solve the issue?

Yes. Isolating and closing the page realm repairs the lifecycle owner directly; routing-side cleanup would leave other fixture-installed globals, listeners, timers, and storage vulnerable to leakage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5890806fbe56.

Labels

Label changes:

  • add P2: This is a bounded developer-test reliability repair with no claimed production behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only repair makes no user-visible runtime change; its supplied evidence is focused ordered and shuffled Vitest coverage.

Label justifications:

  • P2: This is a bounded developer-test reliability repair with no claimed production behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only repair makes no user-visible runtime change; its supplied evidence is focused ordered and shuffled Vitest coverage.

Evidence

What I checked:

Likely related people:

  • steipete: The supplied related history credits this person with the merged mock-Gateway installation pattern and the deferral suite that made the shared-window lifetime defect visible. (role: feature-history contributor; confidence: high; commits: d6fc3d34e201, fc6cf5e6907d, 400521eecb0e; files: ui/src/test-helpers/control-ui-e2e.ts, ui/src/test-helpers/control-ui-e2e.deferral.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the remaining relevant exact-head CI job complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 5171ab7 into main Aug 27, 2026
350 of 353 checks passed
@steipete
steipete deleted the codex/qa-mock-gateway-fixture-lifetime-20260827 branch August 27, 2026 18:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…penclaw#131052)

* test(ui): isolate serialized mock gateway page lifetimes

* test(ui): satisfy fixture lifecycle lint contracts

* test(ui): name fixture scripts without lint suppression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui dependencies-changed PR changes dependency-related files maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant