You pushed on branch codex/feedback-unattended-setup-20261004 2026-11-22 10:05:52 +08:00
New Pull Request
Files
lc-mcp/tests/test_theme_pack_systems.py
T
ywsandClaude Opus 5.5 885412f0e0 复查 V1.6.2 与 11-16~11-22 补丁: 返回按钮 TypeError、事件兜底连点、截图熔断线程
- 返回按钮(I-15): V1.6.2 在首次引导页拿 click_element 的返回值当坐标再点, 它返回 True → TypeError,
  镜牢任务退出。install_back_button_result 只在 `x := auto.click_element(返回)` 这种调用时只找不点,
  由上游点一次; 只看真假的调用照常点; 上游源码里没有这种写法就不装
- 事件兜底(I-16): LCP_EVENT_FALLBACK=1 时每轮都抢先点第 1 项, 上游走不到判定/继续/开始战斗;
  runs 里 1014 条 fallback_first, 73 段同屏连点 10~11 次, 最长 110 次。改成每屏只点一次、与按表共用 5 次上限
- 事件点击点只在这一项自己那行 OCR 字里取(原来整屏找子串, 叙述或别的选项是它的子串时会点错)
- 截图熔断(I-17): 只在任务主线程计数和中止(retry_monitor 线程里抛只会打死那条线程, 两次熔断都记了两条);
  要求连续出错满 30 秒、至少 20 次, 一闪而过的坏帧不再停掉任务
- 卡包: 优选阈值默认 1 与注释/提交说明/实机一致(LCP_THEME_PACK_THRESHOLD=0 不动上游);
  「刷新」OCR 范围按 set_win_size/1440 缩放
