已开启
fix(ci): build.sh 变更分析失败时不再静默跳过测试 #136
fix(ci): build.sh 变更分析失败时不再静默跳过测试 #136
已开启
lizhe创建于 22 天前
lizhe
22 天前

问题

build.sh:98 调用变更分析工具(scripts/ci/parse_changed_ops.py)后没有检查返回码:

ops=$("$PYTHON" "$REPO_ROOT/scripts/ci/parse_changed_ops.py" "$CHANGED_LIST")
echo "affected ops: [$ops]"
if [[ -z "$ops" ]]; then
    echo "[INFO] no operator affected, skip tests"
    exit 0
fi

工具异常退出时 stdout 为空,于是被执行成「没有算子受影响」,整个算子测试阶段零用例执行却判定成功(CI 假绿)。这是 #22「命令失败后仍可能以成功结束」的一种具体形态。

可触发的真实场景:

  1. 运行的 python 缺 PyYAML — build.sh 自己在第 52-57 行处理了「conda 环境找不到就退回默认 python」,退回后的系统 python 装不全 requirements.txt 里的包时,分析工具直接 ModuleNotFoundError 退出;
  2. test/test_config.yaml schema 被改坏 — 例如新增 module 结点时把 src 写成 mapping(Module.__init__ 里 Path(p) 直接 TypeError),此时该 PR 自己的用例也会被静默跳过;
  3. 其它任何分析侧异常(文件路径/编码/依赖问题)。

改动

if ! ops=$("$PYTHON" "$REPO_ROOT/scripts/ci/parse_changed_ops.py" "$CHANGED_LIST"); then
    echo "[ERROR] changed-file analysis failed ($CHANGED_LIST); refusing to skip tests" >&2
    exit 1
fi

只在分析成功且确实无算子受影响时才跳过(skip_all_tests: true 的既定跳过路径不受影响)。

验证(本机 before/after 实跑)

同一份 build.sh(before = master e5f6641,after = 本 MR),同一份真实 scripts/ci/parse_changed_ops.py / operator_list.yaml / run_tests.sh / test/test_config.yaml;沙箱仅把 install_deps.sh 换成桩(真脚本要求平台本地 cannbotdsl/torch wheel),并把 PYTHON 指向一个只做 MSYS→原生路径转换的 wrapper(CI 在 Linux 上无此问题)。

场景 before after
① 分析工具因缺 PyYAML 崩溃(rc=1,stdout 空) rc=0,[INFO] no operator affected, skip tests(零用例却成功) rc=1,[ERROR] changed-file analysis failed … refusing to skip tests
② test_config.yaml schema 坏(TypeError) rc=0,同上静默跳过 rc=1,明确报错
③ 对照:skip_all_tests: true 的既定跳过 rc=0,no operator affected rc=0,no operator affected(无回归)
④ 对照:正常识别算子 rc=4,affected ops: [flash_attn] rc=4,affected ops: [flash_attn](无回归)

场景④ 的 rc=4 来自沙箱里 test/flash_attn 用例目标不存在(pytest 用法错误),两个版本一致;它同时说明测试阶段的返回码本来就是透传的。

没测什么:本机没有 cannbotdsl / torch / torch_npu / NPU,没有跑通完整的 build.sh 流水线(未执行真实算子用例),也没有在平台的 conda 环境里复现场景①;以上结论限于脚本层的 before/after 行为对比。bash -n build.sh 通过,本机无 shellcheck。

范围边界

#22 里另一条「git diff 双失败被当成『无变更』」(build.sh:93-96)不在本 MR 内——该区域正有 !59 在改,刻意不碰以免两处同时改同一段。本 MR 只修分析步骤这一段。

likedislike
合并受阻
Llizhe
22 天前 创建了 pull request,commit e1f22e3f
Llizhe
22 天前 关联了issue:[Bug-Report|缺陷反馈]: build.sh 命令失败后仍可能以成功结束
lizhe
22 天前 评论:

compile

likedislike
lizhe
22 天前 评论:

/check-cla

