diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0143936..385aa8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,9 +57,15 @@ jobs: run: python astrbot_plugin_bond/scripts/build_package.py --output "${{ runner.temp }}/bond-check.zip" framework: - name: AstrBot 4.28.0 插件装配 + name: AstrBot ${{ matrix.astrbot-version }} 插件装配 runs-on: ubuntu-latest timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + astrbot-version: ['4.28.0', '4.29.4'] + env: + BOND_EXPECTED_ASTRBOT_VERSION: ${{ matrix.astrbot-version }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -69,7 +75,7 @@ jobs: with: python-version: '3.12' - name: 安装真实框架 - run: python -m pip install AstrBot==4.28.0 + run: python -m pip install AstrBot==${{ matrix.astrbot-version }} - name: 独立进程验证装配与卸载 run: >- python astrbot_plugin_bond/scripts/smoke_astrbot.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c003e6..be5e21c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 更新说明 -## 0.5.11 — 2026-11-09 +## 0.5.12 — 2026-11-09 -- 修改一处文案错误。 +- 取消 AstrBot 版本上限,最低要求保留为 4.28,允许宿主后续版本加载。 +- 补充 AstrBot 4.29.4 真实框架验证,覆盖关系注入、工具续跑、OneBot 消息及原生页面认证。 diff --git a/README.md b/README.md index d1f2604..b63c5df 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@

- v0.5.11 · AstrBot ≥4.28 / <5 · OneBot aiocqhttp · AGPL-3.0 + v0.5.12 · AstrBot ≥4.28 · OneBot aiocqhttp · AGPL-3.0

--- @@ -94,7 +94,7 @@ Bond 是面向 **长期多人群聊** 的关系记忆插件。它分别记录 Bo ### 1. 安装并确认 Bot -- 使用 AstrBot `>=4.28,<5` 和 `aiocqhttp`;真实框架装配已在 `4.28.0` 验证,Python 版本跟随宿主要求。 +- 使用 AstrBot `>=4.28` 和 `aiocqhttp`;真实框架装配验证覆盖 `4.28.0`、`4.29.4`,Python 版本跟随宿主要求。后续版本可加载,兼容性以实际框架验证为准。 - 在 AstrBot 的插件管理中通过本仓库地址安装;也可下载 main 的 ZIP,解压到 `data/plugins/astrbot_plugin_bond/`。**插件目录必须全小写**。 - 重载后打开 Bond 管理页面,在「详细设置 → 基础设置」**先手动选择日常评估模型**(不自动跟随聊天模型),再按需开启自动评估、在回复中体现关系,填入适用群与需要忽略的机器人账号。尚未发现 Bot 时也可完成这些设置。 - 在「详细设置 → 基础设置」选择关系模式,在「关系变化」调整基础参数;新安装默认为 Galgame。保存并重载后生效。连接 OneBot 后点击“刷新 Bot 列表”,选中需要管理的 Bot 与数据空间。 diff --git a/docs/ACCEPTANCE.md b/docs/ACCEPTANCE.md index 9aa0d7e..0078aee 100644 --- a/docs/ACCEPTANCE.md +++ b/docs/ACCEPTANCE.md @@ -2,6 +2,24 @@ 本文保留 PR0 至 PR7 的代码验证记录,并补充后续版本的验证范围;早期需求沿用 T01–T34 编号。更新日期为 2026-11-03。完整宿主、真实平台和模型语义验收另列,不以离线测试代替。 +## 0.5.12 框架兼容检查(2026-11-09) + +- 插件要求改为 `>=4.28`,版本与注册信息同步为 0.5.12。CI 的真实框架矩阵包含 4.28.0、4.29.4,五个 smoke 通过 `BOND_EXPECTED_ASTRBOT_VERSION` 核对实际导入版本。 +- Windows Python 3.12 全量离线测试首次为 1539 passed、8 failed、1 skipped,耗时 370.17 秒。8 项发布脚本测试因 PATH 选中 WSL Bash 而失败;将 Git Bash 提前后定向重跑为 8 passed,耗时 50.87 秒。合计 1547 项通过,跳过项为当前 Windows 身份无法创建符号链接。 +- Node 页面测试 94 passed,耗时 0.47 秒。134 个 Python 文件通过锁定版本 Black、Ruff 格式检查;项目元数据与公开内容检查通过。 +- AstrBot 4.28.0 与 4.29.4 分进程、使用新空目录通过全部五类 smoke。装配覆盖 2 Bot/4 SQLite、18 路 API、请求与回复钩子、真实人格选择器的会话切换和显式禁用,以及合成 JWT 经宿主认证函数、FastAPI/Quart 桥的访问与参数校验。真实 ToolLoopAgentRunner 的初始调用、工具续跑和空输出重试均通过,OneBot 每版 24 个合成消息用例通过,诊断覆盖 2 Bot × 2 数据空间。 +- 本地验证环境补齐 Quart、aiocqhttp、pyotp、pycryptodome 后,两版本完整装配 smoke 通过;此前的缺依赖退出属于验证环境问题。下表为最终通过记录的进程耗时。 + +| 检查 | AstrBot 4.28.0 | AstrBot 4.29.4 | +| --- | --- | --- | +| 装配、人格与原生页面认证 | 通过,14.06 秒 | 通过,11.88 秒 | +| OneBot 消息元数据 | 24 例通过,15.55 秒 | 24 例通过,9.22 秒 | +| 诊断、认证与空间隔离 | 通过,11.28 秒 | 通过,9.81 秒 | +| runner 关系快照 | 3 场景通过,14.38 秒 | 3 场景通过,未单独计时 | +| 被动熟悉度 | 通过,13.83 秒 | 通过,未单独计时 | + +- 本次使用本地真实框架源码、合成消息、SQLite 与离线 Provider。Windows 异步测试在正常用户环境运行,以完成事件循环本机 socketpair 初始化。真实 QQ、联网模型、完整宿主登录、浏览器及第三方插件同装未验收。 + ## 0.5.1 分阶段导入验证(2026-11-06) 本次将 0.5.1 源码按独立维护、消息快照与行为指导、分级诊断三个 PR 导入 0.4.4 基线,并修复导入审查中确认的问题。 diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 9b7cc4b..3999cb5 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -85,15 +85,19 @@ python scripts/build_package.py --output artifacts/bond-check.zip ## 真实框架与合成回放 -另建 `.venv-framework`,安装 `AstrBot==4.28.0`,使用这个环境的解释器分别执行以下命令。每次使用新的空输出目录,示例目录已用过时换一个名称。 +另建 `.venv-framework`,分别安装 CI 矩阵中的 `AstrBot==4.28.0` 和 `AstrBot==4.29.4`,使用对应环境的解释器分进程执行以下命令。每次使用新的空输出目录,示例目录已用过时换一个名称。版本固定用于验证基线,插件元数据只声明最低要求 `>=4.28`。 + +运行前将 `BOND_EXPECTED_ASTRBOT_VERSION` 设为本次框架版本,例如 PowerShell 的 `$env:BOND_EXPECTED_ASTRBOT_VERSION = "4.29.4"`,或 Bash 的 `export BOND_EXPECTED_ASTRBOT_VERSION=4.29.4`。脚本核对实际导入版本,输出也使用实际版本号。本地已有源码检出时可通过 `PYTHONPATH` 指向对应框架目录;离线 pytest 进程须清除该变量,防止混用真实框架与测试桩。 ```text python scripts/smoke_astrbot.py --session-dir artifacts/framework-run --runtime-dir artifacts/framework-run/runtime python scripts/smoke_message_metadata.py --session-dir artifacts/metadata-run python scripts/smoke_diagnostics.py --runtime-dir artifacts/diagnostics-run +python scripts/smoke_relation_runner.py --runtime-dir artifacts/relation-run +python scripts/smoke_passive_familiarity.py --runtime-dir artifacts/passive-run ``` -这些脚本分别验证真实框架装配与卸载、OneBot 合成消息转换,以及诊断认证拒绝、脱敏和空间隔离。它们不会连接真实 QQ 或 Provider;认证上下文由测试模拟,不能代替完整宿主登录、浏览器和 Angel Heart 同装验收。 +这些脚本分别验证真实框架装配与卸载、OneBot 合成消息转换、诊断认证拒绝、脱敏和空间隔离,以及 runner 关系快照与被动熟悉度。装配检查还使用真实人格选择器验证会话人格切换和显式禁用,使用合成 JWT 经宿主认证函数和 FastAPI/Quart 桥验证原生页面访问。它们使用合成数据与离线 Provider,完整宿主登录、浏览器和 Angel Heart 同装仍须单独验收。 关系合成回放在离线环境执行: @@ -111,7 +115,7 @@ python scripts/replay_relations.py --arms baseline model-a --output artifacts/re | 工作流 | 触发时机 | 检查内容 | | --- | --- | --- | -| CI | PR、main 推送、手动 | Linux Python 3.10/3.12 和 Windows Python 3.12 离线测试、Node 22 页面测试、元数据、公开内容、Python 3.12 安装包;独立作业验证 AstrBot 4.28.0 装配。 | +| CI | PR、main 推送、手动 | Linux Python 3.10/3.12 和 Windows Python 3.12 离线测试、Node 22 页面测试、元数据、公开内容、Python 3.12 安装包;独立矩阵验证 AstrBot 4.28.0、4.29.4 装配与全部 smoke。 | | Code Format Check | PR、main 推送、手动 | `requirements-dev.txt` 锁定版本的 Black 与 Ruff 格式检查。 | | CodeQL | PR、main 推送、每周、手动 | Python 静态安全分析。 | | release | main 版本变更通过 CI 后;或 `v*` tag、手动指定已有 tag | 检查当前版说明、源码、格式与归档,验证 annotated tag 后发布 ZIP、SHA-256 和 CHANGELOG。 | diff --git a/main.py b/main.py index 6be6359..6a6fa35 100644 --- a/main.py +++ b/main.py @@ -84,7 +84,7 @@ def _group_entry_id(event) -> str | None: "astrbot_plugin_bond", "yiwuerxin, Timeance", "Bond 关系好感系统:三维关系与成员印象", - "0.5.11", + "0.5.12", "https://github.com/timeance/Astrbot_plugin_bond", ) class BondPlugin(Star): diff --git a/metadata.yaml b/metadata.yaml index 7fb6bc8..cdd8041 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -2,7 +2,7 @@ name: astrbot_plugin_bond display_name: Bond 关系好感系统 short_desc: 按 Bot 隔离的三维关系与成员印象 desc: 保存熟悉度、亲近度、信任度与成员印象,支持分级评估、人格适配及管理面板。 -version: 0.5.11 +version: 0.5.12 author: yiwuerxin, Timeance repo: https://github.com/timeance/Astrbot_plugin_bond tags: @@ -11,4 +11,4 @@ tags: - 人格适配 support_platforms: - aiocqhttp -astrbot_version: ">=4.28,<5" +astrbot_version: ">=4.28" diff --git a/scripts/smoke_astrbot.py b/scripts/smoke_astrbot.py index eea9369..a6864a4 100644 --- a/scripts/smoke_astrbot.py +++ b/scripts/smoke_astrbot.py @@ -1,4 +1,4 @@ -"""真实 AstrBot 4.28.0 装配 smoke;不连接平台、网络模型或真实 Provider。""" +"""真实 AstrBot 装配 smoke;不连接平台、网络模型或真实 Provider。""" from __future__ import annotations @@ -15,6 +15,124 @@ OLD_USER = "8001" +def check_framework_version() -> str: + import astrbot + + expected = os.environ.get("BOND_EXPECTED_ASTRBOT_VERSION") + if expected: + assert astrbot.__version__ == expected, (astrbot.__version__, expected) + return astrbot.__version__ + + +async def _check_persona(context, judge) -> None: + from unittest.mock import AsyncMock, patch + + from astrbot.core.persona_mgr import PersonaManager + + from astrbot_plugin_bond.services.self_impression_service import ( + SelfImpressionService, + ) + + manager = PersonaManager(None, SimpleNamespace(default_conf={})) + manager.personas_v3 = [ + {"name": "synthetic-one", "prompt": "合成人格一"}, + {"name": "synthetic-two", "prompt": "合成人格二"}, + ] + conversation = SimpleNamespace(persona_id="synthetic-one") + conversations = SimpleNamespace( + get_curr_conversation_id=AsyncMock(return_value="synthetic-conversation"), + get_conversation=AsyncMock(return_value=conversation), + ) + # 只替换会话与偏好存储,使用宿主真实的人格选择器。 + with ( + patch.object(context, "persona_manager", manager), + patch.object(context, "conversation_manager", conversations), + patch.object( + context, "astrbot_config_mgr", SimpleNamespace(get_conf=lambda _: {}) + ), + patch("astrbot.core.persona_mgr.sp.get_async", new=AsyncMock(return_value={})), + ): + impression = SelfImpressionService(context) + for persona_id, prompt in ( + ("synthetic-one", "合成人格一"), + ("synthetic-two", "合成人格二"), + ): + conversation.persona_id = persona_id + expected = (persona_id, prompt) + assert ( + await judge._persona_ctx_for("synthetic:group:7001", "aiocqhttp") + == expected + ) + assert ( + await impression._persona_ctx("synthetic:group:7001", "aiocqhttp") + == expected + ) + conversation.persona_id = "[%None]" + assert (await judge._persona_ctx_for("synthetic:group:7001", "aiocqhttp"))[ + 1 + ] == "" + assert await impression._persona_ctx("synthetic:group:7001", "aiocqhttp") == ( + "当前 Bot", + "", + ) + + +async def _check_dashboard_bridge(context) -> None: + import jwt + from fastapi import FastAPI, Request + + from astrbot.dashboard.api.auth import require_dashboard_user + from astrbot.dashboard.api.plugins import dashboard_plugin_extension_route + from astrbot.dashboard.asgi_runtime import FastAPIAppAdapter + from astrbot.dashboard.responses import ApiError + + app = FastAPI() + FastAPIAppAdapter(app) + app.state.core_lifecycle = SimpleNamespace(star_context=context) + app.state.jwt_secret = "synthetic-bond-smoke-signing-key-only" + token = jwt.encode( + {"username": "synthetic-admin"}, app.state.jwt_secret, algorithm="HS256" + ) + + async def call(endpoint, *, body=None, authenticated=False): + payload = json.dumps(body or {}).encode() + + async def receive(): + return {"type": "http.request", "body": payload, "more_body": False} + + headers = [(b"content-type", b"application/json")] + if authenticated: + headers.append((b"authorization", f"Bearer {token}".encode())) + request = Request( + { + "type": "http", + "app": app, + "method": "POST" if body is not None else "GET", + "path": f"/api/plug/astrbot_plugin_bond/{endpoint}", + "query_string": b"", + "headers": headers, + "scheme": "http", + "server": ("synthetic.invalid", 80), + }, + receive, + ) + try: + username = await require_dashboard_user(request) + except ApiError as exc: + return exc.status_code, None + response = await dashboard_plugin_extension_route( + f"astrbot_plugin_bond/{endpoint}", request, username + ) + return response.status_code, json.loads(response.body) + + assert (await call("bots"))[0] == 401 + assert (await call("profile", body={"username": "synthetic-admin"}))[0] == 401 + status, body = await call("bots", authenticated=True) + assert status == 200 and body["success"] is True + # 已认证写请求经宿主桥转发后,仍执行插件参数校验。 + assert (await call("profile", body={}, authenticated=True))[0] == 400 + + def _context(Context, config): context = Context( event_queue=asyncio.Queue(), @@ -56,7 +174,7 @@ async def check(plugin_dir: Path, runtime_dir: Path) -> None: from astrbot_plugin_bond.main import BondPlugin from astrbot_plugin_bond.storage.migrations import SCHEMA_VERSION - assert astrbot.__version__ == "4.28.0", astrbot.__version__ + check_framework_version() schema = json.loads((plugin_dir / "_conf_schema.json").read_text(encoding="utf-8")) config_path = runtime_dir / "bond_config.json" config = AstrBotConfig(str(config_path), schema=schema) @@ -201,6 +319,7 @@ async def stale_member(): } old_deps = await plugin._runtime.select(BOT_IDS[0], "per_group") + await _check_persona(context, old_deps.judge) # 通过真实 main 装配确认新安装默认,而非仅检查配置快照。 assert config["relation_mode"] == "galgame" assert old_deps.favor._relation_caps == dict( @@ -1006,6 +1125,7 @@ async def call(handler, path, method="GET", body=None, username=None): restored = await old_deps.favor.get(OLD_GROUP, OLD_USER) assert restored is not None and restored.favor == 12 assert (data_dir / "backups" / BOT_IDS[0] / backup_name).is_file() + await _check_dashboard_bridge(context) finally: await plugin.terminate() @@ -1111,8 +1231,8 @@ async def call(handler, path, method="GET", body=None, username=None): "Galgame×2额度、F30/A30/T60衰减、三维独立基线、新旧配置、窗口预算、回复钩子、scope 持久化、冻结 listener、18 路 WebUI、群白名单、主人标记、人格中立查询资料、私聊 Bot 发现、认证、备份恢复、损坏提示词降级、卸载。" ) print( - "LIMIT: 未启动完整 AstrBot dashboard HTTP server;认证通过 Quart g.username" - "模拟宿主中间件已写入的管理面板用户,不连接真实平台或模型。" + "LIMIT: 原生页面认证验证使用合成 JWT、真实宿主认证函数及 FastAPI/Quart 桥;" + "未启动完整 HTTP server 或浏览器,不连接真实平台或模型。" ) diff --git a/scripts/smoke_diagnostics.py b/scripts/smoke_diagnostics.py index be2e8b2..11f7d3d 100644 --- a/scripts/smoke_diagnostics.py +++ b/scripts/smoke_diagnostics.py @@ -1,4 +1,4 @@ -"""真实 AstrBot 4.28.0 诊断装配与宿主认证模拟;仅合成数据、无网络。""" +"""真实 AstrBot 诊断装配与宿主认证模拟;仅合成数据、无网络。""" from __future__ import annotations @@ -10,10 +10,11 @@ from pathlib import Path from types import SimpleNamespace -from smoke_astrbot import _context, _response_parts +from smoke_astrbot import _context, _response_parts, check_framework_version async def check(root, runtime): + version = check_framework_version() from astrbot.api import AstrBotConfig from astrbot.api.star import Context, StarTools from quart import Quart, g @@ -169,7 +170,7 @@ def failed_erase(selector): finally: await plugin.terminate() print( - "PASS diagnostics: 2 Bot/2 scope、旧配置默认档位与显式选择、真实配置重载、脱敏导出、认证拒绝、选择性清除、正式状态不变、关闭后历史管理。" + f"PASS AstrBot {version} diagnostics: 2 Bot/2 scope、旧配置默认档位与显式选择、真实配置重载、脱敏导出、认证拒绝、选择性清除、正式状态不变、关闭后历史管理。" ) print("LIMIT: Quart认证上下文为合成,不是完整HTTP登录/浏览器或真实聊天验收。") diff --git a/scripts/smoke_message_metadata.py b/scripts/smoke_message_metadata.py index 3a0b29b..31f93e7 100644 --- a/scripts/smoke_message_metadata.py +++ b/scripts/smoke_message_metadata.py @@ -1,4 +1,4 @@ -"""真实 AstrBot 4.28.0 消息元数据取证;仅合成 OneBot 数据,禁止网络。""" +"""真实 AstrBot 消息元数据取证;仅合成 OneBot 数据,禁止网络。""" from __future__ import annotations @@ -262,7 +262,9 @@ async def check() -> dict: from astrbot_plugin_bond.api.listeners import _chain_flags from astrbot_plugin_bond.core.assessment import locally_relevant - assert astrbot.__version__ == "4.28.0", astrbot.__version__ + from smoke_astrbot import check_framework_version + + check_framework_version() reply_messages = { 9101: _payload([_segment("text", text="合成 Bot 上文")], 9101, BOT), 9102: _payload([_segment("text", text="合成他人上文")], 9102, OTHER), diff --git a/scripts/smoke_passive_familiarity.py b/scripts/smoke_passive_familiarity.py index eb4bf1f..74359c4 100644 --- a/scripts/smoke_passive_familiarity.py +++ b/scripts/smoke_passive_familiarity.py @@ -1,4 +1,4 @@ -"""真实 AstrBot 4.28.0 的被动熟悉度钩子检查;合成事件、SQLite,禁止网络。""" +"""真实 AstrBot 的被动熟悉度钩子检查;合成事件、SQLite,禁止网络。""" from __future__ import annotations @@ -13,7 +13,7 @@ from pathlib import Path from unittest.mock import patch -from smoke_astrbot import _context +from smoke_astrbot import _context, check_framework_version BOT, GROUP, ACTIVE, DIRECT = "10001", "7001", "8001", "8002" NOW = 1_800_000_000.0 @@ -38,7 +38,7 @@ async def check(plugin_dir: Path, runtime_dir: Path): from astrbot_plugin_bond.main import BondPlugin from astrbot_plugin_bond.services.assessment_service import AssessmentConfig - assert astrbot.__version__ == "4.28.0" + check_framework_version() schema = json.loads((plugin_dir / "_conf_schema.json").read_text(encoding="utf-8")) config = AstrBotConfig(str(runtime_dir / "config.json"), schema=schema) assert config["passive_familiarity"] is True @@ -234,7 +234,7 @@ async def dispatch(current): finally: await legacy_plugin.terminate() print( - "PASS AstrBot 4.28.0: schema重载、真实事件/主钩子、自定义被动+0.6、触发者排除、A/T与全部保温不变、请求人格/历史保留、重试、后续直接评估及实际优先级排序。" + f"PASS AstrBot {astrbot.__version__}: schema重载、真实事件/主钩子、自定义被动+0.6、触发者排除、A/T与全部保温不变、请求人格/历史保留、重试、后续直接评估及实际优先级排序。" ) print( "LIMIT: 钩子直接调用,Provider为离线预置分类;未连接QQ、真实模型或启动完整平台pipeline/其他插件。高于1000的接管监听器仍可能先执行。" diff --git a/scripts/smoke_relation_runner.py b/scripts/smoke_relation_runner.py index c14212b..4e7f2e9 100644 --- a/scripts/smoke_relation_runner.py +++ b/scripts/smoke_relation_runner.py @@ -1,4 +1,4 @@ -"""真实 AstrBot 4.28 runner → 离线记录 Provider;全程合成数据,禁止网络。""" +"""真实 AstrBot runner → 离线记录 Provider;全程合成数据,禁止网络。""" from __future__ import annotations @@ -13,6 +13,8 @@ from types import SimpleNamespace from unittest.mock import patch +from smoke_astrbot import check_framework_version + BOT, GROUP, USER = "10001", "7001", "8001" @@ -43,7 +45,7 @@ async def check(runtime_dir: Path) -> None: from astrbot_plugin_bond.services.prompt_service import PromptService from astrbot_plugin_bond.storage.router import BotScopeStorageRouter - assert astrbot.__version__ == "4.28.0", astrbot.__version__ + check_framework_version() router = BotScopeStorageRouter(runtime_dir / "synthetic") levels = LevelTable.from_config(None) deps = Deps( @@ -234,7 +236,10 @@ def text(row): finally: await deps.registry.cancel_and_wait_all() await router.close() - print("PASS AstrBot 4.28.0 actual ToolLoopAgentRunner → offline Provider:", results) + print( + f"PASS AstrBot {astrbot.__version__} actual ToolLoopAgentRunner → offline Provider:", + results, + ) print( "LIMIT: 实际主消息/请求钩子直接调用;未启动完整平台 pipeline、真实模型或网络。" )