--- kind: task slug: bootstrap-vitest-and-ci title: Bootstrap Vitest in 3 packages and add GitHub Actions CI plan_slug: multitenant-saas-hardening epic_slug: test-foundation status: ready priority: P1 tenant_id: global owner: unassigned cursor_todo_id: null updated_at: "2026-06-01" --- # Task summary Add Vitest to `packages/database`, `packages/shared`, and `packages/ai`. Write one real test in each. Wire `pnpm test` through Turborepo. Add `.github/workflows/ci.yml`. ## Description ### Vitest setup Install at the workspace root: ``` pnpm -w add -D vitest @vitest/coverage-v8 ``` In each target package, add `vitest.config.ts` (minimal, ESM) and a `test` script in `package.json`: ```json "scripts": { "test": "vitest run", "test:watch": "vitest" } ``` Then in `turbo.json`, add a `test` pipeline entry that depends on `build` only where strictly needed (probably not for these packages): ```json "test": { "dependsOn": ["^build"], "outputs": [] } ``` Add `pnpm test` to the root `package.json` scripts as `turbo test`. ### First tests (don't fake them) - `packages/database`: pick one of the markdown-backlog helpers (`parseBacklogMarkdown` in `src/markdown-backlog/parse.ts`). Write a test that parses a known-good Plan-template fixture and asserts the fields. Then write a test for a malformed file (non-map front matter) and assert it throws the documented error. This is high-value: the importer's parsing rules are load-bearing. - `packages/shared`: pick a zod schema and verify happy + sad paths. If `generateId` was just rewritten to use Web Crypto, add a test that asserts the output looks like a UUID v4 (regex match). Cheap, but it catches future "let's import randomUUID from somewhere again" regressions. - `packages/ai`: harder because of provider env. Mock the provider in the test (Vercel AI SDK has `MockLanguageModel` patterns). Verify your prompt-assembly helper produces the right message array given a known input. ### GitHub Actions Create `.github/workflows/ci.yml`: - Runs on `pull_request` and `push` to `main`. - Matrix: just Node 20 for now. - Steps: checkout, setup-node, setup-pnpm, `pnpm install --frozen-lockfile`, `pnpm lint`, `pnpm type-check`, `pnpm test`. - Cache pnpm store via `actions/cache`. Don't bother with Turbo Remote Cache — local Turbo caching inside the runner is enough at this scale. Pin pnpm to 9.x (same as local; `AGENTS.md` says pnpm 9). Don't use the corepack auto-detect mode for now — explicit versions are more reproducible. ### Anti-goals - No React Testing Library. No JSDOM environment. Adding browser-shape tests is its own project. - No coverage thresholds in v1. Get tests running first; threshold-policing comes when there's enough surface to police. ## Subtasks - [ ] Install Vitest at the workspace root. - [ ] Add `vitest.config.ts` + `test` script to the 3 packages. - [ ] Write 3 real tests (one per package) that fail if their target is broken. - [ ] Wire `turbo test` and root `pnpm test`. - [ ] Add `.github/workflows/ci.yml`. - [ ] Push to a branch, open a PR, verify CI runs. ## Owner or assignee Unassigned ## Status ready ## Estimation M ## Acceptance criteria - [ ] `pnpm test` exits 0 from a clean clone. - [ ] CI runs on PR and gates merge on success. - [ ] Each of the 3 tests fails when its target is mutated (verify by intentionally breaking each one). ## Links to related Epic / Plan - Epic: `./Epic-test-foundation.md` - Plan: `../Plan-multitenant-saas-hardening.md`