from pathlib import Path

from generate_variants import (
    DEFAULT_AGENT_COMMAND,
    INTERCHANGEABILITY_RULE,
    build_prompt,
    diversity_brief,
    load_contract,
)


def test_contract_lookup_and_prompt() -> None:
    document, contract = load_contract(Path("specs/zipdiv.toml"), "validate_crc")
    prompt = build_prompt(document, contract, "pub trait ValidateCrc {}", 2)
    assert "candidate 2" in prompt
    assert "validate_crc" in prompt
    assert INTERCHANGEABILITY_RULE in prompt
    assert "Diversity brief for this candidate" in prompt
    assert "Return ONLY" in prompt


def test_diversity_briefs_are_deterministic_and_distinct() -> None:
    briefs = [diversity_brief("validate_crc", index) for index in range(1, 6)]
    assert len({brief["algorithm"] for brief in briefs}) == 5
    assert len({brief["control_flow"] for brief in briefs}) == 5
    assert len({tuple(sorted(brief.items())) for brief in briefs}) == 5
    assert diversity_brief("validate_crc", 3) == diversity_brief("validate_crc", 3)


def test_codex_is_the_default_noninteractive_agent() -> None:
    assert DEFAULT_AGENT_COMMAND.startswith("codex exec ")
    assert "--output-last-message {output}" in DEFAULT_AGENT_COMMAND
