Skip to content

release: pin the rubash source revision, fail hard on drift (rubash#827) - #424

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/release-rubash-pin
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/release-rubash-pin

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Motivation

Conclusion B of the rubash#827 forensics: the niubash release pipeline never pinned rubash at all. Every release job cloned rubash master at build time into ../rubash, where the committed [patch] path override deterministically wins over the git dependency — so the released engine was "whatever rubash master HEAD was when the pipeline ran." That is how v1.4.0 (run 38506862578) compiled e785c3c8f610 while the release era declared rubash v1.4.0 (f69e7900), and faithfully shipped the pre-#819 stale-HOME behavior of rubash#754.

The existing "Pin rubash revision" steps only recorded the clone (plus a shallow-clone dirty check that can never fire on CI); nothing compared it to an expectation, and no pin file existed — a double standard right next to winuxcmd-pin.json (niubash#312/#327), which hard-verifies the bundled WinuxCmd zip bytes. This PR extends that same pin discipline to the engine source.

What lands

a. Pin file — scripts/release/rubash-pin.json (same home and style as winuxcmd-pin.json; the ticket's installer/ path was an example, this is the repo's actual pin directory):

  • rubash_rev: full 40-char commit sha (abbreviated forms cannot be fetched — git resolves the fetch argument server-side as a ref name; same lesson as perfbudget's Fetch-Pinned pins).
  • rubash_version: the Cargo.toml version AT that rev, so rev and self-declared version cannot drift silently.
  • Notes carry the bump flow: rubash 发新版 → 改这一个文件的两个字段,一个 commit 完成;python scripts/release/verify-rubash-pin.py --fetch 冒烟 → niubash CI 对新 pin 绿 → 落 tag。
  • Initial pin: 992d5c5e6fa679cc5c7fa2bf4297173240e56fd5 (v1.4.0), the rubash master HEAD niubash master CI (117147a) is green against.

b. Kill the float — release.yml, all 8 rubash-consuming jobs (build-windows/linux/macos/android/openharmony, journey, perfbudget, publish-crates): the clone is now Checkout pinned rubash revision — git init + fetch --depth 1 origin <pinned sha> + checkout + submodules (only where today's clone fetched submodules), then rev-parse HEAD must equal the pin or the job dies. The build jobs' "Pin rubash revision" steps additionally re-derive the revision and cross-check it against the clone step's output (belt and suspenders). The windows job preserves/restores the pin file like the other #312 pins, so a dispatch of an old tag runs today's pin while a tag push reads the pin committed at the tag. The release body discloses the pin.

Choice note (recommendation ②, option (i)): the pinned clone feeds the existing [patch] path dependency instead of CI-injecting a patch into Cargo.toml (option (ii)). Rationale: the patch already applies on release CI — the committed Cargo.lock is in path form (no source line for rubash), so cargo build --locked would fail if the git dependency were resolved instead — meaning the tree the patch resolves to is the real, existing float. Pinning that tree's content is the minimal fix: zero manifest churn, identical --locked semantics on every job, and build.rs's checkout fallback (which the banner already prefers under the patch) now describes a named revision. Option (ii) would add a CI-side manifest mutation that must stay in sync with the lockfile across tag-push vs dispatch — more moving surface for the same guarantee. Local Cargo.toml stays untouched: a developer's sibling worktree keeps its local-override purpose.

c. build.rs — dirty worktree content digest (recommendation ③, the #488 blind spot): a dirty rubash tree now stamps <rev>-dirty-<8 hex>, where the digest is sha256 over git diff HEAD --binary. A bare -dirty is honest but not verifiable (two different dirty trees would print identical banners); the digest makes the stamp name WHICH uncommitted state was compiled. Clean trees are byte-for-byte unchanged: the -dirty rule and the untracked-files exemption keep their exact semantics, so the release smoke greps (Niubash <version> , rubash git <rev>) and the head -1 version-gate shapes are untouched — confirmed by running tests/rubash_revision_banner.rs (2 passed) and the musl/ci grep shapes.

d. Tests/gates:

  • tests/build_rs_dirty.rs: build.rs included via #[path]; fixture repos cover clean / dirty / staged-but-uncommitted / untracked-exempt / restored trees, digest stability, and digest sensitivity to content. 5 passed.
  • scripts/release/verify-rubash-pin.py: the standalone auditor. --fetch dry-runs the exact release fetch recipe into a temp dir and verifies (rev + version + clean); --self-test proves a tampered rev, wrong version, dirty tree, and missing checkout all fail; --fetch-self-test does both against the real remote — pass + tamper-rejection both demonstrated live.
  • Wired in: ci.yml runs the self-test on every PR; pin-freshness.yml runs the weekly fetch dry-run so a rotted pin (e.g. upstream rewrite) surfaces as a report, not a red release.
  • ci.yml's dev-line rubash clones deliberately stay floating on master: development should keep testing tomorrow's engine; only the release pipeline pins.

Verification

  • Truthful end-to-end in a throwaway double clone (this branch + GitHub rubash at the pinned rev, i.e. CI's exact resolution shape): cargo check --locked green; cargo test --locked (build_rs_dirty + rubash_revision_banner) 7/7; niu --version prints exactly rubash git 992d5c5e6fa6 — the release smoke grep's expected substring.
  • verify-rubash-pin.py --fetch-self-test live: pinned rev fetched, verified, tampered rev rejected; Windows temp cleanup hardened (git's read-only objects no longer strand fixture dirs).
  • Workflow YAML parsed and reviewed; no actionlint on this box — CI is the arbiter.
  • Cargo.lock is unchanged (sha2 already in the root deps list; the build-dependency adds no new resolution).

Refs rubash#827 (recommendations ② and ③). Follow-ups it deliberately does not attempt: release-body warning for the shipped v1.4.0 assets, v1.4.1 re-cut, and the tag-discipline proposal (filed separately).

Conclusion B of the rubash#827 forensics: the niubash release pipeline
never pinned rubash at all. Every job cloned rubash master at build time
into ../rubash, where the committed [patch] path override deterministically
wins over the git dependency -- so the released engine was "whatever rubash
master HEAD was when the pipeline ran". v1.4.0 (run 38506862578) compiled
e785c3c8f610 while the release era declared rubash v1.4.0 (f69e7900) and
faithfully shipped the pre-#819 stale-HOME behavior of rubash#754.

The "Pin rubash revision" steps only recorded and dirty-checked the clone;
nothing compared it to an expectation, and no pin file existed -- a double
standard next to winuxcmd-pin.json (niubash#312/#327), which hard-verifies
the bundled WinuxCmd zip bytes.

- scripts/release/rubash-pin.json: the source twin of winuxcmd-pin.json.
  rubash_rev (full 40-char sha; abbreviated forms cannot be fetched) +
  rubash_version (the Cargo.toml version AT that rev) + the bump flow.
  Initial pin: 992d5c5e6fa6 (v1.4.0), the master HEAD niubash CI is green
  against.
- release.yml: every rubash clone (8 jobs) is now "Checkout pinned rubash
  revision" -- init, fetch --depth 1 the pinned sha, checkout, submodules,
  then rev-parse HEAD must equal the pin or the job dies. The build jobs'
  "Pin rubash revision" steps additionally cross-check the clone step's
  output. The windows job preserves/restores the pin file like the other
  #312 pins (a dispatch of an old tag runs today's pin). The release body
  discloses the pin. ci.yml's dev line stays floating on rubash master on
  purpose: development should keep testing tomorrow's engine.
- build.rs: a dirty worktree now stamps `-dirty-<8 hex>`, a sha256 digest
  over `git diff HEAD --binary` (#488/#827 recommendation 3 -- a bare HEAD
  hash does not guarantee content, and two different dirty trees must not
  print the same banner). Clean trees are unchanged: the `-dirty` rule and
  the untracked-files exemption keep their exact semantics, so the release
  smoke greps (`Niubash <version> `, `rubash   git <rev>`) and the banner
  tests are untouched -- verified by tests/rubash_revision_banner.rs.
- tests/build_rs_dirty.rs: build.rs included via #[path]; fixture repos
  cover clean/dirty/staged/untracked/restore, digest stability, and digest
  sensitivity to content.
- scripts/release/verify-rubash-pin.py: the standalone auditor (used by the
  release captain and pin-freshness). --fetch dry-runs the exact fetch
  recipe into a temp dir; --self-test proves a tampered rev / wrong
  version / dirty tree / missing checkout all fail; --fetch-self-test does
  both against the real remote (wired into pin-freshness.yml, plus the
  self-test on every PR in ci.yml).

Choice note (rubash#827 recommendation 2): the pinned clone feeds the
existing [patch] path dependency (option i) instead of CI-injecting a patch
into Cargo.toml (option ii) -- the patch already applies on release CI (the
committed Cargo.lock is in path form; --locked would fail otherwise), so
pinning the tree it resolves to is the minimal, no-manifest-churn fix and
keeps `cargo build --locked` semantics identical on every job.

The current pin names rubash 992d5c5e6fa6 (v1.4.0). Bumping it is one
commit to scripts/release/rubash-pin.json; see its notes.
@caomengxuan666

Copy link
Copy Markdown
Member Author

代码评审(独立):fix/release-rubash-pin(rubash#827 结论 B 落地)

结论:APPROVE-WITH-NITS — 无 BLOCKER;3 条非阻塞备注见末尾。不合并。

评审基于 head b3ef4fb 对 origin/master 的完整 diff(8 文件,与主张一致,无夹带),全部验证点实做于独立 detached worktree,未触碰主检出。

逐项验证(全部实做)

  1. pin 文件(scripts/release/rubash-pin.json):rubash_rev 为完整 40 位 sha(992d5c5e6fa6…),rubash_version=1.4.0,升级流程与历史背景注释齐全。--fetch-self-test 真网验证该 rev 可 fetch 且 checkout 自称 1.4.0,无漂移。
  2. release.yml 八个 rubash 消费 job(build-windows / linux / macos / android、build-openharmony、journey、perfbudget、publish-crates):grep 全文已无任何浮动 git clone 路径;统一 git init → fetch --depth 1 <40位sha> → checkout FETCH_HEAD → rev-parse HEAD 必须 == pin 否则 throw/exit 1;四个 build job 另有独立 "Pin rubash revision" 交叉比对(脏树拒绝 + 与 pin 步骤输出比对);release job 强制三平台 rubash_revision 输出唯一,release body 披露 pin。fail 路径真实(无 || true、无吞错;android/ohos 的 continue-on-error 为既有孵化语义,不在 release needs 内)。缓存污染向量:不存在 — 全文无 actions/cache;pin 步骤遇已存在的 ../rubash 直接 throw 拒绝复用;preserve/restore 仅经 RUNNER_TEMP(每次运行易失),rubash-pin.json 进出 preserve/restore 与 [release][P1] release pipeline pulls live ecosystem state: WinuxCmd 'latest' unpinned + wpm preinstall against the day's index #312 dispatch 语义一致。
  3. 方案 (i) 命门实验(临时目录合成 git 依赖 + [patch] path,实测非读文档):提交的 Cargo.lock 中 rubash 条目确为 path 形态(无 source 行)。patch 路径不存在时 cargo 硬失败 exit 101("patch location … does not contain packages matching dep"),--locked 与否都不回落 git。补充发现:patch 目录存在但版本不满足依赖要求时,不带 --locked 会静默回落 git — 但 release.yml 所有构建/检查/发布步骤全部带 --locked,该形态下同样 exit 101,回落被锁死。方案成立。
  4. build.rs 脏树摘要:干净树标签与旧实现逐字节一致(代码 diff 确认 + 本机实跑 banner 为裸 HEAD);脏树 = <rev>-dirty-<sha256(git diff HEAD --binary) 前8hex>;staged-only 置脏(diff HEAD 覆盖)、untracked-only 不置脏、内容变更必改 digest。tests/build_rs_dirty.rs 5/5、tests/rubash_revision_banner.rs 2/2 本机实跑通过;RUSTFLAGS="-D warnings" 编译两测试目标干净(第一轮的 unused 告警确已在测试 mod 边缘 allow)。
  5. verify 脚本:--self-test 本机通过(无网路径);另建独立 fixture 做 5 项篡改(好 pin / 翻转 rev / 缩写 sha / 版本漂移 / 脏树)——好 pin exit 0,其余全部 exit 1 且报因正确;--fetch-self-test 真网通过;Windows 只读 .git 对象清理可靠(self-test 前后 %TEMP% 零残留目录,force_remove 兼容 py<3.12)。ci.yml 每 PR self-test、pin-freshness.yml 周一 06:00 UTC fetch 干跑均在。
  6. 夹带扫描:diff 文件集 = 主张 8 文件(含 Cargo.toml 新增 [build-dependencies] sha2,为 build.rs 摘要的必要依赖,合理);排除 .github/tests/scripts/build.rs/Cargo.toml 后无任何其他源码改动;GPL/license 关键字零命中;cargo fmt --check 干净;PR CI 全绿(build-and-test + 5 项 cross/target check 全 SUCCESS)。

非阻塞备注

  1. verify-rubash-pin.py 的 fetch 干跑不做 submodule update,与 release.yml 的 pin 步骤略有分叉——rubash 目前无被消费的 submodule 内容则无影响,日后加 submodule 时记得同步脚本。
  2. ci.yml 的 self-test 步骤位于 actions/setup-python 之前,依赖 runner 镜像预装 python;当前绿,挪到 setup-python 之后更稳。
  3. 实验表明唯一静默回落形态需要“patch 版本不匹配 + 无 --locked”同时成立——请长期保持 release 构建步骤的 --locked 不被移除(值得日后写进 pin json notes)。

@caomengxuan666
caomengxuan666 merged commit cee5ad8 into master Oct 19, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/release-rubash-pin branch October 21, 2026 08:15
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