Files
lc-mcp/tests/test_lc_scene_aliases.py
T

111 lines
6.7 KiB
Python

import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
from lc_scene_aliases import normalize
import jev_mirror_agent as agent
from decision_router import DecisionRouter
class EnglishMirrorBoundaryTest(unittest.TestCase):
def test_map_header_without_recognized_floor_number_stops_battle(self):
for label in ('Exploring Floor', 'Exploring FloorT'):
with self.subTest(label=label):
state = normalize({'items': [{'text': label, 'x': 60, 'y': 131,
'w': 302, 'h': 51, 'score': .975}]})
self.assertTrue(agent.battle_is_terminal(state))
with mock.patch.object(agent, 'map_candidates', return_value={}):
self.assertNotIn('battle', agent.candidates(state, previous_battle=True))
def test_enabled_commence_precedes_reselecting_sinners(self):
options = {'button_20': {'description': '当前可见且非灰色按钮:进行判定',
'action': {'tool': 'keypress', 'args': {'key': 'enter'}}},
'sinner_1': {'description': '选择预计成功率高的罪人卡'},
'requires_analysis': {'description': '分析'}, 'wait': {'description': '等待'}}
self.assertEqual(agent.unambiguous_routine(options), 'button_20')
def test_video_clock_does_not_reset_failed_enter_detection(self):
def observation(clock, button='Proceed'):
return {'items': [{'text': text, 'score': 1} for text in (clock, button)]}
self.assertEqual(agent.scene_fingerprint(observation('00:00:42.48')),
agent.scene_fingerprint(observation('00:00:43:02')))
self.assertNotEqual(agent.scene_fingerprint(observation('00:00:43:02')),
agent.scene_fingerprint(observation('00:00:43:02', 'Commence')))
def test_commence_and_split_sinner_header_reach_judgement_boundary(self):
state = {'screen': {'w': 1920, 'h': 1080}, 'items': [
{'text': text, 'x': 1200, 'y': y, 'w': 200, 'h': 40, 'score': 1}
for text, y in [('Choose a character toperform', 445), ('Commence', 949)]]}
state = normalize(state)
self.assertTrue(agent.battle_is_terminal(state))
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(state)
self.assertTrue(any('进行判定' in option['description'] for option in options.values()))
judge = next(option for key, option in options.items() if key.startswith('button_')
and '进行判定' in option['description'])
self.assertEqual(judge['action']['tool'], 'keypress')
self.assertEqual(judge['fallback_action']['tool'], 'click')
def test_merged_english_probabilities_are_explicit_and_idempotent(self):
state = {'screen': {'w': 1920, 'h': 1080}, 'items': [
{'text': 'NormalVeryLowVeryHighVeryHigh', 'x': 906, 'y': 912,
'w': 400, 'h': 29, 'score': .946}]}
normalize(state)
labels = [item for item in state['items'] if item['text'] == '极高']
self.assertEqual(len(labels), 2)
self.assertTrue(all(1100 < item['x'] < 1300 for item in labels))
normalize(state)
self.assertEqual(len(state['items']), 3)
def test_english_outcome_lines_are_not_event_buttons(self):
state = {'screen': {'w': 1920, 'h': 1080}, 'items': [
{'text': text, 'x': 1096, 'y': y, 'w': 300, 'h': 31, 'score': 1}
for text, y in [('Choices', 168), ('Accept the surgery.', 295),
('RunaSloth&GloomAdvantagechecktogaina', 332),
('Keywordless E.G.O Gift.', 362),
('Break the light and run away.', 518)]]}
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(normalize(state))
descriptions = [value['description'] for key, value in options.items()
if key.startswith('event_') and key != 'event_scroll']
self.assertEqual(len(descriptions), 2)
self.assertTrue(any('Advantagecheck' in value for value in descriptions))
def test_empty_observation_is_not_a_normalization_error(self):
self.assertEqual(normalize({'items': None})['items'], [])
def test_route_request_keeps_observed_route_facts_and_omits_unrelated_setup(self):
options = {'route_d': {'description': '正前方有可达事件'},
'route_w': {'description': '上方有可达普通战斗'},
'wait': {'description': '等待'},
'requires_analysis': {'description': '需要分析'}}
with mock.patch.object(agent, 'request_answer', return_value={'choice': 'route_d'}) as request:
agent.decide({}, {'items': [{'text': 'irrelevant party text'}]}, options, [])
self.assertIn('正前方有可达事件', request.call_args.args[1])
self.assertNotIn('irrelevant party text', request.call_args.args[1])
self.assertNotIn('合成', request.call_args.args[3])
def test_sinner_request_only_offers_explicit_maximum_probability(self):
options = {'sinner_1': {'description': '选择预计成功率高的罪人卡'},
'sinner_2': {'description': '选择预计成功率极高的罪人卡'},
'sinner_card_3': {'description': '金黄色(高/极高)'},
'requires_analysis': {'description': '分析'}, 'wait': {'description': '等待'}}
with mock.patch.object(agent, 'request_answer', return_value={'choice': 'sinner_2'}) as request:
agent.decide({}, {}, options, [])
self.assertEqual(set(request.call_args.args[2]), {'sinner_2'})
def test_scoped_probability_distribution_passes_router_and_keeps_scope(self):
options = {'sinner_1': {'description': '选择预计成功率高的罪人卡'},
'sinner_2': {'description': '选择预计成功率极高的罪人卡'},
'requires_analysis': {'description': '分析'}, 'wait': {'description': '等待'}}
router = DecisionRouter({'model': 'test-model', 'apiKey': 'test-key'}, agent.decide)
response = {'choice': 'sinner_2', 'latency_ms': 1, 'probabilities': {'sinner_2': 1}}
with mock.patch.object(agent, 'request_answer', return_value=response):
decision = router.choose({}, options)
self.assertEqual(decision.choice, 'sinner_2')
self.assertEqual(decision.candidate_scope, ['sinner_2'])
self.assertEqual(decision.probabilities, {'sinner_1': 0, 'sinner_2': 1,
'requires_analysis': 0, 'wait': 0})