Files
lc-mcp/tests/test_theme_pack_systems.py
T
ywsandClaude Opus 5.5 4db3cd2605 卡包: 体系分不再把 P 不过去的包抬上来(I-19); 拖拽兜底拆成独立补丁(I-20)
- I-19 用户「老是选择 p 不过去的包」: AALC 表里负分 = Boss 难打/拖时间(绝望骑士、时间杀人魔、卡塞蒂 -5),
  体系分 +6 直接加上去 -5 变 +1, 震颤队每局 3/4 层去打憎恶与绝望/时间杀人时间(3 层 16.7 分钟 vs 同层 8~11)。
  现在卡包在 AALC 的原权重 < THEME_PACK_LIFT_MIN(0) 时体系分只折成 ±0.9 小数, 同档排先后、不跨档;
  0 分及以上照旧加满; 兔子洞路线分不变。权重可能是小数(绝望 -5→-4.4)。
  回放 11-15~11-21 的 61 次选包: 15 次改选(全是 3/4/5 层的憎恶与绝望/时间杀人时间)。
- I-20 fb7a0ec 的拖拽兜底挂在加分补丁里: 加分关掉/没体系时不生效, 且拖完马上截图会把转场中的成功也当失败。
  改成 install_theme_pack_drag_retry 单独装: 3 秒内每 0.5 秒看「刷新」, 消失即确认, 一直在才下移 160(1440 标定)再拖。
- theme_pack_systems.json 说明同步; ISSUES 记 I-19/I-20。

单测: 795 passed(新增 test_theme_pack_drag_retry 9 例, test_theme_pack_systems +3)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:10:36 +00:00

440 lines
26 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)
# 路线分不看难度档: 兔子洞 4 层就是要去打 -5 的憎恶与绝望
self.assertEqual(ap.theme_pack_bonus(dict(self.by_name['憎恶与绝望'], route=12), None, b, base=-5), 12)
def test_hard_packs_only_get_a_tiebreak(self):
# ISSUES I-19: AALC 负分 = 难打/拖时间, 体系分折成 ±0.9 以内, 不跨 AALC 的整数档
b = self.bonus
self.assertEqual(ap.theme_pack_bonus(self.by_name['憎恶与绝望'], 'tremor', b, base=-5), 0.6)
self.assertEqual(ap.theme_pack_bonus(self.by_name['WARP快车谋杀案'], 'bleed', b, base=-5), 0.1)
self.assertEqual(ap.theme_pack_bonus(self.by_name['自动工厂'], 'charge', b, base=-2), -0.3)
self.assertEqual(ap.theme_pack_bonus(self.by_name['憎恶与绝望'], 'tremor', b, base=0), 6)
self.assertEqual(ap.theme_pack_bonus(self.by_name['憎恶与绝望'], 'bleed', b, base=-5), 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')
# WARP 专属 5 件充能、开店 2 件、绝望/绞丝社区推荐, 但 AALC 判成难打(负分): 只在同档里往前挪, 到不了 0
self.assertEqual((result['谋杀'], result['开店']), (-4.4, -2.6))
self.assertEqual((result['绝望'], result['绞丝']), (-4.4, -4.4))
self.assertEqual(result['赌徒'], 0)
self.assertEqual((result['遗忘'], result['自动']), (-3, -2.3)) # 速刷攻略说拖时间; 自动工厂本来就是 -2
self.assertEqual(result['地狱鸡'], 1)
self.assertEqual(info['谋杀'], {'packs': ['WARP快车谋杀案', 'WARP快车谋杀案 复刻'], 'system': 'charge',
'from': -5, 'to': -4.4})
self.assertLess(max(v for k, v in result.items() if k in info and info[k]['from'] < 0), 0)
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.9)
self.assertEqual(result['WARP快车谋杀案 复刻'], -4.4)
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):
# AALC 没收录的卡包按「未知」算, 也就是当成难打的: 只比别的 -5 包靠前
packs = [pack('黎明后贯穿而来之楔', pierce=3)]
result, info = self.boost({'遗忘': 0, '未知': -5}, 'pierce', packs=packs)
self.assertEqual(result['黎明后贯穿而来之楔'], -4.4)
self.assertEqual(result['未知'], -5)
result, info = self.boost({'遗忘': 0, '未知': 0}, 'pierce', packs=packs)
self.assertEqual(result['黎明后贯穿而来之楔'], 6)
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': -4.4, '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['电闪雷鸣'], -4.4)
@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['自动工厂'], -2.3) # AALC 已经是 -2, 「拖时间」只在同档里往后排
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_does_not_fight_a_hard_boss_for_its_gifts(self):
# ISSUES I-19: 原来 WARP(-5, 卡塞蒂)对充能队加到 1, 压过 0 分的落泪者们
picked, _, _ = self.play(self.FLOOR4, 'charge')
self.assertEqual(picked, '落泪者们')
self.assertIn('patch: 镜牢卡包按体系加分(theme_pack_systems.json', self.log)
self.assertIn('卡包按体系 charge 加分: ', self.log)
self.assertIn('谋杀 -5→-4.4', self.log)
self.assertEqual(len(self.refreshes), 4) # 没有打得过的本体系卡包: 先刷新
def test_tremor_team_skips_the_despair_knight(self):
# 11-16~11-21 实机: 震颤队每局 3 层都选憎恶与绝望(绝望 -5 → 1), 那层平均 18 分钟
self.assertEqual(self.play(['憎恶与绝望', '受情感压迫者', '宅邸的副产物'], 'tremor')[0], '受情感压迫者')
self.assertEqual(self.play(['时间杀人时间', '某个世界'], 'tremor')[0], '某个世界')
def test_among_hard_packs_the_system_still_decides(self):
# 5 层常见全是 -5: 这时还是挑本体系的
self.assertEqual(self.play(['伏行深渊', 'WARP快车谋杀案', '压抑的暴怒'], 'charge')[0], 'WARP快车谋杀案')
self.assertEqual(self.play(['伏行深渊', 'WARP快车谋杀案'], 'unknown_system')[0], '伏行深渊')
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(['钉与锤', '身无分文的赌徒'], 'pierce', audit=True)
args, kwargs = record.call_args
self.assertEqual(args, ('theme_pack', '赌徒', 'preferred'))
self.assertEqual(kwargs['system_bonus'], {'packs': ['身无分文的赌徒'], 'system': 'pierce', 'from': 0, 'to': 6})
# 普通模式: 复刻只在困难出现, 不算进「谋杀」这个键
picked, record, _ = self.play(['伏行深渊', 'WARP快车谋杀案'], 'charge', audit=True)
self.assertEqual(record.call_args[0], ('theme_pack', '谋杀', 'highest_weight'))
self.assertEqual(record.call_args[1]['system_bonus'],
{'packs': ['WARP快车谋杀案'], 'system': 'charge', 'from': -5, 'to': -4.4})
def test_audit_keeps_a_key_with_a_space(self):
# 困难模式震颤队: 只有复刻 20区的奇迹 有震颤专属饰品, 用全名键「20区的奇迹 复刻」; 审计不能截在空格前
picked, record, _ = self.play(['钉与锤', '20区的奇迹 复刻'], 'tremor', audit=True, hard=True)
self.assertEqual(picked, '20区的奇迹 复刻')
args, kwargs = record.call_args
self.assertEqual(args, ('theme_pack', '20区的奇迹 复刻', '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(['钉与锤', '身无分文的赌徒'], 'pierce')[0], '身无分文的赌徒')
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()