Skip to content

fix(plugin): 修复开放插件 v4 版本与来源持久化 - #805

Closed
dengyh wants to merge 2 commits into
TencentBlueKing:developfrom
dengyh:ai/fix-open-plugin-contract
Closed

fix(plugin): 修复开放插件 v4 版本与来源持久化#805
dengyh wants to merge 2 commits into
TencentBlueKing:developfrom
dengyh:ai/fix-open-plugin-contract

Conversation

@dengyh

@dengyh dengyh commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

变更内容

  • 目录同步在远端失败或响应畸形时返回明确错误,并复用 uniform_api schema 校验
  • 编辑器严格区分 component.version 的 wrapper 版本与子插件业务版本,不再给业务版本自动添加 v
  • 保存 uniform_api_plugin_id / uniform_api_plugin_source_key,兼容并可修复此前误存业务版本的 v4 节点
  • uniform_api 配置新增可选 source_key,允许多个展示 api_key 共享同一个准入与执行来源
  • 同源展示配置的目录按 source_key 聚合后一次性刷新,避免两个入口互相将插件标记下架
  • 流程编辑器按 api_key 展示与查询,按真实 source_key 保存和执行

验证

  • pytest tests/interface/space/test_space_config.py tests/interface/plugin/services/test_open_plugin_catalog.py tests/interface/plugin/services/test_open_plugin_grant.py tests/interface/plugin/services/test_open_plugin_snapshot.py -v --no-cov
  • 49 tests passed
  • 修改 Vue 文件 ESLint、pre-commit 通过
  • 完整 webpack 在本地因已安装依赖缺少 @blueking/bkflow-canvas-editor-vue2 未完成,报错位于未改动的 TaskOperation.vue

--story=133649781

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查总结

本 PR 为开放插件系统引入了 wrapper_versionplugin_sourceplugin_code 等字段的全链路持久化,从 meta schema 校验到前端节点配置保存/回显均有覆盖。整体思路清晰,向后兼容处理(旧节点 fallback)合理,测试覆盖充分。

主要建议:

  1. 后端错误处理应使用项目自定义异常类而非泛化的 ValueError
  2. 测试文件的 # -*- coding: utf-8 -*- 文件头不应被删除
  3. 前端硬编码的 'v4.0.0' fallback 建议抽为常量

无 Critical 级别问题。

)
return list_result.json_resp.get("data", {}).get("apis", [])
if not list_result.result:
raise ValueError("开放插件目录请求失败: {}".format(list_result.message))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 建议使用项目自定义异常 APIRequestError 替代 ValueError,便于上层调用(如 celery 定时同步任务)做分类处理和结构化日志。

if not list_result.result:
raise ValueError("开放插件目录请求失败: {}".format(list_result.message))
if not isinstance(list_result.json_resp, dict):
raise ValueError("开放插件目录响应不是合法 JSON")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 同上,APIResponseError 更贴切——请求成功但响应格式异常。

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# -*- coding: utf-8 -*- 文件头被移除了,项目其他文件仍保留此声明,建议恢复以保持一致。

? savedPluginVersion || latestVersion || defaultVersion
: component.version || 'v2.0.0';
// 兼容旧版页面曾把业务版本误存到 component.version 的节点。
const wrapperVersion = savedWrapperVersion || (isOpenPlugin ? 'v4.0.0' : component.version || 'v2.0.0');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'v4.0.0' 硬编码 fallback 建议抽为文件顶部常量(如 DEFAULT_OPEN_PLUGIN_WRAPPER_VERSION),与后端 WRAPPER_VERSION 保持语义对齐。

await this.loadAtomConfig({ atom: plugin, version: apiVersion, space_id: this.spaceId });
// component.version 保存 uniform_api 包装器版本,业务版本独立保存在隐藏字段中。
const wrapperVersion = resp.data.wrapper_version || resp.data.version || 'v2.0.0';
await this.loadAtomConfig({ atom: plugin, version: wrapperVersion, space_id: this.spaceId });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storeOutputs 加了 || [] fallback 很好,避免了 wrapperVersion 不在 pluginOutput 中时的 undefined 报错。

@codecov-commenter

codecov-commenter commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.26%. Comparing base (c900e20) to head (fcbe73c).
⚠️ Report is 8 commits behind head on develop.

Files with missing lines Patch % Lines
bkflow/plugin/services/open_plugin_catalog.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #805      +/-   ##
===========================================
- Coverage    83.28%   83.26%   -0.02%     
===========================================
  Files          319      320       +1     
  Lines        20114    20143      +29     
===========================================
+ Hits         16751    16773      +22     
- Misses        3363     3370       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增量审查总结

第二次提交引入了 source_key 配置项的完整支持——展示配置与执行来源分层,目录同步按有效 source_key 聚合后刷新。实现清晰,测试覆盖充分,文档同步及时。

之前的评论状态

之前报告的问题(ValueError → 自定义异常、coding: utf-8 文件头、前端 'v4.0.0' 硬编码)在本次提交中未修改,仍然建议处理。

新代码审查结论

本次增量无新的 Critical/Important 级别问题。新增的 _effective_source_key 方法兼容 dict 和 Pydantic model 两种配置格式,sync_space_plugins 的 id-based 聚合逻辑正确避免了多入口互相标记下架的问题。前端 crtSourceKey 计算属性和 apiTabListsourceKey 传递链路完整。

@dengyh

dengyh commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

相关提交已按分支规范迁移并推送至 feat/sops-open-plugin-backend(PR #698)。develop 仅作为联调目标,本 PR 不再单独合入。

@dengyh dengyh closed this Jul 17, 2026
@dengyh
dengyh deleted the ai/fix-open-plugin-contract branch July 17, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants