Merged
feat(gates): 引入仓内门禁骨架与依赖图门禁 #54
feat(gates): 引入仓内门禁骨架与依赖图门禁 #54
Merged
JunyiAdd on Sep 24
Total: 5 files changed+1504-3
MOAT.xml+16-3
@@ -29,12 +29,22 @@
29 <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/>29 <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/>
30 <filteritem type="filename" name="*.yml" desc="YAML configuration files, no license header required"/>30 <filteritem type="filename" name="*.yml" desc="YAML configuration files, no license header required"/>
31 <filteritem type="filename" name="*.csv" desc="CSV test case files, no license header required"/>31 <filteritem type="filename" name="*.csv" desc="CSV test case files, no license header required"/>
32- </filefilter>32+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/LICENSE-APACHE" desc="Apache License 2.0 full text shipped with the plugin; it is the licence itself, not a file carrying one."/>
33+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/README.OpenSource" desc="Third-party component register in JSON; a header would break the array."/>
34+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
35+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
36+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>
37+</filefilter>
33 <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">38 <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
34 <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no copyright header required"/>39 <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no copyright header required"/>
35 <filteritem type="filename" name="*.yml" desc="YAML configuration files, no copyright header required"/>40 <filteritem type="filename" name="*.yml" desc="YAML configuration files, no copyright header required"/>
36 <filteritem type="filename" name="*.csv" desc="CSV test case files cannot contain a copyright header without breaking their schema"/>41 <filteritem type="filename" name="*.csv" desc="CSV test case files cannot contain a copyright header without breaking their schema"/>
37- </filefilter>42+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/LICENSE-APACHE" desc="Apache License 2.0 full text shipped with the plugin; it is the licence itself, not a file carrying one."/>
43+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/README.OpenSource" desc="Third-party component register in JSON; a header would break the array."/>
44+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
45+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
46+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>
47+</filefilter>
38 <filefilter name="licenseFileNamePolicyFilter" desc="Explicitly licensed components excluded from the repository default license policy">48 <filefilter name="licenseFileNamePolicyFilter" desc="Explicitly licensed components excluded from the repository default license policy">
39 <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE."/>49 <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE."/>
40 <filteritem type="filepath" name="vendor/cannbot-skills/.*" desc="Git submodule distributed under its own repository license."/>50 <filteritem type="filepath" name="vendor/cannbot-skills/.*" desc="Git submodule distributed under its own repository license."/>
@@ -86,7 +96,10 @@
86 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/LICENSE-APACHE" desc="Apache License 2.0 full text shipped for the ascendopgenagent-derived files."/>96 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/LICENSE-APACHE" desc="Apache License 2.0 full text shipped for the ascendopgenagent-derived files."/>
87 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/ascendc-evaluation/scripts/template/CppExtension/setup.py" desc="Contains a block taken from the Ascend samples CppExtensionInvocation setup template (gitee.com/ascend/samples, Apache-2.0); records that source in its header."/>97 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/ascendc-evaluation/scripts/template/CppExtension/setup.py" desc="Contains a block taken from the Ascend samples CppExtensionInvocation setup template (gitee.com/ascend/samples, Apache-2.0); records that source in its header."/>
88 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/ascendc-evaluation/scripts/template/CppExtension/csrc/pytorch_npu_helper.hpp" desc="Third-party torch_npu helper header (BSD-3-Clause); vendored for the pybind operator template, keeps upstream BSD-3-Clause license, exempt from CANN-2.0 header policy."/>98 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/ascendc-evaluation/scripts/template/CppExtension/csrc/pytorch_npu_helper.hpp" desc="Third-party torch_npu helper header (BSD-3-Clause); vendored for the pybind operator template, keeps upstream BSD-3-Clause license, exempt from CANN-2.0 header policy."/>
89- </filefilter>99+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/README.OpenSource" desc="Third-party component register in JSON; a header would break the array."/>
100+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
101+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
102+</filefilter>
90 <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">103 <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
91 </filefilter>104 </filefilter>
92 <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">105 <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
@@ -0,0 +1,163 @@
1+#!/usr/bin/env bash
2+# -----------------------------------------------------------------------------------------------------------
3+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
4+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5+# CANN Open Software License Agreement Version 2.0 (the "License").
6+# Please refer to the License for details. You may not use this file except in compliance with the License.
7+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9+# See LICENSE in the root of the software repository for the full text of the License.
10+# -----------------------------------------------------------------------------------------------------------
11+# =============================================================================
12+# report.sh - Output layer for the repository gates
13+# =============================================================================
14+# The gates under tests/unit/ come from cann/cannbot-skills, where they source
15+# tests/lib/test-helpers.sh — a 64 KB library whose remaining functions drive a
16+# CLI-based behaviour suite that this repository does not run. This file
17+# provides the part those gates use, with the same names and the same output,
18+# so a gate moves across without an edit beyond its `source` line.
19+#
20+# Contract: 11 functions, 4 tracking variables, 3 path variables, 7 colour
21+# variables. The gates run under `set -euo pipefail`; a missing name aborts
22+# them, so every name below is defined unconditionally.
23+# =============================================================================
24+ 
25+# Paths. SKILLS_DIR is the repository root and keeps its name from the source
26+# repository, where the root is the Skill tree itself.
27+LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
28+TESTS_DIR="$(cd "$LIB_DIR/.." && pwd)"
29+SKILLS_DIR="$(cd "$LIB_DIR/../.." && pwd)"
30+ 
31+# Test tracking. declare -g so the counters stay global even when this file is
32+# sourced from inside a function, where a plain assignment would make them local.
33+declare -g TEST_PASSED=0
34+declare -g TEST_FAILED=0
35+declare -g TEST_SKIPPED=0
36+declare -g TEST_START_TIME=0
37+ 
38+# ANSI colour codes
39+RED='\033[0;31m'
40+GREEN='\033[0;32m'
41+YELLOW='\033[0;33m'
42+BLUE='\033[0;34m'
43+CYAN='\033[0;36m'
44+BOLD='\033[1m'
45+NC='\033[0m' # No Color
46+ 
47+enable_colors() {
48+ RED='\033[0;31m'
49+ GREEN='\033[0;32m'
50+ YELLOW='\033[0;33m'
51+ BLUE='\033[0;34m'
52+ CYAN='\033[0;36m'
53+ BOLD='\033[1m'
54+ NC='\033[0m'
55+}
56+ 
57+disable_colors() {
58+ RED=''
59+ GREEN=''
60+ YELLOW=''
61+ BLUE=''
62+ CYAN=''
63+ BOLD=''
64+ NC=''
65+}
66+ 
67+# NO_COLOR wins over FORCE_COLOR; without either, colour follows the terminal.
68+setup_colors() {
69+ if [ -n "${NO_COLOR:-}" ]; then
70+ disable_colors
71+ elif [ -n "${FORCE_COLOR:-}" ]; then
72+ enable_colors
73+ elif [ -t 1 ]; then
74+ enable_colors
75+ else
76+ disable_colors
77+ fi
78+}
79+ 
80+print_pass() {
81+ echo -e " ${GREEN}[PASS]${NC} $*"
82+}
83+ 
84+print_fail() {
85+ echo -e " ${RED}[FAIL]${NC} $*"
86+}
87+ 
88+print_info() {
89+ echo -e " ${BLUE}[INFO]${NC} $*"
90+}
91+ 
92+print_warn() {
93+ echo -e " ${YELLOW}[WARN]${NC} $*"
94+}
95+ 
96+print_error() {
97+ echo -e " ${RED}[ERROR]${NC} $*"
98+}
99+ 
100+print_section_header() {
101+ local name="$1"
102+ echo ""
103+ echo -e "${BOLD}${CYAN}=== $name ===${NC}"
104+ echo ""
105+}
106+ 
107+print_status_passed() {
108+ echo -e "${GREEN}${BOLD}STATUS: PASSED${NC}"
109+}
110+ 
111+print_status_failed() {
112+ echo -e "${RED}${BOLD}STATUS: FAILED${NC}"
113+}
114+ 
115+# Usage: print_test_banner "Test Name" ["description"]
116+print_test_banner() {
117+ local name="$1"
118+ local description="${2:-}"
119+ 
120+ echo ""
121+ echo "========================================"
122+ echo " $name"
123+ echo "========================================"
124+ [ -n "$description" ] && echo "" && echo "$description"
125+ echo ""
126+}
127+ 
128+# Usage: init_test_tracking
129+init_test_tracking() {
130+ TEST_PASSED=0
131+ TEST_FAILED=0
132+ TEST_SKIPPED=0
133+ TEST_START_TIME=$(date +%s)
134+}
135+ 
136+# Usage: print_test_summary
137+# Returns 1 when anything failed, so a gate can end with it.
138+print_test_summary() {
139+ local end_time
140+ end_time=$(date +%s)
141+ local duration=$((end_time - TEST_START_TIME))
142+ 
143+ echo ""
144+ echo "========================================"
145+ echo -e " ${BOLD}Test Results Summary${NC}"
146+ echo "========================================"
147+ echo ""
148+ echo -e " ${GREEN}Passed:${NC} $TEST_PASSED"
149+ echo -e " ${RED}Failed:${NC} $TEST_FAILED"
150+ echo -e " ${YELLOW}Skipped:${NC} $TEST_SKIPPED"
151+ echo " Duration: ${duration}s"
152+ echo ""
153+ 
154+ if [ "$TEST_FAILED" -gt 0 ]; then
155+ print_status_failed
156+ return 1
157+ else
158+ print_status_passed
159+ return 0
160+ fi
161+}
162+ 
163+setup_colors
@@ -0,0 +1,153 @@
1+#!/usr/bin/env bash
2+# -----------------------------------------------------------------------------------------------------------
3+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
4+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5+# CANN Open Software License Agreement Version 2.0 (the "License").
6+# Please refer to the License for details. You may not use this file except in compliance with the License.
7+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9+# See LICENSE in the root of the software repository for the full text of the License.
10+# -----------------------------------------------------------------------------------------------------------
11+# =============================================================================
12+# run-gates.sh - Run the repository gates
13+# =============================================================================
14+# Usage:
15+# bash tests/run-gates.sh [gate ...]
16+#
17+# With no argument every registered gate runs. An argument selects one gate by
18+# the name it is registered under.
19+#
20+# Exit codes:
21+# 0 every gate that ran passed and every prerequisite was met
22+# 1 a gate failed
23+# 2 every gate that ran passed, but a prerequisite was missing and the gates
24+# needing it were skipped
25+#
26+# A gate whose prerequisite is missing is skipped rather than run: without the
27+# vendored Skill repository the dependency graph gate would report every
28+# submodule-provided skill as absent, which says nothing about the change under
29+# test and buries anything that does.
30+# =============================================================================
31+ 
32+set -uo pipefail
33+ 
34+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35+source "$SCRIPT_DIR/lib/report.sh"
36+ 
37+REPO_ROOT="$SKILLS_DIR"
38+SKILLS_SUBMODULE="vendor/cannbot-skills"
39+ 
40+# 判定范围与 CI 中的激活范围一致:只有这些路径下的发现判红,其余照常打印
41+# 但记为告警。marketplace.json 计入,因为 cake 自身的登记就写在那里;
42+# 代价是该文件中与 cake 无关的错误也会判红。
43+export DG_ERROR_SCOPE="plugins-community/collaborative-agent-kernel-evolution/:tests/:.claude-plugin/marketplace.json"
44+ 
45+# Registered gates, in run order: <name>:<path relative to tests/>
46+GATES=(
47+ "dependency-graph:unit/test-dependency-graph.sh"
48+)
49+ 
50+# Gates that cannot run without the vendored Skill repository checked out.
51+GATES_NEEDING_SKILLS_SUBMODULE=(
52+ "dependency-graph"
53+)
54+ 
55+# Gates that cannot run without python3 and PyYAML.
56+GATES_NEEDING_PYYAML=(
57+ "dependency-graph"
58+)
59+ 
60+contains() {
61+ local needle="$1"
62+ shift
63+ local item
64+ for item in "$@"; do
65+ [ "$item" = "$needle" ] && return 0
66+ done
67+ return 1
68+}
69+ 
70+skills_submodule_present() {
71+ [ -e "$REPO_ROOT/$SKILLS_SUBMODULE/.git" ]
72+}
73+ 
74+pyyaml_present() {
75+ python3 -c "import yaml" >/dev/null 2>&1
76+}
77+ 
78+missing_prerequisite() {
79+ local name="$1"
80+ if contains "$name" "${GATES_NEEDING_SKILLS_SUBMODULE[@]}" && ! skills_submodule_present; then
81+ echo "$SKILLS_SUBMODULE is not checked out; run: git submodule update --init --recursive --depth 1"
82+ return 0
83+ fi
84+ if contains "$name" "${GATES_NEEDING_PYYAML[@]}" && ! pyyaml_present; then
85+ echo "python3 cannot import yaml; run: pip install PyYAML"
86+ return 0
87+ fi
88+ return 1
89+}
90+ 
91+selected=("$@")
92+prerequisite_missing=0
93+ 
94+print_test_banner "CANNBot Repository Gates" "Repository root: $REPO_ROOT"
95+init_test_tracking
96+ 
97+for entry in "${GATES[@]}"; do
98+ name="${entry%%:*}"
99+ path="${entry#*:}"
100+ 
101+ if [ "${#selected[@]}" -gt 0 ] && ! contains "$name" "${selected[@]}"; then
102+ continue
103+ fi
104+ 
105+ reason="$(missing_prerequisite "$name")"
106+ if [ -n "$reason" ]; then
107+ print_section_header "$name"
108+ print_warn "skipped: $reason"
109+ TEST_SKIPPED=$((TEST_SKIPPED + 1))
110+ prerequisite_missing=1
111+ continue
112+ fi
113+ 
114+ print_section_header "$name"
115+ if bash "$SCRIPT_DIR/$path"; then
116+ TEST_PASSED=$((TEST_PASSED + 1))
117+ print_pass "$name"
118+ else
119+ TEST_FAILED=$((TEST_FAILED + 1))
120+ print_fail "$name"
121+ fi
122+done
123+ 
124+if [ "${#selected[@]}" -gt 0 ]; then
125+ for name in "${selected[@]}"; do
126+ registered=0
127+ for entry in "${GATES[@]}"; do
128+ [ "${entry%%:*}" = "$name" ] && registered=1
129+ done
130+ if [ "$registered" -eq 0 ]; then
131+ print_error "no such gate: $name"
132+ TEST_FAILED=$((TEST_FAILED + 1))
133+ fi
134+ done
135+fi
136+ 
137+# print_test_summary reports only the gates that ran, so the verdict below it is
138+# what the caller should read.
139+summary_rc=0
140+print_test_summary || summary_rc=1
141+ 
142+if [ "$summary_rc" -ne 0 ]; then
143+ print_error "run-gates: a gate failed"
144+ exit 1
145+fi
146+ 
147+if [ "$prerequisite_missing" -ne 0 ]; then
148+ print_error "run-gates: a prerequisite was missing; the gates needing it did not run"
149+ exit 2
150+fi
151+ 
152+print_pass "run-gates: every registered gate passed"
153+exit 0
@@ -0,0 +1,123 @@
1+#!/usr/bin/env bash
2+# -----------------------------------------------------------------------------------------------------------
3+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
4+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5+# CANN Open Software License Agreement Version 2.0 (the "License").
6+# Please refer to the License for details. You may not use this file except in compliance with the License.
7+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9+# See LICENSE in the root of the software repository for the full text of the License.
10+# -----------------------------------------------------------------------------------------------------------
11+# =============================================================================
12+# Test: Dependency Graph Integrity
13+# =============================================================================
14+# Validates cross-references between marketplace.json, plugin.json, AGENTS.md,
15+# and agent .md files.
16+#
17+# Rules tested:
18+# - DG-01: marketplace.json skills paths exist
19+# - DG-02: marketplace.json dependencies valid
20+# - DG-03: plugin.json agents paths exist
21+# - DG-04: plugin.json dependencies valid
22+# - DG-05: AGENTS.md skills references exist
23+# - DG-06: Agent .md skills references exist
24+# - DG-07: Orphaned skills detection (warn)
25+# - DG-08: Orphaned agents detection (warn)
26+# - DG-09: Circular dependency detection
27+# - DG-10: init.sh INCLUDED_SKILLS covers all marketplace-declared skills
28+# - DG-11: Workflow/runtime skill references covered by install whitelist
29+# =============================================================================
30+ 
31+set -euo pipefail
32+ 
33+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34+source "$SCRIPT_DIR/../lib/report.sh"
35+ 
36+echo "=== Test: Dependency Graph Integrity ==="
37+echo ""
38+echo "Validates cross-references between marketplace.json, plugin.json,"
39+echo "AGENTS.md, and agent .md files."
40+echo "Run time: ~5 seconds (no CLI needed)"
41+echo ""
42+ 
43+DEPENDENCY_VALIDATOR="$LIB_DIR/dependency_validator.py"
44+ 
45+if [ ! -f "$DEPENDENCY_VALIDATOR" ]; then
46+ print_error "dependency_validator.py not found: $DEPENDENCY_VALIDATOR"
47+ exit 1
48+fi
49+ 
50+print_section_header "Dependency Graph Validation (DG-01 to DG-09)"
51+ 
52+tmp=$(mktemp)
53+exit_code=0
54+python3 "$DEPENDENCY_VALIDATOR" "$SKILLS_DIR" > "$tmp" 2>&1 || exit_code=$?
55+ 
56+error_count=0
57+warn_count=0
58+summary_skills=0
59+summary_agents=0
60+ 
61+parsed=$(python3 - <<'PYEOF' "$tmp"
62+import json, sys
63+with open(sys.argv[1]) as f:
64+ for line in f:
65+ line = line.strip()
66+ if not line:
67+ continue
68+ try:
69+ obj = json.loads(line)
70+ except json.JSONDecodeError:
71+ continue
72+ if "summary" in obj:
73+ s = obj["summary"]
74+ print(f"SUMMARY\t{s.get('total_skills',0)}\t{s.get('total_agents',0)}")
75+ else:
76+ level = obj.get("level", "")
77+ rule = obj.get("rule", "")
78+ msg = obj.get("msg", "")
79+ print(f"{level}\t{rule}\t{msg}")
80+PYEOF
81+)
82+ 
83+while IFS=$'\t' read -r field1 field2 field3; do
84+ [ -z "$field1" ] && continue
85+ if [ "$field1" = "SUMMARY" ]; then
86+ summary_skills="$field2"
87+ summary_agents="$field3"
88+ continue
89+ fi
90+ case "$field1" in
91+ error)
92+ ((error_count++)) || true
93+ print_error "${field2}: ${field3}"
94+ ;;
95+ warn)
96+ ((warn_count++)) || true
97+ print_warn "${field2}: ${field3}"
98+ ;;
99+ esac
100+done <<< "$parsed"
101+ 
102+rm -f "$tmp"
103+ 
104+echo ""
105+echo "========================================"
106+echo -e " ${BOLD}Dependency Graph Test Summary${NC}"
107+echo "========================================"
108+echo ""
109+echo " Total skills: $summary_skills"
110+echo " Total agents: $summary_agents"
111+echo -e " Errors: ${RED}$error_count${NC}"
112+echo -e " Warnings: ${YELLOW}$warn_count${NC}"
113+echo ""
114+ 
115+if [ $error_count -gt 0 ]; then
116+ print_status_failed
117+ echo ""
118+ echo "Please fix the broken dependency references."
119+ exit 1
120+else
121+ print_status_passed
122+ exit 0
123+fi