Fix gift item instance IDs and per-monster cooldown scheduling

Use bag instance IDs required by the client protocol. Apply confirmed feel and giftDate values across stale queries, skip cooling targets, and schedule ready gifts independently of random polling. Replan cultivation locally and retain local strategy errors in diagnostics.
This commit is contained in:
AttilaNet
2026-11-08 13:08:12 +08:00
parent db17fc1288
commit 3b5da7ebcb
8 changed files with 331 additions and 21 deletions
+39
View File
@@ -16,6 +16,8 @@ from ranch_assistant.gui import Window
from ranch_assistant.model import Catalog, Planner, Policy, Snapshot
from ranch_assistant.policy_io import import_config, portable_config
from ranch_assistant.tests.test_core import workspace_temp
from ranch_assistant.tests.test_accounts import fake_client, role_snapshot
from ranch_assistant.api import Session
def monster(catalog, mid, *, level=10, feel=0, scale=.3, species=1001010, process=3):
@@ -174,3 +176,40 @@ class CultivationGuiTests(unittest.TestCase):
self.assertTrue(window.gift_auto_representative.isChecked())
finally:
window.close()
def test_selecting_representatives_replans_locally_without_an_api_request(self):
with workspace_temp() as folder:
window = Window(folder)
window.timer.stop()
calls = []
try:
self.wait(lambda: not window.busy and window.engine.snapshot is not None)
session = Session("http://127.0.0.1/", "synthetic-token", account_id="fixture", server_id=1, role_id=101)
client = fake_client(session, window.catalog, calls)
window.result("connected", (client, Snapshot(role_snapshot(window.catalog, 101))))
window.gift_auto_representative.setChecked(True)
self.wait(lambda: not window.auto_save_timer.isActive() and not window.busy and bool(window.engine.cultivation.selected))
self.assertEqual(calls, [])
self.assertTrue(window.monitoring)
self.assertFalse(window.strategy_toggle.isChecked())
finally:
window.close()
def test_local_selection_failure_is_recorded_as_local_and_keeps_monitoring(self):
with workspace_temp() as folder:
window = Window(folder)
window.timer.stop()
try:
self.wait(lambda: not window.busy and window.engine.snapshot is not None)
window.monitoring = True
with patch.object(window.engine.cultivation, "select", side_effect=ValueError("fixture-selection-failure")):
window.gift_auto_representative.setChecked(True)
self.wait(lambda: any("fixture-selection-failure" in e.get("message", "") for e in window.trace.events))
self.wait(lambda: not window.busy)
event = next(e for e in window.trace.events if "fixture-selection-failure" in e.get("message", ""))
self.assertEqual(event["scope"], "local")
self.assertEqual(event["kind"], "error")
self.assertTrue(window.monitoring)
self.assertFalse(window.strategy_toggle.isChecked())
finally:
window.close()