{% extends '_base.xml.j2' %}

{% block extra_constraints %}
        <rule priority="critical">Do NOT run tests.</rule>
        <rule priority="critical">Do NOT commit changes.</rule>
        <rule priority="high">Each acceptance criterion needs at least one test.</rule>
{% endblock %}

{% block instructions %}
        <phase name="prerequisites">
            <commands><![CDATA[
cat .claudesprint/project/current_issue.json
            ]]></commands>
            <checks>
                <check>changes array has entries (implementation exists)</check>
                <check>current_failures is empty (not here due to failures)</check>
            </checks>
            <fallback>If current_failures non-empty, set step to fix-tests and exit.</fallback>
        </phase>

        <phase name="get_bearings">
            <commands><![CDATA[
pwd
ISSUE_ID=$(cat .claudesprint/project/current_issue.json | jq -r '.issue_id')
claudesprint-tools sprint details "$ISSUE_ID"
git diff --stat 2>/dev/null
            ]]></commands>
        </phase>

        <phase name="write_tests">
            <description>For each acceptance criterion:</description>
            <steps>
                <step>Check if tests already exist</step>
                <step>Write focused tests that verify the criterion</step>
                <step>Follow existing test patterns</step>
                <step>Include edge cases where appropriate</step>
            </steps>
            <guidelines>
                <guideline>Tests should be deterministic and independent</guideline>
                <guideline>Test names should describe what they verify</guideline>
                <guideline>One test per acceptance criterion minimum</guideline>
            </guidelines>
        </phase>

        <phase name="update_state">
            <description>Update state via CLI tools:</description>
            <commands><![CDATA[
# Record all test files created/modified
claudesprint-tools issue change "<test_file>" "<tests added>"
            ]]></commands>
            <note>Do NOT set the next step manually. Step transitions are handled automatically by the workflow engine.</note>
        </phase>

        <phase name="log_and_exit">
            <commands><![CDATA[
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] STEP: write-tests -> run-tests" >> .claudesprint/project/current_issue.log
echo "  Tests added: <test files>" >> .claudesprint/project/current_issue.log
echo "  Coverage: <test coverage summary>" >> .claudesprint/project/current_issue.log
            ]]></commands>
        </phase>
{% endblock %}

{% block termination %}
        <note>No termination tag required for this step.</note>
{% endblock %}
