Test Authoring
Write tests for newly implemented functionality, or improve an existing project's test suite by using coverage data to identify gaps.
In this repository, the Rust workspace spans core/ and crates/, while the React/Vite frontend and Playwright suite live under gui/. For other targets, discover their test layout before selecting commands.
Decide Scope
Confirm which of these the user wants:
- Unit tests (backend and/or frontend)
- E2E tests (usually Playwright)
- Coverage improvement (and any target: e.g. "80%+ service layer")
If the user says "new feature implemented", treat the changed code as the test target (optimize for verifying behavior, not lines).
Discover Project Test Tooling
From repo root, identify:
- Backend language:
- Rust:
core/Cargo.tomlexists - Other: ask for the test command and coverage command
- Frontend:
gui/package.jsonexists (TypeScript/React frontend)- E2E:
- Look for Playwright in
gui/playwright.config.tsandgui/package.json
Prefer scripts in gui/package.json and commands declared by the root Cargo workspace over inventing new ones.
Unit Tests (Backend)
Rust (core/)
Principles:
- Keep tests fast and deterministic.
- Prefer unit tests for business logic without Docker.
- Mock boundaries (repositories, HTTP clients) using traits and mock libraries (e.g.
mockall).
Placement:
- For pure logic: colocate tests in
core/src/**using#[cfg(test)] mod tests. - For API/behavior tests: use
core/tests/**if the project has a test harness there.
Workflow:
- Identify behavior added/changed (inputs, outputs, error cases).
- Add tests for:
- Happy path
- Boundary conditions
- Negative cases (validation, authz, not-found, conflict)
- Run backend tests (project-specific):
cargo test --workspace
Coverage (if requested):
- Prefer
cargo llvm-covif configured, otherwise follow the project's existing coverage commands. - If no coverage tooling exists, propose adding
cargo llvm-covsupport (do not force-install tools without user confirmation).
Unit Tests (Frontend)
If gui/ exists, prefer:
- Unit tests for pure functions and data shaping.
- Component tests for complex rendering/interaction logic.
- Avoid brittle DOM selectors; prefer role/label based selectors in E2E (not unit).
Run commands (project-specific examples):
cd portal && npm testcd portal && npx vitest --run- Coverage:
cd portal && npm test -- --coverage(or existing script)
E2E Tests (Playwright)
Goals:
- Cover critical user journeys with few, stable tests.
- Keep tests reproducible by resetting state when running full-stack.
Recommended split (if applicable):
- Frontend-only E2E: runs against dev server, minimal dependencies.
- Full-stack E2E: start only the repository-owned services required by the test and use project-scoped fixture cleanup.
Workflow:
- Determine target base URL(s) from the project (often
http://localhost:<portal_port>). - Identify the minimal scenario that proves the feature works.
- Implement Playwright tests using stable selectors:
- Prefer
getByRole,getByLabel,getByText.
- For full-stack E2E, always reset first:
cd gui
npx playwright test
If the project already has scripts like test:e2e:full:reset, use them instead.
Coverage-Driven Improvement (Completing Unit/E2E Tests)
When asked to "complete tests" or "increase coverage":
- Run the project's existing coverage command(s).
- Identify the highest-value uncovered behavior:
- Service/business logic over plumbing.
- Branch coverage and error paths over getters/setters.
- Add tests that assert behavior (not implementation details).
- Re-run:
- Unit tests
- Coverage
- E2E (if touched)
If the project has explicit coverage targets, follow them. Otherwise, treat coverage as a signal, not a goal.
Output Artifacts and Iteration Loop
If a change is tied to an approved plan:
- Generate QA docs via
qa-doc-gen. - Execute QA via
qa-testing. - If failures occur, create/fix tickets via
ticket-fix.
Guardrails
- Do not add tests that require external network access.
- Avoid time-based flakiness; use explicit waits/conditions in E2E.
- Prefer deterministic mock fixtures and project-scoped resets for integration environments.