from __future__ import annotations from pathlib import Path import pytest from src.parser import StoryValidationError, parse_story def test_parse_story_success() -> None: parsed = parse_story(Path("data/main_story.yaml")) assert parsed.story.story_id == "demo_story" assert parsed.story.start == "intro" assert "gate" in parsed.story.nodes def test_parse_story_missing_target_fails(tmp_path: Path) -> None: bad_story = tmp_path / "bad.yaml" bad_story.write_text( """ story_id: bad start: a nodes: - id: a text: hello options: - text: go target: missing """.strip(), encoding="utf-8", ) with pytest.raises(StoryValidationError): parse_story(bad_story) def test_parse_story_invalid_effect_fails(tmp_path: Path) -> None: bad_story = tmp_path / "bad_effect.yaml" bad_story.write_text( """ story_id: bad_effect start: a nodes: - id: a text: hello effects: - hp **= 2 end: true """.strip(), encoding="utf-8", ) with pytest.raises(StoryValidationError): parse_story(bad_story)