"""Tests for prompt_builder.pipeline

Execution tests are limited to compile-only mode since we don't
have API keys in the test environment.
"""

import pytest
from prompt_builder import Prompt, Instruction, TokenBudget
from prompt_builder.pipeline import Pipeline, PipelineResult
from prompt_builder.executor import ExecutionConfig


class TestPipelineCompileOnly:
    def test_compile_only(self):
        pipe = Pipeline(budget=TokenBudget(context_window=8000))
        prompt = Prompt(instruction=Instruction(task="Test."))

        result = pipe.compile(prompt)

        assert len(result.messages) >= 1
        assert result.total_tokens > 0

    def test_run_without_executor_raises(self):
        pipe = Pipeline(budget=TokenBudget(context_window=8000))
        prompt = Prompt(instruction=Instruction(task="Test."))

        with pytest.raises(RuntimeError, match="No ExecutionConfig"):
            pipe.run(prompt)

    def test_pipeline_with_execution_config_creates_executor(self):
        pipe = Pipeline(
            budget=TokenBudget(context_window=8000),
            execution=ExecutionConfig(model="openai/gpt-4o"),
        )
        assert pipe.executor is not None


class TestExecutor:
    def test_executor_import_error_without_litellm(self):
        """Executor gives a clear error if litellm not installed."""
        from prompt_builder.executor import Executor, ExecutionConfig
        from prompt_builder import compile, Prompt, Instruction, TokenBudget

        # This test passes as long as the executor class can be instantiated
        # (the import error only happens on .run())
        executor = Executor(ExecutionConfig())
        assert executor.config.model == "openai/gpt-4o"
