Skip to content

test runner: drop the allow_in_preload flag from GetActiveCfg - #39143

Merged
alii merged 2 commits into
mainfrom
farm/00edda36/test-runner-preload-flag
Aug 15, 2026
Merged

alii merged 2 commits into
mainfrom
farm/00edda36/test-runner-preload-flag

Conversation

@robobun

@robobun robobun commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • mordant derived_field on GetActiveCfg (src/runtime/test_runner/bun_test.rs:79): allow_in_preload has the same value for a given signature at both places the struct is built.
  • The two constructions are the only two callers of the lookup: the hook entry point (generic_hook_impl) always passes true, the test/describe entry point (ScopeFunctions::call_as_function) always passes false. The Zig original had the same two callers with the same two constants, so the flag only ever encoded "which caller am I".
  • It is not a property of Signature, though: Signature is the enum used to name the caller in error messages (Signature::Str is any static name, it happens to be used only by hooks today), so a Signature::allow_in_preload() method would be an arbitrary rule hung on a display type.

Fix

  • Delete GetActiveCfg and the flag. get_test_root (was get_active_test_root) only does the runner lookup and takes the Signature for its error message; clone_active_strong, the test/describe path, does the preload check inline before looking up the active file. The hook path calls get_test_root directly, as it already handles preload itself (get_active_file_unless_in_preload, a few lines down).
  • No behavior change: the three throws (outside of the test runner, during preload, outside of a test file) are raised in the same order with the same messages on both paths.
  • mordant-baseline.toml: dropped the derived_field entry for bun_test.rs. A full bun run rust:mordant:baseline additionally drops two entries unrelated to this change that went stale when install: let the walker own the cache dir it walks and build InstallDirState in one go #38271 and crypto: store PBKDF2's key length as usize #37648 landed (always_unwrapped_option in PackageInstall.rs, narrowed_two_ways in node_crypto_binding.rs); left out of this PR on purpose.
  • Verified:
    • test/js/bun/test/bun_test.test.ts: two new tests pin the during preload and outside of the test runner messages for test/describe/beforeAll, plus beforeAll working from a preload. They pass on the release build too, as expected for a refactor.
    • bun bd test on test/js/bun/test/{bun_test,test-test,preload-test,expect-extend-preload,jest-hooks,describe,jest-each,nested-describes,test-only,concurrent} and test/cli/test/bun-test.test.ts: 0 failures.
    • cargo dylint --all -p bun_runtime with the baseline line removed: reports exactly this derived_field finding on the old source, nothing on the new source.

Background

  • bun test --preload <file> runs the preload script before any test file is loaded. At that point there is no active test file, so test()/describe() have nothing to attach to and throw; hooks are allowed and attach to BunTestRoot.hook_scope, becoming global hooks for every file.
  • Signature (js_fns::Signature) is how the test runner names the calling function in those error messages: either a ScopeFunctions object, which prints as the chain the user called (test, test.skip, describe.only, ...), or a static string such as beforeAll().
  • mordant is the lint pack run by bun run rust:mordant; mordant-baseline.toml records pre-existing findings per (lint, file) so CI fails only on new ones, and an entry is removed once its site is fixed.

The flag was constant per caller: hooks passed true, test/describe passed
false. Move the preload check into clone_active_strong (the test/describe
path) and have the hook path call the runner lookup directly, so there is
no flag to keep in sync with the caller. Error messages and their order
are unchanged; tests pin them.

Removes the derived_field baseline entry for bun_test.rs.
@robobun

robobun commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:05 PM PT - Aug 15th, 2026

❌ @robobun, your commit 7d480ec has some failures in Build #98382 (All Failures)


🧪   To try this PR locally:

bunx bun-pr 39143

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

bun-39143 --bun

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 23 minutes

Limit details: You’ve used all 5 included reviews currently available under your plan.

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9a124c13-a9cf-4124-a316-4b92f5bdb780

📥 Commits

Reviewing files that changed from the base of the PR and between 454b1ca and 2a31e92.

📒 Files selected for processing (4)
  • mordant-baseline.toml
  • src/runtime/test_runner/ScopeFunctions.rs
  • src/runtime/test_runner/bun_test.rs
  • test/js/bun/test/bun_test.test.ts

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

@robobun

robobun commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review.

  • Scope: removes the allow_in_preload flag mordant flagged as derived (derived_field, bun_test.rs), no behavior change. Details in the PR description.
  • mordant: checked locally on bun_runtime with the baseline line removed, the old source reports exactly this finding and the new source reports nothing; the mordant job in this PR's Rust lints run passes with the entry removed as well.
  • test/js/bun/test/bun_test.test.ts gained two tests pinning the preload and outside-the-runner error messages; the test runner suites listed in the description pass on the debug build.
  • CI: build 98382 shows as canceled. All 177 lanes that ran passed; the only jobs that did not run are the two darwin 14 aarch64 test shards, which waited for an agent until they expired and were then canceled along with the build while still queued. Nothing in that build failed, so I have not re-queued it; happy to if a reviewer wants those two shards.
  • Automated review left nothing to address.

@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.

LGTM — behavior-preserving removal of a redundant flag.

What was reviewed:

  • Traced both callers: call_as_function (test/describe, was allow_in_preload: false) now hits the inlined preload check in clone_active_strong; generic_hook_impl (hooks, was true) calls get_test_root which never had the check apply — same three throws in the same order on both paths.
  • Confirmed no other references to GetActiveCfg/get_active_test_root/js_fns::clone_active_strong exist; Signature is Copy so pass-by-value is fine.
  • New tests drain pipes concurrently, snapshot exact messages, and assert the preload beforeAll actually runs — they pin existing behavior (expected for a pure refactor).
Extended reasoning...

Overview

Removes the two-field GetActiveCfg struct from src/runtime/test_runner/bun_test.rs to satisfy a mordant derived_field lint: allow_in_preload was a constant per caller (hooks always true, test/describe always false), so the flag encoded nothing beyond "which of the two callers am I". get_active_test_root becomes get_test_root (runner-exists check only); the preload check moves inline into clone_active_strong, the sole path that ever needed it. ScopeFunctions.rs updates its one call site and drops the GetActiveCfg import. One line removed from mordant-baseline.toml. Two new subprocess tests in bun_test.test.ts pin the three error messages and verify preload hooks still register.

Security risks

None. Internal test-runner control flow; no untrusted input handling, no auth/crypto, no new unsafe blocks or lifetime changes.

Level of scrutiny

Low. This is a small mechanical refactor (~30 lines net) that inlines a boolean whose value was statically determined per call site. I verified equivalence by tracing both call paths: for call_as_function, old = runner check → (is_in_preload && !false) preload throw → active-file check; new = runner check → is_in_preload preload throw → active-file check — identical. For generic_hook_impl, old = runner check → (is_in_preload && !true) never throws → return root; new = runner check → return root — identical. Grep confirms these are the only two callers and no stale references remain.

Other factors

The two new tests follow harness conventions (tempDir, bunEnv, test.concurrent, Promise.all on stdout/stderr/exited, exact snapshots, exit-code asserted last). The PR description correctly notes they pass on release too — appropriate since this is a no-behavior-change refactor and the tests are regression pins, not proof-of-fix. The author scoped the baseline change to just the fixed entry and explicitly left two unrelated stale entries for a separate PR, which is the right call. No prior human review comments to address.

Comment thread src/runtime/test_runner/bun_test.rs
@alii
alii merged commit 486af28 into main Aug 15, 2026
9 of 10 checks passed
@alii
alii deleted the farm/00edda36/test-runner-preload-flag branch August 15, 2026 23:24
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