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

The ten test files that cost pull checks the most seconds each finish in under 30 s, with no test skipped #17030

Merged opened this

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

Merged

Seven of the ten files that cost pull checks the most time were already under 30 s. The other three were over. All three now run well under 30 s alone, and no test was skipped, deleted or weakened.

Notes

opened this

Seven of the ten files that cost pull checks the most time were already under 30 s. The other three were over. All three now run well under 30 s alone, and no test was skipped, deleted or weakened.

The measurement. The forge's kept times store can't be read through the API, so I used the logs of the last 50 finished pull checks on trevato/forge instead. For each file I added up the per-test times bun prints, then took the median across the checks that ran it. Two limits: the logs are cut to their last 512 KB, so this is a sample, and setup outside tests isn't counted. The "after" column is one run of the file alone on this machine, not yet the check's median.

filechecks seentotal smedian s on check (before)alone, mainalone, this branch
test/hollow.test.ts12251.917.318.815.6
test/shards-run.test.ts5208.738.740.911.3
test/boot-idle-memory.test.ts12207.417.019.115.9
test/build-journey.test.ts16193.59.910.812.6
test/release-boot.test.ts12144.011.213.412.3
test/crew-mirror.test.ts12124.510.511.011.3
test/crew-loop.test.ts20121.65.98.011.5
test/engine-split.test.ts3106.833.744.620.7, plus engine-split-keep 17.8
test/page-budget.test.ts3104.837.136.116.7
test/api-pulls-timing.test.ts15101.85.55.58.2

The small ups and downs in the bottom rows are run-to-run noise from single runs.

What changed

  • The shared test preload loads in about 50 ms instead of 2.5 s. test/helpers/preload.ts imported src/spawn/reach.ts, clients.ts and door.ts only to set three test defaults. Each of those pulls in almost the whole forge (4,274 modules) through actions/spawn.ts. The three defaults now live in three small modules that import nothing heavy: src/spawn/reach_default.ts, served_window.ts and watch_probe_default.ts. The old modules read from them, five spawn tests import servedWindow from its new home, and the unused-exports allow list names the new paths. Every bun test process gains this, and it is all of shards-run's gain: that file starts about 30 child bun test runs.
  • page-budget counts five requests a page, not 25. count() called statements(), which already keeps the fewest of five runs, five times over. It now makes the five requests its comment describes, and reports the same counts for all 19 pages.
  • engine-split.test.ts is two files. The stall test's real 12 s wait stays: the stall limit has to be longer than an engine's boot under load. The suites for an engine that is given up, a run started once, and a stream that resumes moved to test/engine-split-keep.test.ts. What both files share is in test/helpers/engine_split.ts, whose until reuses waitFor from test/helpers/poll.ts. There are 14 test( calls before and after. The fixed-wait allowance went from 7 for one file to 2 + 4 across the two.

Not done: I didn't shorten the 12 s stall wait, and I didn't speed up files that were already under 30 s.

Testing: bun x tsc --noEmit and the gate pass. The touched files and the rule tests pass (177 pass, plus shards-run's 2 existing skips). Across the 3,095 files scripts/fast.ts names, 22,563 tests ran in 667 s with 5 failures, none caused by this change:

  • test/kpis-landings-scale.test.ts "the count matches the per-row NOT EXISTS" fails on main the same way: it takes about 8 s, past its timeout.
  • test/composer-draft.test.ts and test/looks.test.ts need Chromium, which can't start in this sandbox.
  • test/pull-budget.test.ts and test/render-csv.test.ts are timing tests that passed when re-run alone.

Some spawn tests try to reach homie--forge.test on main too.

To try it: bun test test/shards-run.test.ts, bun test test/page-budget.test.ts, bun test test/engine-split.test.ts test/engine-split-keep.test.ts. The check's per-file times on this pull are the real "after".

No door: test speed and layout only; no page, action, route or tool changes.

🤖 Generated with Claude Code

Closes #17007

7 earlier comments
commented

Seven of the ten files that cost pull checks the most time were already under 30 s. The other three were over. All three now run well under 30 s alone, and no test was skipped, deleted or weakened.

The measurement. The forge's kept times store can't be read through the API, so I used the logs of the last 50 finished pull checks on trevato/forge instead. For each file I added up the per-test times bun prints, then took the median across the checks that ran it. Two limits: the logs are cut to their last 512 KB, so this is a sample, and setup outside tests isn't counted. The "after" column is one run of the file alone on this machine, not yet the check's median.

filechecks seentotal smedian s on check (before)alone, mainalone, this branch
test/hollow.test.ts12251.917.318.815.6
test/shards-run.test.ts5208.738.740.911.3
test/boot-idle-memory.test.ts12207.417.019.115.9
test/build-journey.test.ts16193.59.910.812.6
test/release-boot.test.ts12144.011.213.412.3
test/crew-mirror.test.ts12124.510.511.011.3
test/crew-loop.test.ts20121.65.98.011.5
test/engine-split.test.ts3106.833.744.620.7, plus engine-split-keep 17.8
test/page-budget.test.ts3104.837.136.116.7
test/api-pulls-timing.test.ts15101.85.55.58.2

The small ups and downs in the bottom rows are run-to-run noise from single runs.

What changed

  • The shared test preload loads in about 50 ms instead of 2.5 s. test/helpers/preload.ts imported src/spawn/reach.ts, clients.ts and door.ts only to set three test defaults. Each of those pulls in almost the whole forge (4,274 modules) through actions/spawn.ts. The three defaults now live in three small modules that import nothing heavy: src/spawn/reach_default.ts, served_window.ts and watch_probe_default.ts. The old modules read from them, five spawn tests import servedWindow from its new home, and the unused-exports allow list names the new paths. Every bun test process gains this, and it is all of shards-run's gain: that file starts about 30 child bun test runs.
  • page-budget counts five requests a page, not 25. count() called statements(), which already keeps the fewest of five runs, five times over. It now makes the five requests its comment describes, and reports the same counts for all 19 pages.
  • engine-split.test.ts is two files. The stall test's real 12 s wait stays: the stall limit has to be longer than an engine's boot under load. The suites for an engine that is given up, a run started once, and a stream that resumes moved to test/engine-split-keep.test.ts. What both files share is in test/helpers/engine_split.ts, whose until reuses waitFor from test/helpers/poll.ts. There are 14 test( calls before and after. The fixed-wait allowance went from 7 for one file to 2 + 4 across the two.

Not done: I didn't shorten the 12 s stall wait, and I didn't speed up files that were already under 30 s.

Testing: bun x tsc --noEmit and the gate pass. The touched files and the rule tests pass (177 pass, plus shards-run's 2 existing skips). Across the 3,095 files scripts/fast.ts names, 22,563 tests ran in 667 s with 5 failures, none caused by this change:

  • test/kpis-landings-scale.test.ts "the count matches the per-row NOT EXISTS" fails on main the same way: it takes about 8 s, past its timeout.
  • test/composer-draft.test.ts and test/looks.test.ts need Chromium, which can't start in this sandbox.
  • test/pull-budget.test.ts and test/render-csv.test.ts are timing tests that passed when re-run alone.

Some spawn tests try to reach homie--forge.test on main too.

To try it: bun test test/shards-run.test.ts, bun test test/page-budget.test.ts, bun test test/engine-split.test.ts test/engine-split-keep.test.ts. The check's per-file times on this pull are the real "after".

No door: test speed and layout only; no page, action, route or tool changes.

🤖 Generated with Claude Code

commented

This pull makes the costliest test files on pull checks cheaper (#17007), and fixes two causes of the last red check.

What changed in the pull

  • Test preload: test/helpers/preload.ts loads in about 50 ms instead of 2.5 s. To get there, the spawn defaults moved into small modules: src/spawn/reach_default.ts, served_window.ts and watch_probe_default.ts.
  • test/page-budget.test.ts: now counts five requests per page instead of 25.
  • test/engine-split.test.ts: split in two. The engine-keep, stream-resume and claim-race tests moved to test/engine-split-keep.test.ts, and both files share test/helpers/engine_split.ts, which polls with waitFor. No test was skipped, deleted or weakened, and the number of test( calls is the same.

What fixes the red check

  • Test budget: the four tests that went over the 2 s limit all moved out of engine-split.test.ts, which was already on the SLOW list in scripts/gate.ts. The new file had no SLOW entry, so it now has its own, with a reason and #17007.
  • Error between tests: ReferenceError: Cannot access 'SEARCH_LIMIT_MAX' before initialization was a real import cycle on main, not something this pull introduced. src/contract/openapi/routes/getApiV1Search.ts imported the limit from src/actions/search.ts, which leads back to the route through core/mcp_card.ts and the OpenAPI index. A shard that loaded search.ts first threw the error. SEARCH_LIMIT and SEARCH_LIMIT_MAX now live in src/actions/search_limit.ts, which imports nothing, and search.ts re-exports them.

The gate and bun x tsc --noEmit pass. I ran 80 test files (search, MCP search, OpenAPI, gate, test-shards, both engine-split files and tui-pull-red-main): 870 passed, 0 failed. I did not run the full suite. Importing search.ts on its own threw the ReferenceError before the fix and loads cleanly after it.

Not done here

  • The before/after median table that #17007 asks for is not in this pull.
  • The keep tests are listed as slow rather than made faster: they kill and restart real engine threads.

To try it: GET /api/v1/search?q=forge&limit=101 on the preview should answer 422 invalid_limit, and the OpenAPI document should still list limit up to 100.

🤖 Generated with Claude Code

commented

The pull check failed on 103 tests because of load-order bugs that the faster test preload had uncovered: when some modules were imported first, they read a constant before it was set. This commit fixes those bugs.

Why it broke. About 460 modules under src/ form one big import loop. The old preload, test/helpers/preload.ts, took 2.5 s because it loaded most of that loop before every test file, always starting from the same module, and that hid the bugs. Since this pull made the preload load almost nothing, each test file enters the loop wherever its first import lands. Thirteen of those starting points read a constant before it existed and threw "Cannot access X before initialization". Each throw stopped a whole shard (a batch of test files run in one process), which is how 103 tests failed. The check log names three of them: watches.test.ts, wave-pulls-sealed.test.ts and web-events.test.ts.

How I found all of them. I mapped the import loops in src/, then loaded each module in a loop first, in its own process, under the test preload. That found 30 failing starting points behind 12 constants, plus one more (NEW_COUNT_CAP) that showed up only after FEED_LIMIT_MAX was fixed. After the fix, the same scan finds none.

The fix. It follows the commit that already did this for SEARCH_LIMIT_MAX:

  • New small modules that import nothing from the loop now hold these constants: LIFETIME_DAYS, FEED_LIMIT_MAX, dependencyWords, VIEW_TTL_MS, PLAN_MAX, COMMENT_MAX and NEW_COUNT_CAP. The modules that read them while loading import them from there. Their old homes re-export them, so no other caller changes.
  • The atlas route (src/http/api/business_plan.ts) now reads ATLAS_BODY_MAX when a request arrives, not while the module loads.
  • forge search (src/cli/commands/search.ts) loads help.ts only when it prints usage. help.ts lists every command, so the static import was itself a loop.
  • ROUTES, getApiV1Feed, COMMENT_ASSET_PATH and newerLabelJs stopped failing once the constants they depended on moved.

Regression test. test/load-order.test.ts loads each of the 13 former failing modules first, each in its own process, in parallel, in about 2 s. With one of the fixes undone it fails and names src/actions/pinned.ts: LIFETIME_DAYS uninitialised.

Checks. bun x tsc --noEmit passes and bun scripts/gate.ts --explain reports 0 failures. I ran 258 test files: every one that imports a changed module, plus watches, unused-exports (the dead-code rule), job-slices, tui-crawlers, brief-lessons, hollow and cli-commands. 2,659 passed and 4 failed, all in test/infra-plan.test.ts. They failed only when all 258 files shared one process; the file passes 29 of 29 alone, and none of its failures was a load-order error. scripts/fast.ts names 3,349 files, more than this sandbox can run, so the forge's check on this push is the full run.

Not done: the 460-module loop itself is still there. I only removed the reads that fail while modules load.

Try it: bun test test/load-order.test.ts, then bun test test/watches.test.ts, which failed alone before this change.

No door: no page, action, route or tool changes behaviour.

🤖 Generated with Claude Code

commented

<!-- look-pages fff35a7db228 --> Look pages for fff35a7, from the gate:

  • look pages (inferred): this pull changes src/web/studio/held_posts.ts; the forge pictures / (src/web/studio/held_posts.ts), /docs (src/web/studio/held_posts.ts), /explore (src/web/studio/held_posts.ts) and 28 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

This pull makes the costliest test files on pull checks cheaper (#17007), and fixes the import-order errors that the lighter test setup exposed.

What changed

  • Test preload: test/helpers/preload.ts loads in about 50 ms instead of 2.5 s. To get there, the spawn defaults moved into small modules: src/spawn/reach_default.ts, served_window.ts and watch_probe_default.ts.
  • test/page-budget.test.ts: now counts five requests per page instead of 25.
  • test/engine-split.test.ts: split in two. The engine-keep, stream-resume and claim-race tests moved to test/engine-split-keep.test.ts, and both files share test/helpers/engine_split.ts, which polls with waitFor. No test was skipped, deleted or weakened. engine-split-keep.test.ts is on the SLOW list beside its parent, because it kills and restarts real engine threads (3–5 s a test).
  • Import-order errors: with the lighter preload, a test file can be the first thing to load a module, so src/ modules load in a different order. src/ is one large import cycle, and 13 entry points into it threw "Cannot access X before initialization" (SEARCH_LIMIT_MAX, LIFETIME_DAYS, FEED_LIMIT_MAX, NEW_COUNT_CAP and others). That is how the earlier check lost tests in its shards. Each constant read while a module loads now lives in a module that imports nothing, and the old home re-exports it. test/load-order.test.ts loads each of those entry points first, in its own process.

Look pages: I added a No look: line instead of pictures. The only change to src/web/studio/held_posts.ts is where it imports the same NEW_COUNT_CAP constant from, so none of the 31 inferred pages renders differently.

Checks run: the gate and bun x tsc --noEmit pass. These test files passed:

  • test/unused-exports.test.ts, test/job-slices.test.ts, test/tui-crawlers.test.ts, test/brief-lessons.test.ts and test/load-order.test.ts: 21 tests.
  • Earlier, the search, OpenAPI, gate, test-shards and engine-split files: 872 tests.

I did not run the full suite.

Not done here: the before/after median table that #17007 asks for is not in this pull.

To try it: GET /api/v1/search?q=forge&limit=101 on the preview should answer 422 invalid_limit. Then run bun test test/load-order.test.ts.

🤖 Generated with Claude Code

commented

The test preload no longer loads most of src/, so test files and shards no longer depend on modules someone else already loaded. Constants that were read while their module was still loading now live in small leaf modules, so no first import meets one uninitialised. test/load-order.test.ts guards this by loading each of the 13 entry points that used to fail first, in its own fresh process.

This push fixes the check failures from the last one:

  • test/load-order.test.ts is in SLOW (#17007). It can't be made faster without losing what it tests. src/actions/search.ts alone reaches 4,286 files (24 MB of source), and parsing them takes about 2.4 s alone, which matches the 2.46 s in the check log. The CPU profile blamed skeleton() in src/core/reserved.ts, but timing it directly showed it takes under 1 ms, so the profiler was misattributing the time. Splitting the test into one test per entry would not help, because one load is already over the 2 s budget.
  • Merged main. The "cold home" budget in test/observability-budget.test.ts fails just as badly at this branch's merge base (about 750–815 ms of CPU against a budget near 740–860 ms), so this branch did not cause it. Current main runs that request in about 400–530 ms; the "asks" removal (#17023) is the likely reason. The merge picks that up, and I did not change the test.
  • Not changed: test/json-big-page.test.ts and test/tui-app-templates.test.ts failed only inside their shards. They pass when run on their own.

Checked: those four test files plus test/gate*.test.ts pass (117 tests), bun x tsc --noEmit is clean, and bun scripts/gate.ts reports notes only.

🤖 Generated with Claude Code

commented

The push is up (c38fe5417). I'm waiting for the forge's check on it; when it ends, its closing lines will give the check's seconds for each SLOW file.

commented

Left #17007 open: 1 unticked item remain (From the kept test times of the last 50 pull checks on trevato/forge, the ten files with the most total seconds are listed in the pull with their median seconds, before and after.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs