Files
lc-mcp/tests/test_lc_scene_aliases.py
Codex Agent 0ddd8650b7 镜牢决策补强: 确认重试回退、快感合成闸门与英文 OCR 别名
- aalc_engine: window_move 下按压保持 0.5s, 避免 Unity 漏点
- jev_mirror_agent: 技能描述抖动时 Enter 未推进改点已核对按钮并限制连续重试;
  结果页指纹忽略剧情与时钟变化; 追加的苦难不再误判为单个饰品场景;
  第 3 层起离开商店前强制做一次有界快感合成检查
- lc_scene_aliases: 补 Mounting Trials / Acquire E.G.O Gift 等标签,
  识别拆分的 Win/Bate 胜率按钮与 Max HP / Defense Level 文本
- tests: 覆盖上述回归点
2026-10-22 15:44:02 +08:00

199 lines
12 KiB
Python

import sys
import unittest
import tempfile
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_server_error_only_offers_retry_above_background_reward_cards(self):
state = {'items': [
{'text': text, 'x': 1000, 'y': 500, 'w': 120, 'h': 35, 'score': 1}
for text in ['Select Encounter Reward Card', 'A servererror hasoccurred.',
'Retry 4', 'Close', 'Gain55~83Cost', 'Confirm']]}
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(normalize(state))
self.assertEqual(set(options), {'wait', 'requires_analysis', 'retry_network'})
def test_purchased_badge_blocks_reopening_even_when_ocr_omits_it(self):
from PIL import Image
item = {'text': '替换奥提斯的技能', 'x': 838, 'y': 496, 'w': 196, 'h': 30}
with tempfile.TemporaryDirectory() as folder:
canvas = Image.new('L', (1920, 1080))
with Image.open(agent.REPO_ROOT / 'assets/ui/purchased_english.png') as badge:
canvas.paste(badge.convert('L'), (874, 330))
bought = str(Path(folder) / 'bought.png')
blank = str(Path(folder) / 'blank.png')
canvas.save(bought)
Image.new('L', (1920, 1080)).save(blank)
self.assertTrue(agent.purchased_slot({'screen': {'path': bought, 'w': 1920, 'h': 1080}}, item))
self.assertFalse(agent.purchased_slot({'screen': {'path': blank, 'w': 1920, 'h': 1080}}, item))
def test_english_skill_payment_confirm_requires_validated_skill_pair(self):
state = {'floor': 1, 'screen': {'w': 1920, 'h': 1080}, 'items': [
{'text': text, 'x': x, 'y': y, 'w': 100, 'h': 35, 'score': 1}
for text, x, y in [("Replace Outis's Skill", 382, 179),
('SKILL2', 781, 318), ('SKILL3', 1532, 319),
('Spend 75 Cost to replace this Skill?', 728, 734),
('Confirm', 1161, 796), ('Cancel', 732, 793)]]}
with mock.patch.object(agent, 'button_enabled', return_value=True):
self.assertIn('buy_swap', agent.candidates(normalize(state)))
state['items'][1]['text'] = 'SKILL1'
self.assertNotIn('buy_swap', agent.candidates(state))
def test_split_enhance_menu_and_truncated_skill_shop_label_are_recognized(self):
state = {'items': [
{'text': text, 'x': x, 'y': y, 'w': 100, 'h': 30, 'score': 1}
for text, x, y in [('Enhance', 222, 564), ('Gifts', 238, 587),
("Replace Outis's Skil", 838, 496)]]}
labels = [item['text'] for item in normalize(state)['items']]
self.assertIn('强化饰品', labels)
self.assertTrue(any('技能替换' in label and '奥提斯' in label for label in labels))
def test_stock_refresh_does_not_use_keyword_refresh(self):
state = {'floor': 1, 'symbol_upgraded': True, 'items': [
{'text': text, 'x': x, 'y': 167, 'w': 89, 'h': 31, 'score': 1}
for text, x in [('商店', 337), ('刷新', 1478), ('刷新', 1694), ('离开', 1626)]]}
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(state)
self.assertEqual(options['shop_refresh']['action']['args']['x'], 1522)
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_result_story_ocr_changes_do_not_reset_continue_fallback(self):
def observation(story, clock, button='Continue'):
return normalize({'items': [{'text': text, 'score': score} for text, score in
[('Result', .99), (button, .99), (story, .95), (clock, .98)]]})
first = observation('You lookaway and continue on your path.', '00:00:10:02')
second = observation('You look away and continue on your path.', '00:00:10:16')
self.assertEqual(agent.scene_fingerprint(first), agent.scene_fingerprint(second))
self.assertNotEqual(agent.scene_fingerprint(first),
agent.scene_fingerprint(observation('same', '00:00:10:16', 'Battle!')))
def test_english_layer_cards_are_not_single_gift_observation(self):
state = {'screen': {'w': 1278, 'h': 731}, 'items': [
{'text': text, 'x': x, 'y': y, 'w': 90, 'h': 25, 'score': .99}
for text, x, y in [('Acquire E.G.O Gift', 250, 159), ('Mounting Trials', 250, 425),
('DefenseLevel +1, MaxHP+7.5%', 250, 491),
('Select', 1080, 572), ('0/2', 1160, 569), ('Refuse Gift', 900, 572)]]}
normalize(state)
self.assertIn('防御等级 +1, 体力上限+7.5%', [item['text'] for item in state['items']])
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(state)
self.assertTrue(any(key.startswith('hardship_') for key in options))
self.assertNotIn('decline_extra_observation', options)
self.assertNotIn('hardship_confirm', options)
state['items'][-2]['text'] = '选择2/2'
with mock.patch.object(agent, 'button_enabled', return_value=True):
options = agent.candidates(state)
self.assertEqual(set(options), {'requires_analysis', 'wait', 'hardship_confirm'})
def test_split_win_rate_button_starts_battle_loop_without_wave_label(self):
state = normalize({'screen': {'w': 1278, 'h': 731}, 'items': [
{'text': text, 'x': 993, 'y': y, 'w': 30, 'h': 16, 'score': .97}
for text, y in [('Win', 542), ('Bate', 554)]]})
self.assertTrue(agent.battle_is_visible(state))
self.assertIn('battle', agent.candidates(state))
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})