How to run tests and what each suite proves. Use this while implementing or reviewing changes.
Install Bun using the official Installation guide. If the shell cannot find bun, configure PATH per Add Bun to your PATH.
| Command | Purpose |
|---|---|
bun install |
Install dependencies (run once after clone). Use Bun only — not npm/yarn/pnpm (see TECHNICAL.md). |
bun test |
Full suite: scanner unit tests, DB integration, Next API route tests. |
bun run test:scan |
src/scan + src/lib (scanner + card-id unit tests). |
bun run test:web |
Only tests/web/**/*.test.ts. |
bun run scan |
CLI smoke (requires TARGET_REPO and writable CODEPIECE_DB / default data/). |
bun run db:clear |
Deletes default data/codepiece.db (+ WAL/SHM) and data/scan-memory.json if present — use before a clean re-seed. |
bun run seed:samples |
Scans samples/the-algorithms-typescript ( TheAlgorithms/TypeScript snapshot) into data/codepiece.db with --force and REPO_LABEL=TheAlgorithms/TypeScript. |
bun run db:stats |
Read-only SQLite summary (CODEPIECE_DB): counts, swipes by action, per-user swipes, cards by repo_label, file sizes. |
For complete local verification before a PR:
bun install
bun test
bun run buildbun run build runs next build: typecheck, lint, and write the production bundle to .next/. It does not open a URL. To run the built app, use bun run start and open http://localhost:4000 (port 4000 in package.json). Port conflicts and dev issues: TROUBLESHOOTING.md.
Optional CLI smoke (writes under data/ unless you override CODEPIECE_DB):
bun run seed:samplesOr: REPO_LABEL=TheAlgorithms/TypeScript TARGET_REPO=./samples/the-algorithms-typescript bun run scan -- --force if you need --force explicitly.
bun testruns under the Bun runtime: the DB layer usesbun:sqlite(seesrc/db/client.ts).next build/next devrun on Node and usebetter-sqlite3. Both hit the same schema and SQL.CODEPIECE_DB=:memory:— set inside tests so SQLite is isolated; do not rely ondata/codepiece.dbin CI.TARGET_REPO— only required for manualbun run scanor optional e2e (not required forbun test).- Full env reference:
TECHNICAL.md(“Environment variables”).
| File | Covers |
|---|---|
paths.test.ts |
Path ignore rules (node_modules, dist, .d.ts), directory walk, content hash, LICENSE hint. |
extract.test.ts |
ts-morph extraction: JSDoc context, line limit (~200 LOC), class methods. |
memory.test.ts |
JSON scan-memory load/save roundtrip. |
run-scan.test.ts |
End-to-end: temp tree → runScan() → rows in cards table (:memory: DB). |
| File | Covers |
|---|---|
src/lib/card-id.test.ts |
Deterministic card id hashing (repo + path + symbol). |
| File | Covers |
|---|---|
api-routes.test.ts |
Route handlers imported directly: seed :memory: DB + GET /api/cards/next (cookie session, memo, focus-repo order vs global random fallback) + PUT /api/cards/memo (set/clear) + POST /api/swipes + GET/PUT /api/queue (repoLabel) + GET /api/cards/browse + GET /api/dashboard/stats (session-scoped aggregates). |
These tests do not start the HTTP server; they call GET/POST exported functions with Request objects.
The swipe UI (app/swipe-client.tsx) is thin; API tests cover the contract it depends on. Optional follow-up: Playwright or component tests with happy-dom — not required in this repo unless you add them.
bun run db:clear(optional) thenbun run seed:samples(or the equivalentTARGET_REPO/REPO_LABELscan -- --forcefromsamples/README.md)bun run dev(port 4000, Turbopack).EADDRINUSEor stale dev cache:TROUBLESHOOTING.md.- Open http://localhost:4000 — Home loads; open Swipe (header or Start swiping). With cards in the DB, a card should appear; Like/Skip should succeed in the network tab.
docker compose up(see README.md).- On the host, with the same DB path the container uses:
REPO_LABEL=TheAlgorithms/TypeScript TARGET_REPO=./samples/the-algorithms-typescript CODEPIECE_DB=data/codepiece.db bun run scan - Reload the app in the browser. Hot reload / restarts:
TROUBLESHOOTING.md.
COMMANDS.md—bun run …scripts (quick reference).TECHNICAL.md— stack, DB ownership, environment variables.TROUBLESHOOTING.md— ports, Docker, scan, UI.plan/v1-plan.md— feature checklist and Implementation status.plan/PRODUCTION.md— production Docker / Compose rollout (not covered by automated tests here).AGENTS.md— doc read order for implementers.