Streamline mirror confirmations and enforce updated rupture route

Browse Source
This commit is contained in:
Codex Agent
2026-10-02 21:21:31 +08:00
parent 6523f648fd
commit 97eca204c2
10 changed files with 772 additions and 38 deletions
+104 -2
View File
@@ -8,6 +8,95 @@ import jev_mirror_agent as agent
class SceneRegressionTest(unittest.TestCase): class SceneRegressionTest(unittest.TestCase):
def setUp(self):
stop = mock.patch.object(agent, 'STOP_FILE')
self.stop = stop.start()
self.stop.exists.return_value = False
self.addCleanup(stop.stop)
def test_takeover_interrupts_between_p_and_enter(self):
self.stop.exists.side_effect = [False,False,True]
bridge = mock.Mock()
bridge.call.return_value = {'ok':True}
result = agent.execute(bridge,{'tool':'battle','args':{}})
self.assertTrue(result['stopped'])
self.assertEqual(result['pairs'],0)
self.assertEqual(bridge.call.call_args_list,[mock.call('keypress',{'key':'p'})])
def test_takeover_stops_remaining_dialog_confirmations(self):
self.stop.exists.side_effect = [False,True]
bridge = mock.Mock()
bridge.call.return_value = {'ok':True}
with mock.patch.object(agent.time,'sleep'):
result=agent.execute(bridge,{'tool':'advance_dialog','args':{'presses':5}})
self.assertTrue(result['stopped'])
self.assertEqual(bridge.call.call_count,1)
@mock.patch.object(agent,'button_enabled',return_value=True)
def test_floor_pack_rules_are_enforced_before_decision(self,_enabled):
state={'floor':4,'screen':{'w':1920,'h':1080},'items':[
{'text':t,'x':x,'y':y,'w':100,'h':40} for t,x,y in
[('选择4层主题卡包',750,153),('2号线',276,665),('3号线',909,665),('刷新1/3',1570,49)]]}
options=agent.candidates(state)
self.assertNotIn('pack_drag_1',options)
self.assertIn('pack_drag_3',options)
state['floor']=5
state['items'][0]['text']='选择5层主题卡包'
options=agent.candidates(state)
self.assertEqual(set(options),{'wait','requires_analysis','required_pack'})
self.assertEqual(agent.fixed_fallback(options),'required_pack')
state['items'][1]['text']='1号线'
options=agent.candidates(state)
self.assertIn('pack_refresh',options)
self.assertFalse(any(k.startswith('pack_drag') for k in options))
state['items'][-1]['text']='刷新0/3'
self.assertNotIn('pack_refresh',agent.candidates(state))
@mock.patch.object(agent,'button_enabled',return_value=True)
def test_thunderbranch_observation_exception_keeps_startup_battery_priority(self,_enabled):
state={'items':[{'text':t,'x':700,'y':500,'w':150,'h':40} for t in
('额外E.G.O饰品观测','可选择0/1','雷枝','拒绝饰品','确认')]}
options=agent.candidates(state)
self.assertIn('select_thunderbranch',options)
self.assertNotIn('decline_extra_observation',options)
state['items'].append({'text':'标准负载电池','x':900,'y':500,'w':150,'h':40})
options=agent.candidates(state)
self.assertIn('select_startup_battery',options)
self.assertNotIn('select_thunderbranch',options)
state['items']=state['items'][:-1]
state['items'][0]['text']='选择E.G.O饰品'
self.assertNotIn('select_thunderbranch',agent.candidates(state))
def test_ambiguous_event_is_not_assumed_free(self):
options={'event_1':{'description':'当前事件选项:拔出荧光灯;结果:'},
'event_scroll':{},'wait':{},'requires_analysis':{}}
self.assertEqual(agent.fixed_fallback(options),'event_scroll')
options['event_2']={'description':'当前事件选项:按下按钮;结果:选择后获得破裂饰品'}
self.assertEqual(agent.fixed_fallback(options),'event_2')
def test_sinner_very_high_precedes_high_and_generic_gold(self):
options={'sinner_1':{'description':'预计成功率高'},
'sinner_2':{'description':'预计成功率极高'},
'sinner_card_0':{'description':'金黄色(高/极高)'}}
self.assertEqual(agent.fixed_fallback(options),'sinner_2')
@mock.patch.object(agent,'button_enabled',return_value=True)
def test_pending_thunderbranch_cannot_leave_shop(self,_enabled):
state={'symbol_upgraded':True,'floor':3,'thunderbranch_pending':True,'items':[
{'text':t,'x':100,'y':100,'w':100,'h':40} for t in
('商店','刷新','强化饰品','离开')]}
options=agent.candidates(state,refresh_used=4)
self.assertEqual(set(options),{'wait','requires_analysis','prepare_thunderbranch'})
self.assertEqual(agent.fixed_fallback(options),'prepare_thunderbranch')
def test_jev_rate_limit_fails_without_sleep_or_second_request(self):
error=agent.urllib.error.HTTPError('https://example.test',429,'rate limit',{},None)
with mock.patch.object(agent.urllib.request,'urlopen',side_effect=error) as request, mock.patch.object(agent.time,'sleep') as sleep:
with self.assertRaises(agent.urllib.error.HTTPError):
agent.decide({'apiKey':'test'}, {'items':[]},{'wait':{'description':'wait'}},[])
self.assertEqual(request.call_count,1)
sleep.assert_not_called()
def test_single_extra_gift_decline_preserves_core_and_multi_cards(self): def test_single_extra_gift_decline_preserves_core_and_multi_cards(self):
state = {'items': [{'text':t,'x':100,'y':100,'w':100,'h':40} for t in state = {'items': [{'text':t,'x':100,'y':100,'w':100,'h':40} for t in
('获得E.G.O饰品','石版字符','拒绝饰品','选择')]} ('获得E.G.O饰品','石版字符','拒绝饰品','选择')]}
@@ -294,6 +383,8 @@ class SceneRegressionTest(unittest.TestCase):
('是在感谢我们吗?',112,707)]]} ('是在感谢我们吗?',112,707)]]}
options = agent.candidates(state) options = agent.candidates(state)
self.assertEqual(options['event_finish']['action'], self.assertEqual(options['event_finish']['action'],
{'tool':'advance_dialog','args':{'presses':5}})
self.assertEqual(options['event_finish']['fallback_action'],
{'tool':'click','args':{'x':1679,'y':956}}) {'tool':'click','args':{'x':1679,'y':956}})
def test_loading_offers_wait_and_never_auto_escalates(self): def test_loading_offers_wait_and_never_auto_escalates(self):
@@ -313,8 +404,19 @@ class SceneRegressionTest(unittest.TestCase):
def test_event_encounter_result_clicks_start_battle(self, _enabled): def test_event_encounter_result_clicks_start_battle(self, _enabled):
state = {'items': [{'text': t, 'x': x, 'y': y, 'w': 100, 'h': 40} state = {'items': [{'text': t, 'x': x, 'y': y, 'w': 100, 'h': 40}
for t,x,y in [('结果',1088,162), ('开始战斗',1594,943)]]} for t,x,y in [('结果',1088,162), ('开始战斗',1594,943)]]}
self.assertEqual(agent.candidates(state)['event_finish']['action'], options=agent.candidates(state)
{'tool':'click','args':{'x':1644,'y':963}}) self.assertEqual(options['event_finish']['action'],{'tool':'advance_dialog','args':{'presses':5}})
self.assertEqual(options['event_finish']['fallback_action'],{'tool':'click','args':{'x':1644,'y':963}})
@mock.patch.object(agent,'button_enabled',return_value=True)
def test_layer_confirmation_requires_full_selection_then_batches_enter(self,_enabled):
state={'items':[{'text':t,'x':1500,'y':900,'w':200,'h':40} for t in
('追加的苦难','获得E.G.O饰品','选择1/2')]}
self.assertNotIn('hardship_confirm',agent.candidates(state))
state['items'][-1]['text']='选择2/2'
options=agent.candidates(state)
self.assertEqual(options['hardship_confirm']['action'],{'tool':'advance_dialog','args':{'presses':3}})
self.assertEqual(options['hardship_confirm']['fallback_action']['args'],{'x':1600,'y':920})
@mock.patch.object(agent, 'button_enabled', return_value=True) @mock.patch.object(agent, 'button_enabled', return_value=True)
def test_shop_loading_blocks_stale_stock_refresh_and_leave(self, _enabled): def test_shop_loading_blocks_stale_stock_refresh_and_leave(self, _enabled):