- .gitignore 放行 docs/feedback/runs/**/logs/*.log(INDEX 说的过滤日志此前被 *.log 挡掉, 没进仓库)
- README 补 LCP_EVENT_FALLBACK / LCP_THEME_PACK_THRESHOLD; BACKLOG 记 V1.6.2 影响; ISSUES 加 I-15~I-17

单测: 769 passed(新增上游真实 select_battle_team 端到端: 不装补丁 TypeError, 装了点一次)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:17:07 +00:00

408 lines
23 KiB
Python

# -*- coding: utf-8 -*-
"""镜牢卡包按体系加分(BACKLOG R-01 / ISSUES I-08)。
theme_pack_list.yaml 几乎全是 0, 所有卡包并列最高分, 每层拿最左边那个。补丁在 AALC 选卡包时把
「卡包对当局体系的加分」(lc_mcp/data/theme_pack_systems.json, 数据来自 wiki.gg)临时加到权重表上。
端到端用例执行上游真实的 select_theme_pack, 卡面按 AALC 的规则(按表顺序取第一个子串命中的键)认。
"""
import ast
import json
import logging
import os
import re
import sys
import tempfile
import types
import unittest
from pathlib import Path
from types import SimpleNamespace
from unittest import mock
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO))
from lc_mcp import aalc_patches as ap # noqa: E402
THEME = REPO / 'vendor' / 'aalc' / 'tasks' / 'mirror' / 'select_theme_pack.py'
EXAMPLE = REPO / 'vendor' / 'aalc' / 'assets' / 'config' / 'theme_pack_list.example.yaml'
BONUS = {'featured': 6, 'unique': (0, 1, 4, 6), 'recommend': 6, 'avoid': 3}
BUILD = REPO / 'scripts' / 'build_theme_pack_systems.py'
def example_weights(*sections):
"""读 AALC 自带的 theme_pack_list.example.yaml(只认 `键: 整数` 这种行)。"""
found, current = {}, None
for line in EXAMPLE.read_text(encoding='utf-8').splitlines():
header = re.match(r'^(\w+):\s*$', line)
if header:
current = header.group(1)
continue
item = re.match(r'^\s+(\S.*?):\s*(-?\d+)', line)
if item and current in sections:
found[item.group(1)] = int(item.group(2))
return found
def pack(zh, en='x', featured=(), recommend=(), avoid=(), normal='1F', hard='1F', **unique):
return {'zh': zh, 'en': en, 'featured': list(featured), 'unique': unique, 'recommend': set(recommend),
'avoid': set(avoid), 'normal': normal, 'hard': hard}
class ThemePackTableTest(unittest.TestCase):
def setUp(self):
self.bonus, self.packs = ap.load_theme_pack_systems()
self.by_name = {p['zh']: p for p in self.packs}
def test_table_covers_the_current_theme_packs(self):
self.assertEqual(len(self.packs), len({p['id'] for p in self.packs}))
self.assertGreaterEqual(len(self.packs), 120)
self.assertEqual(self.bonus, BONUS)
def test_keyword_packs_and_story_packs(self):
# wiki.gg: Featured Gifts 用体系分类的就是体系包; 专属饰品按体系计数
self.assertEqual(self.by_name['电闪雷鸣']['featured'], ['charge'])
self.assertEqual(self.by_name['动力渐盈']['featured'], ['charge'])
self.assertEqual(self.by_name['尸山血海']['featured'], ['bleed'])
self.assertEqual(self.by_name['LCB定期体检']['featured'], ['burn', 'rupture'])
self.assertEqual(self.by_name['当斩之物']['featured'], ['slash'])
self.assertEqual(self.by_name['WARP快车谋杀案']['unique']['charge'], 5)
self.assertEqual(self.by_name['时间杀人时间']['unique']['tremor'], 5)
self.assertEqual(self.by_name['被遗忘者们']['unique'], {})
def test_community_entries_are_attached(self):
self.assertEqual(self.by_name['憎恶与绝望']['recommend'], {'burn', 'tremor', 'sinking', 'charge'})
self.assertEqual(self.by_name['被遗忘者们']['avoid'], {'*'})
self.assertEqual(self.by_name['琥珀色的黄昏']['avoid'], {'bleed'})
self.assertEqual(self.by_name['琥珀色的黄昏']['recommend'], {'sinking'})
def test_community_tiers(self):
b = self.bonus
self.assertEqual(ap.theme_pack_bonus(self.by_name['憎恶与绝望'], 'charge', b), 6) # 专属 2 件 4, 推荐 6
self.assertEqual(ap.theme_pack_bonus(self.by_name['地狱鸡'], 'poise', b), 6)
self.assertEqual(ap.theme_pack_bonus(self.by_name['琥珀色的黄昏'], 'bleed', b), 0) # 专属 3 件, 但攻略说不划算
self.assertEqual(ap.theme_pack_bonus(self.by_name['被遗忘者们'], 'charge', b), -3)
self.assertEqual(ap.theme_pack_bonus(self.by_name['当碎之物'], 'blunt', b), 3) # 体系包 6, 拖时间 -3
def test_route_bonus_ignores_system_and_avoid(self):
b = self.bonus
self.assertEqual(ap.theme_pack_bonus(dict(self.by_name['被遗忘者们'], route=5), None, b), 5)
self.assertEqual(ap.theme_pack_bonus(dict(self.by_name['憎恶与绝望'], route=2), 'charge', b), 6) # 取大的
self.assertEqual(ap.theme_pack_bonus(self.by_name['憎恶与绝望'], None, b), 0)
def test_bonus_tiers(self):
self.assertEqual(ap.theme_pack_bonus(self.by_name['电闪雷鸣'], 'charge', self.bonus), 6)
self.assertEqual(ap.theme_pack_bonus(self.by_name['WARP快车谋杀案'], 'charge', self.bonus), 6)
self.assertEqual(ap.theme_pack_bonus(self.by_name['开店抢购'], 'charge', self.bonus), 4)
self.assertEqual(ap.theme_pack_bonus(self.by_name['WARP快车谋杀案'], 'bleed', self.bonus), 1)
self.assertEqual(ap.theme_pack_bonus(self.by_name['电闪雷鸣'], 'bleed', self.bonus), 0)
def test_bad_tables_are_rejected(self):
for data in ({'bonus': {'featured': 6, 'unique': []}, 'packs': [pack('a')]},
{'bonus': BONUS | {'unique': [0, 1]}, 'packs': []},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('a', featured=['fire'])]},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('a', burn=0)]},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('', 'x')]},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('a')],
'community': {'recommend': [{'pack': '不存在', 'systems': ['burn']}]}},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('a')],
'community': {'recommend': [{'pack': 'a', 'systems': ['*']}]}},
{'bonus': {'featured': 6, 'unique': [0, 1]}, 'packs': [pack('a')],
'community': {'avoid': [{'pack': 'a', 'systems': []}]}}):
with self.subTest(data=data), tempfile.TemporaryDirectory() as d:
path = os.path.join(d, 't.json')
with open(path, 'w', encoding='utf-8') as fh:
json.dump(data, fh, ensure_ascii=False, default=list)
with self.assertRaises(ValueError):
ap.load_theme_pack_systems(path)
class BoostTest(unittest.TestCase):
def setUp(self):
self.bonus, self.packs = ap.load_theme_pack_systems()
def boost(self, weights, system, language='zh_cn', packs=None):
return ap.boost_theme_pack_weights(dict(weights), packs or self.packs, system, self.bonus, language)
@unittest.skipUnless(EXAMPLE.is_file(), 'vendor/aalc 子模块未检出')
def test_charge_team_in_normal_mode(self):
weights = example_weights('theme_pack_list_cn')
result, info = self.boost(weights, 'charge')
self.assertEqual((result['谋杀'], result['开店']), (1, 1)) # WARP 专属 5 件充能, 开店 2 件
self.assertEqual((result['绝望'], result['绞丝']), (1, 1)) # 社区推荐
self.assertEqual(result['赌徒'], 0)
self.assertEqual((result['遗忘'], result['自动']), (-3, -5)) # 速刷攻略说拖时间
self.assertEqual(result['地狱鸡'], 1)
self.assertEqual(info['谋杀'], {'packs': ['WARP快车谋杀案', 'WARP快车谋杀案 复刻'], 'system': 'charge',
'from': -5, 'to': 1})
self.assertEqual(set(result), set(weights) | {k for k in info if k not in weights})
# 加过分的键排在最前面
self.assertEqual(list(result)[:len(info)], list(info))
@unittest.skipUnless(EXAMPLE.is_file(), 'vendor/aalc 子模块未检出')
def test_keyword_packs_in_hard_mode(self):
weights = example_weights('theme_pack_list_cn', 'theme_pack_list_hard_cn')
result, _ = self.boost(weights, 'charge')
self.assertEqual((result['电闪雷鸣'], result['动力']), (6, 6))
result, _ = self.boost(weights, 'bleed')
self.assertEqual(result['渗出的'], 6)
@unittest.skipUnless(EXAMPLE.is_file(), 'vendor/aalc 子模块未检出')
def test_shared_key_takes_the_smaller_bonus_and_the_reprint_gets_its_full_name(self):
# 「谋杀」同时命中原版(流血 1 件)和复刻(流血 3 件)
result, info = self.boost(example_weights('theme_pack_list_cn'), 'bleed')
self.assertEqual(result['谋杀'], -4)
self.assertEqual(result['WARP快车谋杀案 复刻'], 1)
order = list(result)
self.assertLess(order.index('WARP快车谋杀案 复刻'), order.index('谋杀'))
@unittest.skipUnless(EXAMPLE.is_file(), 'vendor/aalc 子模块未检出')
def test_key_shared_with_an_unrelated_pack_is_left_alone(self):
# 「区的奇」= 20区的奇迹 + 复刻; 只有复刻有震颤专属饰品
result, info = self.boost(example_weights('theme_pack_list_cn'), 'tremor')
self.assertEqual(result['区的奇'], 0)
self.assertEqual(result['20区的奇迹 复刻'], 1)
self.assertNotIn('区的奇', info)
def test_pack_unknown_to_aalc_starts_from_the_unknown_weight(self):
packs = [pack('黎明后贯穿而来之楔', pierce=3)]
result, info = self.boost({'遗忘': 0, '未知': -5}, 'pierce', packs=packs)
self.assertEqual(result['黎明后贯穿而来之楔'], 1)
self.assertEqual(result['未知'], -5)
def test_english_keys(self):
packs = [pack('WARP快车谋杀案', 'Murder on the WARP Express', charge=5),
pack('电闪雷鸣', 'Thunder and Lightning', featured=['charge']),
pack('被遗忘者们', 'The Forgotten')]
result, _ = self.boost({'forgot': 0, 'warp': -5, 'thunder': 0, 'unknown': -5}, 'charge', 'en', packs)
self.assertEqual(result, {'thunder': 6, 'warp': 1, 'forgot': 0, 'unknown': -5})
def test_unrelated_keys_keep_their_weight(self):
weights = {'信仰': 0, '赌徒': -1}
result, info = self.boost(weights, 'charge')
self.assertEqual((result['信仰'], result['赌徒']), (0, -1))
self.assertNotIn('信仰', info)
# 表里没有的充能卡包补全名键, 从「未知」(表里也没有就 -5)起算
self.assertEqual(result['电闪雷鸣'], 1)
@unittest.skipUnless(EXAMPLE.is_file(), 'vendor/aalc 子模块未检出')
def test_packs_missing_from_the_difficulty_do_not_block_a_key(self):
# 「海·边」也是活动专用包 去·海·边·激·蟹 的一部分; 普通/困难都不会出现它, 不算冲突
weights = example_weights('theme_pack_list_cn')
self.assertEqual(self.boost(weights, 'pierce')[0]['海·边'], 0)
result, _ = ap.boost_theme_pack_weights(dict(weights), self.packs, 'pierce', self.bonus, 'zh_cn', False)
self.assertEqual((result['海·边'], result['区的奇'], result['赌徒']), (6, 6, 6))
# 困难模式 20区的奇迹 复刻 也会出现, 它和突刺无关, 「区的奇」就不动
weights = example_weights('theme_pack_list_cn', 'theme_pack_list_hard_cn')
result, _ = ap.boost_theme_pack_weights(dict(weights), self.packs, 'pierce', self.bonus, 'zh_cn', True)
self.assertEqual(result['区的奇'], 0)
def test_penalties_follow_the_same_shared_key_rule(self):
packs = [pack('被遗忘者们', avoid=['*']), pack('自动工厂', avoid=['*']), pack('遗忘的工厂')]
result, info = self.boost({'遗忘': 0, '工厂': -2}, 'charge', packs=packs)
self.assertEqual(result['遗忘'], 0) # 遗忘的工厂 不减分, 有加有不加就不动短键
self.assertEqual(result['被遗忘者们'], -3) # 改用全名
self.assertEqual(result['工厂'], -2)
self.assertEqual(result['自动工厂'], -5)
def test_system_without_any_pack_changes_nothing(self):
packs = [pack('被遗忘者们'), pack('电闪雷鸣', featured=['charge'])]
weights = {'遗忘': 0, '电闪雷鸣': -5}
self.assertEqual(self.boost(weights, 'burn', packs=packs), (weights, {}))
@unittest.skipUnless(BUILD.is_file(), 'scripts 目录缺失')
class GeneratorFormatTest(unittest.TestCase):
def test_generator_writes_the_shipped_file_byte_for_byte(self):
import importlib.util
spec = importlib.util.spec_from_file_location('build_theme_pack_systems', BUILD)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
text = Path(ap.THEME_PACK_SYSTEMS_FILE).read_text(encoding='utf-8')
self.assertEqual(module.dump_table(json.loads(text)), text)
class Match:
def __init__(self, value, text):
self.value, self.text, self.position = value, text, [0, 0]
@unittest.skipUnless(THEME.is_file(), 'vendor/aalc 子模块未检出')
class UpstreamSelectThemePackTest(unittest.TestCase):
"""执行上游真实的 select_theme_pack(普通模式, 中文)。"""
def setUp(self):
self.lines = []
tree = ast.parse(THEME.read_text(encoding='utf-8'))
self.node = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == 'select_theme_pack')
self.node.decorator_list = []
def play(self, cards, system, patched=True, audit=False, env=None, hard=False, route=None):
positions = [(300 + 300 * i, 300) for i in range(len(cards))]
weights = example_weights('theme_pack_list_cn', *(('theme_pack_list_hard_cn',) if hard else ()))
lookups = []
self.refreshes = refreshes = []
def find_language_text(zh, en, crop):
# AALC: 按表的顺序, 第一个(去空格、不分大小写)是卡面文字子串的键
x = (crop[0] + crop[2]) / 2
text = cards[min(range(len(cards)), key=lambda i: abs(positions[i][0] - x))].replace(' ', '').lower()
lookups.append(zh)
for key, value in zh.items():
if key.replace(' ', '').lower() in text:
return Match(value, key)
return None
auto = SimpleNamespace(
model=None, take_screenshot=lambda: object(), mouse_to_blank=lambda *a, **k: None,
find_element=lambda target, **kw: list(positions) if 'theme_pack_features' in target else False,
find_language_text=find_language_text, mouse_drag_down=mock.Mock(),
click_element=lambda target, *a, **k: refreshes.append(target) or True if 'refresh' in target else False)
theme_list = SimpleNamespace(preferred_thresholds=0, get_effective_theme_pack_list=lambda *a: dict(weights))
ns = dict(auto=auto, TextMatchResult=Match, sleep=lambda *a: None, back_init_menu=mock.Mock(),
log=logging.getLogger('AALC'), theme_list=theme_list,
cfg=SimpleNamespace(set_win_size=720, select_event_pack=False, skip_event_pack=False),
path_manager=SimpleNamespace(current_language='zh_cn'))
exec(compile(ast.Module(body=[self.node], type_ignores=[]), str(THEME), 'exec'), ns)
theme_mod = types.ModuleType('tasks.mirror.select_theme_pack')
theme_mod.theme_list = theme_list
mirror_mod = types.ModuleType('tasks.mirror.mirror')
mirror_mod.select_theme_pack = ns['select_theme_pack']
mirror_mod.Mirror = type('Mirror', (), {'__init__': lambda self, system: setattr(self, 'system', system)})
package = types.ModuleType('tasks.mirror')
package.mirror, package.select_theme_pack = mirror_mod, theme_mod
logger = logging.getLogger('AALC')
with mock.patch.dict(sys.modules, {'tasks': types.ModuleType('tasks'), 'tasks.mirror': package,
'tasks.mirror.mirror': mirror_mod,
'tasks.mirror.select_theme_pack': theme_mod}), \
mock.patch.object(logger, 'level', logging.DEBUG), mock.patch.object(logger, 'propagate', False), \
mock.patch.object(ap.decisions, 'record') as record:
if patched:
self.assertIsNotNone(ap.install_theme_pack_systems(log=self.lines.append, env=env or {},
route=route, route_name='兔子洞路线'))
if audit:
ap.install_theme_pack_audit(log=self.lines.append)
mirror_mod.Mirror(system)
mirror_mod.select_theme_pack(hard, 4, 1, False)
self.assertEqual(theme_list.get_effective_theme_pack_list(), weights, '权重表的原方法必须还原')
drag = auto.mouse_drag_down.call_args[0]
picked = cards[positions.index(drag)]
return picked, record, lookups
@property
def log(self):
return '\n'.join(self.lines)
FLOOR4 = ['伏行深渊', '落泪者们', 'WARP快车谋杀案', '堕落的忧郁']
def test_upstream_takes_the_leftmost_of_equal_weights(self):
self.assertEqual(self.play(self.FLOOR4, 'charge', patched=False)[0], '落泪者们')
def test_charge_team_takes_the_charge_pack(self):
picked, _, _ = self.play(self.FLOOR4, 'charge')
self.assertEqual(picked, 'WARP快车谋杀案')
self.assertIn('patch: 镜牢卡包按体系加分(theme_pack_systems.json', self.log)
self.assertIn('卡包按体系 charge 加分: ', self.log)
self.assertIn('谋杀 -5→1', self.log)
FLOOR1 = ['被遗忘者们', '身无分文的赌徒', '钉与锤']
def test_slow_pack_is_avoided_and_pierce_takes_its_route(self):
self.assertEqual(self.play(self.FLOOR1, 'charge', patched=False)[0], '被遗忘者们')
self.assertEqual(self.play(self.FLOOR1, 'charge')[0], '身无分文的赌徒') # 被遗忘者们 -3
self.assertEqual(self.play(['钉与锤', '身无分文的赌徒'], 'pierce')[0], '身无分文的赌徒')
def test_bleed_team_does_not_take_the_original_warp(self):
# 原版 WARP 只有 1 件流血专属饰品, 加 1 分仍然低于 0 分的卡包
self.assertEqual(self.play(self.FLOOR4, 'bleed')[0], '落泪者们')
def test_audit_records_the_system_bonus(self):
picked, record, _ = self.play(self.FLOOR4, 'charge', audit=True)
args, kwargs = record.call_args
self.assertEqual(args, ('theme_pack', '谋杀', 'preferred'))
# 普通模式: 复刻只在困难出现, 不算进「谋杀」这个键
self.assertEqual(kwargs['system_bonus'], {'packs': ['WARP快车谋杀案'], 'system': 'charge', 'from': -5, 'to': 1})
def test_audit_keeps_a_key_with_a_space(self):
# 困难模式流血队: 复刻 WARP 专属流血 3 件, 用全名键「WARP快车谋杀案 复刻」; 审计不能截在空格前
picked, record, _ = self.play(['钉与锤', 'WARP快车谋杀案 复刻'], 'bleed', audit=True, hard=True)
self.assertEqual(picked, 'WARP快车谋杀案 复刻')
args, kwargs = record.call_args
self.assertEqual(args, ('theme_pack', 'WARP快车谋杀案 复刻', 'preferred'))
self.assertEqual(kwargs['system_bonus']['to'], 1)
def test_audit_without_bonus_has_no_system_field(self):
_, record, _ = self.play(self.FLOOR4, 'bleed', audit=True)
self.assertNotIn('system_bonus', record.call_args[1])
def test_unknown_system_keeps_upstream_weights(self):
picked, _, lookups = self.play(self.FLOOR4, 'unknown_system')
self.assertEqual(picked, '落泪者们')
self.assertEqual(lookups[0], example_weights('theme_pack_list_cn'))
def test_zero_point_floor_refreshes_first_by_default(self):
# 用户 11-16「卡包均分低就刷新」: 最高 0 分时先刷新, 上游点满 4 次「刷新」后取最高分
picked, _, _ = self.play(self.FLOOR4, 'unknown_system')
self.assertEqual(picked, '落泪者们')
self.assertEqual(len(self.refreshes), 4)
self.assertIn('卡包优选阈值 0 → 1', self.log)
def test_threshold_env_zero_keeps_upstream_threshold(self):
self.play(self.FLOOR4, 'unknown_system', env={ap.THEME_PACK_THRESHOLD_ENV: '0'})
self.assertEqual(self.refreshes, [])
self.assertNotIn('卡包优选阈值', self.log)
def test_system_pack_is_taken_without_refreshing(self):
self.assertEqual(self.play(self.FLOOR4, 'charge')[0], 'WARP快车谋杀案')
self.assertEqual(self.refreshes, [])
def test_rabbit_hole_route_without_a_system(self):
# 兔子洞编队没有体系; 困难模式 AALC 默认「绝望」「号线」都是 -5, 不加分拿 0 分的落泪者们
route = ap.load_rabbit_hole()['theme_packs']
floor4 = ['2号线', '憎恶与绝望', '落泪者们']
self.assertEqual(self.play(floor4, None, hard=True)[0], '落泪者们')
self.assertEqual(self.play(floor4, None, hard=True, route=route)[0], '憎恶与绝望') # 2号线留给 5 层
self.assertIn('卡包按体系 (无)+兔子洞路线 加分: ', self.log)
self.assertIn('兔子洞路线 身无分文的赌徒+10 地狱鸡+10 去·海·边+10 憎恶与绝望+12 2号线+10', self.log)
self.assertEqual(self.play(['电闪雷鸣', '2号线'], None, hard=True, route=route)[0], '2号线')
self.assertEqual(self.play(['地狱鸡', '去·海·边'], None, hard=True, route=route)[0], '地狱鸡')
self.assertEqual(self.play(['憎恶与绝望', '去·海·边'], None, hard=True, route=route)[0], '去·海·边')
def test_route_beats_the_system_bonus_and_unknown_names_are_errors(self):
picked, _, _ = self.play(self.FLOOR4, 'charge', route={'落泪者们': 20, '不存在的包': 5})
self.assertEqual(picked, '落泪者们')
self.assertIn('[ERROR] [lc_mcp] 兔子洞路线卡包不在卡包表里, 不加分: 不存在的包', self.log)
def test_env_zero_and_bad_table(self):
self.assertIsNone(ap.install_theme_pack_systems(log=self.lines.append, env={ap.THEME_PACK_SYSTEMS_ENV: '0'}))
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, 'bad.json')
with open(path, 'w', encoding='utf-8') as fh:
fh.write('{}')
self.assertIsNone(ap.install_theme_pack_systems(log=self.lines.append,
env={ap.THEME_PACK_SYSTEMS_ENV: path}))
self.assertIn('[ERROR] [lc_mcp] 卡包体系表读不了', self.log)
def test_upstream_without_the_weight_lookup_is_an_error(self):
with mock.patch('inspect.getsource', return_value='def select_theme_pack(): pass'):
theme_mod = types.ModuleType('tasks.mirror.select_theme_pack')
theme_mod.theme_list = SimpleNamespace()
mirror_mod = types.ModuleType('tasks.mirror.mirror')
mirror_mod.select_theme_pack = lambda *a: None
package = types.ModuleType('tasks.mirror')
package.mirror, package.select_theme_pack = mirror_mod, theme_mod
with mock.patch.dict(sys.modules, {'tasks': types.ModuleType('tasks'), 'tasks.mirror': package,
'tasks.mirror.mirror': mirror_mod,
'tasks.mirror.select_theme_pack': theme_mod}):
self.assertIsNone(ap.install_theme_pack_systems(log=self.lines.append, env={}))
self.assertIn('[ERROR] [lc_mcp] 上游 select_theme_pack 不再从 theme_list.get_effective_theme_pack_list 取权重',
self.log)
def test_current_upstream_source_has_the_weight_lookup(self):
self.assertIn('theme_list.get_effective_theme_pack_list(', THEME.read_text(encoding='utf-8'))
if __name__ == '__main__':
unittest.main()