Skip to content

Commit 46db4aa

Browse files
genednaclaude
andcommitted
v0.38.22: strip source signature headers from trunk layer messages (FU-01, #28)
Trunk N=1 pushes synthesized ancestor/descendant layer commits from the tip's raw git-internal message, which still carries the client's gpgsig header block; after server signing that block landed in the layer body, so git/libra log showed 'gpgsig -----BEGIN PGP SIGNATURE-----' as the subject. Add split_commit_message (Git header grammar) and use the body for the N=1 layer message and the N>1 squash listing subjects. Plan: docs/plan/plan-20260923.md FU-01. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Eli Ma <eli@patch.sh>
1 parent f3414e2 commit 46db4aa

7 files changed

Lines changed: 372 additions & 32 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mega2"
3-
version = "0.38.21"
3+
version = "0.38.22"
44
edition = "2024"
55
# Two [[bin]] targets exist; keep `cargo run -p mega2` unambiguous.
66
default-run = "mega2"

‎docs/plan/plan-20260923.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
| CLI 注册 | `builtin()` / `builtin_exec()` / `load_mode()` 三处;`LoadMode::None` 存在;`reqwest` 已是依赖 | `src/commands/mod.rs:22-30,92-124`;`Cargo.toml:72` |
8282
| 迁移 | 最近迁移 `m20260921_000100_fix_git_tag_unique`(`src/jupiter/migration/mod.rs:138,262`);本计划新增两个有序迁移:`m20260923_000100_import_repo_cleanups`(FU-14,清理台账表)与 `m20260923_000200_canonicalize_import_repo_paths`(FU-15,存量别名路径改写,forward-only);`audit_logs` 有 `idx_audit_logs_target`,无按 JSON 字段的索引 | `src/jupiter/migration/mod.rs:155-262`;`m20260306_121829_create_bots_related_table.rs:350-370` |
8383
| 测试 target | `tests/` 下 15 个 target(14 个 `integration_*` + `orbit_backend_integration`);相关:`integration_git_cli`、`integration_api_write_trunk` | `ls tests/` |
84-
| 基线全量测试 | tip `137065f`、规范栈 `docker compose -p mega2-it -f docker/docker-compose.test.yml --profile git up -d --wait`(`MEGA2_IT_GIT_WORKDIR` 指向会话临时目录、`MEGA2_IT_GIT_UID/GID=$(id -u/-g)`)上 `source .env.test && cargo test --all --no-fail-fast`:lib 1656 通过、`integration_git_cli` 24/24 通过;**6 个本机环境失败**(与本计划改动面无关):`integration_git_lfs` 的 `storage_events_basic_upload`、`storage_events_presigned_gap`、`trunk_push_auth_none_round_trip`、`trunk_push_auth_token_round_trip`(宿主 `git-lfs/3.8.0` ≠ 钉住的 `3.7.1`);`integration_oci_docker_gated`(`docker push failed: unauthorized`);`integration_object_storage_s3_compatible_smoke`(RustFS PUT 经 macOS 系统代理返回 `502 Bad Gateway`;直连 RustFS 正常) | 2026-09-23 本地运行(1114 s);`scutil --proxy` |
84+
| 基线全量测试 | tip `137065f`、规范栈 `docker compose -p mega2-it -f docker/docker-compose.test.yml --profile git up -d --wait`(`MEGA2_IT_GIT_WORKDIR` 指向会话临时目录、`MEGA2_IT_GIT_UID/GID=$(id -u/-g)`)上 `source .env.test && cargo test --all --no-fail-fast`:lib 1656 通过、`integration_git_cli` 24/24 通过;**6 个本机环境失败**(与本计划改动面无关):`integration_git_lfs` 的 `storage_events_basic_upload`、`storage_events_presigned_gap`、`trunk_push_auth_none_round_trip`、`trunk_push_auth_token_round_trip`(宿主 `git-lfs/3.8.0` ≠ 钉住的 `3.7.1`);`integration_oci_docker_gated`(`docker push failed: unauthorized`);`integration_object_storage_s3_compatible_smoke`(RustFS PUT 经 macOS 系统代理返回 `502 Bad Gateway`;直连 RustFS 正常)。另:macOS `ld` 在链接 lib 测试二进制时输出 `warning: linker stderr: ld: __eh_frame section too large (max 16MB)`(`linker_messages`,基线同样存在,非本计划代码引入) | 2026-09-23 本地运行(1114 s);`scutil --proxy` |
8585
| 外部参照 | Libra `0.23.46`(与报告一致);git `2.54.0`;git-internal `0.10.2` | `libra --version`;`git --version`;`Cargo.toml:45` |
8686

8787
### 复现证据(2026-09-23,本地 storage-only 栈,`push_auth=none`,tip `137065f` 的 debug 构建)
@@ -176,6 +176,8 @@
176176
| 2026-09-23 | 计划 R20 Codex FAIL(1×P1) | 事实基线迁移行、自审可行性、Rollback / Migration 默认、兼容收口与 FU-23 release note AC 统一声明两个有序迁移(FU-14、FU-15)及 FU-15 的不可逆改写、冲突保留与告警 | 卡号不变 | 事实基线、评审结论表、字段默认、兼容收口、FU-23 |
177177
| 2026-09-23 | 计划 R21 Codex FAIL(1×P1) | ADR-FU-04 第 1 条与 FU-04 要求 `import_dir` 首组件属于 `root_dirs`(`monorepo_import_dir_shape` 断言 `root_dirs=["project"]`+`import_dir="/vendor"` 被拒);FU-18 `import_root_push_rejected` 追加「首推不改变根树顶层名集合」断言;风险表同步 | 卡号不变 | ADR-FU-04、FU-04/18 卡、风险 |
178178
| 2026-09-23 | 计划 R22 Codex PASS | 计划评审闭环,Phase 0 退出;进入 FU-01 | 卡号不变 | 状态横幅、Review log |
179+
| 2026-09-23 | FU-01 评审 P2 | ADR-FU-01 第 1 条的返回类型文字与实现对齐(`headers: Vec<(&str, String)>`,键借用) | 卡号不变 | ADR-FU-01 |
180+
| 2026-09-23 | FU-01 C 组执行 | C 组 ① 版本面 parity 预检命令改为排除 `target/` 与 `.libra/` 的 `find`(原 `rg -l --glob` 扫描巨大的 `target/` 超时) | 卡号不变 | 执行检查必备需求 C 组 |
179181

180182
> 说明:R1 修订发生在任何实现开工之前,按 G-09 以本表为闭环凭证整体重排卡号(旧编号未被任何提交或外部文档引用)。
181183
@@ -188,7 +190,7 @@
188190
- **Status:** Accepted
189191
- **Context:** git-internal 把 committer 行后的一切放进 `Commit.message`。Mega2 在 N=1 层消息、squash 主题、物化 commit、ImportRepo attach 根消息四处把它当作纯消息复用(E9–E11)。
190192
- **Decision:**
191-
1. 在 `src/common/utils.rs` 提供唯一 helper `split_commit_message(message: &str) -> CommitMessageParts { headers: Vec<(String, String)>, body: &str }`,文法(按字节,不 trim、不改 CRLF):
193+
1. 在 `src/common/utils.rs` 提供唯一 helper `split_commit_message(message: &str) -> CommitMessageParts<'_> { headers: Vec<(&str, String)>, body: &str }`(键借用自原消息,值为拼接后的续行),文法(按字节,不 trim、不改 CRLF):
192194
- `message` 以 `\n` 开头 → `headers = []`,`body = message[1..]`。
193195
- 否则逐行(以 `\n` 结尾)解析额外头块:行以单个空格开头 → 续行,必须有前一个头,否则整块判定为「非头块」;行为 `key SP value`,`key` 由 `[A-Za-z0-9-]` 组成且非空 → 新头;遇到空行 → 头块结束,`body` = 其后全部字节;遇到其它行或文件结束仍无空行 → 整块判定为「非头块」。
194196
- 「非头块」回落:`headers = []`,`body = message`(原样;覆盖历史未成帧消息,如 `create new directory demo`)。
@@ -347,7 +349,7 @@
347349

348350
- **开工:** `libra status --short --branch`(禁止 `git status`);`test -f .env.test`;规范测试栈 `docker compose -p mega2-it -f docker/docker-compose.test.yml --profile git up -d --wait`(先 `mkdir -p` 并 `chmod 1777` 共享 git 工作根;导出 `MEGA2_IT_GIT_WORKDIR`、`MEGA2_IT_GIT_UID`、`MEGA2_IT_GIT_GID`,`docs/refactoring/test-infra.md`)。
349351
- **本机基线环境失败(`DEP-FU-05`):** C 组 ③ 的全量测试以 `source .env.test && cargo test --all --no-fail-fast` 运行;失败集必须是「事实基线 → 基线全量测试」所列 6 个用例的子集,且每个失败的原因与基线逐字同类(版本断言 `git-lfs/3.8.0`、`docker push failed: unauthorized`、S3 PUT `502 Bad Gateway`);任何其它失败、或上述用例的原因漂移,即判红。不得 `#[ignore]`、跳过或修改这些用例;环境修复(安装 `git-lfs 3.7.1`、为 S3 客户端绕过系统代理、Docker registry 凭据)属用户动作,修复后恢复全绿口径。
350-
- **C 组(每张独立发布的 `implementation`、`migration` 或 `release` 卡——含 FU-14、FU-15、FU-23——顺序强制):** ① 版本面 parity 预检:`rg -n '^version' Cargo.toml` 与 `rg -l '^\[package\]' --glob '**/Cargo.toml'`(预期各一处)→ ② 按本卡 `Version increment` bump `Cargo.toml`,`cargo build` 刷新 `Cargo.lock` → ③ 在已 bump 树上 `cargo +nightly fmt --all --check`、`cargo clippy --all-targets --all-features -- -D warnings`、`source .env.test && cargo test --all --no-fail-fast`(全部 target 必须都已运行,再按「本机基线环境失败」口径比对失败集;环境修复后失败集必须为空) → ④ `cargo build`、`cargo build --tests` 0 错误 0 警告 → ⑤ 暂存前快照 `libra diff --staged --name-only`:非空(他人已暂存的工作)即停止并登记交接,不提交;为空才 `libra add <本卡路径>`,并校验暂存集 ⊆ 本卡写集 + 版本面,然后 `libra commit -s -m "v<version>: <summary>"` → ⑥ `libra push origin main`,并以 `libra --json status` 确认 `ahead=0` → ⑦ `libra tag -m "v<version>: <summary>" v<version>` + `libra push origin refs/tags/v<version>` → ⑧ 基于最终 diff 手写 release note(Highlights、用户可见变更、兼容/配置/迁移说明、验证结果、已知限制),`gh release create v<version> -R gitmono-dev/mega2 --title "v<version>" --notes-file <file>`(禁止 `--generate-notes`)。
352+
- **C 组(每张独立发布的 `implementation`、`migration` 或 `release` 卡——含 FU-14、FU-15、FU-23——顺序强制):** ① 版本面 parity 预检:`rg -n '^version' Cargo.toml` 与 `find . -name Cargo.toml -not -path './target/*' -not -path './.libra/*'`(预期各一处;不得对含 `target/` 的全仓做 `rg -l` 扫描——FU-01 执行时该扫描超时)→ ② 按本卡 `Version increment` bump `Cargo.toml`,`cargo build` 刷新 `Cargo.lock` → ③ 在已 bump 树上 `cargo +nightly fmt --all --check`、`cargo clippy --all-targets --all-features -- -D warnings`、`source .env.test && cargo test --all --no-fail-fast`(全部 target 必须都已运行,再按「本机基线环境失败」口径比对失败集;环境修复后失败集必须为空) → ④ `cargo build`、`cargo build --tests` 0 错误 0 警告 → ⑤ 暂存前快照 `libra diff --staged --name-only`:非空(他人已暂存的工作)即停止并登记交接,不提交;为空才 `libra add <本卡路径>`,并校验暂存集 ⊆ 本卡写集 + 版本面,然后 `libra commit -s -m "v<version>: <summary>"` → ⑥ `libra push origin main`,并以 `libra --json status` 确认 `ahead=0` → ⑦ `libra tag -m "v<version>: <summary>" v<version>` + `libra push origin refs/tags/v<version>` → ⑧ 基于最终 diff 手写 release note(Highlights、用户可见变更、兼容/配置/迁移说明、验证结果、已知限制),`gh release create v<version> -R gitmono-dev/mega2 --title "v<version>" --notes-file <file>`(禁止 `--generate-notes`)。
351353
- **D 组(每张 bump 卡,推送 tag 后):**
352354
```bash
353355
SHA=$(libra rev-parse HEAD) # 在打 tag 的同一提交上取得
@@ -499,7 +501,7 @@
499501

500502
**Task type:** `implementation`
501503

502-
**Lifecycle / Acceptance:** `pending` /
504+
**Lifecycle / Acceptance:** `in-progress` / `remote-pending`(A/B 通过;ER-05 Codex PASS + Claude PASS;C 组在 bump 后的 `0.38.22` 树上全绿:fmt、clippy 0 警告、`cargo test --all --no-fail-fast` 18 个 target 全部运行且失败集恰为 6 个基线环境用例(原因同类)、`cargo build` 0 警告、`cargo build --tests` 仅基线同有的 macOS `ld` 链接器提示;待 D 组 `docker` job)
503505

504506
**Description:** 按 ADR-FU-01 第 1–4、6 条,新增 `split_commit_message` helper(取代 `parse_commit_msg`),并让 `TrunkProvenance` 的 N=1 层消息与 squash 列表主题使用源 commit 正文。唯一行为轴是「trunk 合成 commit 的消息不携带源签名头」。
505507

@@ -2429,6 +2431,7 @@ Result 只允许 `PASS` 或 `FAIL`。`FAIL` 必须列出 P0/P1 条目并在下
24292431
| 计划 R20 | R19 修订全文 | FAIL | P1:多处仍称「仅一个迁移」,release note 与兼容清单遗漏 FU-15 —— R20 修订关闭 | 无 | `codex exec -s read-only` |
24302432
| 计划 R21 | R20 修订全文 | FAIL | P1:`import_dir` 首组件可不在 `root_dirs`,ImportRepo 首推会新建顶层根 —— R21 修订关闭 | 无 | `codex exec -s read-only` |
24312433
| 计划 R22 | R21 修订全文(FU-01..FU-23) | **PASS** | 无 | 无 | `codex exec -s read-only`(codex-cli 0.155.1),2026-09-23;Phase 0 退出 |
2434+
| FU-01 R1 | FU-01 diff(utils.rs、trunk_provenance.rs、integration_git_cli.rs、trunk-push.md) | PASS | 无 | Claude 第二评审 4×P2:trunk-push.md §3.2 旧句、ADR-FU-01 类型文字、层头部不得含客户端 armor 的断言——均已修复并重跑 `signed_push_` 与 fmt;第 4 项(全量测试)由 C 组承担 | Codex `VERDICT: PASS`;Claude `VERDICT: PASS` |
24322435
24332436
## 非目标与延后项
24342437

‎docs/refactoring/trunk-push.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ CREATE INDEX mega_refs_path_pattern
12361236

12371237
**3.2 message 与 trailer**
12381238

1239-
链长为 1 时退化为 tip 的 message 原样,零损失。链长 N > 1 时(`ordered_commits` 是 tip 在前,枚举时反转为拓扑升序):
1239+
链长为 1 时退化为 tip 的 message **正文**原样(`gpgsig` 等额外头剥离,见下文),零损失。链长 N > 1 时(`ordered_commits` 是 tip 在前,枚举时反转为拓扑升序):
12401240

12411241
```
12421242
Squash 3 commits at /project/foo
@@ -1276,7 +1276,7 @@ Mono-Squash-Range: 9f8e7d6..i7j8k9l0m1n2
12761276
Mono-Squash-Count: 3
12771277
```
12781278

1279-
N = 1 时不存在 squash,各层 roll-up 的 message 一律取客户端 commit 的 message 原样,无 `Mono-Squash-*` trailer。
1279+
N = 1 时不存在 squash,各层 roll-up 的 message 一律取客户端 commit 的 message **正文**原样,无 `Mono-Squash-*` trailer。「正文」指 commit 对象中头/体空行之后的字节:git-internal 把 `gpgsig` / `gpgsig-sha256` 等额外头放在 `Commit.message` 里,合成层 commit 必须先按 Git 头文法剥离这些头(`src/common/utils.rs` 的 `split_commit_message`),否则客户端签名块会落进合成 commit 的正文、`git log --oneline` 显示为 `gpgsig -----BEGIN PGP SIGNATURE-----`(issue #28;[`plan-20260923.md`](../plan/plan-20260923.md) FU-01)。合成层 commit 只带服务端签名;客户端签名只保留在被推路径逐字落地的 commit 上。squash 清单中的逐条主题同样取正文首个非空行。
12801280

12811281
这条规则同时限定了体积:**一次推送只产生一份完整枚举**,与已物化祖先/后代的层数无关。若各层都带完整枚举,体积会是「枚举 × 层数」,而层数随 `ls-remote` 这类只读操作单调增长(见写入模型一节对物化的说明),代价将不可控。`Mono-Squash-Commit` 是**不可变的 commit id**(被推路径 squash commit 的对象 id)——不是「当前 tip」这类活引用表述:后续推送推进 `main@P` 后,该 id 仍精确指向那份完整清单,`git show <id>` 一跳可达。
12821282

‎src/ceres/pack/trunk_provenance.rs‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use git_internal::{
1212
},
1313
};
1414

15-
use crate::common::errors::MegaError;
15+
use crate::common::{
16+
errors::MegaError,
17+
utils::{commit_body_subject, split_commit_message},
18+
};
1619

1720
/// Server-sign a trunk synthetic commit without rewriting identity.
1821
pub type TrunkMegaSign = std::sync::Arc<dyn Fn(&Commit) -> Result<Commit, MegaError> + Send + Sync>;
@@ -52,7 +55,10 @@ impl TrunkProvenance {
5255
squash_commit_id,
5356
range,
5457
land_ts,
55-
n1_message: tip.message.clone(),
58+
// git-internal keeps extra headers (e.g. the client's `gpgsig`) in
59+
// `message`; a synthesized layer commit carries only the body, and
60+
// the server signature is embedded separately (ADR-FU-01).
61+
n1_message: split_commit_message(&tip.message).body.to_owned(),
5662
}
5763
}
5864

@@ -214,12 +220,7 @@ fn identity_key(sig: &Signature) -> String {
214220
}
215221

216222
fn commit_subject(message: &str) -> String {
217-
message
218-
.lines()
219-
.find(|line| !line.trim().is_empty())
220-
.unwrap_or("")
221-
.trim()
222-
.to_owned()
223+
commit_body_subject(split_commit_message(message).body).to_owned()
223224
}
224225

225226
fn author_date_range_trailer(topo_asc: &[Commit]) -> Option<String> {
@@ -426,11 +427,30 @@ mod tests {
426427
assert_eq!(land.timezone, "+0000");
427428
}
428429

430+
const SIGNED_TIP_MESSAGE: &str = "gpgsig -----BEGIN PGP SIGNATURE-----\n \n wsBcBAABCAAQBQJ\n =abcd\n -----END PGP SIGNATURE-----\n\nfeat: signed subject\n\nbody\n";
431+
429432
#[test]
430-
fn n1_layer_message_is_verbatim() {
431-
let tip = commit("feat: keep me\n\nbody\n", alice(9), None);
433+
fn n1_layer_message_is_body() {
434+
// Unsigned tip as git-internal parses it: leading header/body newline.
435+
let tip = commit("\nfeat: keep me\n\nbody\n", alice(9), None);
432436
let plan = TrunkProvenance::from_tip(&tip, 1, "/p", tip.id.to_string(), None, 99);
433-
assert_eq!(plan.layer_message("/"), tip.message);
437+
assert_eq!(plan.layer_message("/"), "feat: keep me\n\nbody\n");
434438
assert!(!plan.layer_message("/").contains("Mono-Squash"));
439+
440+
// Signed tip: the client's signature header never reaches the layer body.
441+
let signed = commit(SIGNED_TIP_MESSAGE, alice(10), None);
442+
let plan = TrunkProvenance::from_tip(&signed, 1, "/p", signed.id.to_string(), None, 99);
443+
assert_eq!(plan.layer_message("/"), "feat: signed subject\n\nbody\n");
444+
assert!(!plan.layer_message("/").contains("BEGIN PGP SIGNATURE"));
445+
}
446+
447+
#[test]
448+
fn squash_subject_skips_signature() {
449+
let a = commit(SIGNED_TIP_MESSAGE, alice(10), None);
450+
let b = commit("\nfix: second\n", bob(11), Some(a.id));
451+
let msg = squash_message("/p", &[a, b.clone()], None, &b.author);
452+
assert!(msg.contains("feat: signed subject"), "{msg}");
453+
assert!(msg.contains("fix: second"), "{msg}");
454+
assert!(!msg.contains("gpgsig"), "{msg}");
435455
}
436456
}

0 commit comments

Comments
 (0)