import json from pathlib import Path from app.prompts import render_digest, system_prompt VALID = json.loads((Path(__file__).parent / "fixtures" / "canon_log_valid.json").read_text()) def test_system_prompt_strips_the_header(): body = system_prompt("narrator") assert isinstance(body, str) and body.strip() != "" # The human-facing markdown title above the '---' is not part of the prompt. assert "# Narrator prompt" not in body def test_digest_has_the_narrative_context(): d = render_digest(VALID) assert "Location: the Greywater docks" in d assert "Arrived at Greywater by barge before dawn" in d assert "Established facts:" in d assert "the harbourmaster is named Oda Fenn" in d assert "Companions present: Brannoc Thane, Cadwyn Vell" in d assert "Active quest: The Missing Ledger — Find who took Fenn's ledger" in d assert "Fortune: Fortune spits on you" in d assert "Player: Aldric, a sellsword" in d assert d.rstrip().endswith("Describe the scene as it is now.") def test_digest_omits_raw_numbers_and_ids(): d = render_digest(VALID) # §7/§2: no disposition integers, no ids, no schema_version leak into the prompt. assert "disposition" not in d assert "40" not in d and "15" not in d # the deserter dispositions assert "brannoc_thane" not in d # ids stay out; names only assert "schema_version" not in d def test_narrator_body_is_authored(): body = system_prompt.__wrapped__("narrator") # bypass lru_cache in case of prior load assert "TBD" not in body assert "[FACT:" in body # the tag instruction is present assert "second person" in body # the core task is present