You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix shared-worker test environment and import isolation - #40121
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.
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.
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: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Description check
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 checks: 4 passed
Check name
Status
Explanation
Title check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
process.envproperty in the existing process-descriptor restoration, preserving the object captured by Vitest's environment proxy.vi.dynamicImportSettled()before restoring mocks, globals, and the shared module cache.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
pnpm check:changed: all 13 selected checks pass; rerun immediately before push confirmed the passing cache.pnpm check:flaky-test-pattern-ratchetpasses.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
Agent skill upstream boundary
Checklist