Skip to content

test(install): run bun-pack.test.ts concurrently and assert the exact pack output - #40959

Merged
Jarred-Sumner merged 2 commits into
mainfrom
robobun/c5255591/bun-pack-test-concurrent
Aug 30, 2026
Merged

Jarred-Sumner merged 2 commits into
mainfrom
robobun/c5255591/bun-pack-test-concurrent

Conversation

@robobun

@robobun robobun commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • test/cli/install/bun-pack.test.ts takes 10.7s on debian 13 x64-asan in the serial phase (build 108487). Its 80 tests run one at a time, each with one to five bun pm pack spawns.
  • The assertions are loose: the harness pack() helper only checks that stderr lacks error:, warning:, failed and panic:, tarballs are checked with toMatchObject, and the --filename="out/foo.tgz" error case accepts any outcome.

Fix

  • Each test builds its tree with tempDir instead of the shared beforeEach directory. The describes are describe.concurrent, the top-level tests test.concurrent.
  • A local runPack() returns stdout and stderr, raw and normalized with normalizeBunSnapshot. The normalized stdout masks the shasum, the integrity and the packed size, which depend on the compressor.
  • Every test asserts that err is "" (or the exact $ script echo), the exact stdout, the exit code, and the full entry list with toEqual. Error cases assert the exact message and that nothing was written.
  • Verified: local debug+ASAN build, 80 tests in 20.6s and 21.8s before, 83 tests in 6.9s, 6.9s and 7.0s after. --rerun-each=3 passes 249 of 249. CI debian 13 x64-asan: 10.7s before, 3.0s after (build 108529).

Background

  • describe.concurrent runs a group's async tests up to --max-concurrency at a time (20, or 5 in ASAN builds). Groups and top-level test.concurrent tests overlap, so a shared module-level directory is not safe.
  • toMatchInlineSnapshot works in concurrent tests, but one call site cannot hold different values across test.each rows. The tables compare a line array instead.
Notes

no test proof · iteration 1 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/install/bun-pack.test.ts

… pack output

Each test builds its tree in its own tempDir instead of the shared
beforeEach directory. The describe blocks are describe.concurrent and
the top-level tests are test.concurrent.

A local runPack() replaces the harness pack() helper. It returns the
normalized stdout and stderr. The shasum, the integrity and the packed
size depend on the compressor, so it masks them. Each test asserts that
stderr is empty (or the exact script echo), the exact stdout, the exit
code, and the full entry list of the tarball.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • test/cli/install/bun-pack.test.ts
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f1da7290-4a22-482c-812c-a20738746068

📥 Commits

Reviewing files that changed from the base of the PR and between 41906a4 and a3ddc38.

📒 Files selected for processing (1)
  • test/cli/install/bun-pack.test.ts

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@robobun

robobun commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 4:18 AM PT - Aug 30th, 2026

✅ @robobun, your commit a3ddc38f93c815ba66298c10cf8783071a4ce1a0 passed in Build #108539! 🎉


🧪   To try this PR locally:

bunx bun-pr 40959

That installs a local version of the PR into your bun-40959 executable, so you can run:

bun-40959 --bun

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed this PR and didn't find any bugs. Because it rewrites ~80 tests across a ~3100-line diff, a human spot-check that no case lost coverage in the conversion would still be worthwhile.

What was reviewed:

  • runPack helper — drains stdout/stderr/exited concurrently, uses await using, bunEnv, and normalizeBunSnapshot; masking regexes only match the intended summary lines.
  • Assertion direction — toMatchObject/toContain replaced with toEqual/inline snapshots and err checked before exitCode; assertions are strictly tighter than before.
  • Concurrency safety — shared module-level packageDir removed in favor of per-test tempDir, so describe.concurrent groups don't share state.
  • test.each tables (scoped names, invalid package.json, --destination, --gzip-level) — each row still exercises the same input as the old for-loop version, plus new negative assertions that no tarball was written on error.
Extended reasoning...

Overview

