feat(phase2): llm report writer (P5.3)
- New module src/pf1e_simulator/report.py with ReportContext, build_report_context, LLMReportPolicy, ReportBudget, format_llm_report, build_report_prompt - Prompt pack fixture: tests/fixtures/prompt_pack_fs/report.md (FR narrator) - CLI integration: --llm-report + --output flags, mutually exclusive with --transcript - Budget enforcement: ReportBudget integrates with CostBudget, allows max_retries+1 calls - Tests: test_report_context, test_report_prompt_pack, test_llm_report_policy, test_format_llm_report, test_cli_llm_report, test_report_budget (27 new tests)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""CLI integration test for --llm-report flag (P5.3 T5)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from pf1e_simulator.cli import main
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MAP = ROOT / "data" / "maps" / "sample_arena.yaml"
|
||||
|
||||
|
||||
def _argv_common() -> list[str]:
|
||||
return [
|
||||
"--map", str(MAP),
|
||||
"--side", "players", str(ROOT / "data" / "monsters" / "goblin.json"),
|
||||
"--side", "monsters", str(ROOT / "data" / "monsters" / "orc.json"),
|
||||
]
|
||||
|
||||
|
||||
def test_cli_llm_report_mutually_exclusive_with_transcript() -> None:
|
||||
"""--llm-report and --transcript are mutually exclusive."""
|
||||
argv = [*_argv_common(), "--llm-report", "--transcript"]
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main(argv)
|
||||
assert exc_info.value.code == 2
|
||||
|
||||
|
||||
def test_cli_output_requires_llm_report() -> None:
|
||||
"""--output requires --llm-report."""
|
||||
argv = [*_argv_common(), "--output", "report.md"]
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main(argv)
|
||||
assert exc_info.value.code == 2
|
||||
|
||||
|
||||
def test_cli_llm_report_requires_api_key_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""--llm-report fails gracefully when PF1E_LLM_API_KEY not set."""
|
||||
monkeypatch.delenv("PF1E_LLM_API_KEY", raising=False)
|
||||
monkeypatch.delenv("PF1E_PROMPT_PACK_DIR", raising=False)
|
||||
|
||||
argv = [*_argv_common(), "--llm-report"]
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main(argv)
|
||||
assert exc_info.value.code == 2
|
||||
|
||||
|
||||
def test_cli_llm_report_requires_prompt_pack_dir(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""--llm-report fails gracefully when PF1E_PROMPT_PACK_DIR not set."""
|
||||
monkeypatch.setenv("PF1E_LLM_API_KEY", "test-key")
|
||||
monkeypatch.delenv("PF1E_PROMPT_PACK_DIR", raising=False)
|
||||
|
||||
argv = [*_argv_common(), "--llm-report"]
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
main(argv)
|
||||
assert exc_info.value.code == 2
|
||||
Reference in New Issue
Block a user