Skip to content

Commit e97ed48

Browse files
genednaclaude
andcommitted
v0.39.2: fresh-stack product writes and ImportRepo namespace guard (FU-06, #25, #29)
Product writes (create-entry, edit/save, delete-entry, move-entry) now: - run an unconditional ImportRepo namespace guard on every rewritten operand (path_policy::check_write_operands): import_dir and below, and for removals a strict ancestor of a nested import_dir, return 400 MONO_PATH_NOT_ALLOWED; paths inside a live ImportRepo keep their ImportApiService behaviour; - when no non-root main tip covers the write (fresh stack), classify the first-level root of the user's path and land on it after lazily materializing it with the advertise primitive; writes outside root_dirs or landing on / return MONO_PATH_NOT_ALLOWED naming the user's path; a strict ancestor of a nested import_dir is never materialized (MONO_PATH_UNINITIALIZED names the directory to provision). Same-path concurrent API writes remain bounded by ADR-TP-10 (DEFER-FU-12); advertise/review materialization of nested import_dir ancestors is DEFER-FU-13. Docs: deploy-trunk.md, refactoring/directory-entry-api.md, errors.md. Tests: create_entry_fresh_stack_without_clone, fresh_stack_concurrent_writes, api_write_outside_roots_path_policy, api_write_custom_root_dirs, api_write_nested_root_fresh_stack, api_write_import_namespace_guard, import_attach_after_import_dir_api_write, path_policy::tests::write_operand_guard. Plan: docs/plan/plan-20260923.md FU-06 (Codex R3 PASS, Claude R2 PASS). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Eli Ma <eli@patch.sh>
1 parent decc03b commit e97ed48

9 files changed

Lines changed: 650 additions & 39 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.39.1"
3+
version = "0.39.2"
44
edition = "2024"
55
# Two [[bin]] targets exist; keep `cargo run -p mega2` unambiguous.
66
default-run = "mega2"

‎docs/deploy-trunk.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ CL merge 只经 MonoWriteQueue;`[monorepo]` 无 `merge_writer` 键([`plan-20
2323

2424
产品 **API 写**(`POST /api/v1/create-entry`、`POST /api/v1/delete-entry`、`POST /api/v1/move-entry`、`POST /api/v1/edit/save`)在 trunk 下经 **`git.push_auth`** 鉴权后,将对象写入存储并用 **MonoWriteQueue** 前进 path tip(与 `git push` 同 tip 权威;见 [`plan-20260904.md`](./plan/plan-20260904.md))。`delete-entry` / `move-entry` 在 `is_directory=false` 时可删 / 移文件(省略字段仍只针对目录;见 [`refactoring/directory-entry-api.md`](./refactoring/directory-entry-api.md))。成功响应的 `cl_link` 为 `null`,不创建 `mega_cl` / `refs/cl/*`。写后同栈 `git clone` / `git pull` 可读到新内容。集成黑盒见 [`refactoring/integration.md`](./refactoring/integration.md) 的 `integration_api_write_trunk`。monorepo **tag 写**(`POST /api/v1/tags`、`DELETE /api/v1/tags/{name}`;plan-20260917 LB-04 起挂在 storage-only)同样经 `git.push_auth` 鉴权——create 以 `path_context`(缺省 `/`)、delete 以选择器 `path`(省略或空 = `/`):省略 path 的 delete 与 root / 缺省 `path_context` 的 create 需要能覆盖 `/` 的 token(`paths` 省略/空 = whole repo),`?path=/project` 的 delete 与非根 `path_context` 的 create 可用覆盖该 path 的 token——但只写 tag 元数据(`refs/tags/*`;注解 tag 另写 `mega_tag.path`),不经 MonoWriteQueue、不前进 path tip;`GET /api/v1/tags/list` 与 `GET /api/v1/tags/{name}` 不要求 Authorization;`POST /api/v1/tags/list` 回 **405**。
2525

26+
产品写的落点:写路径之上已有非根 `main` tip 时,在最深的那个 tip 上落地(与此前相同)。全新栈上(`service init` 之后只有根 `/` 有 tip)**不需要先 clone 任何祖先路径**:写路径合法时(首组件列在 `root_dirs` 中、不在 `import_dir` 之下),服务端先惰性物化其一级根(例如 `/project`,与 clone / ls-remote 触发的物化是同一原语),再在其上落地,落地 commit 的父即物化 commit。例外:`import_dir` 嵌套在某个根之下时(如 `/third-party/vendor`),该一级根(`/third-party`)是 `import_dir` 的严格祖先,服务端永不物化它(否则其下的 ImportRepo 挂载会被拒绝),该根下尚无 tip 的写返回 **409** `MONO_PATH_UNINITIALIZED`,需先开通更深的非 import 路径。以下写入在落点解析之前返回 **400** `MONO_PATH_NOT_ALLOWED: …`(错误契约见 [`errors.md`](errors.md) 的 PathPolicyError 小节):根外路径(首组件不在 `root_dirs` 中,如 `/vendor/x` 或已存在的 `/.cedar`);在 `/` 下新建顶层目录,以及共同父为 `/` 的跨顶层 move / 顶层目录删除(产品写从不在 `/` 落地);`import_dir` 命名空间内、不经 ImportRepo 处理的操作数:`import_dir` 本身;从父目录删除 / 移动挂载叶子(`path=/third-party`、`name=<repo>`——**不论该仓库是否存活**,因为请求按父路径分派到 Monorepo);`git_repo` 行已不存在(清理之后)的叶子内部路径;以及移动的目的地(不论 `main@/third-party` 是否曾被物化——ImportRepo 只由 Git 推送创建)。**存活 ImportRepo 内部**的路径仍按 `git_repo` 分派给 ImportRepo 处理,行为不变(edit/save 可写;delete / move 返回既有 409;目的地是存活 ImportRepo 的 move 返回 409)。错误消息点名用户写的路径;只有跨顶层 move 与删除顶层目录(首组件是合法根、但落点只能是 `/`)点名 `/`。`MONO_PATH_UNINITIALIZED` 消息提到的开通 CLI / API 在后续版本提供(plan-20260923 FU-07 / FU-08)。同一落点 tip 上已有排队或执行中的写入时(全新栈上即同一一级根,例如同时写 `/project/a` 与 `/project/b`),第二个并发写仍按 ADR-TP-10 被拒(目前表现为 500,见 [`plan-20260923.md`](plan/plan-20260923.md) `DEFER-FU-12`),客户端应串行写或重试。
27+
2628
启动期 fail-closed(`Config::validate` / `AppContext::new`):
2729

2830
1. `trunk` + `cedar.enforcement != "off"` → 拒绝。

‎docs/errors.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ use crate::common::errors::{ApiError, MegaError, RvError};
110110

111111
## PathPolicyError:Monorepo 路径策略(plan-20260923)
112112

113-
`PathPolicyError`(`src/common/errors/mod.rs`)是路径「创建 / 写入」策略的领域错误,经 `MegaError::PathPolicy(#[from])` 包装;包装层用 `#[error("{0}")]`,文本原样透出,没有 `Other error:` 前缀。`NotAllowed` 与 `Invalid` 由唯一的分类函数 `ceres::pack::path_policy::classify_creation_path` 判定(规则见 [`plan/plan-20260923.md`](./plan/plan-20260923.md) ADR-FU-04;同模块的 `in_import_namespace`、`is_import_dir_ancestor`、`not_allowed` 供调用方复用,不得复制判断);`Uninitialized` 与 `Conflict` 由调用方按树状态产生。客户端 JSON 路径入口先经 `strict_creation_path_input`(拒绝 NUL、`\`,要求原始输入已是规范路径)。
113+
`PathPolicyError`(`src/common/errors/mod.rs`)是路径「创建 / 写入」策略的领域错误,经 `MegaError::PathPolicy(#[from])` 包装;包装层用 `#[error("{0}")]`,文本原样透出,没有 `Other error:` 前缀。`NotAllowed` 与 `Invalid` 由 `ceres::pack::path_policy` 判定:创建分类走唯一的分类函数 `classify_creation_path`,产品写的 ImportRepo 命名空间守卫走 `check_write_operands`(ADR-FU-06)(规则见 [`plan/plan-20260923.md`](./plan/plan-20260923.md) ADR-FU-04;同模块的 `in_import_namespace`、`is_import_dir_ancestor`、`not_allowed` 供调用方复用,不得复制判断);`Uninitialized` 与 `Conflict` 由调用方按树状态产生。客户端 JSON 路径入口先经 `strict_creation_path_input`(拒绝 NUL、`\`,要求原始输入已是规范路径)。
114114

115115
| 变体 | 码 | HTTP(`ApiError`) | 含义 |
116116
|---|---|---|---|
117117
| `NotAllowed { path, allowed_roots, import_dir }` | `MONO_PATH_NOT_ALLOWED` | 400 | 目标路径不在任何 `root_dirs` 之下,或位于 `import_dir` 之下(import 优先:ImportRepo 由推送创建) |
118118
| `Uninitialized { path }` | `MONO_PATH_UNINITIALIZED` | 409 | 合法根下的路径尚未开通;消息点名 `mega2 path provision --server <url> <path>` 与 `POST /api/v1/path/provision` |
119-
| `Invalid { path, reason }` | `MONO_PATH_INVALID` | 400 | 路径非规范(相对、`.` / `..` 段、重复或尾斜杠)、含 NUL / `\`,或为根 `/` |
119+
| `Invalid { path, reason }` | `MONO_PATH_INVALID` | 400 | 路径非规范(相对、`.` / `..` 段、重复或尾斜杠)、含 NUL / `\`,或为根 `/`(分类原语的判定;产品写落点为 `/` 时按 `NotAllowed` 返回,见 ADR-FU-06) |
120120
| `Conflict { path, component }` | `MONO_PATH_CONFLICT` | 409 | 路径上的某个组件已存在且不是目录 |
121121

122122
文本格式(Git 面与 API 面同一文本):`Display` = `"<CODE>: <人读消息>"`,恒为单行——路径以带引号的转义形式出现(`Uninitialized` 开通命令里的路径只转义、不加引号),根名、原因等其余片段中的控制字符(换行、NUL 等)按 `\n` / `\0` 形式转义,保证能放进 Git `ng` 行且无法伪造多行输出。产品写经 `GitError` 返回时,`MegaError::PathPolicy` 转为 `[code:400|409] <文本>`(`PathPolicyError::http_status`),`ApiError` 据此设置状态并剥去标记;裸 `PathPolicyError` 与 `MegaError::PathPolicy` 则按类型映射且原样输出(不再从文本中解析 `[code:…]`,路径里出现该字样也不会截断消息)。三条通道的 `err_message` 都是原文。Git report-status 的 `ng` 行与 API `err_message` 都携带这段原文,客户端可按冒号前的码分支;码是公开契约,改名需 minor 版本并更新本节。`NotAllowed` 只列出允许的根(`/<name>`,排序)与 ImportRepo 目录,任何变体都不包含配置文件路径、`base_dir`、数据库 / Redis / 对象存储地址或凭据。

0 commit comments

Comments
 (0)