perf: speed up test and coverage runs #184
Open
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.
This PR speeds up the local edit→test loop by making coverage opt-in and reducing the largest luacov hot spots.
Key changes
make testis now fast (no coverage);make test-covruns coverage +luacov..luacovconfig to focus coverage on plugin code (exclude tests/mocks).vim.waittest mock.Verification
make checkmake testmake test-cov📋 Implementation Plan
Speed up test runs (busted / luacov)
Context / Why
Running the repo’s tests via
make testis currently painfully slow (~4m+), which breaks the local edit→test loop.Primary goal: make the default developer test command fast again, while keeping a coverage-producing path for CI/release quality.
Targets
make test): <15s (current suite can run in ~9s without coverage)make test-cov): materially faster than today (~4m17s), ideally <90sEvidence (what we verified)
Makefile:testrunsbusted --coverage -vover alltests/**/*_{spec,test}.lua. (Makefile:25–35)make testwith coverage: ~4m17s (423 tests)tests/unit/terminal_spec.lua(~1m50s vs ~8s without)lua/claudecode/server/tcp.luabuilds + shuffles an entire port range array before binding. (lua/claudecode/server/tcp.lua:26–35)lua/claudecode/server/utils.luaprecomputes a 256×256 XOR lookup table at module load. (lua/claudecode/server/utils.lua:367–391)tests/mocks/vim.luamockvim.waitusesos.execute("sleep 0.001"), spawning a shell repeatedly. (tests/mocks/vim.lua:712–724)package.loaded[...]inbefore_each, forcing repeated module reloads (amplifies module-load hot spots), e.g.tests/unit/terminal_spec.lua:225+.nvim --headlessper file and wraps each innix develop, with a 30s timeout. (scripts/run_integration_tests_individually.sh:30–33)Plan
Phase 0 — Lock in a baseline (so improvements are measurable)
DEVELOPMENT.mddocumenting the expected ballpark timings and the two modes:make test(fast, no coverage)make test-cov(coverage)Phase 1 — Fast-by-default local tests (biggest win)
Makefile:make testto runbusted -v …without--coverage.make test-cov(ormake coverage) that runsbusted --coverage -v ….COVERAGE=1 make testas an alias.make test:DEVELOPMENT.md(currently recommendsmake testas the primary command; seeDEVELOPMENT.md:79–95).README.md(mentionsmake test; see aroundREADME.md:779).make test-cov.Phase 2 — Reduce coverage-enabled runtime (so CI stays reasonable)
lua/claudecode/server/tcp.lua:lua/claudecode/server/utils.lua:bit.bxor(available in Neovim) or compute XOR directly per byte.apply_mask(apply_mask(data, mask), mask) == data).tests/helpers/reload.lua) to reset stateful globals without nukingpackage.loadedbroadly.package.loaded[...] = nilfrombefore_each→setup(per-file) where isolation allows.tests/unit/terminal_spec.luasince it dominates coverage time.vim.waitmock intests/mocks/vim.lua:os.execute("sleep …")withvim.loop.sleep/uv.sleep(no shell) or a pure-Lua approach suitable for unit tests..luacovconfig to focus coverage on plugin code:tests/,tests/mocks/, and third-party deps; includelua/claudecode/.Phase 3 — Integration test speed / reliability (separate, but related)
nix developper integration file inscripts/run_integration_tests_individually.sh:IN_NIX_SHELLlike the Makefile does.plenary.test_harness.test_directoryhangs, either:Validation / Success Criteria
make test(no coverage): consistently <15s.make test-cov(coverage): improves materially from ~4m17s to <90s (or at least 2× faster), withtests/unit/terminal_spec.luano longer dominating.luacov.report.out,luacov.stats.out).Generated with
mux• Model:openai:gpt-5.2• Thinking:xhigh