test(install): make bun-pm-scan.test.ts hermetic and concurrent
Closed
RO
1mo ago+199+199+012345678901234567890123456789-350-350-012345678901234567890123456789
What
test/cli/install/bun-pm-scan.test.ts was resolving express/lodash/axios from npmjs.org once per test (14 installs total) and ran every test serially. Build #86620 clocked it at 16s on windows-aarch64; a local debug+ASAN run hit 51s with a 5s-timeout in the express install.
How
- Serve packages from the in-process
SimpleRegistryalready used by the other scanner tests (left-pad/is-even/is-odd) instead of npmjs.org. No more public-internet dependency. - Generate the three needed lockfiles once in
beforeAlland drop the text into each test's temp dir.bun pm scanonly reads the lockfile, so the 14 per-testbun installcalls are gone (3 installs total now, in parallel). - Run the whole suite under
describe.concurrent; every test owns its own temp dir so there is no shared state. - Check stdout/stderr before
exitCode, add positive stderr assertions to the negative-path tests, and assert the actual scanner payload shape in scanner receives correct package format (it used to only check for aPACKAGES:marker). - Replace the always-passes
body-parserbranch in the transitive-dependency test with a deterministic assertion onmy-app › is-even › is-odd. The previous version fell through toexpect(exitCode).toBeDefined()wheneverbody-parserwasn't in the tree. - Drop
tmpdirSyncin favour oftempDir, and trim the slow-scansetTimeoutfrom 1200ms to 1050ms (the reporting threshold is>= 1000ms).
Verification
bun bd test test/cli/install/bun-pm-scan.test.ts (debug + ASAN, Linux x64):
| before | after | |
|---|---|---|
| wall time | 51.44s | 11.4 / 13.8 / 15.0s (3 runs) |
| result | 16 pass, 1 timeout | 17 pass |
| expect() calls | 44 | 65 |
Release build: 33.1s with 4 timeouts -> 1.9s, 17 pass.
Same 17 tests, no skips.
[stamp-90s] gate passed · iteration 1 · 1 files touched
passes on PR (with fix)
Test-only change.
Debug/ASAN (expected pass):
$ bun bd test 'test/cli/install/bun-pm-scan.test.ts'
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test test/cli/install/bun-pm-scan.test.ts
bun test v1.4.0 (fe89e9828)
test/cli/install/bun-pm-scan.test.ts:
(pass) bun pm scan > configuration > shows error when no security scanner configured [154.67ms]
(pass) bun pm scan > configuration > shows error when lockfile doesn't exist [141.38ms]
(pass) bun pm scan > configuration > shows error when package.json doesn't exist [149.06ms]
(pass) bun pm scan > scanner execution > scanner version validation [1331.58ms]
(pass) bun pm scan > scanner execution > scanner receives correct package format [1398.00ms]
(pass) bun pm scan > vulnerability detection > detects warning vulnerabilities [1366.77ms]
(pass) bun pm scan > vulnerability detection > handles mixed vulnerabilities [1395.68ms]
(pass) bun pm scan > vulnerability detection > detects fatal vulnerabilities [1502.69ms]
(pass) bun pm scan > vulnerability detection > no vulnerabilities found [1438.24ms]
(pass) bun pm scan > dependency paths > shows correct path for transitive dependencies [1406.70ms]
(pass) bun pm scan > error handling > handles scanner crash [1386.02ms]
(pass) bun pm scan > dependency paths > shows correct path for direct dependencies [1557.03ms]
(pass) bun pm scan > error handling > handles invalid JSON from scanner [1430.94ms]
(pass) bun pm scan > error handling > handles missing required fields in advisory [1430.28ms]
(pass) bun pm scan > output formatting > singular vs plural in summary [1416.65ms]
(pass) bun pm scan > differences from bun add/install > does not show 'installation aborted' message [1455.30ms]
(pass) bun pm scan > output formatting > shows timing for slow scans [2501.60ms]
17 pass
0 fail
66 expect() calls
Ran 17 tests across 1 file. [9.18s]
Exit: 0
diff hotspot
test/cli/install/bun-pm-scan.test.ts | 549 +++++++++++++----------------------
1 file changed, 199 insertions(+), 350 deletions(-)
gate history · 2 passed · 0 rejected · iteration 1
evidence per changed file
file reads edits tests
test/cli/install/bun-pm-scan.test.ts 5 9 0