learning_ai_common_plat/AI.dev/PROMPTS/test-gap-analysis.md
saravanakumardb 32c7b1ba7e docs(prompts): add 14 reusable AI prompts for ecosystem-wide workflows
- roadmap-execution: phased roadmap execution with checkpoints
- new-product-scaffold: scaffold new ByteLyst product repos
- prd-to-implementation: convert PRDs to concrete plans
- cross-repo-debug: systematic multi-repo debugging
- backend-module-crud: Fastify CRUD modules (types/repo/routes/tests)
- platform-integration: wire products into common platform
- refactor-with-tests: test-first safe refactoring
- test-gap-analysis: coverage gap identification and remediation
- type-safety-sweep: TypeScript error triage and fix
- dependency-health-check: cross-repo dependency audit
- pre-release-validation: comprehensive release checklist
- docker-production-prep: production Docker images
- agents-md-sync: keep AI instruction files accurate
- ecosystem-audit: full ecosystem health dashboard
2026-05-17 16:48:58 -07:00

3.7 KiB

name description argument-hint agent
test-gap-analysis Identify test coverage gaps in a repo, prioritize by risk, and generate targeted tests for the most critical uncovered code. Repo name or path, e.g. "learning_ai_efforise", "learning_ai_flowmonk backend only", "all product backends" agent

Test Gap Analysis Prompt

Audit test coverage in a ByteLyst repo, identify the riskiest gaps, and generate high-value tests.

Context — ByteLyst Testing Conventions

  • Runner: Vitest for all TypeScript code
  • Pattern: Tests live in __tests__/ or alongside source as <module>.test.ts
  • Helpers: buildTestApp() via src/test-helpers.ts for Fastify inject testing
  • Mocks: @bytelyst/testing for shared mock utilities
  • Coverage targets: Backend 80%, Web 70%, Shared packages 90%

Analysis Protocol

Step 1: Inventory

Scan the repo and build a map:

Source files:      N files
Test files:        M files
Coverage ratio:    M/N (% of source files with tests)

For each source module, classify:

  • Has tests
  • ⚠️ Has partial tests (some functions uncovered)
  • No tests
  • 🔒 Low risk (config, types-only, re-exports)
  • 🔴 High risk (business logic, data mutations, auth)

Step 2: Prioritize Gaps

Rank uncovered code by risk:

Priority Category Why
P0 Auth/security logic Vulnerabilities if broken
P0 Data mutation (repository.ts) Data corruption if broken
P1 Business logic (services, engines) Core features break
P1 API routes with validation Contract violations
P2 Utility functions Indirect failures
P3 UI components (rendering) Visual but not critical
P4 Config, types, re-exports Very low risk

Step 3: Generate Tests

For each P0/P1 gap, generate tests following this structure:

import { describe, it, expect, beforeEach, vi } from 'vitest';

describe('<Module>', () => {
  // Setup
  beforeEach(() => {
    // Fresh state for each test
  });

  // Happy path
  it('should <expected behavior> when <condition>', async () => {
    // Arrange
    // Act
    // Assert
  });

  // Validation
  it('should reject invalid input', async () => {
    // Test Zod schema validation
  });

  // Auth
  it('should enforce user ownership', async () => {
    // Test that user A cannot access user B's data
  });

  // Edge cases
  it('should handle <edge case>', async () => {
    // Empty arrays, null values, missing fields
  });

  // Error paths
  it('should throw NotFoundError for missing <entity>', async () => {
    // Test error handling
  });
});

Step 4: Run & Validate

pnpm test --coverage
pnpm typecheck

Step 5: Report

Output a coverage gap report:

## Test Gap Analysis: <Repo>

### Summary
- Source files: N
- Test files: M (before) → M+K (after)
- Coverage: X% → Y%

### Gaps Filled (this session)
| Module | Tests Added | Risk Level |
|--------|-------------|------------|

### Remaining Gaps
| Module | Risk Level | Effort | Suggested Next Step |
|--------|------------|--------|---------------------|

### Recommendations
1. ...
2. ...

Step 6: Commit

git add .
git commit -m "test(<scope>): fill coverage gaps in <modules>

- Added N tests across M modules
- Coverage: X% → Y%
- Focus: <P0/P1 risk areas addressed>"
git push

Anti-Patterns to Avoid

  • Don't write snapshot tests for API responses (too brittle)
  • Don't test private implementation details (test behavior, not internals)
  • Don't mock the thing you're testing (mock dependencies only)
  • Don't write tests that always pass regardless of code changes
  • Don't chase 100% coverage — focus on high-risk code