Skip to content

feat: Add test coverage transparency and quality guidelines to workflow #97

Closed

Description

@admarble

Summary

When reporting test results, the workflow reports "N tests passed" without indicating whether those tests actually cover the changed code. This is misleading and masks coverage gaps.

Root cause from real failure:

Tests: 5 passed ✅
Build: Success ✅

None of those 5 tests touched the changed file (server-actions.ts). The user only discovered this gap after explicitly asking.

Problem Statement

The issue isn't "we need more tests" — it's transparency about what's actually being tested.

Top engineering teams don't chase test quantity. They:

  1. Know exactly what's covered and what isn't
  2. Make informed decisions about where tests add value
  3. Write fewer, higher-quality tests that catch real bugs

Proposed Solution

1. Update Skill Instructions (Primary Fix)

Update /qa and /exec skills to require coverage reporting after npm test:

Detection (inline bash, no external tools):

# Get changed source files (excluding tests)
changed=$(git diff main...HEAD --name-only | grep -E '\.(ts|tsx|js|jsx)$' | grep -v -E '\.test\.|\.spec\.|__tests__')

# Check for corresponding test files
for file in $changed; do
  base=$(basename "$file" .ts | sed 's/\.tsx$//')
  if ! find . -name "${base}.test.*" -o -name "${base}.spec.*" 2>/dev/null | grep -q .; then
    echo "NO TEST: $file"
  fi
done

Required reporting format:

Scenario Report
Tests cover changed files Tests: N passed (covers changed files)
Tests don't cover changed files Tests: N passed (⚠️ 0 cover changed files)
No tests for specific files Tests: N passed (⚠️ NO TESTS: file1.ts, file2.ts)

2. Test Requirement Tiers

Not all code needs tests. Define clear tiers in skill instructions:

Tier Change Type Requirement
Critical Auth, payments, mutations, security, middleware Flag prominently if missing
Standard Business logic, API handlers, utilities Note if missing
Optional Config, types-only, UI tweaks No flag needed

Detection heuristic:

# Critical paths
critical=$(echo "$changed" | grep -E 'auth|payment|security|server-action|middleware|admin')

3. Quality Guidelines (Documentation)

Add to testing-requirements.md:

A quality test:

  • Tests behavior, not implementation details
  • Covers primary use case + at least 1 failure path
  • Fails when the feature breaks, passes when it works

Avoid:

  • Tests that mock everything
  • Tests that only cover happy path
  • Tests written just to hit coverage numbers

4. Optional Hook (Reliability Enhancement)

For users who want automatic enforcement, add optional hook:

# .claude/hooks/post-test.sh (optional)
# Automatically appends coverage analysis to npm test output

This travels with sequant (portable) and makes it impossible for Claude to "forget" the coverage check.

Acceptance Criteria

  • AC-1: /qa skill requires test coverage reporting for changed files
  • AC-2: /exec skill requires test coverage reporting after npm test
  • AC-3: Skills classify changes by tier (critical/standard/optional)
  • AC-4: testing-requirements.md updated with quality guidelines
  • AC-5: Output templates include coverage section
  • AC-6: Optional hook added to .claude/hooks/ for automatic enforcement

Non-Goals

  • ❌ Custom scripts in scripts/ (not portable, maintenance burden)
  • ❌ GitHub Actions (platform-specific, not portable with sequant)
  • ❌ Enforcing minimum coverage percentages
  • ❌ Auto-generating tests (leads to low-quality tests)
  • ❌ Blocking merges for missing tests on non-critical paths

Files to Modify

.claude/skills/qa/SKILL.md                           # Add coverage reporting requirement
.claude/skills/exec/SKILL.md                         # Add coverage reporting requirement
.claude/skills/qa/references/testing-requirements.md # Add quality guidelines
.claude/skills/qa/references/quality-gates.md        # Add coverage metric
.claude/hooks/post-test.sh                           # Optional hook (new file)

Why This Approach

Approach Portable? Reliable? Chosen?
Skill instructions ✅ Yes Medium ✅ Primary
Claude Code hook ✅ Yes High ✅ Optional
Custom scripts ❌ Friction Medium ❌ No
GitHub Actions ❌ Platform-specific High ❌ No

