diff --git a/scripts/epic-execute-lib/design-phase.sh b/scripts/epic-execute-lib/design-phase.sh index 37bbc39ec..c01a8b1fe 100644 --- a/scripts/epic-execute-lib/design-phase.sh +++ b/scripts/epic-execute-lib/design-phase.sh @@ -507,6 +507,48 @@ get_last_design() { echo "$LAST_DESIGN" } +# Build a focused "planned test files" context block from the design plan (#7). +# Lets the TDD test-spec phase reuse the test files the design already proposed, +# rather than independently deciding the test surface. Reads the in-memory plan +# first, then the persisted file (resume-safe). Requires a JSON plan + jq. +# Arguments: +# $1 - story_id +build_planned_test_files_context() { + local story_id="$1" + + local design="$LAST_DESIGN" + if [ -z "$design" ] && [ -n "${DESIGN_DIR:-}" ]; then + local design_file="$DESIGN_DIR/${story_id}-design.md" + [ -f "$design_file" ] && design=$(cat "$design_file") + fi + + if [ -z "$design" ] || ! command -v jq >/dev/null 2>&1; then + echo "" + return + fi + + local files + files=$(echo "$design" | jq -r '.test_files[]? | "- \(.path): \(.covers)"' 2>/dev/null || echo "") + + if [ -z "$files" ]; then + echo "" + return + fi + + cat << EOF + +## Planned Test Files (from design phase) + +The design phase already identified the intended test files below. Align your +specifications with these paths and reuse them; only introduce a new test file +when a scenario genuinely isn't covered here, and call out any deviation. + + +$files + +EOF +} + # Build the design context block for dev phase prompt # Returns formatted design context for inclusion in prompts build_design_context_for_dev() { diff --git a/scripts/epic-execute-lib/tdd-flow.sh b/scripts/epic-execute-lib/tdd-flow.sh index e25a1a094..676ed3e7c 100644 --- a/scripts/epic-execute-lib/tdd-flow.sh +++ b/scripts/epic-execute-lib/tdd-flow.sh @@ -54,6 +54,13 @@ execute_test_spec_phase() { design_context=$(get_last_design) fi + # Get the test files the design phase already planned, so the test-spec + # phase reuses them instead of deciding the test surface independently (#7). + local planned_tests="" + if type build_planned_test_files_context >/dev/null 2>&1; then + planned_tests=$(build_planned_test_files_context "$story_id") + fi + local spec_prompt="You are a Test Architect (TEA) generating test specifications from acceptance criteria. ## Your Task @@ -89,7 +96,7 @@ $arch_contents $design_context - +$planned_tests ## Exploration Commands First, explore existing test patterns in the codebase: