Merged
feat(gates): 引入仓内门禁骨架与依赖图门禁 #54
feat(gates): 引入仓内门禁骨架与依赖图门禁 #54
Merged
JunyiAdd on Sep 24
Junyi
JunyiCollaborators
Sep 24

这个 MR 做什么

从 cann/cannbot-skills 搬入依赖图门禁,补上本仓运行它所缺的输出层与 runner,新增一个只在 cake 改动时激活的 CI stage,并修掉 cake 五个文件在 scripts/oat_check.sh 下的 OAT 发现。

A  tests/lib/dependency_validator.py
A  tests/lib/report.sh
A  tests/run-gates.sh
A  tests/unit/test-dependency-graph.sh
A  .gitcode/workflows/gates_action.yml
M  .gitcode/workflows/cannbot-actions.yml     (+9 行,新增 stage3)
M  OAT.xml                                    (+15 行,头部策略过滤器登记)

一、门禁骨架

tests/lib/report.sh(新建) 导入源的门禁 source 的是 tests/lib/test-helpers.sh——一个 64 KB 的库,其余函数服务于本仓不跑的 CLI 行为用例。本文件只提供这些门禁用到的部分:11 个函数、4 个计数变量、3 个路径变量、7 个颜色变量,名称与输出格式与导入源一致。后续门禁移过来只需改 source 一行。

tests/unit/test-dependency-graph.sh(搬入) 与导入源的差异只有 source 那一行。

tests/lib/dependency_validator.py(搬 767 行,七处改动)

  1. _is_inside_nested_git_repo 原实现从 file_path.parent 起向上找 .git,不在仓库根停止。检出目录的任一祖先含 .git 时整棵树被剪枝,技能与 agent 均发现为 0。改为只检查仓库根与目标路径之间的目录。
  2. marketplace 的 source 支持对象形(git-subdir 按 .gitmodules 的 URL 映射到子模块工作区路径,local 按仓库根解析)。原实现对其调用 .lstrip 直接抛 AttributeError。
  3. 子模块内的技能根(ops/graph/model/infra)单独登记——工作区遍历会剪掉子模块。
  4. 新增 DG-12:plugin-sources.json 声明的技能路径必须存在。
  5. DG-07 只统计本仓自带的技能。
  6. DG-11 的安装白名单增加 plugin-sources.json 一路,此前对 ops-direct-invoke 整条规则空转。
  7. 新增 DG_ERROR_SCOPE:范围内的发现判红,范围外降为告警并标注,规则名与内容不变。未设时行为与导入源一致。

另:_collect_plugin_agent_skills 深度 6、类内方法排列不符 G.CLS.06、_output_findings 直接写 stdout 触发 G.LOG.02,均为导入源既有问题,因该文件在本仓算新增会被记为新发现,一并整改。整改前后逐方法 AST 比对一致,校验器输出逐字节不变。

tests/run-gates.sh(新建) 按名登记门禁并汇总。前置条件缺失时跳过对应门禁并以退出码 2 结束。退出码 0 全过、1 门禁失败、2 前置缺失。

二、激活范围与判定范围

cannbot-actions.yml 只加 9 行声明 stage3,现有三个 stage 与 on: 触发器均未改动。gates_action.yml 照 cann/cannbot-skills 的 ut_action.yml:先 uses: checkout 取到工作区路径,再执行仓内脚本。

激活范围(未命中即打印原因并退出 0)与判定范围(范围外的发现降为告警)一致:

plugins-community/collaborative-agent-kernel-evolution/    cake 插件本体
tests/                                                     门禁自身
.claude-plugin/marketplace.json                            cake 的登记写在这里(仅判定范围)

这样别人插件的缺陷不会让 cake 的 PR 变红,本门禁也不会去红别人。代价是 marketplace.json 中与 cake 无关的错误也会判红,这一点在代码注释中写明。

平台的 if: 在两个仓里只出现过 default() 与 always(),没有按路径过滤的先例,所以激活判断放在脚本里。改动清单两级取法:merge commit 用 HEAD^1..HEAD,否则退回 origin/<目标分支>...HEAD,都取不到时打印原因并退出 0——宁可漏跑,也不让与 cake 无关的 MR 因为本 stage 变红。

触发沿用现有的 /compile,未加 pull_request 自动触发:两个仓的 on: 都无该触发器,平台是否支持未经证实,而 on: 写错会影响该文件的全部 stage。

三、OAT.xml