This PR is a test-only refactor of test/cli/install/bun-pack.test.ts (~1731 additions / ~1364 deletions, net ~3100 diff lines). It replaces the module-level beforeEach + tmpdirSync() shared directory and the harness pack/packExpectError helpers with per-test using dir = tempDir(...) fixtures and a local runPack helper. Tests move to test.concurrent/describe.concurrent, tarball assertions switch from toMatchObject on entry objects to toEqual on exact pathname arrays, and stdout is asserted via toMatchInlineSnapshot with shasum/integrity/packed-size masked. Error paths now assert exact stderr, exit code 1, and that no stray files were written. No production code is touched.

Security risks

None. This is a test file for bun pm pack; it spawns the debug bun binary against local tempDir fixtures, contacts no network, and adds no new dependencies or FFI. The only "sensitive" content is a path-traversal test case (../../outside-pkg), which was already present and now asserts more (exact error text plus a full directory listing showing nothing escaped).

Level of scrutiny

Medium. The change is mechanical and aligns tightly with the repo's test conventions (tempDir over tmpdirSync, normalizeBunSnapshot, stderr-before-exit-code, concurrent subprocess tests, await using proc, Promise.all on the three pipes). Assertions move in the tightening direction throughout, which is what REVIEW.md asks for. That said, 80+ test bodies were rewritten by hand — the risk isn't a bug in any one helper but a transcription slip in one row of a test.each table or a snapshot that quietly encodes weaker behavior than the old toMatchObject covered. The bug hunt ran to dry_streak without findings, but a human skim of a handful of conversions (especially the bundledDependencies, workspace: lockfile, and lifecycle-script blocks I didn't excerpt here) would give more confidence than an automated pass alone.

Other factors

No CODEOWNERS entry covers this path. There are no prior review comments or objections on the timeline. The PR description reports local verification (80→83 tests, 20.6s→6.9s under debug+ASAN, --rerun-each=3 clean) and is candid about behavior it snapshots as-is (e.g. // vs @// name handling, --dry-run size reporting). Test count increased and no test/test.each was skipped or removed based on the diff structure I read. The size alone is why I'm deferring rather than approving.

@robobun

robobun commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator Author

For the spot check of the three blocks the review names, this is the old assertion next to the new one.

bundledDependencies

  • basic (both key spellings), basic (true), scoped: the old toMatchObject entry list is now a toEqual on the full pathname list, plus err is "" and the stdout lines (bundled dep1, Total files, Bundled deps: 1).
  • invalid value: old toContain("error:") and toContain("to be a boolean or an array of strings") is now the exact message, exit code 1, and a readdir that shows no tarball.
  • resolve dep of bundled dep, scoped names, scoped names match on scope and name together: the old Total files and Bundled deps checks are in the snapshot, the entry lists are the same four, four and three paths as before.
  • ignore deps that aren't directories: the old not.toContain("Bundled deps") is covered by the snapshot, which has no such line.

workspaces with a lockfile

  • All six workspace: specs still run bun install and then assert the same three entries and the same JSON.parse(contents) object with the expected spec. New: err is "", exit code 0, and the stdout lines.
  • fails gracefully: the old toContain on the error is the exact message. After the install the tarball entries are the same three, and the test now also checks that pkg1 resolved to 1.1.1 in the packed package.json.

Lifecycle scripts

  • execution order: the same four entries and the same three results strings. New: stderr is exactly the three $ <bun> script.js <event> lines in prepack, prepare, postpack order.
  • #17195: the two exists checks are a readdir of the whole directory, the entries are the same three, and the packed package.json is checked to carry 2.0.0-snapshot.test.

The claude-find-issues job failed inside the action itself (result is_error:true after 740ms, before it ran anything). It is not related to this diff.

…script cases

The scripts embed the path to the bun binary. On the darwin CI agent that
path is long enough for package.json to pass 512 bytes, and the pack
summary then prints its size as 0.58KB instead of NNNB.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

@Jarred-Sumner
Jarred-Sumner merged commit b316fd4 into main Aug 30, 2026
5 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the robobun/c5255591/bun-pack-test-concurrent branch August 30, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants