"""Tests for the DM style tuning system and the arc commit tool.""" from pathlib import Path from storied.testing import call_tool from storied.tools import ToolContext from storied.tools.scene import commit_arc as _commit_arc from storied.tools.scene import tune as _tune def tune(tuning: str) -> str: return call_tool(_tune, tuning=tuning) def commit_arc(content: str) -> str: return call_tool(_commit_arc, content=content) class TestTune: """Tests for the tune tool.""" def test_tune_creates_style_file(self, ctx: ToolContext, tmp_path: Path): tune("Lean into intrigue and social encounters.") style_path = tmp_path / "worlds" / ctx.world_id / "style.md" assert style_path.exists() def test_tune_writes_content(self, ctx: ToolContext, tmp_path: Path): tune("More exploration, less combat.") content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() assert "More exploration, less combat." in content def test_tune_has_heading(self, ctx: ToolContext, tmp_path: Path): tune("Keep pacing slow.") content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() assert content.startswith("# Style\n") def test_tune_replaces_existing(self, ctx: ToolContext, tmp_path: Path): tune("Lots of combat.") tune("Actually, less combat.") content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() assert "Actually, less combat." in content assert "Lots of combat." not in content def test_tune_returns_confirmation(self, ctx: ToolContext): result = tune("Dark and atmospheric tone.") assert "updated" in result.lower() class TestCommitArc: """Tests for the arc_architect's commit_arc tool.""" def test_commit_arc_creates_arc_file( self, ctx: ToolContext, tmp_path: Path, ): commit_arc("# Campaign Arc\n\n## Premise\nA quiet mystery.\n") arc_path = tmp_path / "worlds" / ctx.world_id / "arc.md" assert arc_path.exists() def test_commit_arc_writes_content_verbatim( self, ctx: ToolContext, tmp_path: Path, ): content = ( "# Campaign Arc\n\n## Premise\nA wedding postponed twice.\n" "\n## Off the Table\n- the cosmic-prisoner trope\n" ) commit_arc(content) arc_path = tmp_path / "worlds" / ctx.world_id / "arc.md" assert arc_path.read_text() == content def test_commit_arc_replaces_existing( self, ctx: ToolContext, tmp_path: Path, ): commit_arc("# Campaign Arc\n\n## Premise\nFirst draft.\n") commit_arc("# Campaign Arc\n\n## Premise\nSecond draft.\n") content = (tmp_path / "worlds" / ctx.world_id / "arc.md").read_text() assert "Second draft." in content assert "First draft." not in content def test_commit_arc_returns_confirmation(self, ctx: ToolContext): result = commit_arc("# Campaign Arc\n\n## Premise\nA test.\n") assert "committed" in result.lower()