Refine ranch tree, growth sync and monitoring policies
This commit is contained in:
@@ -11,11 +11,9 @@ import uuid
|
||||
from unittest.mock import patch
|
||||
|
||||
import requests
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from ranch_assistant.api import ApiError, Client, DEFAULT_KEY, Session, decode, encode
|
||||
from ranch_assistant.engine import Engine, demo_snapshot
|
||||
from ranch_assistant.farming import FarmBudget, FarmConfig, FarmRunner, matches
|
||||
from ranch_assistant.model import Catalog, Planner, Policy, Snapshot
|
||||
|
||||
|
||||
@@ -144,63 +142,7 @@ class CoreTests(unittest.TestCase):
|
||||
self.assertEqual(post.call_count, 1)
|
||||
self.assertNotIn("private-token", str(raised.exception))
|
||||
|
||||
def test_budget_stamina_tickets_stale_and_persistent_daily_limit(self):
|
||||
snapshot = self.snapshot()
|
||||
config = FarmConfig(daily_limit=1)
|
||||
with workspace_temp() as folder:
|
||||
budget = FarmBudget(Path(folder) / "runs.json")
|
||||
self.assertTrue(budget.check(snapshot, config, self.catalog)[0])
|
||||
snapshot.raw["master"]["ti"] = 5
|
||||
self.assertFalse(budget.check(snapshot, config, self.catalog)[0])
|
||||
snapshot.raw["master"]["ti"] = 100
|
||||
snapshot.raw["items"] = []
|
||||
self.assertFalse(budget.check(snapshot, config, self.catalog)[0])
|
||||
snapshot = self.snapshot()
|
||||
snapshot.received_at -= 60
|
||||
self.assertFalse(budget.check(snapshot, config, self.catalog)[0])
|
||||
snapshot.received_at = time.time()
|
||||
budget.reserve(snapshot, config)
|
||||
restarted = FarmBudget(Path(folder) / "runs.json")
|
||||
self.assertFalse(restarted.check(snapshot, config, self.catalog)[0])
|
||||
|
||||
def test_farm_screen_gate_and_real_tap_sequence(self):
|
||||
with workspace_temp() as folder:
|
||||
folder = Path(folder)
|
||||
blank = Image.new("RGB", (200, 400), "black")
|
||||
ready, victory = blank.copy(), blank.copy()
|
||||
draw = ImageDraw.Draw(ready)
|
||||
draw.rectangle((10, 10, 99, 39), fill="green")
|
||||
draw.rectangle((20, 300, 99, 349), fill="red")
|
||||
ImageDraw.Draw(victory).rectangle((100, 200, 179, 249), fill="blue")
|
||||
boxes = {"stage": (10, 10, 100, 40), "entry": (20, 300, 100, 350), "victory": (100, 200, 180, 250)}
|
||||
templates = {}
|
||||
for name, box in boxes.items():
|
||||
(victory if name == "victory" else ready).crop(box).save(folder / f"{name}.png")
|
||||
templates[name] = {"screen": [200, 400], "box": box, "file": name + ".png", "stage_id": "bd00"}
|
||||
class FakeAdb:
|
||||
image = ready
|
||||
taps = []
|
||||
def foreground(self): return True
|
||||
def screenshot(self): return self.image
|
||||
def tap(self, x, y): self.taps.append((x, y))
|
||||
adb = FakeAdb()
|
||||
runner = FarmRunner(adb, self.catalog, folder)
|
||||
runner.config = FarmConfig(templates=templates)
|
||||
runner.start()
|
||||
bad = ready.copy()
|
||||
ImageDraw.Draw(bad).rectangle(boxes["stage"], fill="black")
|
||||
adb.image = bad
|
||||
runner.tick(self.snapshot())
|
||||
self.assertEqual(adb.taps, [])
|
||||
adb.image = ready
|
||||
with patch("ranch_assistant.farming.time.monotonic", return_value=10): runner.tick(self.snapshot())
|
||||
self.assertEqual(len(adb.taps), 1)
|
||||
adb.image = victory
|
||||
with patch("ranch_assistant.farming.time.monotonic", return_value=13): runner.tick(self.snapshot())
|
||||
adb.image = ready
|
||||
with patch("ranch_assistant.farming.time.monotonic", return_value=16): runner.tick(self.snapshot())
|
||||
self.assertEqual(runner.completed, 1)
|
||||
self.assertEqual(len(adb.taps), 2)
|
||||
|
||||
|
||||
class WireIntegrationTests(unittest.TestCase):
|
||||
@@ -242,7 +184,8 @@ class WireIntegrationTests(unittest.TestCase):
|
||||
engine = Engine(catalog, client)
|
||||
engine.policy = Policy(strategy="gold", protect_star=6, protect_quality=5, fill=False)
|
||||
engine.poll()
|
||||
self.assertFalse(any(p.endswith("stackCheckProcess") or p.endswith("monsterSell") for p, _ in calls))
|
||||
self.assertTrue(any(p.endswith("stackCheckProcess") for p, _ in calls))
|
||||
self.assertFalse(any(p.endswith("monsterSell") for p, _ in calls))
|
||||
engine.auto = True
|
||||
snapshot, _, _ = engine.poll()
|
||||
self.assertEqual(sum(p.endswith("monsterSell") for p, _ in calls), 1)
|
||||
|
||||
Reference in New Issue
Block a user