2026-10-13 18:00 那轮升级报"前 6 个候选都不需要升级或无法读取", 逐层复盘出三个缺陷, 它们互相叠加, 单看每一个都不像问题: 1. 满级人格被误判成"长按没打开详情" (scripts/levelup.py) 详情页判定写的是 'Level Up' not in txt, 但满级(Lv.40)时那个按钮显示的是 MAX。 实测 Zwei 满级后长按成功, 却因画面里没有 'Level Up' 被判失败跳过。 抽成 detail_page_open(): Level Up / Uptie / Summary+Sanity 任一即可。 顺带统一了 cmd_progress 与 cmd_card 两处不一致的判定。 2. 满级时进度条反推等级偏低 6 级 (scripts/levelup.py) 满级后进度条分母是"下一级"的需求, 而等级已封顶: Zwei 是 LV40/MAX、 进度条 0/6075, 而 6075 在表里对应 Lv.35, 反推成 34。 改为满级时以直读的 LV 为准(取最大值, 避开技能等级)。 3. Uptie 弹窗关不掉, 一直挡着后续所有输入 (scripts/levelup.py, lc_ui.py) Tier IV 弹窗多了 Shard::Thread Exchange 一排, Cancel 实际在 (380,675), 而代码写死 (526,660) —— 落在 Cancel 与 Use Egoshard Crate 之间的空白, 点下去毫无反应。弹窗是模态的, 之后每一次长按都被它吞掉, 于是六张卡全跳过。 加 lc_ui.click_text(): 按文本找元素并点识别框**中心**。 实测 OCR 返回的 (x,y) 是文本框左上角, 直接点常常落空(346,660 无效, 380,675 才中)。 再加 levelup.dismiss_modal(): 每次长按前先清残留弹窗, 比事后补救可靠。 实测结果(N Corp 与 LCB Sinner 各自 33->40): 详情页: Zwei 真实等级=40 已达目标, 跳过 (修复前报"长按未打开详情") 详情页: N Corp 真实等级=33 升级: OK 33->40 (弹窗未关也按详情页判定) 新增测试 6 个(detail_page_open 4 个 + 满级读取 2 个), 全套 223/223 通过。
209 lines
8.2 KiB
Python
209 lines
8.2 KiB
Python
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
|
|
import lc_ui # noqa: E402
|
|
import levelup # noqa: E402
|
|
|
|
|
|
def shot(w, h, items=()):
|
|
return {'ok': True, 'screen': {'path': 'x.png', 'w': w, 'h': h},
|
|
'items': [dict(i) for i in items]}
|
|
|
|
|
|
class ScaleTest(unittest.TestCase):
|
|
"""脚本坐标按 1600x900 写, 实际客户区可能是 1280x720 或 1920x1080。"""
|
|
|
|
def setUp(self):
|
|
lc_ui._scale = None
|
|
|
|
def test_720p_items_and_clicks_use_base_coordinates(self):
|
|
calls = []
|
|
|
|
def probe(tool, args=None, quiet=True):
|
|
calls.append((tool, args))
|
|
return shot(1280, 720, [{'text': 'Level Up', 'x': 800, 'y': 400, 'w': 80, 'h': 20}])
|
|
|
|
with mock.patch.object(lc_ui, 'probe', probe):
|
|
item = lc_ui.items()[0]
|
|
lc_ui.click(1600, 900)
|
|
lc_ui.long_press(800, 450)
|
|
self.assertEqual((item['x'], item['y'], item['w']), (1000, 500, 100))
|
|
self.assertEqual(calls[1], ('click', {'x': 1280, 'y': 720, 'times': 1}))
|
|
self.assertEqual(calls[2], ('drag', {'from_x': 640, 'from_y': 360, 'to_x': 640, 'to_y': 360}))
|
|
|
|
def test_click_before_any_state_reads_client_size_first(self):
|
|
calls = []
|
|
|
|
def probe(tool, args=None, quiet=True):
|
|
calls.append((tool, args))
|
|
return shot(1920, 1080)
|
|
|
|
with mock.patch.object(lc_ui, 'probe', probe):
|
|
lc_ui.click(100, 100)
|
|
self.assertEqual(calls, [('get_state', None), ('click', {'x': 120, 'y': 120, 'times': 1})])
|
|
|
|
|
|
class Screens:
|
|
"""按顺序返回预设画面的假 state(), 记录点击。"""
|
|
|
|
def __init__(self, *screens):
|
|
self.screens = list(screens)
|
|
self.clicks = []
|
|
self.keys = []
|
|
|
|
def state(self):
|
|
texts = self.screens.pop(0) if len(self.screens) > 1 else self.screens[0]
|
|
return {'items': [{'text': t, 'x': x, 'y': y} for t, x, y in texts]}
|
|
|
|
def patch(self):
|
|
return mock.patch.multiple(levelup, state=self.state, time=mock.Mock(),
|
|
click=lambda *a, **k: self.clicks.append(a),
|
|
keypress=lambda k: self.keys.append(k))
|
|
|
|
|
|
DETAIL = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('547/885', 400, 250)]
|
|
POWERUP = [('Owned:3', 900, 380), ('Owned:0', 900, 485), ('Owned:7', 900, 595), ('Cancel', 603, 670)]
|
|
|
|
|
|
class LevelUpVerdictTest(unittest.TestCase):
|
|
|
|
def test_detail_page_without_exp_change_is_not_success(self):
|
|
# 旧逻辑只要回到详情页(有 Level Up / Uptie)就算成功
|
|
screens = Screens(DETAIL, POWERUP, POWERUP, DETAIL, DETAIL)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_level_up(hint=17)
|
|
self.assertFalse(ok, desc)
|
|
|
|
def test_level_increase_is_success(self):
|
|
after = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('100/1261', 400, 250)]
|
|
screens = Screens(DETAIL, POWERUP, POWERUP, after, after)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_level_up(hint=17)
|
|
self.assertTrue(ok, desc)
|
|
self.assertIn('17->19', desc)
|
|
|
|
def test_popup_still_open_after_confirm_is_cancelled(self):
|
|
screens = Screens(DETAIL, POWERUP, POWERUP, POWERUP)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_level_up(hint=17)
|
|
self.assertFalse(ok)
|
|
self.assertEqual(screens.clicks[-1], levelup.POWERUP_CANCEL)
|
|
|
|
def test_popup_still_open_but_level_rose_is_still_success(self):
|
|
"""2026-10-13 实机: Zwei Lv.33 -> Lv.40(MAX), 券也扣了, 但 Confirm 后弹窗仍在。
|
|
|
|
旧逻辑据此直接判 FAIL, 是假阴性。详情页的等级才是事实来源。
|
|
"""
|
|
after = [('Level Up', 1164, 235), ('Uptie', 1367, 235), ('0/6075', 400, 250)]
|
|
# 注意 state() 的消耗次数: 详情页 x1, 弹窗打开 x1, ticket_balance() x1,
|
|
# 点完 MAX 再读 x1, Confirm 之后再读 x1 —— 所以弹窗要连给 4 次。
|
|
screens = Screens(DETAIL, POWERUP, POWERUP, POWERUP, POWERUP, after, after)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_level_up(hint=33)
|
|
self.assertTrue(ok, desc)
|
|
# 等级必须是从详情页读出来的(547/885 -> 17, 0/6075 -> 34), 不是从弹窗猜的
|
|
self.assertIn('17->34', desc)
|
|
# 仍然要把残留弹窗关掉, 不能把它留给下一步
|
|
self.assertIn(levelup.POWERUP_CANCEL, screens.clicks)
|
|
|
|
|
|
UPTIE_POPUP = [('Currency Req.', 700, 300), ('Skills Gained', 700, 400),
|
|
('Owned:2', 900, 450), ('Uptie', 1085, 580)]
|
|
|
|
|
|
class UptieVerdictTest(unittest.TestCase):
|
|
|
|
def test_popup_still_open_is_failure_even_with_skills_gained(self):
|
|
screens = Screens(UPTIE_POPUP, UPTIE_POPUP)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_uptie()
|
|
self.assertFalse(ok, desc)
|
|
self.assertEqual(screens.keys, [])
|
|
|
|
def test_success_dialog_is_confirmed_without_esc(self):
|
|
done = [('Uptied!', 700, 300), ('Confirm', 772, 661)]
|
|
screens = Screens(UPTIE_POPUP, done, done)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_uptie()
|
|
self.assertTrue(ok, desc)
|
|
self.assertEqual(screens.keys, [])
|
|
self.assertEqual(screens.clicks[-1], levelup.UPTIE_DONE_CONFIRM)
|
|
|
|
def test_unknown_screen_presses_esc_once_and_never_clicks_blind(self):
|
|
story = [("I swear to you! I will return this favor", 500, 700)]
|
|
screens = Screens(UPTIE_POPUP, story, story, story)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_uptie()
|
|
self.assertFalse(ok)
|
|
self.assertEqual(screens.keys, ['esc'])
|
|
self.assertNotIn(levelup.UPTIE_CANCEL, screens.clicks)
|
|
|
|
def test_cutscene_skip_prompt_counts_as_success(self):
|
|
story = [("I swear to you!", 500, 700)]
|
|
skip = [('Skip this story?', 700, 400), ('Confirm', 900, 600)]
|
|
screens = Screens(UPTIE_POPUP, story, story, skip, skip)
|
|
with screens.patch():
|
|
ok, desc = levelup.do_uptie()
|
|
self.assertTrue(ok, desc)
|
|
self.assertEqual(screens.clicks[-1], (900, 600))
|
|
|
|
|
|
class DetailPageDetectTest(unittest.TestCase):
|
|
"""详情页判定。
|
|
|
|
2026-10-13 实机: Zwei 满级后详情页上的按钮是 MAX 而不是 Level Up,
|
|
代码却用 'Level Up' not in txt 判断"长按有没有打开详情", 于是把成功的
|
|
长按判成失败, 六张卡全部跳过, 升级环节空跑还报"无需升级"。
|
|
"""
|
|
|
|
def test_normal_detail_page(self):
|
|
self.assertTrue(levelup.detail_page_open('Level Up | Uptie | 547/885'))
|
|
|
|
def test_maxed_identity_without_level_up_label(self):
|
|
# 满级: 有 MAX 和 Uptie, 但没有 'Level Up'
|
|
t = 'Zwei Assoc. South Section 6 | LV40 | 0/6075 | MAX | Uptie++ | Summary | Sanity'
|
|
self.assertTrue(levelup.detail_page_open(t))
|
|
|
|
def test_sections_only(self):
|
|
self.assertTrue(levelup.detail_page_open('Summary | Skill | E.G.O | Sanity'))
|
|
|
|
def test_grid_is_not_detail_page(self):
|
|
t = 'TEAMS#1 | IDENTITIES | E.G.O | Facades | Details | ALL | SELECTED'
|
|
self.assertFalse(levelup.detail_page_open(t))
|
|
|
|
|
|
class MaxLevelReadTest(unittest.TestCase):
|
|
"""满级时进度条反推会偏低, 要以直读为准。
|
|
|
|
实测 Zwei LV40/MAX 的进度条是 0/6075, 而 6075 在表里对应 Lv.35,
|
|
反推成 34 —— 比真实等级低了 6 级。
|
|
"""
|
|
|
|
def _read(self, items):
|
|
screens = Screens([(i['text'], i['x'], i['y']) for i in items])
|
|
with screens.patch():
|
|
return levelup.read_detail(hint=None)
|
|
|
|
def test_maxed_uses_direct_level(self):
|
|
items = [{'text': 'Zwei Assoc. South Section 6', 'x': 1079, 'y': 155},
|
|
{'text': 'LV40', 'x': 900, 'y': 218},
|
|
{'text': '0/6075', 'x': 1000, 'y': 234},
|
|
{'text': 'MAX', 'x': 700, 'y': 240}]
|
|
lvl, name, bar = self._read(items)
|
|
self.assertEqual(lvl, 40)
|
|
|
|
def test_non_maxed_still_prefers_bar(self):
|
|
# 进度条 547/885 反推 Lv.17, 直读 LV17 一致
|
|
items = [{'text': 'LCB Sinner', 'x': 900, 'y': 155},
|
|
{'text': 'LV17', 'x': 900, 'y': 218},
|
|
{'text': '547/885', 'x': 1000, 'y': 234}]
|
|
lvl, name, bar = self._read(items)
|
|
self.assertEqual(lvl, 17)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|