Now I have enough data. Let me compile the comprehensive report.
Iterative Testing Loop Improvement — Research Report
1. Key Findings
🏆 Finding #1: bun test --changed (v1.3.13) — Direct answer to the biggest pain point
Bun v1.3.13 (released April 20, 2026) shipped bun test --changed, which only runs test files whose module graph reaches a file git reports as changed. This is a game-changer for the feedback loop.
bun test --changed # uncommitted (unstaged + staged + untracked)
bun test --changed=HEAD~1 # diff against a specific commit
bun test --changed --watch # re-filter on every restart
How it works: Bun builds the full import graph of all test files, walks reverse edges from changed source files, and runs only affected test files. It's a scan-only operation (no linking/emitting code), so overhead is minimal.
The project currently uses Bun 1.3.6 (per package.json). Upgrading to 1.3.13+ unlocks --changed, --parallel, --isolate, and --shard.
Source: Bun v1.3.13 blog post | PR #29262
🏆 Finding #2: bun test --parallel and --isolate solve the concurrency constraint
The project requires --concurrency=1 because integration tests share a DuckDB singleton. Bun v1.3.13+ offers two solutions:
--isolate: Runs each test file in a fresh global environment within the same process. Microtasks are drained, sockets closed, timers cancelled, subprocesses killed, and a clean global object created between files. VM-level transpilation cache means shared deps are only parsed once.
--parallel[=N]: Distributes test files across worker processes (up to CPU count). Files are partitioned for cache locality with work-stealing. Per-file console.log output is buffered and flushed atomically, so output never interleaves.
These allow removing --concurrency=1 constraints, replacing with per-file isolation instead. DuckDB connections opened in beforeAll/closed in afterAll per file will be fully independent.
Source: Bun v1.3.13 blog — --isolate and --parallel
🏆 Finding #3: bun test --shard=M/N parallelizes CI test jobs
For CI, --shard splits test files across multiple runners deterministically:
# In a GitHub Actions matrix:
bun test --shard=1/3
bun test --shard=2/3
bun test --shard=3/3
Test files are sorted by path for determinism and distributed round-robin. Composes naturally with --changed (sharding applied after the changed-files filter).
Impact: The integration and chatbot CI jobs (which use --concurrency=1) could be sharded across parallel runners.
Source: Bun v1.3.13 blog — --shard
🏆 Finding #4: Lefthook is severely underutilized
Current lefthook.yml only runs biome check --write on pre-commit. Lefthook supports:
parallel: true — run multiple commands concurrently (currently serial)
root option — run commands in specific subdirectories, useful for the src/tabs/ organization
glob filtering — already used but could extend to typecheck only changed .ts files
pre-push hook — run the full test suite or typecheck before pushing
lefthook-local.yml — personal overrides (e.g., .only guard is bypassed by individuals)
interactive: true — for commit message prompts
- Script pipelining (
piped: true) — chain commands with priority
The Evil Martians article demonstrates monorepo patterns that map directly to this project's src/tabs/ structure.
Source: Evil Martians Lefthook guide
🏆 Finding #5: No bunfig.toml exists — missed configuration surface
The project has no bunfig.toml. This could centralize:
[test] section with concurrentTestGlob, timeouts, retry counts
- Preload scripts for test setup
- Environment variable overrides
This is a quick win that requires no code changes.
🏆 Finding #6: DuckDB test isolation pattern — per-test connection or in-memory DB
The root cause of --concurrency=1 is the DuckDB singleton in src/core/db.ts. Research shows three isolation patterns for database-backed tests:
| Pattern | Pros | Cons |
|---|
Per-file connection (open in beforeAll, close in afterAll) | Simple, deterministic | Slower if many files |
| In-memory DuckDB with fixture data | Fast, fully isolated | Requires more setup per test file |
| Savepoint rollback (transaction per test) | Fastest for read-only tests | Doesn't work for schema changes |
The --isolate flag in bun 1.3.13 effectively achieves pattern #1 automatically (fresh global environment per file = fresh connection).
🏆 Finding #7: CI could be parallelized further with --shard and --changed
Current CI has 9 serial jobs (guards → lint → format → typecheck → unit → regression → integration → chatbot → audit) that run in parallel (same level). The bottleneck jobs (integration, chatbot, regression) use --concurrency=1. Using --shard across CI matrix runners could cut wall-clock time significantly.
Additionally, using --changed in PR CI would skip tests unrelated to the diff.
2. Concrete Recommendations
Ranked by impact-to-effort ratio:
🔴 HIGH IMPACT / LOW EFFORT (Do this week)
R1. Upgrade Bun from 1.3.6 → 1.3.13+ (or latest stable)
- Why: Unlocks
--changed, --parallel, --isolate, --shard
- What: Update
package.json "packageManager": "bun@1.3.13" (or 1.3.14 if released)
- Risk: Low — this is a patch-level upgrade within 1.3.x. Verify with
bun run ci after upgrade.
- Evidence: Bun v1.3.13 blog notes "Fixes 82 issues (addressing 381 👍)"; changelog shows stability improvements. Source
R2. Create bunfig.toml with test defaults
[test]
# Tests that match these patterns run concurrently by default
concurrentTestGlob = [
"**/__tests__/*.test.ts", # chatbot unit tests (mocked)
"**/tests/formatters.test.ts", # hub unit tests (no DB)
]
# Default timeout for all tests
timeout = 10000
R3. Update package.json scripts to use --changed in development
{
"scripts": {
"test:changed": "bun test --changed",
"test:changed:watch": "bun test --changed --watch",
"test:quick": "bun test --changed --bail",
"test:file": "bun test ./src/tests --concurrency=1"
}
}
Add documentation for:
-
bun test:changed — run tests affected by working tree changes
-
bun test:changed:watch — watch mode that re-filters on each change
-
bun test:quick — stop at first failure, only changed tests
-
Why: Directly solves "long feedback loops between file-scoped checks and full CI"
-
Evidence: bun test --changed syntax verified in Bun v1.3.13 changelog
R4. Add test documentation to AGENTS.md / README
Document the exact workflows:
# Local TDD loop (0.5-2s per iteration):
bun test:changed:watch
# Pre-commit sanity (typecheck + changed tests):
bun run typecheck && bun test:quick
# Full regression before PR:
bun run ci:integration
- Why: The pain point mentions "No watch-mode test runner usage documented"
- What: Add a "Test Workflows" section to both AGENTS.md files
🟡 MEDIUM IMPACT / MEDIUM EFFORT (Do this sprint)
R5. Upgrade to bun test --parallel for CI jobs
After upgrade to 1.3.13+, replace --concurrency=1 with --parallel in CI for the integration and chatbot jobs:
# Current (slow, serial within process):
run: bun test src/tests --concurrency=1
# New (parallel across workers, isolated per file):
run: bun test src/tests --parallel=4
- Risk: DuckDB writes are the concern. Tests using
beforeAll/afterAll per file (which is the pattern) will be safe since each file opens its own connection. The --isolate flag ensures global envs are clean between files.
- What: Test locally first with
bun test src/tests --parallel and watch for failures. If DuckDB file contention is an issue, the CI fixture is read-only so concurrent reads are safe.
- Evidence: DuckDB supports concurrent readers natively. DuckDB Concurrency docs
R6. Enhance Lefthook with parallel pre-commit pipeline
# lefthook.yml
pre-commit:
parallel: true
commands:
biome:
glob: '*.{ts,tsx,json}'
run: bunx biome check --write --no-errors-on-unmatched --files-ignore-unknown=true {staged_files}
stage_fixed: true
typecheck-changed:
glob: '*.ts'
run: bunx tsc --noEmit --pretty false
skip:
- merge
- rebase
test-changed:
glob: '*.ts'
run: bun test --changed --bail
pre-push:
commands:
typecheck:
run: bun run typecheck
unit:
run: bun run test:unit
lint:
run: bun run lint
- Why: Single biome check is underutilizing Lefthook. Adding typecheck on staged files catches TS errors before they reach CI (which takes 10-15 min for typecheck alone).
- Risk:
test-changed in pre-commit might be slow for large changesets. Make it optional or skip by default.
- Evidence: Lefthook docs — parallel, Lefthook monorepo patterns
R7. Add .only/.skip local guard via lefthook-local.yml
The CI has guards against .only/.skip, but nothing prevents local commits. Add a lefthook-local.yml (gitignored) with personalized overrides, or document how to create one:
# lefthook-local.yml (gitignored)
pre-commit:
commands:
guard-only:
run: |
if rg -n '\.(only|skip)\(' src/tests --glob '*.ts' >/dev/null 2>&1; then
echo "⚠️ Focused tests (.only) found — remove before committing"
rg -n '\.(only|skip)\(' src/tests --glob '*.ts'
exit 1
fi
- Why: "Test focus guards (.only/.skip blocked in CI but not locally)" — this bridges the gap
🟢 LOWER IMPACT / HIGHER EFFORT (Future)
R8. Use --shard in CI to parallelize the slowest jobs
Split the regression/integration/chatbot jobs into a matrix:
integration:
strategy:
matrix:
shard: [1/3, 2/3, 3/3]
steps:
- run: bun test src/tests --shard=${{ matrix.shard }} --concurrency=1
- Why: Even with
--concurrency=1, 3 parallel runners cut wall-clock time by ~3x
- Evidence: Bun v1.3.13 —
--shard
R9. In-memory DuckDB for unit-style chatbot tests
For chatbot tests that don't need the real database, create an in-memory DuckDB helper:
import { Database } from '@duckdb/node-api';
export function createTestDb() {
const db = new Database(':memory:');
// Create minimal schema and insert fixtures
return db;
}
- Why: These tests could run in parallel without
--concurrency=1
- What: Convert chatbot tests to use per-file in-memory databases
- Evidence: DuckDB
:memory: database mode supports full SQL with no filesystem dependency
R10. Add lefthook post-merge hook for bun install
post-merge:
commands:
deps:
glob: "{bun.lock,package.json}"
run: bun install --frozen-lockfile
- Why: Ensures deps are always up-to-date after pulling
- Evidence: Evil Martians Lefthook patterns
3. Source URLs
Most Relevant
Secondary — Broader Context
4. Implementation Notes
A. Applying to --concurrency=1 constraint
Current situation: All test scripts hardcode --concurrency=1 because:
- DuckDB is a singleton (
src/core/db.ts) — multiple test files sharing the same DB file cause state pollution
- Snapshot ordering depends on deterministic execution
- OpenTUI tests share renderer state
After Bun 1.3.13 upgrade:
--parallel + --isolate handles #1: each test file gets a fresh global environment, so the DuckDB singleton is re-initialized per file
- For #2:
--randomize + --seed can give deterministic ordering, or sharding sorts by path
- For #3: OpenTUI tests rarely conflict if scoped to individual test files
B. Applying to DuckDB-specific constraints
DuckDB supports multiple concurrent readers on the same file. The CI fixture (nba.ci.duckdb) is read-only during tests. Per-file beforeAll → initDb() → afterAll → closeDb() pattern is safe with --parallel.
If contention arises: Switch to --isolate (no parallelism across workers, but per-file isolation within a single process). This is still faster than --concurrency=1 because environment sanitization eliminates cross-file pollution.
C. Applying to LangGraph/Chatbot tests
Chatbot tests already use mock.module() effectively. They mock ../db.js and @langchain/openai. These tests are ideal candidates for --parallel — they're fully isolated per file, don't touch the real database, and don't share state.
Action: Remove --concurrency=1 from test:chatbot script after Bun upgrade, or change to --concurrency=4.
D. Applying to CI pipeline
Current CI jobs flow:
guards → lint, format, typecheck, unit, regression, integration, chatbot, audit (parallel)
↓
ci-success (gate)
With --shard, the integration and chatbot jobs become parallel matrices. With --changed, PR CI would skip work for unrelated changes (e.g., changing only src/shared/theme.ts shouldn't retypecheck src/tabs/chatbot/ fully).
E. Applying to Lefthook
The current pre-commit hook runs only biome check --write. After improvements:
- Parallel execution:
biome, typecheck, and optionally test:changed run concurrently
- Monorepo-aware: Use
root option if different tabs need different treatment
- Graduated checks:
pre-commit does fast checks (lint + typecheck), pre-push does slower checks (full test suite)
F. Applying to snapshot management
Current pain point: Snapshot regeneration requires UPDATE_SNAPSHOTS=1 NBA_DUCKDB_PATH=data/fixtures/nba.ci.duckdb.
Recommendation: Add a convenience script:
bun run snapshots:update
# => UPDATE_SNAPSHOTS=1 NBA_DUCKDB_PATH=data/fixtures/nba.duckdb bun test src/tests/golden_snapshot.test.ts --concurrency=1
And document it prominently.
Summary: Implementation Roadmap
| # | Change | Effort | Impact | Depends On |
|---|
| R1 | Upgrade Bun 1.3.6 → 1.3.13+ | 5 min | 🔴 Critical | — |
| R2 | Create bunfig.toml | 10 min | 🟢 Moderate | — |
| R3 | Update scripts + docs | 30 min | 🔴 Critical | R1 |
| R4 | Document test workflows | 20 min | 🟢 Moderate | — |
| R5 | Replace --concurrency=1 with --parallel | 1 hr | 🔴 Critical | R1 |
| R6 | Enhance Lefthook pipeline | 1 hr | 🟡 Medium | — |
| R7 | Add local .only guard | 15 min | 🟡 Medium | — |
| R8 | CI --shard matrix | 2 hr | 🟡 Medium | R1 |
| R9 | In-memory DuckDB for chatbot tests | 4 hr | 🟢 Low | — |
| R10 | Post-merge hook for deps | 10 min | 🟢 Nice-to-have | — |
Top 3 to execute immediately (in order):
- R1:
bun upgrade to 1.3.13+ (fundamental enabler for everything else)
- R3: Add
bun test --changed scripts and document them (immediate DX improvement)
- R4: Document test workflows in AGENTS.md (unblocks the team)