Repository navigation
Conversation
A test file can replace Promise.resolve, Promise.prototype.then and the other public Promise methods. The runner called them at 33 sites. So test() threw while Promise.resolve was replaced, and a replaced then() lost subtests. - The runner calls private names: Promise.$resolve, $then, $newPromise. - A link of the subtest chain is an async function that awaits the previous link. A then() callback that returns a promise calls the public then(). - untilStopped() replaces Promise.race() for the timeout of a test, and for the timeout and the signal of a hook. - mock_timers.ts makes its promise with $newPromise().
|
Updated 1:55 AM PT - Oct 26th, 2026
✅ @robobun, your commit 226eaffad8b4b7054c3d9af49f09b795ce59906c passed in 🧪 To try this PR locally: bunx bun-pr 46959That installs a local version of the PR into your bun-46959 --bun |
|
Status: ready for review. The base of this PR is #46919. How it was reproduced: a |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline findings, I also checked the dropped .catch(() => {}) defuses in createStopController and on the plan pending promise: every current caller in executeTestNode hands stop.promise and pending to untilStopped synchronously (or awaits pending directly), and the stop timer's $rejectPromise fires at most once since dispose() clears the single timer, so no new unhandled rejection is reachable from those sites.
Extended reasoning...
The change rewrites ~33 public Promise call sites in src/js/node/test.ts and one in mock_timers.ts to JSC private intrinsics, restructures the subtest chain around async step functions, and adds three fixtures plus seven tests. It touches no auth, injection, or data-exposure surface; the hostile-userland concern is the point of the change. Three confirmed findings are posted inline, so a human look is already signalled; this note only records the defuse-removal check that was examined and ruled out.
A hook with a signal can abort that signal and then throw. The abort rejects the stop promise of the hook before the runner gives that promise a reaction, so `bun test` reported the abort as an unhandled error. The runner now marks the stop promise as handled when the hook has a signal. Tests: - Two tests of the chain fixture had names that end in "fails the suite" and did not observe that failure. Their suites are no longer todo, so the two tests fail, and the test compares the errors and the verdicts of the fixture with an exact list. - The fixture for replaced methods says that a replaced Promise.prototype.constructor is not covered.
|
The three inline findings, with 226eaff:
One result of the verification for this push is new in the description: the vendored |
There was a problem hiding this comment.
I re-reviewed after the follow-up commit and found no bugs; it addresses the three inline points from the earlier pass (the $pokePromiseAsHandled(stop) in the signal branch, the two chain-fixture tests now running un-todo'd with an exact report() comparison, and the constructor-replacement caveat noted in the fixture). Because this rewrites the subtest-chain and timeout-race scheduling of node:test with acknowledged microtask-timing changes, a human look at the ordering contract would still be worthwhile.
What was reviewed:
untilStoppedandraceWithTimeoutAndSignal: both racers attach a reaction before anything can reject; the timer-only path needs no poke since the timer cannot fire beforeuntilStoppedruns or the finally clears it.appendSubtestStep/awaitSuiteGate/scheduleSkipDirective: each link awaits the previous one rather than resolving a promise with a promise, andsubtestChainstaysundefineduntil the first subtest.- Every
$-intrinsic introduced ($pokePromiseAsHandled,$isPromise, the FirstResolvingFunctionCallCheck pair,$newPromise) is declared insrc/js/builtins.d.tsand already used by sibling builtins;mock_timers.tsstill clears the listener and timer on both settle paths.
Extended reasoning...
The PR replaces every public Promise call in src/js/node/test.ts (and one in src/js/internal/test_runner/mock_timers.ts) with JSC private intrinsics, restructures the per-test subtest chain into async links that await their predecessor, and swaps Promise.race for an untilStopped helper; the second commit adds $pokePromiseAsHandled(stop) for a hook that aborts its own signal before throwing and tightens the chain fixture to an exact report assertion. It touches no auth, crypto, or input-parsing surface. The three inline comments from the prior run are all addressed in the code, and no CODEOWNERS entry covers the changed paths. The reason for defer rather than approve is the size and subtlety of the scheduling rewrite, which changes observable microtask ordering in two documented cases and is the kind of Node-compat contract a maintainer should weigh.
|
Closing as stale: this PR has had no review and no new commit since October 26, 2026. The branch stays, so the work is not lost. To pick it up again, update the branch from main and reopen this PR. |
Problem
bun test,test()throws when the file replacedPromise.resolve:error: replaced Promise.resolveatnew TestNode, then# Unhandled error between tests, 0 pass. Node passes.src/js/node/test.ts:1556. A replacedthenmakes subtests fail or not run.Fix
Promise.$resolve,$then,$newPromise) andawait. A subtest chain link is an async function that awaits the previous link.test/js/node/test_runner/node-test.test.ts, 7 new tests, 6 fail on the base. Self-reviewed as the earlier single PR: 10 concerns raised, 10 addressed.Background
thenof the second one.awaitof a native promise calls no method..$thenfor.then: 4 chain links pass an async callback, so a replacedthenstill runs.Downsides
skipis set aftert.test()returned settles one microtask earlier. A thenable from an inlinedescribe()callback gets 1then()call (base: 2).Notes
Origin. A differential run against Node found this. The tracker has no issue for it. The smallest file:
Node v26.3.0: 1 pass. The base (#46919 at 022175c) and
main: 0 pass, 1 fail, 1 error. This branch: 1 pass. The same file withPromise.prototype.thenand a subtest: the subtest fails on the base and passes here and in Node.Why a swap of the method names is not enough. The engine calls the public
thenwhen a promise is resolved with a native promise. Checked on JSC and on V8 with a wrapper that counts calls ofPromise.prototype.then:thencallsoriginalThen.call(p, async () => {})return promiseresolve(promise)in anew Promiseexecutorawait promisethencallback that returns no promiseOn the base four chain links resolve a promise with a promise:
subtestChain.then(async () => ...)inscheduleImmediateBeforeHook,.then(run)inscheduleSubtestandscheduleSuiteSubtest, and.then(() => gate.promise)inaddSuite. A throwingthenrejects such a link, and the links after it do not run.What changed in the runner (
src/js/node/test.ts)TestNode.subtestChainstarts asundefined. No promise is made for a node that has no subtest.appendSubtestStep(owner, step)appends an async link. The step awaits the link before it, does its work and records a failure on its node. The three async links use it: a subtest, an inline suite, abeforehook added to a running test. The stored link isstep(previous).$then(). That plain reaction keeps the links that wait out of the async stack of the step that runs.$thenlink. Its callback returns nothing.awaitSuiteGate()awaits the link before the suite, one more microtask, and then the gate. The gate opens when the value of thedescribe()callback settles.untilStopped(stop, promise)replacesPromise.race([stop, promise])for the timeout of a test. The race of a hook rejects onestoppromise from its timer and its abort listener, and then usesuntilStopped()too..catch()on the stop promise and the one on the plan promise.untilStopped()attaches a reaction to each of them at once.run():await undefinedin place ofawait Promise.resolve(), and$pokePromiseAsHandled()in place of.catch(() => {})on the promise that reads the stderr of a child.internal/test_runner/mock_timers.ts:$newPromise()in place ofPromise.withResolvers().Results that change for a file that replaces nothing (each has a test in
fixtures/33-subtest-chain.js, and Node v26.3.0 gives the same verdict for each test of that file)describe()callback in a running test that returns a thenable:then()is called 1 time (base: 2).then()throws fails its suite (base: the throw leavesdescribe()and fails the test with that error).main: the test that runs fails withAbortError, Node passes it). The abort rejects the stop promise of the hook beforeuntilStopped()gives it a reaction, so the runner marks that promise as handled. Only a hook with a signal pays for the mark.skip = trueaftert.test()returned settles one microtask earlier. Node ignores that assignment.Measurements (the base is #46919 at 022175c. Its numbers for a test that passes are the numbers of
main)fixtures/32-replaced-promise-methods.jswith its last block removed (that block throws at declaration on the base). A preload wraps the ten methods for the whole process. Base: 436 (resolve 172, then 228, race 19, catch 11, withResolvers 6). This branch: 1. The fixture makes that one call itself. Node v26.3.0 passes the fixture, so each recorded window is empty.node/test.js: 33 to 0 (resolve 10, then 14, race 4, catch 4, withResolvers 1).mock_timers.js: 1 to 0.bun:jscheapStats(), slope between N=100 and N=300, GC off, debug build), base to this branch: declaration of a test 15 to 14, run of a top-level test 39 to 39, awaited subtest 62 to 61, skipped subtest 16 to 14, subtest with a timeout 79 to 75, top-level test with a timeout 55 to 51, inline suite with one test 118 to 117, subtest underbeforeEachandafterEach78 to 77, subtest under abeforeEachwith a timeout 87 to 88, two subtests with oneawait125 to 123.JSC::MicrotaskQueue::enqueue, N=0 and N=200, debug build): top-level test 5 to 5, awaited subtest 11 to 10, skipped subtest 3 to 3, subtest with a timeout 12 to 11, inline suite with one test 21 to 19.vmEntryToJavaScript*entries): top-level test 6 to 6, awaited subtest 9 to 9, skipped subtest 3 to 3, subtest with a timeout 9 to 10, inline suite with one test 15 to 17. Anawaitresumes in JS where athenreaction with a native callback did not.node/test.js65,067 to 65,676 B,mock_timers.js18,717 to 18,857 B. Host functions added: 0.perfis not in the build container. The instruction counts come fromperf_event_openwithPERF_COUNT_HW_INSTRUCTIONSfor user space, the counter thatperf stat -e instructions:ureads.Order that user code sees. 54 traces record the order of subtest bodies and of the code after
await t.test()against a counter of microtasks. 44 are the same as on the base. 9 differ for the subtest whoseskipis set late. 1 differs for thedescribe()thenable. The AsyncLocalStorage store that a subtest body sees is the same.Existing tests. Of the 31 runs of the existing fixtures, 30 print the same output as on
main.07-failing-hooks.jsdiffers in two stack frames of the runner. The two fixtures of #46919 print the same output on the base and on this branch.Vendored Node tests. 112 of the 113 vendored Node tests that use
node:testgive the same result as onmainon the debug build. The other one,test-runner-mock-timers-scheduler.js, asserts that its first mocked wait takes less than 100 ms of wall-clock time. On the debug build that time is at the limit: median 98 ms onmainand 100 ms on this branch, and the test fails in 7 and in 12 of 20 runs. On release builds the time is 2 ms on both (20 runs each), and the test passes. A mocked wait after the first one takes the same time on both (0.11 ms on the debug build).Coverage. 51 variants of the compiled runner each put one public call back or remove one part: each changed call site, the
awaitof the link before in each step, the extra microtask and the wait of the gate, the plain reaction at the end of a link, the order of an abort against a hook that ended, the mark on the stop promise of a hook, and the record of adescribe()callback that rejects. At least one new test fails for each. Review found that the last of these had no test: two tests of33-subtest-chain.jshad suites withtodo, so they passed with and without that record. The test now compares the errors and the verdicts of that fixture with an exact list. One of the 7 new tests passes on the base: it pins that an error of atest:stderrlistener ofrun()still goes to the stream only.Not changed
describe()callback in a running test that awaits its own child test waits until the test times out. Node passes. The base does the same.Symbol.specieslookups ofthenstay, as in Node.awaitof a native promise reads itsconstructor. A file that replacesPromise.prototype.constructormakes eachawaitcall the publicthen(), in this runner and in the runner of Node. Node v26.3.0 makes 11 such calls for a test with two subtests, and 0 with the intrinsic constructor. The fixture says that it does not cover this..then(),.catch(),.finally()and the static Promise methods oversrc/js. The rule is not part of this PR.Other PRs
$newPromiseand anuntilStopped()for the same lines. The names here are the same. The second one to land needs a rebase.onlyunder --test-only #46797 (open) callsparent.subtestChain.$then(noop)in a new module. With this changesubtestChaincan beundefined, andtscreports it.appendSubtestStep()writer for the chain.[human-review] gate passed · iteration 0 · 6 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 0
evidence per changed file