Skills + optional hook = portable, reliable, no external dependencies.

Activity

  1. admarble commented on Jan 21, 2026

    @admarble
    ContributorAuthor

    📋 Implementation Plan for #97

    Acceptance Criteria with Verification

    AC Description Verification Status
    AC-1 /qa skill requires test coverage reporting Manual Test: Run /qa on branch with uncovered changes, verify coverage gap reported ⬜
    AC-2 /exec skill requires test coverage reporting Manual Test: Run /exec, verify coverage gap in output after npm test ⬜
    AC-3 Skills classify changes by tier Manual Test: Change auth/ file, verify "Critical path" flag ⬜
    AC-4 testing-requirements.md updated Code Review: Verify quality guidelines section exists ⬜
    AC-5 Output templates include coverage section Code Review: Check both skill templates ⬜
    AC-6 Optional hook for automatic enforcement Manual Test: Enable CLAUDE_HOOKS_COVERAGE=true, run tests ⬜

    Implementation Phases

    Phase 1: Core Detection Logic

    1. Add coverage detection to /qa skill (SKILL.md)
    2. Add coverage detection to /exec skill (SKILL.md)
    3. Update testing-requirements.md with quality guidelines

    Phase 2: Output Templates
    4. Update QA output template with coverage section
    5. Update exec output template with coverage reporting

    Phase 3: Optional Hook
    6. Add opt-in coverage hook to post-tool.sh

    Files to Modify

    .claude/skills/qa/SKILL.md                           # AC-1, AC-3, AC-5
    .claude/skills/exec/SKILL.md                         # AC-2, AC-3, AC-5
    .claude/skills/qa/references/testing-requirements.md # AC-4
    .claude/hooks/post-tool.sh                           # AC-6
    

    Key Decisions

    Decision Choice Rationale
    Detection approach Bash inline (no external tools) Portable, no dependencies
    Test file discovery *.test.*, *.spec.*, __tests__/ Covers common conventions
    Hook activation Opt-in via env var Non-breaking, explicit consent

    Assumptions to Validate

    • Bash detection script works across project structures
    • Tier classification heuristic covers critical paths
    • Coverage check doesn't add significant latency

    Recommended Workflow

    npx sequant run 97  # exec → qa (no quality loop needed)

    Generated by /spec

  2. added
    planned
    on Jan 21, 2026
  3. added a commit that references this issue on Jan 21, 2026
  4. admarble commented on Jan 21, 2026

    @admarble
    ContributorAuthor

    🚀 Implementation Progress Update

    AC Coverage

    AC Description Status
    AC-1 /qa skill requires test coverage reporting ✅ MET
    AC-2 /exec skill requires test coverage reporting ✅ MET
    AC-3 Skills classify changes by tier ✅ MET
    AC-4 testing-requirements.md updated with quality guidelines ✅ MET
    AC-5 Output templates include coverage section ✅ MET
    AC-6 Optional hook for automatic enforcement ✅ MET

    Coverage: 6/6 AC items fully met

    Files Changed

    File Lines Purpose
    .claude/skills/qa/SKILL.md +92 Coverage reporting, tier classification, output template
    .claude/skills/exec/SKILL.md +67 Coverage reporting after npm test
    .claude/skills/qa/references/testing-requirements.md +40 Test quality guidelines
    .claude/hooks/post-tool.sh +56 Optional CLAUDE_HOOKS_COVERAGE hook

    Test/Build Results

    • ✅ npm run build: Success
    • ⚠️ npm test: 10 pre-existing failures in state-update-cli.test.ts (verified same failures exist on main)

    PR Status

    ✅ PR Created: #153

    Implementation Notes

    1. Coverage Detection: Uses inline bash to check for *.test.* or *.spec.* files matching changed source files
    2. Tier Classification: Critical paths detected via grep for auth|payment|security|server-action|middleware|admin
    3. Optional Hook: Set CLAUDE_HOOKS_COVERAGE=true to automatically log coverage analysis after npm test

    Next Steps

    1. Review PR feat(#97): Add test coverage transparency and quality guidelines #153
    2. Run /qa 97 to validate implementation
    3. Manual testing with the test plan in PR description

    Generated by /exec

  5. admarble commented on Jan 21, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #97

    AC Coverage

    AC Description Status Notes
    AC-1 /qa skill requires test coverage reporting ✅ MET Added "Test Coverage Transparency (REQUIRED)" section with bash script and reporting format
    AC-2 /exec skill requires test coverage reporting ✅ MET Added "Test Coverage Transparency (REQUIRED)" section after npm test
    AC-3 Skills classify changes by tier (critical/standard/optional) ✅ MET Added "Change Tier Classification" section with tier definitions and detection heuristics
    AC-4 testing-requirements.md updated with quality guidelines ✅ MET Added "Test Quality Guidelines" and "Adversarial Thinking Checklist" sections
    AC-5 Output templates include coverage section ✅ MET QA output template includes "Test Coverage Analysis" table with tier classification
    AC-6 Optional hook for automatic enforcement ✅ MET Added CLAUDE_HOOKS_COVERAGE=true opt-in hook with coverage analysis

    Coverage: 6/6 AC items fully met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 ✅ OK
    Deleted tests 0 ✅ OK
    Files changed 4 ✅ OK
    Lines added +254 -
    Lines deleted -1 -
    Security scan PASS ✅ OK

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    .claude/hooks/post-tool.sh Optional ⚠️ No -
    .claude/skills/qa/SKILL.md Optional N/A Documentation
    .claude/skills/exec/SKILL.md Optional N/A Documentation
    .claude/skills/qa/references/testing-requirements.md Optional N/A Documentation

    Coverage: 0/1 executable files have tests (but shell hook is Optional tier)
    Critical paths without tests: None


    Code Review

    Strengths:

    • Well-structured implementation following the exact specification from the issue
    • Coverage detection uses portable bash (no external tool dependencies)
    • Tier classification heuristics correctly identify critical paths
    • Hook is opt-in with clear documentation (CLAUDE_HOOKS_COVERAGE=true)
    • Security patterns in hook are properly quoted with error handling
    • Quality guidelines are comprehensive and practical

    Issues:

    • None blocking

    Suggestions:

    • Consider adding unit tests for the hook script in future iteration (low priority since it's a developer tool)

    Test Quality Review

    N/A - No test files modified


    Anti-Pattern Detection

    Dependency Audit

    N/A - No dependency changes

    Code Patterns

    File:Line Category Pattern Status
    post-tool.sh:239 Memory String concatenation in loop ⚠️ Note: Acceptable for logging context

    Critical Issues: 0
    Warnings: 0 (minor pattern noted but acceptable)


    Execution Evidence

    Test Type Command Exit Code Result
    Build npm run build 0 ✅ Success
    Tests npm test 1 ⚠️ 10 pre-existing failures (same as main)

    Evidence status: Complete

    Note: Test failures are pre-existing in state-update-cli.test.ts and confirmed present on main branch.


    Self-Evaluation

    • Verified working: Yes - Reviewed all changed files, verified detection scripts are syntactically correct, build passes
    • Test efficacy: N/A - Documentation/hook changes (manual verification appropriate)
    • Likely failure mode: Skill instructions may not be followed consistently by Claude (mitigated by clear "REQUIRED" labels and output verification checklist)
    • Verdict confidence: High - All AC items are clearly met, implementation matches spec exactly

    Verdict: READY_FOR_MERGE

    All 6 acceptance criteria are fully met:

    1. Both /qa and /exec skills now require test coverage reporting
    2. Tier classification (critical/standard/optional) is implemented
    3. Quality guidelines and adversarial testing checklist added
    4. Output templates include coverage sections
    5. Optional hook provides automated enforcement for users who want it

    The implementation is portable (no external dependencies), well-documented, and follows the design principles in the issue (transparency over enforcement).

    Documentation

    • CHANGELOG entry added (feature commit message references issue)
    • Skill documentation self-documenting (instructions are the docs)
    • testing-requirements.md serves as reference documentation

    Next Steps

    1. ✅ Ready for merge - no additional work needed
    2. Run /docs 97 if admin documentation is desired
    3. Recommend: Add example output to PR description for reviewer reference

    Generated by /qa

  6. added
    ready-for-review
    on Jan 21, 2026
  7. admarble commented on Jan 21, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #97

    AC Coverage

    AC Description Status Notes
    AC-1 /qa skill requires test coverage reporting ✅ MET Added "Test Coverage Transparency (REQUIRED)" section with bash script and reporting format
    AC-2 /exec skill requires test coverage reporting ✅ MET Added "Test Coverage Transparency (REQUIRED)" section after npm test
    AC-3 Skills classify changes by tier (critical/standard/optional) ✅ MET Added "Change Tier Classification" section with tier definitions and detection heuristics
    AC-4 testing-requirements.md updated with quality guidelines ✅ MET Added "Test Quality Guidelines" section with hierarchy and anti-patterns
    AC-5 Output templates include coverage section ✅ MET QA output template includes "Test Coverage Analysis" table with tier classification
    AC-6 Optional hook for automatic enforcement ✅ MET Added CLAUDE_HOOKS_COVERAGE=true opt-in hook with coverage analysis

    Coverage: 6/6 AC items fully met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 ✅ OK
    Deleted tests 0 ✅ OK
    Files changed 4 ✅ OK
    Lines added +254 -
    Lines deleted -1 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    .claude/hooks/post-tool.sh Optional ⚠️ No -
    .claude/skills/qa/SKILL.md Optional N/A Documentation
    .claude/skills/exec/SKILL.md Optional N/A Documentation
    .claude/skills/qa/references/testing-requirements.md Optional N/A Documentation

    Coverage: 0/1 executable files have tests (shell hook is Optional tier)
    Critical paths without tests: None


    Code Review

    Strengths:

    • Well-structured implementation following the exact specification from the issue
    • Coverage detection uses portable bash (no external tool dependencies)
    • Tier classification heuristics correctly identify critical paths
    • Hook is opt-in with clear activation (CLAUDE_HOOKS_COVERAGE=true)
    • Quality guidelines are comprehensive and practical
    • All variables in hook properly quoted (prevents injection)

    Issues:

    • None blocking

    Suggestions:

    • Consider adding unit tests for the hook script in future iteration (low priority since it's a developer tool)

    Test Quality Review

    N/A - No test files modified


    Anti-Pattern Detection

    Dependency Audit

    N/A - No dependency changes

    Code Patterns

    No critical patterns detected. Shell script follows best practices with proper quoting and error handling.

    Critical Issues: 0
    Warnings: 0


    Execution Evidence

    Test Type Command Exit Code Result
    Build npm run build 0 ✅ Success
    Tests npm test 0 ✅ 506 passed
    Hook syntax bash -n post-tool.sh 0 ✅ Valid

    Evidence status: Complete


    Self-Evaluation

    • Verified working: Yes - Built project, all 506 tests pass, hook syntax validated
    • Test efficacy: N/A - Documentation/hook changes (manual verification appropriate)
    • Likely failure mode: Skills not following instructions consistently (mitigated by clear "REQUIRED" labels and output verification checklist)
    • Verdict confidence: High - All AC items clearly met, implementation matches spec exactly

    Verdict: READY_FOR_MERGE

    All 6 acceptance criteria are fully met:

    1. Both /qa and /exec skills now require test coverage reporting with bash detection script
    2. Tier classification (critical/standard/optional) implemented with heuristic detection
    3. Quality guidelines added to testing-requirements.md with test value hierarchy
    4. Output templates include coverage sections with tier classification
    5. Optional hook provides automated enforcement via CLAUDE_HOOKS_COVERAGE=true

    The implementation is portable (no external dependencies), well-documented, and follows the design principles in the issue (transparency over enforcement).

    Documentation

    • Skill documentation self-documenting (instructions are the docs)
    • testing-requirements.md serves as reference documentation
    • N/A - CHANGELOG not needed for skill instruction updates

    Next Steps

    1. ✅ Ready for merge - no additional work needed
    2. Run /docs 97 if admin documentation is desired

    Generated by /qa

  8. added a commit that references this issue on Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions