Skip to content

test: isolate cwd-mutating unit tests - #3540

Merged
kojiwakayama merged 2 commits into
mainfrom
fix/test-cwd-runner-race
Aug 10, 2026
Merged

kojiwakayama merged 2 commits into
mainfrom
fix/test-cwd-runner-race

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pre-push intermittently failed after thousands of parallel unit tests with NotFound: Unable to get CWD while AJV loaded during cli/commands/styles/command.test.ts. This was observed while pushing PR #3538, but the failure is separate from that build-extension fix.

This changes test:unit into three phases:

  • broad parallel discovery that excludes all cwd-mutating files
  • a serial cwd phase for the Deno.chdir users
  • an isolated parallel two-file mutex probe

The regression test in src/testing/cwd.test.ts pins that partition so future task changes do not put cwd mutation back into broad parallel discovery.

Root cause

Deno.chdir is process-global. The filesystem lock serializes the tests that intentionally change cwd, but arbitrary Deno and Node module loaders do not acquire that lock before resolving modules. A parallel module loader can therefore observe the process while another test has moved or removed cwd, producing Unable to get CWD.

Implementation notes

A first attempt using Deno --ignore was rejected because it did not reliably exclude every explicit test path. The final task uses discovery-time find ! -path filters so the broad parallel phase never receives those files.

This builds on the prior writer-lock work in PR #3494.

Validation

  • Focused regression went RED, then GREEN.
  • Earlier deno task test:unit validation passed with 3773 parallel tests / 27898 steps, 10 serial cwd tests / 193 steps, and 2 cwd-exclusion probes.
  • Current normal push hook on rebased origin/main passed deno task test:unit with 3774 parallel tests / 27905 steps, 10 serial cwd tests / 193 steps, and 2 cwd-exclusion probes.
  • deno fmt --check passed. Earlier manual run checked 4977 files; current pre-push checked 4980 files after origin/main advanced.
  • deno lint passed. Earlier manual run checked 4902 files; current pre-push checked 4905 files after origin/main advanced.
  • deno check src/index.ts passed.
  • git diff --check passed.

Related

Summary by CodeRabbit

  • Tests

    • Improved automated test coverage for working-directory-sensitive scenarios.
    • Added validation to ensure test tasks include the correct test suites and exclusions.
    • Enabled parallel execution where appropriate for more efficient test runs.
  • Chores

    • Updated the unit test command to coordinate parallel and serial test groups consistently.

Pre-push intermittently failed after thousands of parallel tests when AJV loaded during cli/commands/styles/command.test.ts and Node could no longer read the process cwd. The filesystem cwd lock serializes test writers, but arbitrary Deno and Node module loaders do not acquire that lock before resolving modules.

The unit task now partitions discovery into a broad parallel phase that excludes cwd-mutating files, a serial cwd phase, and a separate parallel two-file mutex probe. A regression test pins the task partition so future changes do not reintroduce cwd mutation into broad parallel discovery.

Constraint: Deno.chdir is process-global, so writer serialization alone cannot protect unrelated module loaders in the same process

Rejected: Deno --ignore for this partition | it did not reliably exclude every explicit test path, so discovery-time find ! -path filters are used

Confidence: high

Scope-risk: narrow

Related: #3538

Related: #3494

Tested: focused regression RED then GREEN

Tested: deno task test:unit passed with 3773 parallel tests / 27898 steps, 10 serial cwd tests / 193 steps, and 2 cwd-exclusion probes

Tested: deno fmt --check checked 4977 files

Tested: deno lint checked 4902 files

Tested: deno check src/index.ts

Tested: git diff --check

Not-tested: No additional manual verification was run during git packaging before push hooks
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kojiwakayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f540311d-345d-4443-a962-b975014d9018

📥 Commits

Reviewing files that changed from the base of the PR and between b79080e and 3fa43f3.

📒 Files selected for processing (1)
  • src/testing/cwd.test.ts
📝 Walkthrough

Walkthrough

The unit-test configuration now separates parallel, cwd-sensitive, and cwd-exclusion tasks. A configuration test defines expected test groups and verifies task commands, parallel flags, and path inclusion or exclusion.

Changes

Unit Test Orchestration

Layer / File(s) Summary
Split unit test tasks
deno.json
The test:unit command is replaced with separate parallel, cwd, and cwd-exclusion tasks.
Validate task composition
src/testing/cwd.test.ts
The test defines cwd-sensitive path lists and verifies task flags, inclusion, and exclusion rules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: kwakayama

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: isolating unit tests that mutate the process-wide current working directory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-cwd-runner-race

Comment @coderabbitai help to get the list of available commands.

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/testing/cwd.test.ts`:
- Around line 53-79: Update the assertions in the CWD task-generation test to
verify the groups are disjoint: each CWD_EXCLUSION_TESTS path must be absent
from cwdTask, and each CWD_SCOPED_TESTS path must be absent from exclusionTask,
while preserving the existing positive membership checks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e6b2d873-b7a6-4ba0-9a47-6e5a9b60be29

📥 Commits

Reviewing files that changed from the base of the PR and between bb90d94 and b79080e.

📒 Files selected for processing (2)
  • deno.json
  • src/testing/cwd.test.ts

Comment thread src/testing/cwd.test.ts
@kojiwakayama
kojiwakayama enabled auto-merge August 10, 2026 16:41
@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit ff32887 Aug 10, 2026
35 checks passed
@kojiwakayama
kojiwakayama deleted the fix/test-cwd-runner-race branch August 10, 2026 17:08
kwakayama added a commit that referenced this pull request Aug 10, 2026
Ships the build fixes for veryfront-issue-inbox#456. `veryfront build` has
been broken for every project since 0.1.1206, and 5 of 7 scaffold templates
could not build at all.

- #3538 prime host contracts in the build extension path
- #3541 resolve server-side esm.sh modules with a server target
- #3542 keep optional Deno imports optional
- #3540 isolate cwd-mutating unit tests

The version is embedded in hydration-runtime.generated.ts, so a bump must be
followed by `deno task generate`; the manifests check fails otherwise.

There is no earlier version to pin to: 0.1.1205 fails the same templates with
the CSSProcessor error that #3417 was fixing.
This was referenced Aug 10, 2026
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