import copy import unittest import unittest.mock from dataclasses import asdict from unittest.mock import Mock from ranch_assistant.breakthrough import PATH as BREAKTHROUGH_PATH from ranch_assistant.engine import Engine from ranch_assistant.exploration import ExplorePolicy from ranch_assistant.model import Action, Catalog, EggRule, Policy from ranch_assistant.tests.test_breakthrough import snapshot_with from ranch_assistant.tests.test_core import workspace_temp class RanchAutomationIntegrationTests(unittest.TestCase): def test_breakthrough_is_opt_in_ordered_and_called_with_original_payload(self): client = Mock() snapshot = snapshot_with() client.snapshot.return_value = snapshot engine = Engine(Catalog(), client) engine.snapshot = snapshot engine.policy = Policy(feed_targets={"900": 1}, breakthrough_targets={"900": 1}, egg_rules={}, enabled=True) engine.policy.breakthrough_targets = {} self.assertFalse(any(action.kind == "breakthrough" for action in engine.plans())) engine.policy.breakthrough_targets = {"900": 1} # A checked breakthrough is also a feeding target; it uses the same order. action = engine.plans()[0] self.assertEqual((action.kind, action.path, action.payload), ("breakthrough", BREAKTHROUGH_PATH, {"monId": 900, "itemIds": [600]})) client.call.return_value = {"resCode": 0} engine.auto = True with unittest.mock.patch.object(engine, "read_snapshot"): # Integration route uses the ordinary Action executor, no custom URL. engine.explore_policy = ExplorePolicy() self.assertEqual(action.description.split("(")[0], "突破 #900 绿色史莱姆 → 2 级") def test_egg_keep_count_is_in_policy_and_export(self): from ranch_assistant.policy_io import portable_policy rule = EggRule(enabled=True, action="keep", keep_count=2) policy = Policy(egg_rules={"1001010": asdict(rule)}, breakthrough_targets={"900": 2}) value = portable_policy(policy) self.assertEqual(value["policy"]["egg_rules"]["1001010"]["keep_count"], 2) self.assertEqual(value["targetSpecies"]["breakthrough"], [{"typeId": "", "priority": 2}]) if __name__ == "__main__": unittest.main()