"""Tests for Myco's core game loop.""" from __future__ import annotations import unittest from game.catalog import load_mushrooms from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current from game.progression import current_area, next_area, unlocked_areas from game.state import EMPTY_DEX, welcome_history from models.mushroom import Mushroom from ui.renderers import dex_markdown, mushroom_card, progress_markdown from game.engine import collect_current, discover_mushroom, myco_reply from game.state import EMPTY_DEX, welcome_history from models.mushroom import Mushroom from ui.renderers import dex_markdown, mushroom_card class MycoGameLoopTests(unittest.TestCase): """Coverage for the first playable Myco loop.""" def test_catalog_has_mvp_scale_and_rarities(self) -> None: mushrooms = load_mushrooms() self.assertEqual(len(mushrooms), 30) self.assertEqual({mushroom.rarity for mushroom in mushrooms}, {"Common", "Rare", "Legendary"}) def test_discover_mushroom_returns_current_state_and_myco_prompt(self) -> None: glowcap = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.") mushroom, current, history = discover_mushroom([], catalog=[glowcap]) self.assertEqual(mushroom, glowcap) self.assertEqual(current["name"], "Glowcap") self.assertEqual(history[0], {"role": "assistant", "content": "Hello! I'm Myco. Let's explore the forest."}) self.assertIn("We found a Glowcap", history[1]["content"]) self.assertIn("eat, collect, or study", history[1]["content"]) def test_myco_reply_comments_on_current_mushroom(self) -> None: current = Mushroom( "Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.", ).to_dict() prompt, history = myco_reply("What is it?", welcome_history(), current) self.assertEqual(prompt, "") self.assertEqual(history[-1]["role"], "assistant") self.assertIn("I think this is **Glowcap**", history[-1]["content"]) self.assertIn("not completely sure", history[-1]["content"]) def test_collect_current_adds_once(self) -> None: current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict() collection, history = collect_current(current, [], welcome_history()) second_collection, second_history = collect_current(current, collection, history) self.assertEqual([entry["name"] for entry in collection], ["Glowcap"]) self.assertEqual(second_collection, collection) self.assertIn("already safe", second_history[-1]["content"]) def test_study_current_reveals_magic_hint(self) -> None: current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict() studied, history = study_current(current, welcome_history()) self.assertIsNotNone(studied) assert studied is not None self.assertEqual(studied["magic"], "Tiny spore shimmer") self.assertEqual(studied["studied"], "Yes") self.assertIn("New MycoDex note", history[-1]["content"]) def test_eat_current_keeps_unknown_mushrooms_safe(self) -> None: current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict() history = eat_current(current, welcome_history()) self.assertIn("gently blocks", history[-1]["content"]) self.assertIn("instead of eating", history[-1]["content"]) def test_progression_unlocks_areas_by_collection_count(self) -> None: self.assertEqual(current_area(0).name, "Mossy Trail") self.assertEqual(next_area(0).name, "Crystal Grove") self.assertEqual(current_area(10).name, "Crystal Grove") self.assertEqual(next_area(25).name, "Mushroom Elder") self.assertEqual([area.name for area in unlocked_areas(25)], ["Mossy Trail", "Crystal Grove", "Moonlit Cavern"]) def test_renderers_show_unknown_traits_progress_and_empty_dex(self) -> None: mushroom = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.") card = mushroom_card(mushroom) progress = progress_markdown([]) def test_renderers_show_unknown_traits_and_empty_dex(self) -> None: mushroom = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.") card = mushroom_card(mushroom) self.assertIn("**Edible:** Unknown", card) self.assertIn("**Magic:** Unknown", card) self.assertIn("**Danger:** Unknown", card) self.assertIn("Forest Progress", progress) self.assertIn("Crystal Grove", progress) self.assertEqual(dex_markdown([]), EMPTY_DEX) if __name__ == "__main__": unittest.main()