fix: keep automatic cultivation on one stable primary per species

This commit is contained in:
AttilaNet
2026-11-13 08:51:03 +08:00
parent 01ad2e3ab9
commit 4fbe895999
35 changed files with 2069 additions and 322 deletions
+7 -4
View File
@@ -659,17 +659,20 @@ class ServiceTests(unittest.TestCase):
worker.schedule.clock = lambda: clock[0]
worker.engine.last_heartbeat = clock[0]
monsters = list(worker.engine.snapshot.monsters)
# Use the primary so the request reaches the uncertainty barrier.
species = str(worker.engine.snapshot.monsters[monsters[0]]["typeId"])
recipient = int(worker.engine.cultivation.select(worker.engine.snapshot)[species]["id"])
if kind == "gift":
# Engine overlays confirmed gift timestamps in seconds,
# while an unchanged raw server snapshot uses milliseconds.
mon = next(row for row in worker.engine.client.raw["monsters"] if row["id"] == monsters[0])
mon = next(row for row in worker.engine.client.raw["monsters"] if row["id"] == recipient)
mon["giftTime"] = 1_700_000_000_000
worker.engine.gift_planner.confirmed[monsters[0]] = {
worker.engine.gift_planner.confirmed[recipient] = {
"owner": str(worker.engine.snapshot.raw["master"]["id"]),
"type": str(mon["typeId"]), "feel": int(mon.get("feel") or 0),
"giftTime": 1_700_000_060}
action = Action(kind, "Unconfirmed gift", "monsterService/monsterSendGift",
{"monsterId": monsters[0], "itemId": 1})
{"monsterId": recipient, "itemId": 1})
elif kind == "hatch":
slot = worker.engine.client.raw["stacks"][0]
slot["monsterId"] = -1
@@ -678,7 +681,7 @@ class ServiceTests(unittest.TestCase):
worker.engine.pending_hatches = [action]
else:
action = Action(kind, "Unconfirmed feed", "monsterService/monsterIntensify",
{"targetId": monsters[0], "foods": [monsters[1]]})
{"targetId": recipient, "foods": [monsters[1]]})
before = len(FakeClient.calls)
with patch.object(worker.engine, "plans", return_value=[action]):
if kind == "hatch":
+23 -2
View File
@@ -165,17 +165,38 @@ class TaskLogTests(unittest.TestCase):
market = next(key for key, row in engine.catalog.data["markets"].items() if row.get("money", 0) > 0)
engine.policy.daily_buy_money = 1000000
engine.planner.notes = []
primary = next(iter(engine.cultivation.select(engine.snapshot).values()))
food = next(mon for mon in engine.snapshot.monsters.values()
if mon.get("process") == 3 and mon.get("typeId") == primary["typeId"]
and int(mon["id"]) != int(primary["id"]) and not mon.get("lock") and not mon.get("sysLock"))
original_post = engine.client.http.post
def consume_feed(url, data, **kwargs):
if url.endswith("monsterService/monsterIntensify"):
payload = fixtures.decode(data, engine.client.session.key)
foods = {int(mid) for mid in payload["foods"]}
engine.client.raw["monsters"] = [mon for mon in engine.client.raw["monsters"] if int(mon["id"]) not in foods]
return original_post(url, data, **kwargs)
actions = [
Action("buy", "莉莉托斯市场十连抽蛋 ×10,花费100金币", "gachaService/gachaGetEggs", {"id": market, "num": 1}),
Action("sell", "派遣 测试魔物 #1", "monsterService/monsterSell", {"monsterIds": [1]}),
Action("feed", "喂养 测试魔物 ← 素材", "monsterService/monsterIntensify", {"targetId": 1, "foods": []}),
Action("feed", "喂养 测试魔物 ← 素材", "monsterService/monsterIntensify",
{"targetId": int(primary["id"]), "foods": [int(food["id"])]}),
]
for action in actions:
with self.subTest(kind=action.kind):
worker._running = True
after = self.manager.logs(identifier, debug=True)["next"]
with patch.object(engine, "plans", return_value=[action]):
calls_before = len(fixtures.FakeClient.calls)
with patch.object(engine, "plans", return_value=[action]), \
patch.object(engine.client.http, "post", side_effect=consume_feed):
self.tick(identifier, "poll")
if action.kind == "feed":
self.assertEqual([{key: payload[key] for key in action.payload}
for _, url, payload in fixtures.FakeClient.calls[calls_before:]
if url.endswith(action.path)], [action.payload])
self.assertNotIn(int(food["id"]), engine.snapshot.monsters)
entries = self.entries(identifier, after, debug=True)
result = [row for row in entries if not row["debug"]]
self.assertEqual({row["category"] for row in result}, {"hatching"})
+7 -3
View File
@@ -82,6 +82,7 @@ import ranch_web.policies,ranch_web.views,ranch_web.actions
fields = [field for page in value["pages"] for field in page["form"]]
self.assertTrue(all(field["label"] and isinstance(field["path"], list) for field in fields))
self.assertNotIn(["policy", "feed_target"], [field["path"] for field in fields])
self.assertNotIn(["policy", "keep_better_quality"], [field["path"] for field in fields])
self.assertNotIn(["progression_policy", "battle_mode"], [field["path"] for field in fields])
self.assertEqual(dict(PAGES)["statistics"], "数据分析")
self.assertEqual(dict(PAGES)["plans"], "执行计划")
@@ -114,16 +115,19 @@ import ranch_web.policies,ranch_web.views,ranch_web.actions
if code == 5:
self.assertTrue(row["edits"]["enabled"]["disabled"])
def test_egg_keep_count_and_missing_stock_rule_bind_real_config(self):
def test_fixed_retention_display_preserves_legacy_count_and_missing_stock_rule(self):
config = deepcopy(self.worker.config)
config["policy"]["egg_rules"]["1001010"] = {"enabled": True, "keep_count": 5, "priority": 1, "market_id": "sc_city1"}
self.worker.save_config(config)
dto = self.view("bag", {"category": "eggs"})
row = next(row for row in dto["rows"] if row["id"] == "1001010")
column = next(column for column in dto["columns"] if column["key"] == "keep_count")
column = next(column for column in dto["columns"] if column["key"] == "retention_text")
self.assertEqual(column["label"], "牧场保留")
self.assertEqual(row["keep_count"], 5)
self.assertEqual(column["edit"]["path"], ["policy", "egg_rules", "{id}", "keep_count"])
self.assertEqual(row["retention_text"], "主培养1 + 更优备选≤1")
self.assertNotIn("edit", column)
self.assertNotIn("keep_count", [column["key"] for column in dto["columns"]])
self.assertEqual(self.worker.config["policy"]["egg_rules"]["1001010"]["keep_count"], 5)
self.assertTrue(row["edits"]["market_id"]["options"])
def test_add_rule_species_defaults_follow_current_market_and_desktop_fallback(self):