Skip to content

Commit 433197a

Browse files
genednaclaude
andcommitted
v0.39.0: validate root_dirs / import_dir shape (FU-04, #29)
Config::validate() (config validate, service startup, hot-reload candidates) now checks the [monorepo] path policy shape: - every root_dirs entry is a unique single path component: no '/', '\' or NUL; not '.', '..' or empty; no leading/trailing whitespace; not a root entry init_trees already adds (.cedar, .mega_cedar.json, .buckroot, .buckconfig) and not .git (any case); - import_dir is a canonical absolute non-root path without NUL or '\' whose first component is listed in root_dirs. Errors name the field and never include secrets. Invalid configs that used to produce a broken root tree now fail before startup (minor bump). Shipped config comments, docs/configuration(.zh).md, docs/manual/monorepo-init.md and docs/monorepo.md describe the rules including import-first. Tests: monorepo_root_dirs_rejects_invalid_entries, monorepo_import_dir_shape, monorepo_shape_error_names_field_without_secret, shipped_configs_pass_monorepo_shape, monorepo_shipped_config_comments. Plan: docs/plan/plan-20260923.md FU-04 (Codex R2 PASS, Claude R2 PASS). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Eli Ma <eli@patch.sh>
1 parent fb7672c commit 433197a

14 files changed

Lines changed: 353 additions & 45 deletions

‎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.24"
3+
version = "0.39.0"
44
edition = "2024"
55
# Two [[bin]] targets exist; keep `cargo run -p mega2` unambiguous.
66
default-run = "mega2"

‎config/config-storage-only.none.toml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ url = "redis://127.0.0.1:6379"
125125
# a single public branch `main`.
126126
# 场景:该目录下的路径按导入仓库处理(可保留多分支与客户端 tag);其余一律按
127127
# monorepo 管理,只有 `main` 一个公开分支.
128+
# Shape / 形状: canonical absolute non-root path (no trailing '/', no '//', '.'
129+
# or '..' segments, no '\' or NUL) whose first component is listed in
130+
# `root_dirs`. Import first: a path under import_dir is always an ImportRepo
131+
# (created by Git push), even if `root_dirs` has the same name.
132+
# 规范绝对非根路径(无尾 '/'、无 '//'、'.'、'..' 段,不含 '\' 或 NUL),首组件
133+
# 必须列在 root_dirs 中;import 优先:该目录下的路径一律按 ImportRepo 处理(由
134+
# Git 推送创建),即使 root_dirs 含同名项.
128135
import_dir = "/third-party"
129136

130137
# System admins at `service init` / 初始化时的系统管理员.
@@ -140,6 +147,13 @@ admin = ["mega2"]
140147
# data migration, not a config edit.
141148
# 场景:monorepo 树的固定命名空间,下文 token 的 `paths` 授权就写这些根.
142149
# 重组它们属于数据迁移,不是改配置能解决的.
150+
# Shape / 形状: each entry is a unique single path component: no '/', '\' or
151+
# NUL; not '.', '..' or empty; no leading/trailing spaces; not a reserved root
152+
# entry (.cedar, .mega_cedar.json, .buckroot, .buckconfig, .git). `config
153+
# validate` and startup reject anything else.
154+
# 每项为唯一的单组件目录名:不含 '/'、'\' 或 NUL,不能是 '.'、'..' 或空串,无首尾
155+
# 空格,且不能是根树保留项(.cedar、.mega_cedar.json、.buckroot、.buckconfig、.git),
156+
# 否则校验失败.
143157
root_dirs = ["third-party", "project", "doc", "artifact", "release", "model", "data", "toolchains"]
144158

145159
# Object-ID hash for the repo graph / 仓库图的 Object-ID 哈希.

‎config/config-storage-only.toml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ url = "redis://127.0.0.1:6379"
125125
# a single public branch `main`.
126126
# 场景:该目录下的路径按导入仓库处理(可保留多分支与客户端 tag);其余一律按
127127
# monorepo 管理,只有 `main` 一个公开分支.
128+
# Shape / 形状: canonical absolute non-root path (no trailing '/', no '//', '.'
129+
# or '..' segments, no '\' or NUL) whose first component is listed in
130+
# `root_dirs`. Import first: a path under import_dir is always an ImportRepo
131+
# (created by Git push), even if `root_dirs` has the same name.
132+
# 规范绝对非根路径(无尾 '/'、无 '//'、'.'、'..' 段,不含 '\' 或 NUL),首组件
133+
# 必须列在 root_dirs 中;import 优先:该目录下的路径一律按 ImportRepo 处理(由
134+
# Git 推送创建),即使 root_dirs 含同名项.
128135
import_dir = "/third-party"
129136

130137
# System admins at `service init` / 初始化时的系统管理员.
@@ -140,6 +147,13 @@ admin = ["mega2"]
140147
# data migration, not a config edit.
141148
# 场景:monorepo 树的固定命名空间,下文 token 的 `paths` 授权就写这些根.
142149
# 重组它们属于数据迁移,不是改配置能解决的.
150+
# Shape / 形状: each entry is a unique single path component: no '/', '\' or
151+
# NUL; not '.', '..' or empty; no leading/trailing spaces; not a reserved root
152+
# entry (.cedar, .mega_cedar.json, .buckroot, .buckconfig, .git). `config
153+
# validate` and startup reject anything else.
154+
# 每项为唯一的单组件目录名:不含 '/'、'\' 或 NUL,不能是 '.'、'..' 或空串,无首尾
155+
# 空格,且不能是根树保留项(.cedar、.mega_cedar.json、.buckroot、.buckconfig、.git),
156+
# 否则校验失败.
143157
root_dirs = ["third-party", "project", "doc", "artifact", "release", "model", "data", "toolchains"]
144158

145159
# Object-ID hash for the repo graph / 仓库图的 Object-ID 哈希.

‎config/config.toml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,29 @@ sqlx_logging = false
6161
## - Tags must not be created/updated/deleted via Git client; use Web UI /tags API.
6262
## Only import_dir supports multi-branch and Git-client tags (ImportRepo).
6363
## Mega treats files under this directory as import repo and other directories as monorepo
64+
## Shape: a canonical absolute non-root path (no trailing '/', no '//', '.' or '..' segments,
65+
## no '\' or NUL) whose first component is listed in root_dirs. Import first: a path under
66+
## import_dir is always an ImportRepo (created by Git push), even if root_dirs has the same name.
67+
## 形状:规范绝对非根路径(无尾 '/'、无 '//'、'.'、'..' 段,不含 '\' 或 NUL),首组件必须列在
68+
## root_dirs 中;import 优先:该目录下的路径一律按 ImportRepo 处理(由 Git 推送创建),即使
69+
## root_dirs 含同名项.
6470
import_dir = "/third-party"
6571

6672
# Set System Admin(s) in directory init, these users will be added to the admin group
6773
# Supports multiple admins: admin = ["user1", "user2", "user3"]
6874
admin = ["mega2"]
6975

7076
# Set serveral root dirs in directory init
77+
# Shape: each entry is a unique single path component: no '/', '\' or NUL; not '.', '..'
78+
# or empty; no leading/trailing spaces; not a reserved root entry (.cedar, .mega_cedar.json,
79+
# .buckroot, .buckconfig, .git). `config validate` and startup reject anything else. Only the
80+
# first initialization (`service init`, or the first service start on an empty database)
81+
# creates these directories; changing the list later needs a restart and does not add or
82+
# remove top-level directories of an initialized repository.
83+
# 形状:每项为唯一的单组件目录名:不含 '/'、'\' 或 NUL,不能是 '.'、'..' 或空串,无首尾空格,
84+
# 且不能是根树保留项(.cedar、.mega_cedar.json、.buckroot、.buckconfig、.git),否则校验失败.
85+
# 只有首次初始化(`service init` 或空库上的首次服务启动)会创建这些目录;事后修改需重启,且不会
86+
# 增删已初始化库的顶层目录.
7187
root_dirs = ["third-party", "project", "doc", "artifact", "release", "model", "data", "toolchains"]
7288

7389
# Object-ID format for the initial Monorepo graph and live Git service.

‎docs/configuration.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ One line of purpose and the key entries per section; full comments and defaults
8383
- **`[log]`**: tracing logs. `level` (trace..error), `print_std` (off in production), `with_ansi` (stdout only). All hot-reloadable.
8484
- **`[database]`**: PostgreSQL only (`db_type = "postgres"`). `db_url`, pool `max_connection` / `min_connection`, `acquire_timeout` / `connect_timeout`, `sqlx_logging`. Inject credentials via `MEGA_DATABASE__DB_URL`, not via Vault SecretRef.
8585
- **`[monorepo]`**: product rules (authoritative: [`monorepo.md`](./monorepo.md)). `import_dir` (default `/third-party`, the ImportRepo multi-branch exception), `admin`, `root_dirs` (directory init), `object_format` (`sha1` default; `sha256` / `blake3` are Libra extensions — see [`refactoring/config.md`](./refactoring/config.md) and [`refactoring/protocol.md`](./refactoring/protocol.md)), `push_policy` (`review` default / `trunk`), `max_push_commits` (trunk chain-length bound). Bootstrap: `mega2 --config <path> service init --yes` (see [`manual/monorepo-init.md`](./manual/monorepo-init.md)).
86+
- Path shape (`config validate`, service startup and hot-reload candidates run the same check; a violation fails and names the field): every `root_dirs` entry is a unique single path component — no `/`, `\` or NUL; not `.`, `..` or empty; no leading/trailing spaces; not a reserved root entry (`.cedar`, `.mega_cedar.json`, `.buckroot`, `.buckconfig`, `.git`); `import_dir` is a canonical absolute non-root path (no trailing slash, no `//`, `.` or `..` segments, no NUL or `\`) whose first component is listed in `root_dirs`. **Import first**: a path under `import_dir` is always an ImportRepo (created by Git push), even if `root_dirs` has the same name. `root_dirs` only creates directories at the first initialization (`service init`, or the first service start on an empty database); changing it later needs a restart and does not add or remove top-level directories of an initialized repository (see [`manual/monorepo-init.md`](./manual/monorepo-init.md)).
8687
- **`[monorepo.rename]`**: move/rename detection for diff classification: `similarity_threshold` (0-100), `rename_limit` (0 = unlimited).
8788
- **`[pack]`**: receive-pack decode resources. `pack_decode_mem_size` / `pack_decode_disk_size` (K/M/G, KiB/MiB, and percentages supported), `pack_decode_cache_path`, `clean_cache_after_decode`, `channel_message_size`, `save_entry_concurrency`.
8889
- **`[lfs]`**: `[lfs.ssh].http_url` (href base for the SSH transfer; LFS payloads still move over HTTP), `[lfs.local].lfs_file_path`. In trunk, LFS authorization follows `git.push_auth` — see [`deploy-trunk.md`](./deploy-trunk.md) §6.

‎docs/configuration.zh.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ mega2 --config /etc/mega2/config.toml config secret check redis.url \
8383
- **`[log]`**:tracing 日志。`level`(trace..error)、`print_std`(生产关)、`with_ansi`(仅 stdout)。全部热加载。
8484
- **`[database]`**:仅支持 PostgreSQL(`db_type = "postgres"`)。`db_url`、连接池 `max_connection` / `min_connection`、`acquire_timeout` / `connect_timeout`、`sqlx_logging`。凭据用 `MEGA_DATABASE__DB_URL` 注入,不走 Vault SecretRef。
8585
- **`[monorepo]`**:产品规则(权威 [`monorepo.md`](./monorepo.md))。`import_dir`(默认 `/third-party`,ImportRepo 多分支特例)、`admin`、`root_dirs`(目录初始化)、`object_format`(`sha1` 默认;`sha256` / `blake3` 为 Libra 扩展,见 [`refactoring/config.md`](./refactoring/config.md) 与 [`refactoring/protocol.md`](./refactoring/protocol.md))、`push_policy`(`review` 默认 / `trunk`)、`max_push_commits`(trunk 链长上界)。bootstrap:`mega2 --config <path> service init --yes`(见 [`manual/monorepo-init.md`](./manual/monorepo-init.md))。
86+
- 路径形状(`config validate`、服务启动与热重载候选同一校验,违反即失败并点名字段):`root_dirs` 每项为唯一的单组件目录名——不含 `/`、`\` 或 NUL,不能是 `.`、`..` 或空串,无首尾空格,且不能是根树保留项(`.cedar`、`.mega_cedar.json`、`.buckroot`、`.buckconfig`、`.git`);`import_dir` 为规范绝对非根路径(无尾斜杠,无 `//`、`.`、`..` 段,不含 NUL 与 `\`),且首组件必须列在 `root_dirs` 中。**import 优先**:`import_dir` 之下的路径一律按 ImportRepo 处理(由 Git 推送创建),即使 `root_dirs` 含同名项。`root_dirs` 只在首次初始化(`service init` 或空库上的首次服务启动)时建目录;事后修改需重启,且不会增删已初始化库的顶层目录(见 [`manual/monorepo-init.md`](./manual/monorepo-init.md))。
8687
- **`[monorepo.rename]`**:diff 分类的移动 / 改名检测:`similarity_threshold`(0-100)、`rename_limit`(0 = 不限制)。
8788
- **`[pack]`**:receive-pack 解码资源。`pack_decode_mem_size` / `pack_decode_disk_size`(支持 K/M/G、KiB/MiB 与百分比)、`pack_decode_cache_path`、`clean_cache_after_decode`、`channel_message_size`、`save_entry_concurrency`。
8889
- **`[lfs]`**:`[lfs.ssh].http_url`(SSH 传输的 href 底座,LFS 文件仍走 HTTP)、`[lfs.local].lfs_file_path`。trunk 下 LFS 鉴权随 `git.push_auth`,见 [`deploy-trunk.md`](./deploy-trunk.md) §6。

0 commit comments

Comments
 (0)