From b68403e60114aae10a469e7aae4e320845ebaddd Mon Sep 17 00:00:00 2001 From: Zihao Xu Date: Sun, 18 Jan 2026 01:00:42 -0800 Subject: [PATCH] fix: mock StoryTeller in mock_llm_managers to prevent flaky test (#36) The test_passive_update_loop test was flaky because when misfortune randomly triggers during sim.step(), it calls StoryTeller.tell_story which wasn't mocked, causing real LLM API calls to fail in CI. Added StoryTeller.tell_story to the mock_llm_managers fixture. --- tests/conftest.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 830041c..b19beaa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,6 +83,7 @@ def mock_llm_managers(): patch("src.classes.nickname.process_avatar_nickname", new_callable=AsyncMock) as mock_nick, \ patch("src.classes.relation_resolver.RelationResolver.run_batch", new_callable=AsyncMock) as mock_rr, \ patch("src.classes.history.HistoryManager.apply_history_influence", new_callable=AsyncMock) as mock_hist, \ + patch("src.classes.story_teller.StoryTeller.tell_story", new_callable=AsyncMock) as mock_story, \ patch("src.utils.llm.config.LLMConfig.from_mode", return_value=mock_llm_config) as mock_config: mock_ai.decide = AsyncMock(return_value={}) @@ -90,6 +91,7 @@ def mock_llm_managers(): mock_nick.return_value = None mock_rr.return_value = [] mock_hist.return_value = None + mock_story.return_value = "测试故事" yield { "ai": mock_ai, @@ -97,6 +99,7 @@ def mock_llm_managers(): "nick": mock_nick, "rr": mock_rr, "hist": mock_hist, + "story": mock_story, "config": mock_config }