Skip to content

feat: pipeline_tree静态检查增强 --story=130810130#683

Open
guohelu wants to merge 3 commits intoTencentBlueKing:developfrom
guohelu:develop_0413
Open

feat: pipeline_tree静态检查增强 --story=130810130#683
guohelu wants to merge 3 commits intoTencentBlueKing:developfrom
guohelu:develop_0413

Conversation

@guohelu
Copy link
Copy Markdown
Collaborator

@guohelu guohelu commented Apr 13, 2026

Reviewed, transaction id: 78235

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review 总结

整体设计良好:将分散的校验逻辑统一到 pipeline_validate 模块,通过 BasePipelineValidator + ValidatorHandler 注册机制实现可扩展的校验器框架。__init_subclass__ 自动注册的模式很简洁。

发现的问题

级别 文件 问题
⚠️ 逻辑 validators/template.py MutualExclusionValidator error_nodes 在循环内重置 + 提前 return,只报告第一个违规节点
⚠️ 逻辑 validators/template.py OutputsKeyPatternValidator ''.join(...) 无分隔符,多个 key 时输出不可读
✨ 改进 handler.py register 同名校验器静默覆盖,无重复注册警告
✨ 改进 utils/pipeline.py validate_pipeline_tree_constants re.search 遍历所有 key 构建依赖图,常量数量较大时 O(n²)

肯定的做法

  • 新增 app 正确注册到 engineinterface 两个模块
  • BasePipelineValidator.__init_subclass__ 强制约束子类必须定义 namevalidate_type
  • 测试用例同步更新 mock 路径
  • 新文件均包含开源协议头

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 75.71429% with 68 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@8f93442). Learn more about missing BASE report.

Files with missing lines Patch % Lines
bkflow/utils/pipeline.py 47.91% 25 Missing ⚠️
bkflow/pipeline_validate/validators/template.py 77.38% 19 Missing ⚠️
bkflow/pipeline_validate/validators/task.py 79.62% 11 Missing ⚠️
bkflow/pipeline_validate/handler.py 80.76% 5 Missing ⚠️
bkflow/pipeline_validate/validators/base.py 84.61% 4 Missing ⚠️
bkflow/pipeline_validate/validators/general.py 78.57% 3 Missing ⚠️
bkflow/apigw/serializers/template.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #683   +/-   ##
==========================================
  Coverage           ?   81.18%           
==========================================
  Files              ?      286           
  Lines              ?    16897           
  Branches           ?        0           
==========================================
  Hits               ?    13718           
  Misses             ?     3179           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review 总结

整体设计良好:将分散的校验逻辑统一到 pipeline_validate 模块,通过 BasePipelineValidator + ValidatorHandler 注册机制实现可扩展的校验器框架。__init_subclass__ 自动注册的模式很简洁。

发现的问题

级别 文件 问题
⚠️ 逻辑 validators/template.py MutualExclusionValidator error_nodes 在循环内重置 + 提前 return,只报告第一个违规节点
⚠️ 逻辑 validators/template.py OutputsKeyPatternValidator ''.join(...) 无分隔符,多个 key 时输出不可读
✨ 改进 handler.py register 同名校验器静默覆盖,无重复注册警告
⚡ 性能 utils/pipeline.py validate_pipeline_tree_constants re.search 遍历所有 key 构建依赖图,O(n²) 复杂度

肯定的做法

  • 新增 app 正确注册到 engineinterface 两个模块
  • BasePipelineValidator.__init_subclass__ 强制约束子类必须定义 namevalidate_type
  • 测试用例同步更新 mock 路径
  • 新文件均包含开源协议头


# 检查当前参数值中引用的所有参数
referenced_keys = set()
for other_key in constant_values:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚡ 对每个 key 的 value 遍历所有 other_key 做 re.search,时间复杂度为 O(n²)。可以考虑用一个正则(如 \$\{[a-zA-Z_]\w*\})一次性提取 value 中所有引用的 key,再与 constants 的 key set 取交集,降为 O(n·m)(m 为单个 value 中引用数量)。

# Reviewed, transaction id: 78252
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review 总结(增量审查)

修复提交 7b2e653 已解决上轮审查中 3 个问题。新增的 validate_pipeline_tree_constants 循环引用检测存在一个逻辑缺陷需要关注。

上轮问题跟进

状态 文件 问题
✅ 已解决 validators/template.py MutualExclusionValidatorerror_nodes 位置错误
✅ 已解决 validators/template.py OutputsKeyPatternValidator join 分隔符
✅ 已解决 handler.py 同名校验器静默覆盖
⏳ 未处理 utils/pipeline.py validate_pipeline_tree_constants O(n²) 复杂度(Minor,可后续优化)

新发现

级别 文件 问题
⚠️ Important utils/pipeline.py:523 has_cycle 环路检测使用全局 visited 集合,跨起始节点的环路可能被遗漏


# 遍历当前节点的所有依赖项
for neighbor in graph.get(node, set()):
if neighbor not in visited:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ visited 作为全局集合在多次 DFS 调用间共享,但环路判断依赖 neighbor in path(仅当前递归路径)。如果环路中部分节点已被从其他起始点访问过,neighbor not in visited 为 False 会跳过递归,导致该环路漏检。

修复方式:去掉 visited 集合,改用三色标记法(white/gray/black),或者在每次外层循环起始时重置 visited,只在 path 中检测回边。简化示例:

rec_stack = set()
def has_cycle(node):
    visited.add(node)
    rec_stack.add(node)
    for neighbor in graph.get(node, set()):
        if neighbor not in visited:
            if has_cycle(neighbor):
                return True
        elif neighbor in rec_stack:
            return True
    rec_stack.discard(node)
    return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 此问题已在最新提交 91ba4abc 中解决。改为三色标记法(WHITE/GRAY/BLACK),GRAY 表示当前递归栈中的节点,遇到 GRAY 邻居即为环路,BLACK 节点跳过,逻辑正确。

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review 总结(增量审查)

提交 91ba4abc 修复了上轮审查中报告的循环引用检测逻辑缺陷,至此所有 Critical/Important 级别的问题均已解决。

上轮问题跟进

状态 文件 问题
✅ 已解决 validators/template.py MutualExclusionValidatorerror_nodes 位置错误(commit 7b2e653
✅ 已解决 validators/template.py OutputsKeyPatternValidator join 分隔符(commit 7b2e653
✅ 已解决 handler.py 同名校验器静默覆盖,现已改为 raise ValueError(commit 7b2e653
✅ 已解决 utils/pipeline.py has_cycle 使用全局 visited 导致跨路径环路漏检(commit 91ba4abc,改为三色标记法)
⏳ 未处理 utils/pipeline.py validate_pipeline_tree_constants 依赖图构建 O(n²)(Minor,常量数量通常有限,可后续优化)

本轮新发现

无新增问题。三色标记法(WHITE/GRAY/BLACK)实现正确:GRAY 标记递归栈中节点用于检测回边,BLACK 标记已完全探索的节点避免重复访问,color.get(neighbor, WHITE) 正确处理了不在 graph 中的叶子节点。

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