v1进行时:UpsertUserAll回归基础包体(附加数据一律走extra_data)、解锁位串默认0、适配2026-10服务器维护(token一次性、上传冷却50s、买票冷却40s写入config)、新增落盘与日志开关
This commit is contained in:
1 parent
1d365cc948
commit
ed7d463519
12 files changed
+552
-271
No files matched your search
+119
-20
@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import api
|
||||
import unlockmusic
|
||||
import upsert
|
||||
from unlockmusic import build_unlock_items, make_unlock_extra
|
||||
from api import (
|
||||
BITS_TO_ARRAY,
|
||||
JUDGE_BOXES,
|
||||
@@ -40,7 +41,6 @@ from api import (
|
||||
build_delta,
|
||||
build_favorite_delta,
|
||||
build_play_from_config,
|
||||
build_unlock_items,
|
||||
build_user_all,
|
||||
build_user_game_playlog,
|
||||
build_user_playlog,
|
||||
@@ -1153,30 +1153,51 @@ _unl_all, _ = build_unlock_items(
|
||||
check("全都有时返回空列表", _unl_all == [], str(_unl_all))
|
||||
check("musicId 重复只写一次", len(build_unlock_items([1085, 1085])[0]) == 1)
|
||||
|
||||
# ---- 解锁走 extra_data 钩子(UpsertUserAll 本身不认识"解锁"这件事)----
|
||||
_ua_unl = build_user_all(baseline, login_date_time=1791159576, playlog_id=1,
|
||||
unlock_music_ids=[11414])
|
||||
check("build_user_all 把解锁条目追加进 userItemList",
|
||||
extra_data=make_unlock_extra([11414]))
|
||||
check("callable 形式的 extra_data 会被调用,条目进 userItemList",
|
||||
[it["itemKind"] for it in _ua_unl["userItemList"]] == [5, 6, 7],
|
||||
str(_ua_unl["userItemList"]))
|
||||
check("解锁条目的位串全是 1(新增)", _ua_unl["isNewItemList"] == "111",
|
||||
_ua_unl["isNewItemList"])
|
||||
check("解锁条目的位串全是 0(存量更新,写 1 有概率报错)",
|
||||
_ua_unl["isNewItemList"] == "000", _ua_unl["isNewItemList"])
|
||||
check("位串长度与 userItemList 条数一致",
|
||||
len(_ua_unl["isNewItemList"]) == len(_ua_unl["userItemList"]))
|
||||
check("不给 unlock_music_ids 时不产生 userItem 条目",
|
||||
check("不给 extra_data 时不产生 userItem 条目",
|
||||
build_user_all(baseline, login_date_time=1791159576,
|
||||
playlog_id=1)["userItemList"] == [])
|
||||
|
||||
_ua_unl3 = build_user_all(
|
||||
baseline, login_date_time=1791159576, playlog_id=1,
|
||||
extra_data={"userItemList": [{"itemKind": 5, "itemId": 1085,
|
||||
"stock": 1, "isValid": True}],
|
||||
"isNewItemList": "1"},
|
||||
unlock_music_ids=[11414])
|
||||
check("extra_data 给了 userItemList 时解锁条目追加在其后",
|
||||
[it["itemId"] for it in _ua_unl3["userItemList"]] == [1085, 11414, 11414, 11414],
|
||||
str([it["itemId"] for it in _ua_unl3["userItemList"]]))
|
||||
check("已有条目的位串保留、新条目补 1", _ua_unl3["isNewItemList"] == "1111",
|
||||
_ua_unl3["isNewItemList"])
|
||||
_unl_hook = make_unlock_extra([11414])
|
||||
_out_skip = _unl_hook({"userItemList": [{"itemKind": 5, "itemId": 11414}]},
|
||||
{"userItemList": [], "isNewItemList": ""})
|
||||
check("钩子按服务器快照跳过已有的 kind5(只剩 6/7)",
|
||||
[it["itemKind"] for it in _out_skip["userItemList"]] == [6, 7],
|
||||
str([it["itemKind"] for it in _out_skip["userItemList"]]))
|
||||
check("钩子产出的位串与条目数一致(全 0)", _out_skip["isNewItemList"] == "00",
|
||||
_out_skip["isNewItemList"])
|
||||
check("全已解锁时钩子返回空 dict(基础包体原样不动)",
|
||||
_unl_hook({"userItemList": [{"itemKind": k, "itemId": 11414}
|
||||
for k in (5, 6, 7)]}, {}) == {})
|
||||
|
||||
_out_keep = _unl_hook(
|
||||
{"userItemList": []},
|
||||
{"userItemList": [{"itemKind": 5, "itemId": 1085, "stock": 1, "isValid": True}],
|
||||
"isNewItemList": "1"})
|
||||
check("钩子保留基础包体已有的 userItemList 条目并追加在后",
|
||||
[it["itemId"] for it in _out_keep["userItemList"]] == [1085, 11414, 11414, 11414],
|
||||
str([it["itemId"] for it in _out_keep["userItemList"]]))
|
||||
check("已有位串保留、新条目补 0", _out_keep["isNewItemList"] == "1000",
|
||||
_out_keep["isNewItemList"])
|
||||
|
||||
# ---- new_bit 可显式指定(默认 0;想强制走 INSERT 才传 1)----
|
||||
_out_bit1 = make_unlock_extra([11414], new_bit="1")(
|
||||
{"userItemList": []}, {"userItemList": [], "isNewItemList": ""})
|
||||
check("new_bit='1' 时位串回到 1", _out_bit1["isNewItemList"] == "111",
|
||||
_out_bit1["isNewItemList"])
|
||||
_out_bitx = make_unlock_extra([11414], new_bit="9")(
|
||||
{"userItemList": []}, {"userItemList": [], "isNewItemList": ""})
|
||||
check("非法 new_bit 回落成 0", _out_bitx["isNewItemList"] == "000",
|
||||
_out_bitx["isNewItemList"])
|
||||
|
||||
# ---- unlock_base=False:只解禁难度,不解锁歌曲本体 ----
|
||||
_unl_nobase, _ = build_unlock_items([11414], unlock_base=False)
|
||||
@@ -1186,9 +1207,10 @@ check("unlock_base=False 只写 kind6/7(不写 kind5)",
|
||||
check("unlock_base=False + 标准谱 -> 没有可写的条目",
|
||||
build_unlock_items([1085], unlock_base=False)[0] == [])
|
||||
|
||||
_ua_nobase = build_user_all(baseline, login_date_time=1791159576, playlog_id=1,
|
||||
unlock_music_ids=[11414], unlock_base=False)
|
||||
check("build_user_all(unlock_base=False) 的 userItemList 只有 6/7",
|
||||
_ua_nobase = build_user_all(
|
||||
baseline, login_date_time=1791159576, playlog_id=1,
|
||||
extra_data=make_unlock_extra([11414], unlock_base=False))
|
||||
check("unlock_base=False 走钩子后 userItemList 只有 6/7",
|
||||
[it["itemKind"] for it in _ua_nobase["userItemList"]] == [6, 7],
|
||||
str(_ua_nobase["userItemList"]))
|
||||
|
||||
@@ -1275,6 +1297,44 @@ check("reset 之后记忆清空",
|
||||
has_fresh_read(55555) is False and purchased_charge_ids(77777) == [])
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 13.10 extra_data 的 callable 形态(按服务器快照现算)
|
||||
# =============================================================================
|
||||
|
||||
section("13.10 extra_data 的 callable 形态")
|
||||
|
||||
# 基础包体里 userKaleidxScopeList 默认是空的,用它就能看出"是否真被覆盖"
|
||||
check("基础包体里 userKaleidxScopeList 默认是空",
|
||||
build_user_all(baseline, login_date_time=1791159576,
|
||||
playlog_id=1)["userKaleidxScopeList"] == [])
|
||||
|
||||
_seen = {}
|
||||
|
||||
|
||||
def _extra_hook(snapshot, user_all):
|
||||
_seen["snapshot_keys"] = sorted(snapshot.keys())[:3]
|
||||
_seen["user_all_ok"] = isinstance(user_all, dict) and "userData" in user_all
|
||||
return {"userKaleidxScopeList": _kaleidx, "isNewKaleidxScopeList": "1"}
|
||||
|
||||
|
||||
_ua_cb = build_user_all(baseline, login_date_time=1791159576, playlog_id=1,
|
||||
extra_data=_extra_hook)
|
||||
check("callable 被调用,且拿到归一化快照与已组装的基础包体",
|
||||
_seen.get("user_all_ok") is True and bool(_seen.get("snapshot_keys")),
|
||||
str(_seen))
|
||||
check("callable 产出的节点被写进基础包体",
|
||||
_ua_cb["userKaleidxScopeList"] == _kaleidx,
|
||||
str(_ua_cb["userKaleidxScopeList"])[:120])
|
||||
check("callable 产出的位串生效", _ua_cb["isNewKaleidxScopeList"] == "1",
|
||||
_ua_cb["isNewKaleidxScopeList"])
|
||||
check("callable 返回空 dict 时基础包体不变",
|
||||
build_user_all(baseline, login_date_time=1791159576, playlog_id=1,
|
||||
extra_data=lambda s, u: {})["userKaleidxScopeList"] == [])
|
||||
check("callable 返回 None 时按空处理(不抛异常)",
|
||||
build_user_all(baseline, login_date_time=1791159576, playlog_id=1,
|
||||
extra_data=lambda s, u: None)["userKaleidxScopeList"] == [])
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 14. 副作用闸门
|
||||
# =============================================================================
|
||||
@@ -1375,6 +1435,45 @@ check("--upload-delay 默认 50", _rc.parse_args([])["upload_delay"] == 50.0)
|
||||
check("--per-packet 默认 3", _rc.parse_args([])["per_packet"] == 3)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 13.11 配置阀门与冷却默认值(2026-10 服务器维护后的调整)
|
||||
# =============================================================================
|
||||
section("13.11 配置阀门与冷却默认值")
|
||||
|
||||
import inspect as _inspect
|
||||
|
||||
import config as _cfg
|
||||
|
||||
check("config.UPSERT_SEND_COOLDOWN_SEC = 50(低于 50 秒上传会失败)",
|
||||
_cfg.UPSERT_SEND_COOLDOWN_SEC == 50, str(_cfg.UPSERT_SEND_COOLDOWN_SEC))
|
||||
check("config.BUY_TICKET_COOLDOWN_SEC = 40(买票冷却阀门)",
|
||||
_cfg.BUY_TICKET_COOLDOWN_SEC == 40, str(_cfg.BUY_TICKET_COOLDOWN_SEC))
|
||||
check("config.SAVE_USER_DATA 默认 True(GetNeedUserData 自动落盘)",
|
||||
_cfg.SAVE_USER_DATA is True)
|
||||
check("config.LOG_ENABLED 默认 True(生成日志文件)", _cfg.LOG_ENABLED is True)
|
||||
check("api.is_log_enabled() 默认 True", api.is_log_enabled() is True)
|
||||
check("api.config_save_default() 默认 True", api.config_save_default() is True)
|
||||
|
||||
_bt = __import__("buy_ticket")
|
||||
check("buy_ticket 的 --wait-before 默认取 config.BUY_TICKET_COOLDOWN_SEC",
|
||||
_bt.parse_args([])["wait_before"] == float(_cfg.BUY_TICKET_COOLDOWN_SEC),
|
||||
str(_bt.parse_args([])["wait_before"]))
|
||||
check("buy_ticket 仍支持 --wait-before 覆盖",
|
||||
_bt.parse_args(["--wait-before", "5"])["wait_before"] == 5.0)
|
||||
|
||||
_need_sig = _inspect.signature(api.GetNeedUserData).parameters
|
||||
check("GetNeedUserData 的 save 默认 None(= 看 config 阀门)",
|
||||
_need_sig["save"].default is None, str(_need_sig["save"].default))
|
||||
check("GetNeedUserData 仍有 save_path(显式路径优先)", "save_path" in _need_sig)
|
||||
|
||||
_log_sig = _inspect.signature(api.setup_logging).parameters
|
||||
check("setup_logging 新增 enabled 参数(默认 None = 看 config 阀门)",
|
||||
"enabled" in _log_sig and _log_sig["enabled"].default is None)
|
||||
|
||||
check("unlockmusic 的位串默认 0(存量更新,写 1 有概率报错)",
|
||||
unlockmusic.UNLOCK_NEW_BIT == "0", unlockmusic.UNLOCK_NEW_BIT)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 汇总
|
||||
# =============================================================================
|
||||
|
||||
Reference in new issue
Block a user