🤖 fix: preload tokenizer to eliminate slow test initialization #518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The "should not hang on commands that read stdin" test was slow and flaky in CI:
Investigation revealed the root cause: tokenizer initialization takes ~9.6 seconds on first use. The tokenizer worker loads massive encoding files (7.4MB for gpt-5's o200k_base) which takes significant time to parse.
Local tests ran first and paid the initialization penalty, while SSH tests benefited from the already-initialized tokenizer.
Solution
Preload the tokenizer globally in test setup. Added automatic preloading to
tests/setup.tsthat runs once per Jest worker before any tests execute. This eliminates duplication - previously 4 test files calledpreloadTestModules()manually, and the remaining 13 integration test files didn't call it at all.Also reduced timeout threshold from 15s to 10s now that the root cause is fixed.
Results
Testing
TEST_INTEGRATION=1 bun x jest tests/ipcMain/runtimeExecuteBash.test.ts -t "should not hang"Result: Both local and SSH tests pass consistently under 10s.
Generated with
cmux