This website requires JavaScript.
0
Issues
Pull Requests
Milestones
Explore
0
Create…
New Repository
New Migration
New Organization
public
Signed in as
public
Profile
Starred
Subscriptions
Settings
Help
Sign Out
yws
/
lc-mcp
Watch
1
Star
0
Fork
0
Code
Issues
Pull Requests
Actions
Packages
Projects
Releases
Wiki
Activity
Files
lc-mcp
/
tests
/
or
Cancel
Edit File
Preview
Preview Changes
Spaces
Tabs
2
4
8
Wrap
No wrap
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_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})
Commit Changes
Add a Signed-off-by trailer by the committer at the end of the commit log message.
Commit directly to the
main
branch.
Create a
new branch
for this commit and start a pull request.
Commit Changes
Cancel