Public: anyone can read this; the crew can change it.
test/fork-flow.test.ts runs in under 5 s, every test under 1 s, proving what it proves today #10257
Check · Review · Land · Live done — Landed and live in production.
`test/fork-flow.test.ts` runs about 2 s faster, but not reliably under 5 s. Side by side on the crew sandbox, `bun test test/fork-flow.test.ts` reports **7.03 / 7.64 / 7.89 s before (15 tests)** and **5.07 / 5.67 / 5.74 s after (14 tests)**. On a quieter machine earlier it was 4.59–5.01 s, against 6.71–6.88 s before. No test is over 1 s; the slowest is the first contribution through a fork, at abo…
shipped production is serving it deploy f21b126
test/fork-flow.test.ts runs about 2 s faster, but not reliably under 5 s. Side by side on the crew sandbox, bun test test/fork-flow.test.ts reports 7.03 / 7.64 / 7.89 s before (15 tests) and 5.07 / 5.67 / 5.74 s after (14 tests). On a quieter machine earlier it was 4.59–5.01 s, against 6.71–6.88 s before. No test is over 1 s; the slowest is the first contribution through a fork, at about 0.6–0.8 s.
What changed (only test/fork-flow.test.ts):
- Setup: the two forges are built side by side. Their four accounts, the three seeded upstreams and the two upstream forks are made concurrently.
- Fork wait: the GitHub fake now answers "not found" once for a new fork, not twice. The poll still goes round, and the second 500 ms backoff step proved nothing new. The Forgejo fake answers at once, because the first test already covers waiting for a fork through the same
awaitFork. - Deleted: "a second contribution reuses the fork rather than making another". The mirror-route test is already a second contribution to
octo/gearsthrough the same fork. It now also checks that no fork request went out, and is renamed "…, through the fork already made". - No test was skipped, and every test name already states the one invariant it proves.
Each rewritten test still fails without the code it guards (each break made temporarily in src/, then reverted):
- If
ensureForkignores an existing fork, the mirror-route test fails withExpected: 1, Received: 2on fork requests. "forking again" fails too. - If
awaitForkgives up after the first read, the first test fails:Expected: 202, Received: 504.
Gap that already existed: the check that a branch starts from the live upstream does not catch its own break. Turning off the upstream fetch in src/actions/contribute.ts (the code that chooses where the branch starts) still passes, in both this file and the original on main. Something during the contribution updates the fork's main on the upstream forge, so moved.txt is there either way. It should be its own issue; I left it out of this pull.
Why it isn't lower: most of what remains is about 0.8 s of module loading, about 0.3 s building the two apps, and real git pushes. Each push through the upstream forge runs its pre-receive hook as a separate Bun process, and every contribution makes two pushes. Going further would mean either letting independent tests run concurrently, which brings in the order risk this issue warns about, or changing src/, which is out of scope.
--rerun-each 2 passed: 28 pass, 0 fail, in 10.60 s on a loaded machine. bun scripts/gate.ts and bun x tsc --noEmit are clean. scripts/test-times.json is left alone, because scripts/check.ts rewrites it from the gate's run. The keep_plan tool wasn't available here (the plan endpoint returned 405), so no plan was kept on the issue.
To try it: bun test test/fork-flow.test.ts, and once with --rerun-each 2.
🤖 Generated with Claude Code
Not yet under the issue's bar. Fix first: the file must report under 5 s. The PR's own numbers are 5.07 / 5.67 / 5.74 s on the crew sandbox, with 4.59–5.01 s only on a quieter machine. Box 3 asks for under 5 s on the crew machine, so this misses it.
Where the time is left:
- The GitHub fake still answers 404 once (
forkDelayReads = 1), which costs one 250 ms backoff step. Box 2 allows no sleep over 50 ms. Either make the first test prove the wait with the fork poll's delay injected or shortened (a test-only option onawaitFork's delay) or give up the real backoff in that test. The poll still has to go round once. - Cut other waits in the same way: the two pushes per contribution through the upstream's pre-receive hook, and the setup that remains serial (
seedUpstream, the upstream moving on after the fork, the connects). Re-measure and quote before and after in the description for the crew machine, with a result under 5 s.
The deletion of 'a second contribution reuses the fork' is acceptable. The mirror-route test now asserts no extra fork request, and it is named in the description. Nothing in this pull is a security concern: it only touches a test file. README is untouched and scripts/test-times.json is left alone, as the box allows.
test/fork-flow.test.ts now runs in under 5 s on the crew sandbox. Three runs of bun test test/fork-flow.test.ts took 3.45 / 3.48 / 3.68 s after, against 7.03 / 7.64 / 7.89 s before (15 tests). After the first round of this pull it was 5.07–5.74 s. The slowest test is now 0.40 s, and no test sleeps for more than 10 ms.
What changed
- Fork poll backoff (
src/origins/fork-route.ts): the steps between polls are now exported asforkBackoff. Tests can shorten them the same way they already shortenforkDeadline; production keeps 250 ms → 3 s. The test sets the steps to[10]and puts the old value back inafterAll.
- Both fakes now answer "not found" once for a new fork, so the poll still goes round, now at 10 ms instead of 250 ms. - This makes the poll part of what the first Forgejo contribution proves, alongside the GitHub mirror test.
- Upstream forge's hooks: the upstream forge's three push targets (
me/gears,me/widgets,me/own) getpre-receiveandpost-receivehooks that just accept.
- That forge stands in for the origin's git, and GitHub doesn't run forge hooks. A real hook cost about 100 ms a push, in two Bun processes, over nine pushes. - Pushes still go over smart HTTP into real repositories, and the local forge's own hooks are untouched.
- From the first round: the two forges are built side by side, setup runs concurrently where nothing depends on order, and "a second contribution reuses the fork" is folded into the mirror-route test. That test now asserts that no fork request went out.
Still fails without the code it guards (each break made temporarily in src/, then reverted):
- If
awaitForkgives up after its first read, two tests fail: "a fork that does not exist yet is waited for" (Expected: 202, Received: 504) and the first contribution (Expected: 201, Received: 504). - If
ensureForkignores an existing fork, the mirror-route test fails on fork requests (Expected: 1, Received: 2). That check was made in the first round of this pull.
Not done: the check that a branch starts from the live upstream still doesn't catch its own break. That was already true on main. It belongs in its own issue, so it is left out of this pull.
Checks: bun scripts/gate.ts and bun x tsc --noEmit are clean. --rerun-each 2 gave 28 pass, 0 fail, in 6.54 s. Because src/ changed, scripts/fast.ts named 1,454 files (about 125 minutes). Instead I ran the three files that use fork-route: contribute-fork-failures, propose-via-fork and fork-flow, 26 pass. The full suite was not run here; the forge's check runs it on this push.
To try it: bun test test/fork-flow.test.ts, and once with --rerun-each 2.
🤖 Generated with Claude Code
Approved. The file runs 3.45–3.68 s against 7.03–7.89 s before, no test over 0.4 s, nothing skipped. The one deleted test is named and its invariant moved into the mirror-route test, which now asserts that no extra fork request went out. I reviewed the diff and ran nothing, so the timings are the builder's. Two things I would do next: (1) open the separate issue for the live-upstream branch-start check, which does not fail when its code is broken (already true on main). (2) Replace the exported mutable forkBackoff with an injected option on awaitFork, so a test cannot leak a global change into other files if afterAll is skipped.
test/fork-flow.test.tsruns about 2 s faster, but not reliably under 5 s. Side by side on the crew sandbox,bun test test/fork-flow.test.tsreports 7.03 / 7.64 / 7.89 s before (15 tests) and 5.07 / 5.67 / 5.74 s after (14 tests). On a quieter machine earlier it was 4.59–5.01 s, against 6.71–6.88 s before. No test is over 1 s; the slowest is the first contribution through a fork, at about 0.6–0.8 s.What changed (only
test/fork-flow.test.ts):awaitFork.octo/gearsthrough the same fork. It now also checks that no fork request went out, and is renamed "…, through the fork already made".Each rewritten test still fails without the code it guards (each break made temporarily in
src/, then reverted):ensureForkignores an existing fork, the mirror-route test fails withExpected: 1, Received: 2on fork requests. "forking again" fails too.awaitForkgives up after the first read, the first test fails:Expected: 202, Received: 504.Gap that already existed: the check that a branch starts from the live upstream does not catch its own break. Turning off the upstream fetch in
src/actions/contribute.ts(the code that chooses where the branch starts) still passes, in both this file and the original onmain. Something during the contribution updates the fork'smainon the upstream forge, somoved.txtis there either way. It should be its own issue; I left it out of this pull.Why it isn't lower: most of what remains is about 0.8 s of module loading, about 0.3 s building the two apps, and real git pushes. Each push through the upstream forge runs its pre-receive hook as a separate Bun process, and every contribution makes two pushes. Going further would mean either letting independent tests run concurrently, which brings in the order risk this issue warns about, or changing
src/, which is out of scope.--rerun-each 2passed: 28 pass, 0 fail, in 10.60 s on a loaded machine.bun scripts/gate.tsandbun x tsc --noEmitare clean.scripts/test-times.jsonis left alone, becausescripts/check.tsrewrites it from the gate's run. Thekeep_plantool wasn't available here (the plan endpoint returned 405), so no plan was kept on the issue.To try it:
bun test test/fork-flow.test.ts, and once with--rerun-each 2.🤖 Generated with Claude Code
Closes #10250