Testing & Quality Assurance
Testing philosophy, available test suites, and validation utilities designed to maintain codebase health.
LeadForge OS employs automated unit, integration, and headless smoke tests, supplemented by runtime diagnostics and pre-release gates to guarantee codebase health.
Testing Philosophy
- Isolation by Design: Unit tests must never invoke real network requests, write to production database files, or spawn active headless browsers.
- Deterministic Outputs: Test scripts must yield predictable results using deterministic clock tickers, database transaction rollbacks, and mock LLM configurations.
- Double Verification: Automated test suites are complemented by SRE runtime diagnostics (
doctor) and release gate checks.
Available Test Suites
| Test Suite | Execution Command | Focus Area | Source / Helper |
|---|---|---|---|
| Unit & Integration | pnpm -r test | Validates package-level utilities, validator libraries, CRM repositories, and schema parsers. | Packages tests/ folders |
| AI Integration | pnpm test:ai | Validates model provider connections, timeouts, Zod output schema parsing, and fallback mock completions. | scripts/test-ai.ts |
| Headless Smoke | pnpm test | Runs a simulated Electron process headlessly to verify migrations, EventBuses, and logging loops. | scripts/smoke-test.ts |
Headless Smoke Test Checklist
The smoke test automatically executes the following sequences on boot:
- Connects to an in-memory SQLite instance.
- Applies all 23 database migrations.
- Triggers EventBus publishers and verifies subscribers.
- Boots a test
JobSchedulerinstance.
SRE Diagnostic & Release Checks
Doctor Diagnostics (pnpm doctor)
The doctor diagnostics script tests environment versions, repository health, compilation status, lint rules, and test success:
pnpm doctorIt performs these validation checks:
- Node version compliance ($\ge v18.0.0$) and pnpm version validity.
- Repository health check verify-repo-health.ts.
- ESLint, TypeScript type checking, and
dependency-cruiserboundary validation. - Recursive package test suites (
pnpm -r test). - Writes a Markdown diagnostics report to
report/doctor-report.md.
Release Gate Verification (pnpm release:check)
A strict 10-gate check that must pass before any version distribution is allowed:
pnpm release:checkThe checklist consists of:
- Gate 1: Repository Health check.
- Gate 2: TypeScript typecheck.
- Gate 3: ESLint validation.
- Gate 4: Unit & Integration tests.
- Gate 5: AI Integration tests.
- Gate 6: Headless Desktop Subsystem smoke test.
- Gate 7: Desktop Bundling Dry-Run.
- Gate 8: Changeset and release notes checking.
- Gate 9: Git status cleanliness checking.
- Gate 10: Tag & Version synchronization verification.
Mocking Strategies
Mocking LLM Providers
In unit tests, use the 'mock' provider to bypass OpenRouter connections and return deterministic mock data instantly:
import { PromptRunner } from '@leadforge/ai';
const runner = new PromptRunner({
provider: 'mock',
model: 'stub-model'
});
const summary = await runner.generateSummary({ domain: 'google.com' });Mocking Electron
For running desktop main process tests outside Electron (where safeStorage or ipcMain are unavailable), we provide a mock wrapper at scripts/mock-electron.ts. Import this script at the absolute top of your test entry points:
import { mockElectron } from './mock-electron';
// ... other imports