|
| 1 | +# Implementation Plan: Coverage-Aware Behavior Analysis |
| 2 | + |
| 3 | +**Branch**: `044-coverage-aware-analysis` | **Date**: 2026-04-13 | **Spec**: [spec.md](spec.md) |
| 4 | +**Input**: Feature specification from `/specs/044-coverage-aware-analysis/spec.md` |
| 5 | + |
| 6 | +## Summary |
| 7 | + |
| 8 | +The behavior analysis step in `spectra ai generate` currently treats documentation as a blank slate, identifying all testable behaviors and applying a weak title-similarity heuristic for deduplication. For mature suites this produces wildly inaccurate recommendations (139 new tests when 8 are actually needed). This plan adds a coverage snapshot that feeds existing test index, criteria coverage, and doc section coverage into the analysis prompt so the AI only recommends tests for genuine gaps. |
| 9 | + |
| 10 | +## Technical Context |
| 11 | + |
| 12 | +**Language/Version**: C# 12, .NET 8+ |
| 13 | +**Primary Dependencies**: GitHub Copilot SDK, System.CommandLine, Spectre.Console, System.Text.Json, YamlDotNet |
| 14 | +**Storage**: File-based (Markdown/YAML/JSON in `test-cases/`, `docs/criteria/`, `_index.json`, `_criteria_index.yaml`) |
| 15 | +**Testing**: xUnit (~1279 tests across 3 test projects) |
| 16 | +**Target Platform**: Windows/macOS/Linux CLI |
| 17 | +**Project Type**: CLI tool with MCP server |
| 18 | +**Performance Goals**: Coverage snapshot computation < 2s for 500 tests |
| 19 | +**Constraints**: Prompt token overhead < 5,000 tokens; switch to summary mode > 500 tests |
| 20 | +**Scale/Scope**: Suites up to 500+ tests, 50+ criteria, 20+ doc sections |
| 21 | + |
| 22 | +## Constitution Check |
| 23 | + |
| 24 | +*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.* |
| 25 | + |
| 26 | +| Principle | Status | Notes | |
| 27 | +|-----------|--------|-------| |
| 28 | +| I. GitHub as Source of Truth | PASS | All data read from committed files (`_index.json`, `.criteria.yaml`, `_index.md`) | |
| 29 | +| II. Deterministic Execution | PASS | Same coverage data + same docs = same snapshot; no randomness in snapshot building | |
| 30 | +| III. Orchestrator-Agnostic Design | PASS | Coverage context is injected into the prompt template, not tied to a specific LLM | |
| 31 | +| IV. CLI-First Interface | PASS | Feature is CLI-only; no new UI required; existing flags preserved | |
| 32 | +| V. Simplicity (YAGNI) | PASS | One new model + one builder service + prompt template changes. No new abstractions beyond what's needed. Reuses existing `IndexWriter`, `CriteriaFileReader`, `DocumentIndexReader` | |
| 33 | + |
| 34 | +**Quality Gates**: All existing gates preserved. No new validation rules needed. |
| 35 | + |
| 36 | +## Project Structure |
| 37 | + |
| 38 | +### Documentation (this feature) |
| 39 | + |
| 40 | +```text |
| 41 | +specs/044-coverage-aware-analysis/ |
| 42 | +├── plan.md # This file |
| 43 | +├── research.md # Phase 0 output |
| 44 | +├── data-model.md # Phase 1 output |
| 45 | +├── contracts/ # Phase 1 output |
| 46 | +│ └── coverage-context-contract.md |
| 47 | +├── quickstart.md # Phase 1 output |
| 48 | +└── tasks.md # Phase 2 output (/speckit.tasks) |
| 49 | +``` |
| 50 | + |
| 51 | +### Source Code (repository root) |
| 52 | + |
| 53 | +```text |
| 54 | +src/ |
| 55 | + Spectra.CLI/ |
| 56 | + Agent/ |
| 57 | + Analysis/ |
| 58 | + BehaviorAnalysisResult.cs # Existing |
| 59 | + IdentifiedBehavior.cs # Existing |
| 60 | + CoverageSnapshot.cs # NEW: model + UncoveredCriterion record |
| 61 | + CoverageSnapshotBuilder.cs # NEW: builds snapshot from index/criteria/docs |
| 62 | + CoverageContextFormatter.cs # NEW: formats snapshot for prompt injection |
| 63 | + Copilot/ |
| 64 | + BehaviorAnalyzer.cs # MODIFIED: accept snapshot, inject context |
| 65 | + Commands/ |
| 66 | + Generate/ |
| 67 | + GenerateHandler.cs # MODIFIED: build snapshot before analysis |
| 68 | + Output/ |
| 69 | + AnalysisPresenter.cs # MODIFIED: show coverage summary |
| 70 | + Progress/ |
| 71 | + ProgressPageWriter.cs # MODIFIED: coverage snapshot in HTML |
| 72 | + Prompts/ |
| 73 | + Content/ |
| 74 | + behavior-analysis.md # MODIFIED: add {{coverage_context}} placeholder |
| 75 | + Results/ |
| 76 | + GenerateResult.cs # MODIFIED: add coverage fields to GenerateAnalysis |
| 77 | +
|
| 78 | + Spectra.Core/ |
| 79 | + # No changes — read existing data via existing readers |
| 80 | +
|
| 81 | +tests/ |
| 82 | + Spectra.CLI.Tests/ |
| 83 | + Agent/ |
| 84 | + Analysis/ |
| 85 | + CoverageSnapshotBuilderTests.cs # NEW: 8 tests |
| 86 | + CoverageContextFormatterTests.cs # NEW: 5 tests |
| 87 | + Commands/ |
| 88 | + Generate/ |
| 89 | + GenerateHandlerCoverageTests.cs # NEW: 2 integration tests |
| 90 | + Output/ |
| 91 | + AnalysisPresenterCoverageTests.cs # NEW: 3 tests |
| 92 | + Results/ |
| 93 | + GenerateAnalysisCoverageTests.cs # NEW: 3 tests |
| 94 | +``` |
| 95 | + |
| 96 | +**Structure Decision**: All new files go within the existing `Agent/Analysis/` directory (model + builder + formatter). No new project or directory structure needed — follows existing patterns exactly. |
| 97 | + |
| 98 | +## Complexity Tracking |
| 99 | + |
| 100 | +> No violations — all gates pass. No complexity justification needed. |
0 commit comments