From 1bcd5f97428f3136bf337972caaf719b334fc92d Mon Sep 17 00:00:00 2001 From: xcosmosbox <2162381070@qq.com> Date: Mon, 30 Mar 2026 09:06:49 +0800 Subject: [PATCH] fix(weixin): fix test file version reader --- nanobot/channels/weixin.py | 21 +++------------------ tests/channels/test_weixin_channel.py | 3 +-- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/nanobot/channels/weixin.py b/nanobot/channels/weixin.py index 4341f21d1..7f6c6abab 100644 --- a/nanobot/channels/weixin.py +++ b/nanobot/channels/weixin.py @@ -54,19 +54,8 @@ MESSAGE_TYPE_BOT = 2 MESSAGE_STATE_FINISH = 2 WEIXIN_MAX_MESSAGE_LEN = 4000 - - -def _read_reference_package_meta() -> dict[str, str]: - """Best-effort read of reference `package/package.json` metadata.""" - try: - pkg_path = Path(__file__).resolve().parents[2] / "package" / "package.json" - data = json.loads(pkg_path.read_text(encoding="utf-8")) - return { - "version": str(data.get("version", "") or ""), - "ilink_appid": str(data.get("ilink_appid", "") or ""), - } - except Exception: - return {"version": "", "ilink_appid": ""} +WEIXIN_CHANNEL_VERSION = "2.1.1" +ILINK_APP_ID = "bot" def _build_client_version(version: str) -> int: @@ -84,11 +73,7 @@ def _build_client_version(version: str) -> int: patch = _as_int(2) return ((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF) - -_PKG_META = _read_reference_package_meta() -WEIXIN_CHANNEL_VERSION = _PKG_META["version"] or "unknown" -ILINK_APP_ID = _PKG_META["ilink_appid"] -ILINK_APP_CLIENT_VERSION = _build_client_version(_PKG_META["version"] or "0.0.0") +ILINK_APP_CLIENT_VERSION = _build_client_version(WEIXIN_CHANNEL_VERSION) BASE_INFO: dict[str, str] = {"channel_version": WEIXIN_CHANNEL_VERSION} # Session-expired error code diff --git a/tests/channels/test_weixin_channel.py b/tests/channels/test_weixin_channel.py index c4e5cf552..f4d57a8b0 100644 --- a/tests/channels/test_weixin_channel.py +++ b/tests/channels/test_weixin_channel.py @@ -52,8 +52,7 @@ def test_make_headers_includes_route_tag_when_configured() -> None: def test_channel_version_matches_reference_plugin_version() -> None: - pkg = json.loads(Path("package/package.json").read_text()) - assert WEIXIN_CHANNEL_VERSION == pkg["version"] + assert WEIXIN_CHANNEL_VERSION == "2.1.1" def test_save_and_load_state_persists_context_tokens(tmp_path) -> None: