US01-07: Automate Phase A End-to-End Acceptance (#53)

This commit was merged in pull request #53.
This commit is contained in:
2026-07-15 22:15:30 +02:00
parent 3d5550b07f
commit 19d4ce3785
6 changed files with 372 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
"""Story-to-test traceability for Phase A (Epic E01).
Every story US01-01..US01-07 must map to test files that exist, and every Phase A
test file must be claimed by a story — so a new test can't go unexercised and a
story can't quietly lose its coverage. Whether those tests *pass* is proven by
running the suite; this guards the mapping's completeness.
"""
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[2]
MAP = json.loads((REPO / "tests" / "phase_a_traceability.json").read_text())["stories"]
EXPECTED_STORIES = {f"US01-0{n}" for n in range(1, 8)}
def test_all_phase_a_stories_are_mapped():
assert set(MAP) == EXPECTED_STORIES
def test_every_mapped_test_file_exists_and_is_nonempty():
for story, files in MAP.items():
assert files, f"{story} maps to no tests"
for rel in files:
path = REPO / rel
assert path.is_file(), f"{story}: missing {rel}"
assert path.stat().st_size > 0, f"{story}: empty {rel}"
assert "def test_" in path.read_text(), f"{story}: no tests in {rel}"
def test_no_unexercised_phase_a_test_files():
"""Every test_*.py under tests/ is claimed by a story (no orphan coverage)."""
mapped = {rel for files in MAP.values() for rel in files}
on_disk = {
str(p.relative_to(REPO))
for p in (REPO / "tests").rglob("test_*.py")
if "__pycache__" not in p.parts
}
unmapped = on_disk - mapped
assert not unmapped, f"test files not tied to any story: {sorted(unmapped)}"