"""Tests for abreka.prompts."""

import warnings

from abreka.prompts import get_default_template, render_template


class TestRenderTemplate:
    def test_substitution(self):
        template = "Hello {{name}}, your score is {{score}}."
        result = render_template(template, {"name": "Alice", "score": "95"})
        assert result == "Hello Alice, your score is 95."

    def test_missing_variable_warning(self):
        template = "Hello {{name}}, your {{missing}} is ready."
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            result = render_template(template, {"name": "Alice"})
            assert len(w) == 1
            assert "missing" in str(w[0].message)
        assert "{{missing}}" in result
        assert "Alice" in result

    def test_no_variables(self):
        template = "No variables here."
        assert render_template(template, {}) == "No variables here."

    def test_spaces_in_braces(self):
        template = "{{ name }} and {{  score  }}"
        result = render_template(template, {"name": "Bob", "score": "10"})
        assert result == "Bob and 10"


class TestDefaultTemplates:
    def test_propose_exploit_template_exists(self):
        content = get_default_template("propose_exploit")
        assert "{{goal}}" in content

    def test_propose_explore_template_exists(self):
        content = get_default_template("propose_explore")
        assert "{{goal}}" in content
        assert "{{experiment_context}}" in content

    def test_implement_template_exists(self):
        content = get_default_template("implement")
        assert "{{exp_id}}" in content

    def test_test_template_exists(self):
        content = get_default_template("test")
        assert "{{exp_id}}" in content

    def test_repair_run_template_exists(self):
        content = get_default_template("repair_run")
        assert "{{failure_reason}}" in content
        assert "{{run_output}}" in content

    def test_evaluate_template_exists(self):
        content = get_default_template("evaluate")
        assert "{{run_output}}" in content
