Skip to content

Fix shared-worker test environment and import isolation - #40121

Merged
AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/fix-ci-shared-worker-isolation
Nov 9, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/fix-ci-shared-worker-isolation

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A test could leave its environment or unfinished module loading behind and break unrelated tests that ran later in the same worker. Restore the original environment object and finish background imports before cleaning up each file.

What Changed

  • Include the process.env property in the existing process-descriptor restoration, preserving the object captured by Vitest's environment proxy.
  • Await vi.dynamicImportSettled() before restoring mocks, globals, and the shared module cache.
  • Add one real-worker regression covering an environment replacement followed by an override, plus a background import that must finish before file cleanup completes.

Why

CI run 42558483850 failed independently of tooltip PR #39960. Running the Gitea suite before the relay suite reproduces all seven relay failures: Vitest writes through its proxy into the replacement environment but deletes through the original proxy target. The renderer failure records an unfinished snapshot import from the project-removal suite, which later poisons the clock-skew suite after teardown.

These fixes belong to the shared-worker lifecycle rather than individual application tests. Current main still contains the faulty reset.

Linked Issue

Related PR: #39960 (no changes to that PR).

Visual Proof

N/A — test infrastructure only; no visual or interaction changes.

Testing

  • Manually reproduced the ordered Gitea→relay failure: 7 failures before, all 32 tests passing after.
  • Bun and Node targeted runs: 47 tests each across the regression, Gitea, relay, project-removal, and mirrored clock-skew suites pass.
  • The new regression fails independently when either environment restoration or import draining is reverted.
  • pnpm check:changed: all 13 selected checks pass; rerun immediately before push confirmed the passing cache.
  • pnpm check:flaky-test-pattern-ratchet passes.
  • Full CI unit run: all 12 shards pass, plus relay integration, static analysis, and typecheck (run 42560149338).

Local verification was on macOS; CI covers the complete suite and other configured platforms.

Risk

Level: Low. Only shared unit-test workers change; pending imports now finish before cleanup, which may expose an import that never settles through the existing hook timeout. No production, SSH, mobile, or workspace behavior changes. A plain revert restores the previous runner behavior.

Review

  • Self-reviewed the cleanup order and cross-platform process invocation.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material is copied or translated.

Checklist

  • This PR is small and focused.
  • Explained the failure, resulting behavior, and risk.
  • No visual or interaction changes.
  • Cross-platform, SSH/remote, and path impact considered.
  • Required local checks pass; full build, typecheck, and unit suite remain covered by CI.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The reset helper now waits for pending dynamic imports before cleanup and includes the process.env property descriptor in process-state restoration. A new integration test runs ordered Vitest files in a shared, single-worker process and checks environment cleanup, import completion, and successful process exit.

Merge Risk: Minimal · up to ec1fc

No issue requiring a change before merge is established; proceed with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description follows the repository template's main sections: ELI5, What Changed, Why, Testing, Risk, Review, Agent skill upstream boundary, and Checklist. It explains the cause (environment restor… Add a linked issue in the 'Linked Issue' section using 'Fixes #' for an actual issue. If the author is an outside contributor, the template requires an issue, and 'Related PR' does not satisfy this. If the author is a StablyAI maint…
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title "Fix shared-worker test environment and import isolation" matches the main change: the PR restores process.env in the shared-worker reset and waits for vi.dynamicImportSettled() before clean…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Fix shared-worker test environment and import isolation" matches the main change: the PR restores process.env in the shared-worker reset and waits for vi.dynamicImportSettled() before cleanup. It is specific to the test runner and names both fixes, so a teammate scanning history would understand the primary change.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Full details: Description check

Explanation

The description follows the repository template's main sections: ELI5, What Changed, Why, Testing, Risk, Review, Agent skill upstream boundary, and Checklist. It explains the cause (environment restoration and unfinished background imports in the shared worker), the mechanism (restoring the process.env descriptor and awaiting vi.dynamicImportSettled()), and the risk (low, limited to shared unit-test workers). The Testing section lists concrete verification, including a reproduction with 7 failures before and 32 passing after, and a regression test that fails when either fix is reverted. Gaps: the 'Linked Issue' section does not contain a 'Fixes #' issue link, and it only cites related PR #39960 with no changes to it. The template requires an actual linked issue for outside contributors, so this is a required item. The 'Visual Proof' section is marked N/A with a reason, which is acceptable. The AI Disclosure section is omitted, which is acceptable only if the author is a StablyAI team member. The Review and Checklist items are checked, but the description does not state which platforms were tested beyond macOS, and it does not mention Windows or Linux locally; the author defers this to CI, which is a minor gap.

Resolution

Add a linked issue in the 'Linked Issue' section using 'Fixes #<number>' for an actual issue. If the author is an outside contributor, the template requires an issue, and 'Related PR' does not satisfy this. If the author is a StablyAI maintainer, state that and link any pre-existing issue. Optionally, state the AI Disclosure if AI tools were used, or confirm the author is an internal contributor. Optionally, clarify which platforms were tested locally beyond macOS.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0191730-9bf5-407f-b028-93fed6e74807
Commits

Reviewing files that changed from the base of the PR and between 4fc4d79 and ec1fc29.

Files selected for processing: 2

  • config/scripts/test-runtime/environment/vitest-shared-worker-file-reset.mjs
  • config/scripts/test-runtime/environment/vitest-shared-worker-file-reset.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant