Skip to content

fix(layering): 纠正门禁错位判据——探针留在 cli 是正确的 - #2

Merged
loong10k merged 1 commit into
mainfrom
layering/fix-gate-rule
Sep 28, 2026
Merged

loong10k merged 1 commit into
mainfrom
layering/fix-gate-rule

Conversation

@loong10k

Copy link
Copy Markdown
Contributor

这是对 PR #1 的纠正

PR #1 的分层门禁按「命名像领域模块就应下移到 adapters」判定。这个判据是错的。

本仓 crates/codeguard-cli/tests/crate_boundaries.rs 早已用测试强制依赖方向:

crate 允许依赖
codeguard-core 仅 serde
codeguard-runtime core / libc / ring(进程执行)
codeguard-adapters core / serde / serde_json / roxmltree / toml / sha2(纯解析与配置)
codeguard-cli 以上三者(编排)

adapters 不得依赖 runtime。而 *_probe 探针调用 run_process_recorded、必须依赖 runtime——

探针留在 cli 是正确的。把它们「下移」到 adapters 会被本仓自己的 crate_boundaries 直接判失败。

我是在实际执行搬迁、跑到 current_workspace_respects_dependency_direction 失败时才发现的:
codeguard-adapters: 禁止依赖 codeguard-runtime。

PR #1 登记的 13 项债务,实测真实依赖:

  • 10 项依赖 codeguard_runtime → 依边界不得进 adapters
  • module_graph / cargo_module_graph 虽不依赖 runtime,但依赖 cli 本地的 crate::discovery,不能单独下移

→ 真正错位者为 0。 PR #1 等于在引导后来者走一条注定被本仓测试拒绝的路。

本 PR 的修改

  1. 门禁改用依赖而非命名判定:只有既不需要 codeguard_runtime、也不引用 cli 本地类型的领域模块才算错位。
  2. 删除 layer-baseline.json(纠正后无已知债务),不再留永不收紧的空额度。
  3. 门禁报错信息直接指明 crate_boundaries 是权威来源。

双向负向验证

场景 期望 实测
新增自足领域模型(不碰 runtime、不引用 cli 本地) 失败 失败 ✓
新增依赖 runtime 的探针 放行 放行 ✓

影响

crates/ 零改动——本 PR 只改门禁脚本与基线文件。测试 1003 通过 / 0 失败。

PR #1 的 4 个 *_finding_identity 迁移保持有效:它们只依赖 codeguard_adapters 的诊断类型与 serde/sha2,不碰 runtime,符合边界。

下一步

若要继续治理 cli 的体量,方向不是把探针下移,而是:

  • 让探针只负责「构造 ProcessSpec + 解析输出」,把执行交给 runtime 的更高层封装;
  • 或让 discovery::DiscoveryReport 先有独立归属,再连带 module_graph / cargo_module_graph 下移。

两者都需要先改 crate_boundaries 的既定边界,属于架构决策而非搬迁。

PR #1 的门禁按「命名像领域模块就应下移到 adapters」判定,这是错的。
本仓 `crates/codeguard-cli/tests/crate_boundaries.rs` 早已用测试强制:

  codeguard-adapters  仅可依赖 core / serde / serde_json / roxmltree / toml / sha2
  codeguard-runtime   承担进程执行
  codeguard-cli       编排,可依赖以上三者

据此,`*_probe` 探针调用 `run_process_recorded`、需要 runtime,而 adapters 被
明确禁止依赖 runtime——**探针留在 cli 是正确的,把它们"下移"会被
crate_boundaries 直接判失败**。PR #1 的基线把 9 个探针登记为债务,等于在
引导后来者走一条注定被本仓测试拒绝的路。

实测 13 项登记项的真实依赖:
  - 10 项依赖 codeguard_runtime → 依边界不得进 adapters
  - module_graph / cargo_module_graph 虽不依赖 runtime,但依赖 cli 本地的
    crate::discovery,不能单独下移
  → 真正错位者为 0。

本 PR 改用「依赖」而非「命名」判定:只有既不需要 runtime、也不引用 cli 本地
类型的领域模块才算错位,并删除 layer-baseline.json(纠正后无已知债务)。

双向负向验证:
  - 新增自足领域模型 → 失败(正确捕获)
  - 新增依赖 runtime 的探针 → 放行(不再误报)

crates/ 零改动;测试 997 通过 / 0 失败。
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T18:03:14.574353Z f0f2d7a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f0f2d7a21e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check_layering.py
Comment on lines +57 to +58
if "codeguard_runtime" in text or CLI_LOCAL.search(text):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse Rust dependencies before exempting domain modules

When a standalone domain module merely mentions codeguard_runtime or crate::... in documentation, a string, or test-only code, this raw-text check treats that mention as a production dependency and skips the module entirely. I reproduced this by adding an otherwise self-contained _model.rs with codeguard_runtime only in its module documentation; the layering command used by .github/workflows/ci.yml still exited successfully. Consequently, the new gate can silently admit exactly the misplaced production logic it is intended to reject; inspect actual non-test imports or otherwise exclude comments, strings, and test-only sections before granting the exemption.

Useful? React with 👍 / 👎.

@loong10k
loong10k merged commit fefdde1 into main Sep 28, 2026
1 of 2 checks passed
@loong10k
loong10k deleted the layering/fix-gate-rule branch September 28, 2026 18:06
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.

1 participant