from pathlib import Path from prompts import map_prompt_template, resolve_prompt, summary_prompt_template def test_bundled_prompts_contain_placeholders(): assert "{batch_text}" in map_prompt_template() assert "{final_input}" in summary_prompt_template() assert "Market Intelligence Extractor" in map_prompt_template() assert "Lead Market Intelligence Analyst" in summary_prompt_template() def test_env_prompt_wins_over_file(monkeypatch, tmp_path): monkeypatch.setenv("MAP_PROMPT", "ENV {batch_text}") monkeypatch.setenv("MAP_PROMPT_FILE", str(tmp_path / "missing.txt")) assert resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt") == "ENV {batch_text}" def test_blank_env_falls_through_to_file(monkeypatch, tmp_path): f = tmp_path / "custom.txt" f.write_text("FILE {batch_text}\n") monkeypatch.setenv("MAP_PROMPT", " ") monkeypatch.setenv("MAP_PROMPT_FILE", str(f)) assert resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt") == "FILE {batch_text}\n" def test_missing_file_raises(monkeypatch, tmp_path): monkeypatch.delenv("MAP_PROMPT", raising=False) monkeypatch.setenv("MAP_PROMPT_FILE", str(tmp_path / "nope.txt")) try: resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt") assert False, "expected RuntimeError" except RuntimeError as exc: assert "unreadable" in str(exc) def test_bundled_files_exist(): root = Path(__file__).resolve().parents[1] / "prompt_files" assert (root / "map.txt").is_file() assert (root / "summary.txt").is_file()