likedislike
Llizhe
22 天前 预合并成功(commit_id: b65973bbf60ee31641156e2f7d70ec32ddd56bb4)
CANN-robotCANN-robot成员
22 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
22 天前 评论:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
22 天前 评论:

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

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-cann/cannbot-dsl ❌ (0/2)(You can also ask: 沈敏, 陆玲辉, 金炯, 陈振宇, 刘佳玮) ❌ (0/1)(You can also ask: yang-jiwei, 陆玲辉, 金炯, 沈敏, 陈振宇)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
22 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
22 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
22 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
22 天前 添加了label:ci-pipeline-failed
lizhe
15 天前 评论:

compile

likedislike
Llizhe
15 天前 预合并成功(commit_id: d29a73e082943a64fd113d33d2ba94cc1e5a9f76)
CANN-robot
CANN-robot成员
15 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
15 天前 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
15 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
15 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
15 天前 添加了label:ci-pipeline-failed
CANN-robot
CANN-robot成员
15 天前 评论:

流水线分析报告 — cannbot-dsl run#410

流水线: https://gitcode.com/CANN/cannbot-dsl/actions/runs/6895c32525aa48919bab6a2b6945e1cd | PR#136 | 2026-10-08 23:27:13 ~ 2026-10-08 23:32:44 | 失败 Job 2 个

定界结论: 环境问题 / 依赖缺失 — runner 缺少 cannbot conda 环境, 回退系统 Python 后被 PEP 668 拒绝安装
  • 失败类型: 环境问题(runner 环境依赖缺失, 确定性故障, 重试无效)
  • 根因: Test Job 在环境准备阶段安装 cannbotdsl wheel 时, runner 上不存在测试脚本预期的 conda env cannbot, 回退到系统 Python(python3.12, externally-managed); pip 依据 PEP 668 拒绝系统级安装, wheel 安装失败后脚本 exit 1
  • 排除项: 与本 PR 代码无关 — PR#136 仅修改 build.sh 中 parse_changed_ops 失败时的报错处理(+4/-1); 失败发生在 wheel 安装阶段, 早于变更文件分析逻辑执行; 同 run 其余 11 个 Job(CodeCheck / CodeCheck_precommit / SCA / Antipoison / Test_get-pr 等)全部通过
  • 处置: 由 CI/环境维护者修复:
    • ① 在 runner 镜像预装 cannbot conda 环境(测试脚本预期路径), 并检查 ascend-toolkit set_env.sh 挂载;
    • 或 ② 修改 run_tests 脚本回退路径: 创建 venv 后安装, 或 pip 加 --break-system-packages
    • 修复后重新触发流水线验证; PR 提交者无需改代码

失败根因分析

根因 #1: 环境问题 / 依赖缺失 — conda env 'cannbot' 缺失 + 系统 Python externally-managed
  • 定位步骤: 3_run_tests.log(两个 Test Job 均在 [1/3] env check 阶段失败, 各耗时 12s, 测试用例尚未执行)
  • 影响 Job: Test (job 158427f4), Test (job b437c44b) — 同因
  • 根因证据(日志原文):
[WARN] conda env 'cannbot' not found, using default python
=== [1/3] env check ===
[WARN] ascend-toolkit set_env.sh not found; torch_npu may fail to import
[INFO] installing local cannbotdsl wheel: /opt/cannbot-dsl/whl/20260817_141417/cannbotdsl-0.3.dev126+gfd7852302-cp312-cp312-linux_x86_64.whl
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to install.
note: If you believe this is a mistake, ... You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
[ERROR] failed to install cannbotdsl wheel: /opt/cannbot-dsl/whl/20260817_141417/cannbotdsl-0.3.dev126+gfd7852302-cp312-cp312-linux_x86_64.whl
::error::Process exited with code 1

由门禁失败定界分析自动生成 | repo: cannbot-dsl | run: 6895c32525aa48919bab6a2b6945e1cd | PR#136

likedislike
jon_jin成员
3 天前 评论:

@lizhe_li 您好,存量治理巡查:这个 PR CI 门禁当前失败,暂时无法进入合入流程。请查看流水线日志修复失败项后重新推送;处理后我们会优先安排评审。若两周内无响应,将按社区存量治理流程评估关闭,欢迎随时重开。谢谢贡献!

likedislike