Skip to content

[自动合并 P2-4] 契约兼容性检测门 #89

Description

@randypanding

目标

新增契约兼容性检测门:OpenAPI/proto breaking change 检测;DB migration 必须前后兼容、无 destructive DDL(destructive 需 ADR + 回滚脚本)。这类破坏在无人 review 下只能靠机器发现。

背景(源自 #81 §4.1)

组织的 risk_posture 第一条就是 customer_upgrade_failure——客户本地部署,升级/回滚炸 = 收入损失。API 契约破坏和 destructive migration 是最典型的升级炸弹,而它们在 diff 里看起来人畜无害,人漏审、agent 更不会自查。

涉及文件

  • CI-Workflows/.github/workflows/check.yml(新增 contract-check job)
  • 选型:OpenAPI 用 oasdiff(或 openapi-diff);proto 用 buf breaking;DB migration 按各仓实际使用的迁移工具写 DDL 分类器(destructive 模式清单:DROP TABLE/COLUMNALTER ... TYPENOT NULL 无默认值加列等)
  • governance/policy/(契约文件路径声明、destructive DDL 模式清单、豁免与 ADR 要求)
  • 各业务仓 gate needs 链

执行步骤

  1. 盘点哪些仓有 OpenAPI/proto/DB migration(template-service、agent-registry、agent-platform 优先),在 policy 中声明各仓契约文件位置与迁移目录。
  2. OpenAPI/proto:PR 修改契约文件时,与 base 版本做 breaking change 对比,breaking → 红(或要求 ADR,按 policy 严格度)。
  3. DB migration:新增迁移文件时扫描 DDL,命中 destructive 模式且无回滚脚本/无 ADR → 红;additive(加表、加可空列、加索引)→ 绿。
  4. 无契约文件的仓该 job 判定为 not-applicable 并显式记录(不是静默 skip——aggregator 下该 job 恒 success 且不纳入 needs,或输出明确 "N/A" 日志)。
  5. 接入 gate needs 链。

验收标准

  • 声明了契约的仓:breaking 变更红、兼容变更绿、destructive migration 无 ADR 红 / 有 ADR+回滚脚本绿。
  • 未声明契约的仓:不误报、不静默。
  • policy 声明与实际文件位置对账(文件失踪 → 红,防契约文件被移走后检测失明)。

测试方法(预先指定)

T1 OpenAPI breaking(负向):fixture PR 删除一个 endpoint / 把字段 stringinteger → 断言红,输出指明 breaking 点。

T2 OpenAPI 兼容(正向):fixture PR 新增可选字段、新增 endpoint → 断言绿。

T3 destructive migration(负向):fixture PR 新增含 DROP COLUMN 的迁移,无 ADR → 断言红,错误信息指明 destructive 语句行号。

T4 destructive + 完备手续(正向):同 T3 但附 ADR 引用与回滚脚本(down migration)→ 断言绿。

T5 additive migration(正向):新增加表/加可空列迁移 → 断言绿。

T6 检测器失明防护(核心,负向):fixture PR 把 OpenAPI 文件移动/改名但不更新 policy 声明 → 断言红(policy 声明路径找不到文件即红,防止"移走契约文件让检测器失明")。

T7 DDL 分类器(单元级):准备 ≥12 条预标注 SQL fixture(destructive/additive/边界各半,含 ALTER COLUMN TYPE、加 NOT NULL 无默认值列等 tricky case),断言分类器输出与预标注完全一致。

依赖

  • P1-3(aggregator 模式)
  • 各仓契约现状盘点(执行步骤 1,若盘点结果为"暂无契约文件",本卡降级为只落 DB migration 检测 + policy 骨架,范围收缩须回本 issue 记录)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-merge自动合并计划(#81)工作卡gateGate 工作流相关

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions