Problem
Greplica currently relies on ad-hoc Node scripts in scripts/ for verification:
check-transcript-bundle.js
check-repo-context.js
check-install-options.js
check-graph-view.js
These scripts require a full npm run build before running, import from dist/, use raw node:assert/strict, create temporary directories manually, and provide no coverage reporting, watch mode, or CI-friendly output. As the codebase grows, this approach does not scale and makes it hard to catch regressions early.
Goal
Introduce Vitest as the primary test runner and gradually migrate existing checks into a structured test suite with:
- TypeScript-native unit tests (no build step required for development),
- isolated integration tests for CLI behavior,
- coverage reporting,
- a clear path to CI integration.
Proposed Plan
Phase 0 — Foundation
Phase 1 — Pure Logic Unit Tests
Add co-located .test.ts files for modules with no I/O:
Phase 2 — Service & Repository Tests
Add isolated tests using temporary SQLite databases:
Phase 3 — CLI Integration Tests
Replace the scripts/check-*.js files with integration tests under tests/integration/:
Run these against the built CLI (dist/apps/cli/main.js) in isolated GREPLICA_HOME / temp repo environments.
Phase 4 — Optional Smoke Tests
Phase 5 — CI & Coverage
Open Questions / Tradeoffs
-
Test file location: co-located .test.ts files vs. a mirrored tests/ directory?
Proposal: co-located for unit tests, tests/integration/ for CLI tests.
-
Source vs. dist for unit tests: Vitest can test libs/**/*.ts directly. CLI integration still needs dist/.
Proposal: unit tests against source; integration tests against built CLI.
-
Fate of old scripts: delete scripts/check-*.js once Vitest equivalents are in place and CI-green?
Proposal: remove them to avoid duplication.
-
Default test command scope: should npm test include CLI integration tests? They spawn subprocesses and are slower.
Proposal: npm test runs fast unit + service tests; npm run test:integration runs CLI checks.
-
External dependencies: local embeddings download a model; OpenAI needs an API key.
Proposal: mock embedder in unit tests; skip OpenAI tests silently when the key is missing.
Acceptance Criteria
Labels
enhancement, testing, good first issue (for individual phases)
Problem
Greplica currently relies on ad-hoc Node scripts in
scripts/for verification:check-transcript-bundle.jscheck-repo-context.jscheck-install-options.jscheck-graph-view.jsThese scripts require a full
npm run buildbefore running, import fromdist/, use rawnode:assert/strict, create temporary directories manually, and provide no coverage reporting, watch mode, or CI-friendly output. As the codebase grows, this approach does not scale and makes it hard to catch regressions early.Goal
Introduce Vitest as the primary test runner and gradually migrate existing checks into a structured test suite with:
Proposed Plan
Phase 0 — Foundation
vitestand@vitest/coverage-v8as dev dependencies.vitest.config.tsconfigured for Node,NodeNextresolution, and.jsextension imports.tests/setup.tsfor shared test utilities and environment isolation.isAllowedEdge).Phase 1 — Pure Logic Unit Tests
Add co-located
.test.tsfiles for modules with no I/O:libs/knowledge-graph/edge.test.tslibs/knowledge-graph/proposal.test.tslibs/knowledge-graph/validate-proposal.test.tslibs/config/greplica-config.test.tslibs/session-transcript/markdown.test.tslibs/install/paths.test.tsPhase 2 — Service & Repository Tests
Add isolated tests using temporary SQLite databases:
libs/storage/sqlite/repository.test.tslibs/knowledge-graph/service.test.tsPhase 3 — CLI Integration Tests
Replace the
scripts/check-*.jsfiles with integration tests undertests/integration/:transcript-bundle.test.tsrepo-context.test.tsinstall-options.test.tsgraph-view.test.tsRun these against the built CLI (
dist/apps/cli/main.js) in isolatedGREPLICA_HOME/ temp repo environments.Phase 4 — Optional Smoke Tests
scripts/smoke-*.mjsto optional@smoketagged tests.Phase 5 — CI & Coverage
typecheck,test, andtest:coverage.Open Questions / Tradeoffs
Test file location: co-located
.test.tsfiles vs. a mirroredtests/directory?Proposal: co-located for unit tests,
tests/integration/for CLI tests.Source vs. dist for unit tests: Vitest can test
libs/**/*.tsdirectly. CLI integration still needsdist/.Proposal: unit tests against source; integration tests against built CLI.
Fate of old scripts: delete
scripts/check-*.jsonce Vitest equivalents are in place and CI-green?Proposal: remove them to avoid duplication.
Default test command scope: should
npm testinclude CLI integration tests? They spawn subprocesses and are slower.Proposal:
npm testruns fast unit + service tests;npm run test:integrationruns CLI checks.External dependencies: local embeddings download a model; OpenAI needs an API key.
Proposal: mock embedder in unit tests; skip OpenAI tests silently when the key is missing.
Acceptance Criteria
npm testruns Vitest and passes.scripts/check-*.jsis covered by equivalent Vitest tests.npm run test:coverageproduces a coverage report.Labels
enhancement,testing,good first issue(for individual phases)