116 lines
5.3 KiB
Python
116 lines
5.3 KiB
Python
"""Independent, offline admission checks for pickaxe resource stages."""
|
|
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
|
|
from ranch_assistant.battle_runtime import BattleRuntime, NATIVE_ADMISSION_ENABLED
|
|
from ranch_assistant.battle_simulator import ExperimentalBattleRuntime
|
|
from ranch_assistant.battles import BattleOrchestrator
|
|
from ranch_assistant.game_data import ProgressionData
|
|
from ranch_assistant.maps import stages
|
|
from ranch_assistant.model import Catalog, Snapshot
|
|
from ranch_assistant.sweeping import SweepRunner
|
|
from tools.battle_runtime.inputs import MON_FIELDS
|
|
|
|
|
|
MINES = ("m101", "m113", "m125")
|
|
|
|
|
|
def original_roster():
|
|
"""A complete synthetic level-one roster, never an account snapshot."""
|
|
monster = dict.fromkeys(MON_FIELDS, 0)
|
|
monster.update(id=1000001, typeId=1001010, level=1, mode=2,
|
|
process=3, potentialLevel=1, nicName="")
|
|
history = dict.fromkeys(("numAddMoney", "numChicken", "countBattle"), 0)
|
|
history.update(dict.fromkeys(("monLib", "equipLib", "passAchi",
|
|
"guide_record", "unlockCity"), []))
|
|
history.update(dict.fromkeys((
|
|
"numFeedMonsters", "numKillMonsters", "historyGacha", "passTask",
|
|
"unlockTask", "loopTask", "unlockStage", "passStage",
|
|
"payTypeCount", "everyDayBuyProductNum"), {}))
|
|
history["guide_main"] = ""
|
|
return {
|
|
"master": {"id": 1, "level": 1, "globalAtk": 0,
|
|
"globalDef": 0, "globalHp": 0, "globalDex": 0},
|
|
"monsters": [monster], "monsterAttributes": [], "items": [],
|
|
"teams": [{"teamName": "teamB", "teamType": "battleTeam",
|
|
"monsters": [1000001, 0]}],
|
|
"history": history,
|
|
}
|
|
|
|
|
|
class ResourceRuntimeAdmissionTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.data = ProgressionData()
|
|
source = cls.data.manifest["source"]
|
|
cls.identity = {"apk_sha256": source["apk_sha256"],
|
|
"main_swf_sha256": source["main_swf_sha256"]}
|
|
|
|
def request(self, stage_id, purpose="offline_validation"):
|
|
return {
|
|
"context": "ordinary_stage", "stage_id": stage_id, "difficulty": 1,
|
|
"purpose": purpose, "roster": original_roster(), "team": "teamB",
|
|
"original_data": {"source": "original_apk",
|
|
"resource_identity": self.identity,
|
|
"battle": self.data.stage_battle(stage_id)},
|
|
"battle_position": {"battleType": "stage", "stageId": stage_id,
|
|
"stageLevel": "1", "taskTypeId": None, "taskStep": 0},
|
|
}
|
|
|
|
def test_original_inspection_supports_mining_without_grant_settlement(self):
|
|
for stage_id in MINES:
|
|
with self.subTest(stage=stage_id):
|
|
report = BattleRuntime().inspect(self.request(stage_id))
|
|
self.assertEqual(report["reasons"], [], report)
|
|
self.assertTrue(report["supported"], report)
|
|
self.assertTrue(report["faithful"], report)
|
|
self.assertFalse(report["settlement_eligible"], report)
|
|
|
|
def test_original_online_admission_still_requires_completed_qa(self):
|
|
orchestrator = BattleOrchestrator(None, None, BattleRuntime())
|
|
for stage_id in MINES:
|
|
with self.subTest(stage=stage_id):
|
|
request = self.request(stage_id, "settlement")
|
|
report = BattleRuntime().inspect(request)
|
|
self.assertEqual(report["settlement_eligible"], NATIVE_ADMISSION_ENABLED)
|
|
self.assertEqual(report["native_admission_validation_pending"],
|
|
not NATIVE_ADMISSION_ENABLED)
|
|
supported, reason = orchestrator.inspect({
|
|
"runtime_request": request, "battle_mode": "original"})
|
|
self.assertEqual(supported, NATIVE_ADMISSION_ENABLED, reason)
|
|
|
|
def test_experimental_model_admits_mining_without_claiming_fidelity(self):
|
|
for stage_id in MINES:
|
|
with self.subTest(stage=stage_id):
|
|
report = ExperimentalBattleRuntime().inspect(self.request(stage_id))
|
|
self.assertTrue(report["supported"], report)
|
|
self.assertTrue(report["approximate"], report)
|
|
self.assertFalse(report["faithful"], report)
|
|
self.assertFalse(report["settlement_eligible"], report)
|
|
self.assertFalse(report["experimental_settlement_eligible"], report)
|
|
|
|
|
|
class ResourceSweepBoundaryTests(unittest.TestCase):
|
|
def test_special_resource_stages_cannot_use_empty_data_sweep(self):
|
|
catalog = Catalog()
|
|
snapshot = Snapshot({
|
|
"master": {"id": 1, "ti": 1000, "money": 0},
|
|
"history": {"unlockStage": {key: [1] for key in MINES}},
|
|
"teams": [{"teamName": "teamB", "teamType": "battleTeam",
|
|
"monsters": [1000001]}],
|
|
"monsters": [{"id": 1000001}], "items": [], "currentTasks": [],
|
|
"stacks": [], "rooms": [],
|
|
})
|
|
policy = SimpleNamespace(enabled=True, team="teamB", keep_stamina=0)
|
|
for stage in stages(catalog, snapshot):
|
|
if stage.stage_id not in MINES:
|
|
continue
|
|
with self.subTest(stage=stage.stage_id):
|
|
self.assertFalse(stage.sweep)
|
|
self.assertTrue(SweepRunner(catalog).reason(snapshot, stage, policy))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|