Skip to content

fix(ledger): resolve §6 paths through pub mod / pub use chains (Refs #2847) - #3556

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2847-ledger-export-paths
Nov 14, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2847-ledger-export-paths

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #2847

修了什么

scripts/check-api-ledger.py 的 §6 校验从「子树里有同名声明」改为「记录的路径就是真实导出路径」:

  • item rubash::a::b::Name:从 src/lib.rs 起逐段解析,每一段必须是 pub mod(内联或文件,含 #[path])或把模块 pub use 出来的再导出;末段 Name 必须在该模块顶层以 pub 声明(fn/struct/enum/trait/type/const/static/union/mod),或被该模块 pub use 再导出(具名、as 改名、glob;glob 目标可以是私有模块,如 parser 的 pub use nodes::*)。只认裸 pub,pub(crate) 不算对外面。
  • variant / method:其所属类型路径按同一解析器校验(此前 method 完全不看类型路径)。
  • 诊断区分两种失败:declared in the tree but not exported under rubash::…(路径错)与 not found in tree(符号没了)。
  • 源码级近似:先抹掉注释与字符串/字符字面量,再按花括号深度判定「顶层」;不追宏生成的条目(真遇到会大声失败、需人工处理)。
  • 自检(--self-test)新增一组:真实导出路径(具名/改名/私有模块 glob/#[path]/根再导出/子模块路径)必须过;未再导出、穿私有模块、类型路径错的 item/variant/method 必须各自失败。

删了什么

item_exists 原先的「模块子树 rglob + 声明模式」判定(即 issue 所说的盲区)。PUB_DECL_PATTERNS 只保留用于失败诊断(区分「路径错」与「不存在」)。

依据

工程面,无 GNU 锚。

验证

Owed

  • docs/api-ledger.md §5 第 1 条仍写「proves presence by declaration patterns only」,现已不准确;但该文件要求与 niubash 副本逐字节相同(canary cmp),需 rubash/niubash 成对改,本 PR 未动。
  • 未在 CI(niu-canary.yml 的 ledger / pairing job)上实跑,仅本地 Windows Python 3 运行。

caomengxuan666 and others added 2 commits November 14, 2026 13:11
master fmt drift from #3511 makes `cargo fmt --check` (the pre-commit
hook and CI fmt) fail on every branch; formatting only, no test change.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…2847)

The tripwire proved presence by declaration pattern over the module's
whole subtree, so `item rubash::api::CandidateKind` stayed green while
the real export was `rubash::api::capabilities::CandidateKind`. Item
paths now resolve like a consumer would write them: each module step
must be a `pub mod` (or a `pub use` module re-export) from src/lib.rs,
and the final name must be `pub` at that module's top level or
re-exported there (named, `as` rename, or glob, including globs of
private modules). Variant and method entries resolve their owner type
path the same way. Failures name the step: "declared in the tree but
not exported under <path>" vs "not found in tree".

The pre-#2850 tree (4f0d493~1) is the issue's reproducer: the old
checker reports all 279 symbols present, the new one fails the five
CandidateKind entries. Current master: all 287 present, --niu clean.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666 caomengxuan666 changed the title fix(ledger): resolve §6 paths through pub mod / pub use chains (Fixes #2847) fix(ledger): resolve §6 paths through pub mod / pub use chains (Refs #2847) Nov 14, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 05:13
@caomengxuan666
caomengxuan666 marked this pull request as draft November 14, 2026 05:45
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:PASS

只读 + 决定性腿全部一手跑过,判词 PASS。未推送、未合入。

决定性腿(复核员一手跑过,我核过卷宗与 live 态)

  • L1 新脚本 --repo <master 尖树 8b48c164>:rc=0,all 287 ledger symbols present
  • L2 旧脚本同树对照:rc=0,287 present
  • L3 新脚本 --self-test:rc=0,四段全过(bogus symbol、§2847 导出路径 8 好 + 7 坏且诊断逐字正确、completeness、Session census)
  • L4 复现树 4f0d493c~1 双向对照:旧脚本 all 279 present rc=0(假绿复现);新脚本 rc=1,恰 5 条缺失(item + 4 variant),诊断均为 declared in the tree but not exported under rubash::api::CandidateKind,与正文逐字相符
  • L5 新脚本 --niu <niubash 尖 98853c50>:rc=0,287 present,all 97 consumed niubash paths are recorded;7 条 recorded but not consumed 警告与旧版逐字相同(预存)
  • L6 rustfmt:PR 版 d11 rc=0;master 版 rc=1,diff 恰为 PR 的两个 hunk
  • L7 两份 docs/api-ledger.md sha256 identical(73749785…980)
  • L8 计数:parse_ledger 实得 287(99 item + 58 variant + 130 method),无重复

CI 逐名(run 43560449915,头 8c6ec74):3 fail + 8 pass + 1 skipping,无新失败名。goldens 1350/1 与 macOS 1243/1 均为 issue2875_input_procsub_child_runs_as_rubash_shell;Linux 22/1 为 issue2859_jobs_face_stopped_job_counts。O4 确认:issue2859 此红为 VOID(#3292 类四条全满足——同头 macOS 与 goldens 上该 cell 绿、本 PR 零 Rust 产品代码、不碰 jobs/sleep 面)。API ledger tripwire、niubash builds、cross-target、Windows 编译检查全 pass。

交集:真 merge-base 8b48c16 = live tip,交集 ∅,无需 update-branch。d11 fmt hunk 为 11 支 open PR 共用,先合者落地。

合入体选择(我定的):接受正文 Fixes #2847——#2847 所指的正是本 PR 修掉的机制盲区(item_exists 只匹配声明模式,从不校验真实导出路径),L4 双向复现已证。#2847 随合入自动关闭,不另手关。

合入后 owed:O1 docs/api-ledger.md §5:1451 by declaration patterns only 措辞已不准确,须 rubash/niubash 成对改,另立跟进单;O2 #[path] 只认紧贴上一行(夹 doc 注释/空行会解析失败,全树 14 处现均紧贴,无当前影响),可另立低优先级加固单。

卷宗:/tmp/review-3556/CAPTAIN-VERIFY.md(墙开后搬 ~/workspace/review-3556/)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 07:07
@caomengxuan666
caomengxuan666 merged commit 658ed79 into master Nov 14, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
_check-api-ledger.py _child_module() only inspected the single line
immediately above a 'mod name;' declaration when looking for a
#[path = "..."] attribute. Rust allows doc comments and blank lines
between attributes and the declaration, so a ledger tree using that
layout resolved the fallback <name>.rs instead of the attributed file.
Walk back over contiguous attribute/comment/blank lines instead.

Also reword docs/api-ledger.md #5: the tripwire no longer proves
presence 'by declaration patterns only' — since #3556 it resolves real
export paths (pub mod steps + pub use re-exports, #[path] honored).
The niubash copy of the ledger still needs the same rewording (the
byte-identical cmp check in niu-canary job pairing enforces pairing).

GNU cite: n/a — tooling, not shell semantics.
Refs #3571, #3572

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

[bug] Ledger tripwire does not validate §6 item paths against actual exports

1 participant