MR !15 把 cake 的第三方文件登记进了 licenseFileNamePolicyFilter,但那个过滤器挂在 policyitem type="license" 上,管的是默认许可归属;而 scripts/oat_check.sh(master 的 ce5bb20 引入)报出的是 License Header Invalid 与 Copyright Header Invalid,对应 defaultPolicyFilter 与 copyrightPolicyFilter。本次把五个按格式无法承载许可头的文件登记进这三个过滤器:

文件 为什么不能带头
LICENSE-APACHE 许可证全文本身
README.OpenSource 第三方组件登记,JSON 数组
requirements.txt ×2 pip 依赖清单,注释会被当依赖行
skills/op-dashboard/assets/chart.umd.min.js Chart.js 4.4.7 (MIT) 压缩产物

做法与 master 在同两个过滤器里登记 *.yaml / *.yml / *.csv 一致。

实测 scripts/oat_check.sh:修前 45 条(cake 8、tests/ 1),修后 37 条(cake 与 tests/ 均为 0)。剩余 37 条全部落在 master 既有文件上(plugins-community 20、plugins-official 9、script 7、docs 1),与本分支无关,另行报给引入该体系的一方(issue #16)。该检查目前只是本地 pre-commit 钩子,.gitcode/ 中无引用。

四、验证

仓库根为本分支,master a17dd89,子模块 9ae606b3:

  • bash tests/run-gates.sh 退出码 0,errors 0、warnings 19、total_skills 155、total_agents 31
  • 反向①:给 cake 的 agents/cake.md frontmatter 加不存在的技能名 → errors=1(DG-06)
  • 反向②:给 plugins-community/triton-auto-evolve 的 AGENTS.md 同样加一个 → errors=0,仅记 DG-05 告警
  • 反向③:把 marketplace 中 ops 包的 path 改错 → errors=20(DG-01)
  • 反向④:全部复原 → errors=0
  • 前置缺失:移走 vendor/cannbot-skills/.git 后 run-gates.sh 退出码 2,输出 0 条 DG-01
  • bash -u 下 runner 与门禁脚本均无 unbound variable
  • npm --prefix script test 84/84 全过
  • 激活逻辑 9 个场景(merge commit / 非 merge commit / 取不到清单 / 激活后失败)全部符合预期
  • pycodestyle 无告警,标定过的 CodeCheck 规则复查为 0

上述反向验证均在本地改后复原,本 MR 的 diff 不含这些改动。

未验证:本 stage 在 gitcode 上的实际行为——平台是否认 uses: .gitcode/workflows/ 这种仓内引用、checkout 后能否拉子模块、容器内有无 python3 与 PyYAML。本 MR 改到 tests/,会命中激活条件。

五、门禁在当前 master 上报出的 19 条告警

不阻断(只按 errors 判红),列出供各插件归属方参考。其中两条值得单独说明:

DG-04  Dependency 'ascendc-port-orchestrator-shared-skills' not found in marketplace.json
DG-04  Dependency 'cannbot-knowledge-consumer-skills' not found in marketplace.json
       plugins-community/ascendc-port-orchestrator/.claude-plugin/plugin.json

2348eda 把 ascendc-port-orchestrator 从 cann/cannbot-skills 迁入时,未把它 plugin.json 声明的两个依赖对应的 marketplace 条目一并带来;二者在 cannbot-skills 的 marketplace 中均存在。该插件的依赖在本仓解析不了,属其归属方处理。

其余 17 条为 DG-07(插件自带技能无清单声明)与 DG-08(plugins-official/ops-registry-invoke/ 无 .claude-plugin/plugin.json)。

🤖 Generated with Claude Code

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Junyi's contribution.)
JunyiJunyiCollaborators
Sep 24 Created pull request, commit 854a5adf
CANN-robotCANN-robotCollaborators
Sep 24 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Sep 24 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 24 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/cannbot ✅ 汤平川, 金炯 (2/2) ✅ 汤平川 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

gcw_P2Mh5H1S, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
Junyi
JunyiCollaborators
Sep 24 Comments:

compile

likedislike
74 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 29 Added label: approved
JunyiJunyiCollaborators
Sep 29 Pre merge succeeded (commit_id: 6090f32efd67c10ed820de6ed8a3cfa04659fb9e)
jon_jin
jon_jinCollaborators
Oct 28 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Oct 28 Added label: lgtm
CANN-robotCANN-robotCollaborators
Oct 28 Merged pull request