Repository navigation
Add --parallel=max:N to cap the auto-detected worker count - #37069
THEjacob1000 wants to merge 3 commits into
Conversation
2796718 to
bbcf020
Compare
WalkthroughThe ChangesParallel worker cap
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/runtime/cli/Arguments.rs`:
- Around line 1824-1832: Replace the inline --parallel parsing around cap,
count_str, and parsed with an explicit parser returning Auto, Fixed(u32), or
Max(u32). Distinguish an unset value from empty max:, zero, nonnumeric input,
and numeric overflow; validate the numeric portion with strings::parse_int and
convert only the expected invalid-input result into the existing CLI diagnostic
instead of defaulting failures to zero.
In `@test/cli/test/parallel.test.ts`:
- Around line 1082-1091: Update the subprocess helpers in the parallel test,
including workers and the rejection cases, to start consuming proc.stdout,
proc.stderr, and proc.exited concurrently. Parse the x PARALLEL result from
stderr in workers, drain both streams in every spawned process, and assert the
captured output before validating exitCode.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: f95bfb22-f802-498a-a3cd-6a5c9baaa091
📒 Files selected for processing (3)
docs/test/parallel.mdxsrc/runtime/cli/Arguments.rstest/cli/test/parallel.test.ts
There was a problem hiding this comment.
♻️ Duplicate comments (1)
test/cli/test/parallel.test.ts (1)
1089-1092: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winParse
stderrforx PARALLEL.Line 1089 now drains both pipes, but Line 1092 still matches
stdout. UnderbunEnv, Bun writes the normal test result, includingx PARALLEL, tostderr. Therefore,workers()returnsNaN, and the new cap assertions cannot validate worker counts.Match
stderr, assert that the match exists, and checkexitCodeafter the output assertions. This repeats the unresolved issue from the previous review.Suggested fix
- const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + const [, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); expect(stderr).not.toContain("error:"); + const match = stderr.match(/(\d+)x PARALLEL/); + expect(match).not.toBeNull(); expect(exitCode).toBe(0); - return Number(stdout.match(/(\d+)x PARALLEL/)?.[1]); + return Number(match![1]);Run
bun bd test test/cli/test/parallel.test.tsafter applying the fix.Based on learnings, normal Bun test result output in
test/cli/test/parallel.test.tsis written tostderr. As per coding guidelines, subprocess tests must drainstdout,stderr, and process exit concurrently and assert output beforeexitCode.🤖 Prompt for 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. In `@test/cli/test/parallel.test.ts` around lines 1089 - 1092, Update the workers() helper to extract the PARALLEL count from stderr rather than stdout, assert that the match exists before reading its capture, and perform the exitCode assertion after the output assertions. Preserve concurrent draining of stdout, stderr, and process completion.Sources: Coding guidelines, Learnings
🤖 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.
Duplicate comments:
In `@test/cli/test/parallel.test.ts`:
- Around line 1089-1092: Update the workers() helper to extract the PARALLEL
count from stderr rather than stdout, assert that the match exists before
reading its capture, and perform the exitCode assertion after the output
assertions. Preserve concurrent draining of stdout, stderr, and process
completion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d164e5f8-3997-430e-91e7-a858fed30cef
📒 Files selected for processing (1)
test/cli/test/parallel.test.ts
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
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/runtime/cli/Arguments.rs`:
- Line 623: Use consistent “detected worker count” terminology for the
--parallel help text and documentation, matching the value provided by
bun_core::get_thread_count() rather than describing physical CPU cores. Update
src/runtime/cli/Arguments.rs lines 623-623, docs/test/parallel.mdx lines 10-10,
and docs/test/parallel.mdx lines 19-24; revise the examples and explanatory text
to reflect the detected worker count and its overrides or clamping behavior.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 02713b6c-76d6-4372-8faf-279d5b2ddcd2
📒 Files selected for processing (3)
docs/test/parallel.mdxsrc/runtime/cli/Arguments.rstest/cli/test/parallel.test.ts
| ), | ||
| parse_param!( | ||
| "--parallel <NUMBER>? Run test files in parallel using N worker processes. Implies --isolate. Defaults to CPU core count." | ||
| "--parallel <NUMBER>? Run test files in parallel using N worker processes, or \"max:N\" for the CPU core count capped at N. Implies --isolate. Defaults to CPU core count." |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use one term for the worker-count source.
The help text and documentation describe physical CPU cores, but the implementation uses bun_core::get_thread_count(). That function honors UV_THREADPOOL_SIZE and GOMAXPROCS and clamps the value.
src/runtime/cli/Arguments.rs#L623-L623: Change “CPU core count” to “detected worker count” or document the overrides.docs/test/parallel.mdx#L10-L10: Update the default-count description.docs/test/parallel.mdx#L19-L24: Update the examples and explanatory text.
📍 Affects 2 files
src/runtime/cli/Arguments.rs#L623-L623(this comment)docs/test/parallel.mdx#L10-L10docs/test/parallel.mdx#L19-L24
🤖 Prompt for 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.
In `@src/runtime/cli/Arguments.rs` at line 623, Use consistent “detected worker
count” terminology for the --parallel help text and documentation, matching the
value provided by bun_core::get_thread_count() rather than describing physical
CPU cores. Update src/runtime/cli/Arguments.rs lines 623-623,
docs/test/parallel.mdx lines 10-10, and docs/test/parallel.mdx lines 19-24;
revise the examples and explanatory text to reflect the detected worker count
and its overrides or clamping behavior.
What does this PR do?
Adds
--parallel=max:Ntobun test. Same auto-detected worker count as plain--parallel, capped at N.The point is running one command on machines of different sizes. A 32 core machine that's also running a browser and an editor shouldn't hand every core to the test runner, but a 4 core CI box dedicated to the job should use all 4.
--parallel=max:8gives 8 on the first and 4 on the second, where a fixed--parallel=6oversubscribes the CI box and underutilizes the workstation.Percentages (jest's
--maxWorkers=50%) don't cover this coz they scale down on the small machine too, 50% of 4 is 2. pytest-xdist has the same semantic as a separate--maxprocessesflag, but--parallelalready takes a value here so the cap goes in the value grammar rather than a new flag, especially coz .max:,max:0andmax:abcerror the same way a bad--parallel=Ndoes.How did you verify your code works?
Added a cap test and the three rejection cases to
test/cli/test/parallel.test.ts. They pass underbun bd testand fail underUSE_SYSTEM_BUN=1. Manual testing was also conducted and validated on both linux and macos systemsAI Usage: Documentation was written by Claude