from pathlib import Path

from codex_autorunner.bootstrap import seed_repo_files
from codex_autorunner.core.engine import Engine
from codex_autorunner.core.prompt import build_prompt, build_prompt_text


def test_prompt_calls_out_work_doc_paths(tmp_path: Path) -> None:
    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / ".git").mkdir()
    seed_repo_files(repo, git_required=False)

    engine = Engine(repo)
    prompt = build_prompt(engine.config, engine.docs, prev_run_output=None)

    assert ".codex-autorunner/TODO.md" in prompt
    assert ".codex-autorunner/PROGRESS.md" in prompt
    assert ".codex-autorunner/OPINIONS.md" in prompt
    assert ".codex-autorunner/SPEC.md" in prompt
    assert ".codex-autorunner/SUMMARY.md" in prompt
    assert "Edit these files directly; do not create new copies elsewhere" in prompt


def test_build_prompt_text_includes_prev_run_block() -> None:
    template = "TODO={{TODO}}\nPATH={{TODO_PATH}}\n{{PREV_RUN_OUTPUT}}"
    rendered = build_prompt_text(
        template=template,
        docs={"todo": "Do the thing"},
        doc_paths={"todo": "TODO.md"},
        prev_run_output="finished",
    )

    assert "TODO=Do the thing" in rendered
    assert "PATH=TODO.md" in rendered
    assert "<PREV_RUN_OUTPUT>" in rendered
    assert "finished" in rendered
