from __future__ import annotations

from pathlib import Path

from skills._shared.python.skill_testing import assert_skill_contract


def test_workflows_plan_execute_plan_parallel_contract() -> None:
    skill_root = Path(__file__).resolve().parents[1]
    assert_skill_contract(skill_root)


def test_execute_plan_parallel_requires_test_first_evidence_gate() -> None:
    text = (Path(__file__).resolve().parents[1] / "SKILL.md").read_text(encoding="utf-8")
    assert "## Test-First Evidence Gate" in text
    assert "failing-test evidence or an explicit waiver" in text
    assert "before editing production behavior" in text
    assert "Change classification" in text
    assert "Failing test before fix" in text
    assert "Final validation" in text
    assert "Waiver reason" in text


def test_execute_plan_parallel_defaults_to_whole_plan_without_selector() -> None:
    text = (Path(__file__).resolve().parents[1] / "SKILL.md").read_text(encoding="utf-8")
    normalized = " ".join(text.split())

    assert "whole plan as the target scope" in normalized
    assert "No selector means whole-plan target scope" in normalized
    assert "when absent, use the whole plan as the target scope" in normalized
    assert "Do not silently narrow the request to Sprint 1" in text
    assert "default to Sprint 1" not in text


def test_execute_plan_parallel_requires_suitability_assessment() -> None:
    text = (Path(__file__).resolve().parents[1] / "SKILL.md").read_text(encoding="utf-8")
    normalized = " ".join(text.split())

    assert "Assess whole-plan suitability" in text
    assert "plan size, dependency graph, same-file overlap" in normalized
    assert "dirty worktree overlap, validation availability, credentials" in normalized
    assert "ask the user to confirm either whole-plan target with staged checkpoints" in normalized
    assert "agreed narrower execution window with acceptance gates" in normalized


def test_execute_plan_parallel_main_agent_owns_integration() -> None:
    text = (Path(__file__).resolve().parents[1] / "SKILL.md").read_text(encoding="utf-8")
    normalized = " ".join(text.split())

    assert "The main agent owns plan-wide scope" in text
    assert "dispatch, integration, validation, and final synthesis" in normalized
    assert '"implement this task only"' in text
