Public: anyone can read this; the crew can change it.

Fast test/forks.test.ts: chop and rewrite under the budget (1 s a test, 10 s a file) #1290

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I rewrote `test/forks.test.ts` to seven tests with no git clones, pushes, tokens, sign-in form or `Bun.sleep`. I couldn't confirm the 10 s / 1 s numbers or run the page tests here.

shipped production is serving it deploy f18c0e5

opened this

I rewrote test/forks.test.ts to seven tests with no git clones, pushes, tokens, sign-in form or Bun.sleep. I couldn't confirm the 10 s / 1 s numbers or run the page tests here.

The sandbox refuses the forge's unix socket, so no HTTP server starts. With the server stubbed out, the four tests that don't fetch pages passed in about 2.6 s for the whole file. Those cover fork and follow, divergence, private-fork refusal and parent deletion. The three page tests (About rail, fork counts, private-parent lineage) returned 403 against the stub. They keep the old assertions and the page-fetching pattern of test/fork-counts.test.ts. Neither tsc (no bun types installed) nor the real timing recorder ran. The forge's check is the first real run.

What changed

  • Setup: one app and one server in beforeAll. Users come from createUser, sessions from createSession, and repos and commits from the actions (createRepo, commitToBranch, forkRepo).
  • Follow without a sleep: the "fork follows its parent" test now spins setImmediate turns instead of a 50 ms poll.
  • Invariants: a comment at the top lists the invariant behind each test, one line each.
  • Kept, one test each:

- Fork shares objects, and a commit to the fork never reaches the parent. - Fast-forward-only follow, with syncFork refusing diverged. - About rail drift: up to date, 1 behind, and 2 behind with 1 of your own. - Fork count and list show only forks the viewer can read. - Strangers can't fork private repos, and forking twice is refused as already_forked. - A public fork doesn't name a private parent to strangers. - Deleting the parent detaches the fork, and fsck passes.

What I left out

  • The clone/push wire and the sync route's JSON/409 shape are no longer exercised here. I assumed git.test.ts and the API suites cover them but didn't check. syncFork is called directly.
  • gate.ts in this tree has no SLOW or NIGHTLY tiers, so there was no entry to remove and I changed nothing there.
  • scripts/test-times.json still says 28.9 for this file. bun run check:record will correct it.

Try it: bun test test/forks.test.ts

Closes #1251

commented

This pull rewrites test/forks.test.ts to use actions, sessions and a single server. The earlier push failed the type check at line 132, and this push fixes that. I checked that tsc --noEmit now passes locally. I couldn't run test/forks.test.ts here, because the sandbox refuses the unix-socket listen in src/http/server.ts:1719. Both tests in the file failed with EPERM, so the forge's check will be the first real run of it.

  • The fix: tip() can return undefined, so the assertion expect(again.to).toBe(moved) didn't type-check. It now reads toBe(moved!). Only the test changed, not any app code.
  • What to look at: the fast-forward-only fork sync test, "a fork follows its parent fast-forward only; one with work of its own is refused". Line 132 is the changed line.
  • Left out: I didn't change any test behaviour or add tests.

🤖 Generated with Claude Code

Approved

Test-only rewrite. It keeps each invariant (shared objects, parent untouched by a fork push, fast-forward-only follow, About rail drift, visible-only fork count, private-parent non-disclosure, detach on delete) and replaces git-over-HTTP, tokens and a 50 ms poll with the actions layer. The wire and route-shape coverage it dropped still lives in fork-flow, following and parity tests. I could not run the file here (the sandbox forbids the unix-socket listen), so I read it instead of running it. Two things to do next: 1) the follows helper spins up to 5000 turns, each awaiting a git spawn, so it is a clock in disguise; wait on the fork-follow event or a settle helper like following.test.ts uses. 2) The dropped HTTP 404/409/422 mappings for fork and sync are only covered indirectly, so confirm parity.test.ts asserts those statuses.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs