A 5e storytelling engine with an LLM DM
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 96 lines 3.1 kB view raw
1"""Tests for the DM style tuning system and the arc commit tool.""" 2 3from pathlib import Path 4 5from storied.testing import call_tool 6from storied.tools import ToolContext 7from storied.tools.scene import commit_arc as _commit_arc 8from storied.tools.scene import tune as _tune 9 10 11def tune(tuning: str) -> str: 12 return call_tool(_tune, tuning=tuning) 13 14 15def commit_arc(content: str) -> str: 16 return call_tool(_commit_arc, content=content) 17 18 19class TestTune: 20 """Tests for the tune tool.""" 21 22 def test_tune_creates_style_file(self, ctx: ToolContext, tmp_path: Path): 23 tune("Lean into intrigue and social encounters.") 24 25 style_path = tmp_path / "worlds" / ctx.world_id / "style.md" 26 assert style_path.exists() 27 28 def test_tune_writes_content(self, ctx: ToolContext, tmp_path: Path): 29 tune("More exploration, less combat.") 30 31 content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() 32 assert "More exploration, less combat." in content 33 34 def test_tune_has_heading(self, ctx: ToolContext, tmp_path: Path): 35 tune("Keep pacing slow.") 36 37 content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() 38 assert content.startswith("# Style\n") 39 40 def test_tune_replaces_existing(self, ctx: ToolContext, tmp_path: Path): 41 tune("Lots of combat.") 42 tune("Actually, less combat.") 43 44 content = (tmp_path / "worlds" / ctx.world_id / "style.md").read_text() 45 assert "Actually, less combat." in content 46 assert "Lots of combat." not in content 47 48 def test_tune_returns_confirmation(self, ctx: ToolContext): 49 result = tune("Dark and atmospheric tone.") 50 51 assert "updated" in result.lower() 52 53 54class TestCommitArc: 55 """Tests for the arc_architect's commit_arc tool.""" 56 57 def test_commit_arc_creates_arc_file( 58 self, 59 ctx: ToolContext, 60 tmp_path: Path, 61 ): 62 commit_arc("# Campaign Arc\n\n## Premise\nA quiet mystery.\n") 63 64 arc_path = tmp_path / "worlds" / ctx.world_id / "arc.md" 65 assert arc_path.exists() 66 67 def test_commit_arc_writes_content_verbatim( 68 self, 69 ctx: ToolContext, 70 tmp_path: Path, 71 ): 72 content = ( 73 "# Campaign Arc\n\n## Premise\nA wedding postponed twice.\n" 74 "\n## Off the Table\n- the cosmic-prisoner trope\n" 75 ) 76 commit_arc(content) 77 78 arc_path = tmp_path / "worlds" / ctx.world_id / "arc.md" 79 assert arc_path.read_text() == content 80 81 def test_commit_arc_replaces_existing( 82 self, 83 ctx: ToolContext, 84 tmp_path: Path, 85 ): 86 commit_arc("# Campaign Arc\n\n## Premise\nFirst draft.\n") 87 commit_arc("# Campaign Arc\n\n## Premise\nSecond draft.\n") 88 89 content = (tmp_path / "worlds" / ctx.world_id / "arc.md").read_text() 90 assert "Second draft." in content 91 assert "First draft." not in content 92 93 def test_commit_arc_returns_confirmation(self, ctx: ToolContext): 94 result = commit_arc("# Campaign Arc\n\n## Premise\nA test.\n") 95 96 assert "committed" in result.lower()