atlas-project-harness 0.2.0-beta.30 → 0.2.0-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +17 -1
- package/_support/__pycache__/solution.cpython-312.pyc +0 -0
- package/_support/solution.py +381 -56
- package/package.json +1 -1
- package/scripts/atlas_solution.py +17 -4
- package/shared/gates.md +1 -1
- package/shared/layout.md +1 -1
- package/shared/solution.md +68 -16
- package/templates/atlas.solution.yaml +3 -0
- package/tests/__pycache__/test_atlas_solution.cpython-312-pytest-9.1.1.pyc +0 -0
- package/tests/__pycache__/test_solution_e2e_console.cpython-312-pytest-9.1.1.pyc +0 -0
- package/tests/__pycache__/test_solution_e2e_console.cpython-312.pyc +0 -0
- package/tests/__pycache__/test_solution_guards.cpython-312-pytest-9.1.1.pyc +0 -0
- package/tests/test_atlas_solution.py +128 -0
- package/tests/test_solution_e2e_console.py +4 -2
- package/tests/test_solution_guards.py +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## [v0.2.0-beta.31] - 2026-11-07
|
|
8
|
+
|
|
9
|
+
### 🔒 solution:锁即可复现 pin + `check --strict` CI 门禁(RFC-20261104-02 增量)
|
|
10
|
+
|
|
11
|
+
* **Phase 1 既有能力(2026-11-04/05,非本次变更)**:`atlas solution init|adopt|status|check|lock`(仅 `federated`)与 `atlas solution task`——父级只读整合成员仓,外加窄写成员任务卡;成员目录保持 untracked、不被 ignore。
|
|
12
|
+
* **新增 · 成员 `url`**:清单可声明 `members[].url`;只接受 `http/https/ssh/git/file` 或 `user@host:path`,http(s) userinfo、密码、token/签名查询参数一律拒绝写入清单与锁。
|
|
13
|
+
* **新增 · 锁作为可对账 pin**:锁须被父仓 Git 跟踪且与父仓 `HEAD` 一致,`url` / `path` 须与清单一致;`lock --update` 在 detached HEAD 下拒绝写入 `branch: "HEAD"`。
|
|
14
|
+
* **新增 · `solution diff`**:只读对账,按成员输出自锁以来的 commit / diffstat、已暂存 / 未暂存 / 工作区改动;锁中 commit 不在本地时提示先 fetch。
|
|
15
|
+
* **新增 · `check --strict`**:锁缺失 / 未被父仓跟踪 / 与 `HEAD` 不一致 / 锁↔清单 `url`·`path` 不一致 / 成员 dirty 或无法判断 / 缺 URL / 成员·契约漂移 ⇒ `FAIL`,`overall=FAIL` 时 exit 1;默认 `check` 仍为 WARN。
|
|
16
|
+
* **加固 · 已跟踪路径 / gitlink 硬拒绝**:`init` / `adopt` 写清单前检查 `git ls-files -s`,成员路径已被父仓跟踪(含 mode `160000`)直接拒绝,并给出 `git rm --cached` / `.gitmodules` 修复指引。
|
|
17
|
+
* **加固 · 嵌套 ignore 与 symlink 逃逸**:`.gitignore` / `.ignore` / `.rgignore` 沿成员路径逐级检测;成员 symlink 指向根外时契约哈希返回 `missing`,不读取根外文件。
|
|
18
|
+
* **CI 还原口径**:父仓只存清单与锁;CI 按锁逐成员 clone + checkout 后执行 `atlas solution check --strict`,不提供自动还原命令。可直接复制的命令样例见 `shared/solution.md` §5.1。
|
|
19
|
+
* **风险**:成员目录是 untracked;在 solution 根执行 `git clean -ffdx` 会删除整个成员工作区及未提交改动。
|
|
20
|
+
|
|
21
|
+
### 🧭 solution 分期口径统一与 README 多仓场景
|
|
22
|
+
|
|
23
|
+
* **口径**:`shared/solution.md`、`shared/layout.md`、`docs/guide/quick-start.md` 拆清 `unified` 与成员代码提交属 Phase 2、`import`/`export` 属 Phase 3、多 host / `targets[]` / 跨仓图谱等属 Phase 4 可选增强,不再写成「Phase 2/3」区间;`shared/solution.md` 补「Phase 2 交付后绿地项目恢复默认 `unified`」。
|
|
24
|
+
* **RFC 勘误**:RFC-20261104-02 在 Phase 1「无语义硬门」后加状态注记,说明 `check --strict` 是 opt-in 的结构/可复现门、默认仍 WARN、不判语义兼容。
|
|
25
|
+
* **README**:新增「场景 E:多个独立子仓(solution)」——父级一次 `init` 只建清单、锁与骨架;父仓 `git diff` 看不到成员内容,改用 `atlas solution diff`;CI 按锁 clone + checkout 后跑 `check --strict`;`unified` 属 Phase 2;`git clean -ffdx` 风险提示。
|
|
26
|
+
|
|
7
27
|
## [v0.2.0-beta.30] - 2026-11-06
|
|
8
28
|
|
|
9
29
|
### 🧭 E2E 覆盖维度生成纪律三件套(RFC-20261106-01)
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Atlas — 践行 Project Harness 的全流程 AI 编程工作流
|
|
2
2
|
|
|
3
3
|
<p align="left">
|
|
4
|
-
<img src="https://img.shields.io/badge/version-0.2.0--beta.
|
|
4
|
+
<img src="https://img.shields.io/badge/version-0.2.0--beta.31-blue.svg" alt="Version" />
|
|
5
5
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License" />
|
|
6
6
|
<img src="https://img.shields.io/badge/tests-passing-success.svg" alt="Tests" />
|
|
7
7
|
<a href="https://sunwenzhe-git.github.io/atlas/"><img src="https://img.shields.io/badge/docs-VitePress-green.svg" alt="Docs" /></a>
|
|
@@ -274,6 +274,22 @@ Agent 全量串行初始化 `structure → prd → e2e`。
|
|
|
274
274
|
atlas check --fast
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
+
#### 场景 E:多个独立子仓(solution)
|
|
278
|
+
|
|
279
|
+
前后端已是多个独立 git 仓时,不要在父目录直接 `atlas init`;父级只做一次 `solution init`:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
atlas solution init --name <方案名> --member web=web --member api=api
|
|
283
|
+
atlas solution diff
|
|
284
|
+
atlas solution check --strict
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
- 父级只建立 `atlas.solution.yaml`、锁与父级 PRD 骨架,不迁移成员资产;成员仍是普通 git 仓,日常在自己的分支开发,不受影响。
|
|
288
|
+
- 父仓 `git diff` 看不到成员文件内容,成员改动用 `atlas solution diff` 对账。
|
|
289
|
+
- 锁是提交进父仓、可对账的 pin;CI 按锁逐成员 clone + checkout 后跑 `atlas solution check --strict`,版本对不上直接红。
|
|
290
|
+
- `unified`(成员不再各自开户、资产收归父级)属 Phase 2,当前不提供。
|
|
291
|
+
- ⚠️ 成员目录是 untracked:在父仓执行 `git clean -ffdx` 会连未提交工作一起删除。
|
|
292
|
+
|
|
277
293
|
---
|
|
278
294
|
|
|
279
295
|
## 四、创新设计:E2E 用例评审控制台(人机协同终验)
|
|
Binary file
|
package/_support/solution.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""atlas solution —— 多仓方案层(
|
|
2
|
+
"""atlas solution —— 多仓方案层(federated + pinned workspace)。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
4
|
+
Phase 1 提供只读整合:清单 / 锁解析、成员 git 状态、ignore / gitlink / 非 git 守卫、
|
|
5
|
+
跨仓契约指纹、`status` / `check` / `lock` / `init` / `adopt`。
|
|
6
|
+
|
|
7
|
+
本次增量(Unreleased)把锁升级为可复现基线:
|
|
8
|
+
- 清单可记录 `members[].url`;URL 做 scheme 白名单并拒绝内嵌凭据;
|
|
9
|
+
- 锁记录成员 `url / branch / head(commit)`,作为 `check --strict` 的判据;
|
|
10
|
+
- `check --strict` 把锁缺失 / 锁未跟踪 / 版本或契约漂移 / dirty / 缺 URL 升为 FAIL;
|
|
11
|
+
- `diff` 只读对账:成员相对锁的提交 / diffstat 与工作区改动。
|
|
12
|
+
|
|
13
|
+
CI 按锁还原由流水线自行 clone + checkout 承担(见 `shared/solution.md` §5.1),本模块不提供自动还原命令。
|
|
9
14
|
|
|
10
15
|
**不做**:unified 资产搬迁、成员代码提交(solution_commit)、impact / closeout 多根对账。
|
|
11
16
|
这些属于 Phase 2/3;遇到 `mode: unified` 必须显式拒绝,不得静默降级。
|
|
@@ -23,6 +28,7 @@ import subprocess
|
|
|
23
28
|
import sys
|
|
24
29
|
from datetime import datetime, timezone
|
|
25
30
|
from pathlib import Path, PurePosixPath
|
|
31
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
26
32
|
|
|
27
33
|
MANIFEST_NAME = "atlas.solution.yaml"
|
|
28
34
|
LOCK_NAME = "atlas.solution.lock.json"
|
|
@@ -94,6 +100,76 @@ def _scalar(raw: str):
|
|
|
94
100
|
return v
|
|
95
101
|
|
|
96
102
|
|
|
103
|
+
_URL_SCHEMES = ("http", "https", "ssh", "git", "file")
|
|
104
|
+
_CREDENTIAL_QUERY = re.compile(
|
|
105
|
+
r"(?:^|[?&])(?:access_token|private_token|token|auth|key|sig|signature|"
|
|
106
|
+
r"x-amz-signature|x-amz-credential|x-amz-security-token)=", re.I)
|
|
107
|
+
_SCP_LIKE = re.compile(r"^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+:[^/].*$")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _redact_url(raw: str) -> str:
|
|
111
|
+
"""错误信息里的脱敏展示:只遮蔽 userinfo 与 token 查询参数。"""
|
|
112
|
+
try:
|
|
113
|
+
parts = urlsplit(raw)
|
|
114
|
+
except ValueError:
|
|
115
|
+
return "<redacted>"
|
|
116
|
+
netloc = parts.netloc
|
|
117
|
+
if "@" in netloc:
|
|
118
|
+
user = netloc.rsplit("@", 1)[0]
|
|
119
|
+
masked = "***" if ":" not in user else f"{user.split(':', 1)[0]}:***"
|
|
120
|
+
netloc = f"{masked}@{netloc.rsplit('@', 1)[1]}"
|
|
121
|
+
query = re.sub(
|
|
122
|
+
r"(?i)((?:access_token|private_token|token|auth|key|sig|signature|"
|
|
123
|
+
r"x-amz-signature|x-amz-credential|x-amz-security-token)=)[^&]*",
|
|
124
|
+
r"\1***", parts.query)
|
|
125
|
+
return urlunsplit((parts.scheme, netloc, parts.path, query, parts.fragment))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _validate_url(raw, field: str) -> str | None:
|
|
129
|
+
"""成员仓远端地址:scheme 白名单 + 拒绝内嵌凭据 / 参数注入。
|
|
130
|
+
|
|
131
|
+
允许 http/https/ssh/git/file、SCP 形式 `user@host:path`、本地绝对或 ./ 路径;
|
|
132
|
+
拒绝 `ext::`(git 可执行命令)、前导 `-`、控制字符 / 空白。
|
|
133
|
+
http(s) 的 userinfo 与常见 token 查询参数一律拒绝,避免凭据落进清单与锁。
|
|
134
|
+
"""
|
|
135
|
+
if raw is None:
|
|
136
|
+
return None
|
|
137
|
+
s = str(raw).strip()
|
|
138
|
+
if not s:
|
|
139
|
+
return None
|
|
140
|
+
if s.startswith("-") or re.search(r"[\x00-\x1f\s]", s):
|
|
141
|
+
raise SolutionError(f"{field} 含非法字符(控制字符 / 空白 / 前导 -): {raw!r}")
|
|
142
|
+
parts = urlsplit(s)
|
|
143
|
+
scheme = parts.scheme.lower()
|
|
144
|
+
if scheme:
|
|
145
|
+
if scheme not in _URL_SCHEMES:
|
|
146
|
+
raise SolutionError(
|
|
147
|
+
f"{field} 的 scheme 不在白名单({'/'.join(_URL_SCHEMES)}): {raw!r}")
|
|
148
|
+
if scheme in ("http", "https", "file") and (parts.username or parts.password):
|
|
149
|
+
raise SolutionError(
|
|
150
|
+
f"{field} 含内嵌凭据(userinfo),禁止写入清单/锁;"
|
|
151
|
+
f"请改用 SSH 或凭据管理器: {_redact_url(s)!r}")
|
|
152
|
+
if parts.password:
|
|
153
|
+
raise SolutionError(
|
|
154
|
+
f"{field} 含密码,禁止写入清单/锁;请改用 SSH 或凭据管理器: "
|
|
155
|
+
f"{_redact_url(s)!r}")
|
|
156
|
+
if _CREDENTIAL_QUERY.search(parts.query):
|
|
157
|
+
raise SolutionError(
|
|
158
|
+
f"{field} 查询参数含 token/签名,禁止写入清单/锁: {_redact_url(s)!r}")
|
|
159
|
+
return s
|
|
160
|
+
if _SCP_LIKE.match(s):
|
|
161
|
+
# SCP 形式只允许 user@host:path;出现 user:pass@ 视为密码。
|
|
162
|
+
userinfo = s.split("@", 1)[0]
|
|
163
|
+
if ":" in userinfo:
|
|
164
|
+
raise SolutionError(
|
|
165
|
+
f"{field} 含内嵌密码,禁止写入清单/锁: {_redact_url(s)!r}")
|
|
166
|
+
return s
|
|
167
|
+
if s.startswith("/") or s.startswith("./") or s.startswith("../"):
|
|
168
|
+
return s
|
|
169
|
+
raise SolutionError(
|
|
170
|
+
f"{field} 不是受支持的仓库地址(需要 scheme 白名单、SCP 形式或本地路径): {raw!r}")
|
|
171
|
+
|
|
172
|
+
|
|
97
173
|
def parse_manifest_text(text: str) -> dict:
|
|
98
174
|
"""解析 `atlas.solution.yaml` 的受限 YAML 子集。
|
|
99
175
|
|
|
@@ -153,7 +229,7 @@ def parse_manifest_text(text: str) -> dict:
|
|
|
153
229
|
key, val = s.split(":", 1)
|
|
154
230
|
key = key.strip()
|
|
155
231
|
known = {
|
|
156
|
-
"members": ("name", "path", "assets", "kind", "stack_profile"),
|
|
232
|
+
"members": ("name", "path", "url", "assets", "kind", "stack_profile"),
|
|
157
233
|
"contracts": ("id", "producer", "producer_path", "consumer", "consumer_path"),
|
|
158
234
|
"requirements": ("id", "acs", "member", "task_slug", "assignee", "scope"),
|
|
159
235
|
}[section]
|
|
@@ -213,6 +289,7 @@ def validate_manifest(data: dict, root: Path, phase1: bool = True) -> dict:
|
|
|
213
289
|
members.append({
|
|
214
290
|
"name": mname,
|
|
215
291
|
"path": mpath,
|
|
292
|
+
"url": _validate_url(item.get("url"), f"members[{mname}].url"),
|
|
216
293
|
"assets": assets,
|
|
217
294
|
"kind": str(item.get("kind") or "fullstack").strip() or "fullstack",
|
|
218
295
|
"stack_profile": str(item.get("stack_profile") or "").strip(),
|
|
@@ -309,6 +386,11 @@ def _git(cwd: Path, *args: str, timeout: int = 15) -> tuple[int, str, str]:
|
|
|
309
386
|
return p.returncode, p.stdout, p.stderr
|
|
310
387
|
|
|
311
388
|
|
|
389
|
+
def _git_lines(cwd: Path, *args: str, timeout: int = 15) -> list[str] | None:
|
|
390
|
+
rc, out, _ = _git(cwd, *args, timeout=timeout)
|
|
391
|
+
return out.splitlines() if rc == 0 else None
|
|
392
|
+
|
|
393
|
+
|
|
312
394
|
def _is_git(path: Path) -> bool:
|
|
313
395
|
"""成员必须是**自己的仓根**;仅位于 solution 根工作树内不算。"""
|
|
314
396
|
if not path.is_dir():
|
|
@@ -327,6 +409,13 @@ def _head(path: Path) -> str | None:
|
|
|
327
409
|
return out.strip() if rc == 0 and out.strip() else None
|
|
328
410
|
|
|
329
411
|
|
|
412
|
+
def _member_url(path: Path) -> str | None:
|
|
413
|
+
if not _is_git(path):
|
|
414
|
+
return None
|
|
415
|
+
rc, out, _ = _git(path, "remote", "get-url", "origin")
|
|
416
|
+
return out.strip() if rc == 0 and out.strip() else None
|
|
417
|
+
|
|
418
|
+
|
|
330
419
|
def _branch(path: Path) -> str | None:
|
|
331
420
|
rc, out, _ = _git(path, "rev-parse", "--abbrev-ref", "HEAD")
|
|
332
421
|
return out.strip() if rc == 0 and out.strip() else None
|
|
@@ -417,18 +506,40 @@ def _pattern_matches(pattern: str, rel: str) -> bool:
|
|
|
417
506
|
return regex.match(rel) is not None
|
|
418
507
|
|
|
419
508
|
|
|
509
|
+
def _ignore_sources(root: Path, rel: str) -> list[tuple[str, Path]]:
|
|
510
|
+
"""成员路径上所有可能生效的 ignore 文件:根级 + 逐级祖先目录。
|
|
511
|
+
|
|
512
|
+
`.gitignore` / `.ignore` / `.rgignore` 在子目录同样生效;只查根级会漏掉
|
|
513
|
+
`apps/.ignore` 这类嵌套规则。返回 (相对该 ignore 文件的目录, 文件路径)。
|
|
514
|
+
"""
|
|
515
|
+
sources: list[tuple[str, Path]] = []
|
|
516
|
+
for name in (".gitignore", ".ignore", ".rgignore"):
|
|
517
|
+
path = root / name
|
|
518
|
+
if path.is_file():
|
|
519
|
+
sources.append(("", path))
|
|
520
|
+
base = PurePosixPath()
|
|
521
|
+
for part in PurePosixPath(rel).parts[:-1]:
|
|
522
|
+
base = base / part
|
|
523
|
+
for name in (".gitignore", ".ignore", ".rgignore"):
|
|
524
|
+
path = root / base / name
|
|
525
|
+
if path.is_file():
|
|
526
|
+
sources.append((base.as_posix(), path))
|
|
527
|
+
exclude = root / ".git" / "info" / "exclude"
|
|
528
|
+
if exclude.is_file():
|
|
529
|
+
sources.append(("", exclude))
|
|
530
|
+
return sources
|
|
531
|
+
|
|
532
|
+
|
|
420
533
|
def _ignored_by_file(root: Path, rel: str) -> list[str]:
|
|
421
534
|
reasons: list[str] = []
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
]
|
|
426
|
-
for path in ignore_files:
|
|
535
|
+
rel_path = PurePosixPath(rel)
|
|
536
|
+
for base, path in _ignore_sources(root, rel):
|
|
537
|
+
sub = rel if not base else rel_path.relative_to(base).as_posix()
|
|
427
538
|
ignored = False
|
|
428
539
|
for pattern in _ignore_patterns(path):
|
|
429
540
|
neg = pattern.startswith("!")
|
|
430
541
|
body = pattern[1:].strip() if neg else pattern
|
|
431
|
-
if _pattern_matches(body,
|
|
542
|
+
if _pattern_matches(body, sub):
|
|
432
543
|
ignored = not neg
|
|
433
544
|
if ignored:
|
|
434
545
|
reasons.append(str(path.relative_to(root)))
|
|
@@ -450,11 +561,35 @@ def _tracked_member_paths(root: Path, rel: str) -> list[str]:
|
|
|
450
561
|
return [ln for ln in out.splitlines() if ln.strip()]
|
|
451
562
|
|
|
452
563
|
|
|
564
|
+
def _assert_members_untracked(root: Path, entries: list[dict]) -> None:
|
|
565
|
+
"""init/adopt 写清单前硬拒绝:成员路径已被父仓跟踪(含 submodule gitlink)。
|
|
566
|
+
|
|
567
|
+
只 WARN 会让“父仓 diff 看不到成员内容”的假象被带进新方案;
|
|
568
|
+
这里要求先解除跟踪,工作区文件保留。
|
|
569
|
+
"""
|
|
570
|
+
for m in entries:
|
|
571
|
+
tracked = _tracked_member_paths(root, m["path"])
|
|
572
|
+
if not tracked:
|
|
573
|
+
continue
|
|
574
|
+
gitlinks = [ln for ln in tracked if ln.split(maxsplit=1)[0] == "160000"]
|
|
575
|
+
if gitlinks:
|
|
576
|
+
raise SolutionError(
|
|
577
|
+
f"成员 {m['name']} 路径 {m['path']} 已被 solution 仓登记为 submodule/gitlink"
|
|
578
|
+
f"(mode 160000,{len(gitlinks)} 条)。请先执行 `git rm --cached {m['path']}` "
|
|
579
|
+
f"并删除 .gitmodules 中对应条目(保留工作区文件),再重试;"
|
|
580
|
+
"不要把 submodule 与 solution 混用。")
|
|
581
|
+
raise SolutionError(
|
|
582
|
+
f"成员 {m['name']} 路径 {m['path']} 已被 solution 仓跟踪({len(tracked)} 条)。"
|
|
583
|
+
f"请先执行 `git rm -r --cached {m['path']}`(保留工作区),"
|
|
584
|
+
"确认 .gitignore/.ignore/.rgignore 不命中该路径,再重试。")
|
|
585
|
+
|
|
586
|
+
|
|
453
587
|
def member_state(root: Path, member: dict) -> dict:
|
|
454
588
|
path = (root / member["path"]).resolve()
|
|
455
589
|
state = {
|
|
456
590
|
"name": member["name"],
|
|
457
591
|
"path": member["path"],
|
|
592
|
+
"url": member.get("url") or None,
|
|
458
593
|
"exists": path.is_dir(),
|
|
459
594
|
"git": _is_git(path),
|
|
460
595
|
"branch": None,
|
|
@@ -481,6 +616,12 @@ def member_state(root: Path, member: dict) -> dict:
|
|
|
481
616
|
state["head"] = _head(path)
|
|
482
617
|
state["dirty"] = _status_lines(path)
|
|
483
618
|
state["atlas_baseline"] = _atlas_baseline(path)
|
|
619
|
+
if not state["url"]:
|
|
620
|
+
try:
|
|
621
|
+
# origin 可能内嵌凭据:非法地址不进入状态,避免 status --json 泄露。
|
|
622
|
+
state["url"] = _validate_url(_member_url(path), f"member {member['name']}.url")
|
|
623
|
+
except SolutionError:
|
|
624
|
+
state["url"] = None
|
|
484
625
|
return state
|
|
485
626
|
|
|
486
627
|
|
|
@@ -497,40 +638,62 @@ def _sha256_file(path: Path) -> str:
|
|
|
497
638
|
return "missing"
|
|
498
639
|
|
|
499
640
|
|
|
641
|
+
def _safe_member_file(root: Path, member_rel: str, file_rel: str) -> Path | None:
|
|
642
|
+
"""契约文件必须落在 solution 根内;symlink 指向根外时返回 None,不读外部文件。"""
|
|
643
|
+
root_r = root.resolve()
|
|
644
|
+
member_dir = (root / member_rel).resolve()
|
|
645
|
+
try:
|
|
646
|
+
member_dir.relative_to(root_r)
|
|
647
|
+
except ValueError:
|
|
648
|
+
return None
|
|
649
|
+
target = (member_dir / file_rel).resolve()
|
|
650
|
+
try:
|
|
651
|
+
target.relative_to(root_r)
|
|
652
|
+
except ValueError:
|
|
653
|
+
return None
|
|
654
|
+
return target
|
|
655
|
+
|
|
656
|
+
|
|
500
657
|
def contract_states(root: Path, data: dict) -> list[dict]:
|
|
501
658
|
by_name = {m["name"]: m for m in data["members"]}
|
|
502
659
|
out: list[dict] = []
|
|
503
660
|
for c in data.get("contracts") or []:
|
|
504
|
-
producer = root
|
|
505
|
-
consumer = root
|
|
661
|
+
producer = _safe_member_file(root, by_name[c["producer"]]["path"], c["producer_path"])
|
|
662
|
+
consumer = _safe_member_file(root, by_name[c["consumer"]]["path"], c["consumer_path"])
|
|
506
663
|
out.append({
|
|
507
664
|
"id": c["id"],
|
|
508
665
|
"producer": c["producer"],
|
|
509
666
|
"producer_path": c["producer_path"],
|
|
510
|
-
"producer_sha256": _sha256_file(producer),
|
|
667
|
+
"producer_sha256": _sha256_file(producer) if producer else "missing",
|
|
511
668
|
"consumer": c["consumer"],
|
|
512
669
|
"consumer_path": c["consumer_path"],
|
|
513
|
-
"consumer_sha256": _sha256_file(consumer),
|
|
670
|
+
"consumer_sha256": _sha256_file(consumer) if consumer else "missing",
|
|
514
671
|
})
|
|
515
672
|
return out
|
|
516
673
|
|
|
517
674
|
|
|
518
675
|
def lock_payload(root: Path, data: dict) -> dict:
|
|
676
|
+
members: list[dict] = []
|
|
677
|
+
for m in data["members"]:
|
|
678
|
+
s = member_state(root, m)
|
|
679
|
+
if s["git"] and s.get("branch") == "HEAD":
|
|
680
|
+
raise SolutionError(
|
|
681
|
+
f"成员 {s['name']} 处于 detached HEAD(branch=HEAD);"
|
|
682
|
+
"请先切回分支再执行 lock --update,避免锁里写入不可复现的分支名")
|
|
683
|
+
members.append({
|
|
684
|
+
"name": s["name"],
|
|
685
|
+
"path": s["path"],
|
|
686
|
+
"url": m.get("url"),
|
|
687
|
+
"branch": s["branch"],
|
|
688
|
+
"head": s["head"],
|
|
689
|
+
"atlas_baseline": s["atlas_baseline"],
|
|
690
|
+
})
|
|
519
691
|
return {
|
|
520
692
|
"schema_version": SCHEMA_VERSION,
|
|
521
693
|
"solution": data["solution"],
|
|
522
694
|
"mode": data["mode"],
|
|
523
695
|
"locked_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
524
|
-
"members":
|
|
525
|
-
{
|
|
526
|
-
"name": s["name"],
|
|
527
|
-
"path": s["path"],
|
|
528
|
-
"branch": s["branch"],
|
|
529
|
-
"head": s["head"],
|
|
530
|
-
"atlas_baseline": s["atlas_baseline"],
|
|
531
|
-
}
|
|
532
|
-
for s in (member_state(root, m) for m in data["members"])
|
|
533
|
-
],
|
|
696
|
+
"members": members,
|
|
534
697
|
"contracts": contract_states(root, data),
|
|
535
698
|
}
|
|
536
699
|
|
|
@@ -556,6 +719,19 @@ def read_lock(root: Path) -> dict | None:
|
|
|
556
719
|
return data
|
|
557
720
|
|
|
558
721
|
|
|
722
|
+
def lock_tracking(root: Path) -> dict:
|
|
723
|
+
"""锁文件是否被父仓跟踪、且与父仓 HEAD 一致(CI 复现的前提)。"""
|
|
724
|
+
if not _is_git(root):
|
|
725
|
+
return {"tracked": False, "consistent": None}
|
|
726
|
+
rc, _, _ = _git(root, "ls-files", "--error-unmatch", "--", LOCK_NAME)
|
|
727
|
+
tracked = rc == 0
|
|
728
|
+
consistent = None
|
|
729
|
+
if tracked:
|
|
730
|
+
rc2, _, _ = _git(root, "diff", "--quiet", "HEAD", "--", LOCK_NAME)
|
|
731
|
+
consistent = rc2 == 0
|
|
732
|
+
return {"tracked": tracked, "consistent": consistent}
|
|
733
|
+
|
|
734
|
+
|
|
559
735
|
# ---------------------------------------------------------------- init / adopt
|
|
560
736
|
|
|
561
737
|
def _write_if_missing(path: Path, text: str) -> None:
|
|
@@ -604,10 +780,17 @@ def _install_atlas(root: Path, assets_root: str) -> None:
|
|
|
604
780
|
raise SolutionError("装配 .atlas 不完整(缺 VERSION 或 shared/solution.md);请重试")
|
|
605
781
|
|
|
606
782
|
|
|
607
|
-
def _member_entries(members: list[tuple
|
|
783
|
+
def _member_entries(members: list[tuple], root: Path | None = None) -> list[dict]:
|
|
608
784
|
out: list[dict] = []
|
|
609
|
-
for
|
|
610
|
-
|
|
785
|
+
for item in members:
|
|
786
|
+
name, path, kind = item[0], item[1], item[2]
|
|
787
|
+
explicit_url = item[3] if len(item) > 3 else None
|
|
788
|
+
rel = _safe_rel(path, f"member {name}.path")
|
|
789
|
+
url = explicit_url
|
|
790
|
+
if not url and root is not None:
|
|
791
|
+
url = _member_url(Path(root) / rel)
|
|
792
|
+
out.append({"name": name, "path": rel,
|
|
793
|
+
"url": _validate_url(url, f"member {name}.url"),
|
|
611
794
|
"assets": "member", "kind": kind or "fullstack"})
|
|
612
795
|
return out
|
|
613
796
|
|
|
@@ -639,6 +822,10 @@ def _manifest_text(name: str, members: list[dict], contracts: list[dict] | None
|
|
|
639
822
|
lines += [
|
|
640
823
|
f" - name: {m['name']}",
|
|
641
824
|
f" path: {m['path']}",
|
|
825
|
+
]
|
|
826
|
+
if m.get("url"):
|
|
827
|
+
lines.append(f" url: {_yaml_value(m['url'])}")
|
|
828
|
+
lines += [
|
|
642
829
|
" assets: member",
|
|
643
830
|
f" kind: {m.get('kind') or 'fullstack'}",
|
|
644
831
|
]
|
|
@@ -764,7 +951,7 @@ status: draft
|
|
|
764
951
|
""")
|
|
765
952
|
|
|
766
953
|
|
|
767
|
-
def init_solution(root: Path, name: str, members: list[tuple
|
|
954
|
+
def init_solution(root: Path, name: str, members: list[tuple],
|
|
768
955
|
assets_root: str = "product", install: bool = True,
|
|
769
956
|
contracts: list[dict] | None = None,
|
|
770
957
|
requirements: list[dict] | None = None) -> Path:
|
|
@@ -772,9 +959,11 @@ def init_solution(root: Path, name: str, members: list[tuple[str, str, str]],
|
|
|
772
959
|
if manifest_path(root).exists():
|
|
773
960
|
raise SolutionError(f"{MANIFEST_NAME} 已存在:{manifest_path(root)}")
|
|
774
961
|
name = _validate_name(name, "solution 名称")
|
|
775
|
-
entries = _member_entries(members)
|
|
962
|
+
entries = _member_entries(members, root)
|
|
776
963
|
if not entries:
|
|
777
964
|
raise SolutionError("Phase 1 至少需要一个成员仓(--member name=path)")
|
|
965
|
+
# 写清单前硬拒绝:成员已被父仓跟踪(含 gitlink)时不进入 solution 模型。
|
|
966
|
+
_assert_members_untracked(root, entries)
|
|
778
967
|
validate_manifest({
|
|
779
968
|
"version": SCHEMA_VERSION,
|
|
780
969
|
"solution": name,
|
|
@@ -798,6 +987,12 @@ def init_solution(root: Path, name: str, members: list[tuple[str, str, str]],
|
|
|
798
987
|
tmp = path.with_suffix(path.suffix + ".tmp")
|
|
799
988
|
tmp.write_text(_manifest_text(name, entries, contracts, requirements), encoding="utf-8")
|
|
800
989
|
tmp.replace(path)
|
|
990
|
+
# 成员齐全且不在 detached HEAD 时立即写入首版锁:
|
|
991
|
+
# init 即钉住一组可复现版本;成员尚未 clone 时暂不写,避免 head=None 的“假锁”。
|
|
992
|
+
data = load_manifest(root)
|
|
993
|
+
states = [member_state(root, m) for m in data["members"]]
|
|
994
|
+
if all(s["git"] and s.get("branch") not in (None, "HEAD") for s in states):
|
|
995
|
+
write_lock(root, data)
|
|
801
996
|
return path
|
|
802
997
|
|
|
803
998
|
|
|
@@ -816,7 +1011,7 @@ def detect_members(root: Path) -> list[tuple[str, str, str]]:
|
|
|
816
1011
|
def adopt_solution(root: Path, name: str, members: list[tuple[str, str, str]] | None = None,
|
|
817
1012
|
assets_root: str = "product", install: bool = True) -> tuple[Path, list[dict]]:
|
|
818
1013
|
root = Path(root).resolve()
|
|
819
|
-
entries = _member_entries(members or detect_members(root))
|
|
1014
|
+
entries = _member_entries(members or detect_members(root), root)
|
|
820
1015
|
if not entries:
|
|
821
1016
|
raise SolutionError("未检测到带 Atlas 资产的成员仓;请用 --member name=path 显式指定")
|
|
822
1017
|
path = init_solution(root, name, [(m["name"], m["path"], m.get("kind", "fullstack"))
|
|
@@ -834,6 +1029,12 @@ def status(root: Path) -> dict:
|
|
|
834
1029
|
data = load_manifest(root)
|
|
835
1030
|
states = [member_state(root, m) for m in data["members"]]
|
|
836
1031
|
lock = read_lock(root)
|
|
1032
|
+
for s in states:
|
|
1033
|
+
prev = _lock_member(lock, s["name"])
|
|
1034
|
+
s["locked_head"] = (prev or {}).get("head")
|
|
1035
|
+
s["head_drift"] = bool(prev and prev.get("head")
|
|
1036
|
+
and prev.get("head") != s.get("head"))
|
|
1037
|
+
s["dirty_count"] = len(s["dirty"]) if isinstance(s.get("dirty"), list) else None
|
|
837
1038
|
return {
|
|
838
1039
|
"solution": data["solution"],
|
|
839
1040
|
"mode": data["mode"],
|
|
@@ -860,19 +1061,20 @@ def _lock_contract(lock: dict | None, cid: str) -> dict | None:
|
|
|
860
1061
|
return None
|
|
861
1062
|
|
|
862
1063
|
|
|
863
|
-
def check_solution(root: Path) -> dict:
|
|
1064
|
+
def check_solution(root: Path, strict: bool = False) -> dict:
|
|
864
1065
|
root = Path(root).resolve()
|
|
865
1066
|
data = load_manifest(root)
|
|
866
1067
|
results: list[dict] = []
|
|
1068
|
+
level = "FAIL" if strict else "WARN"
|
|
867
1069
|
add = lambda name, status, detail: results.append(
|
|
868
1070
|
{"check": name, "status": status, "detail": detail})
|
|
869
1071
|
|
|
870
1072
|
add("清单 schema", "PASS", f"{data['solution']} / {data['mode']} / {len(data['members'])} 成员")
|
|
871
1073
|
if not _is_git(root):
|
|
872
|
-
add("solution 根",
|
|
1074
|
+
add("solution 根", level, "不是 git 仓;成员 untracked 没有基线,建议先 git init")
|
|
873
1075
|
rc, cfg_out, _ = _git(root, "config", "--get", "status.showUntrackedFiles")
|
|
874
1076
|
if rc == 0 and cfg_out.strip().lower() == "no":
|
|
875
|
-
add("git 配置",
|
|
1077
|
+
add("git 配置", level,
|
|
876
1078
|
"status.showUntrackedFiles=no 会盲掉 _graph / atlas_check / e2e_console")
|
|
877
1079
|
if data.get("unknown"):
|
|
878
1080
|
add("清单未知键", "WARN", ";".join(data["unknown"]))
|
|
@@ -890,64 +1092,92 @@ def check_solution(root: Path) -> dict:
|
|
|
890
1092
|
|
|
891
1093
|
lock = read_lock(root)
|
|
892
1094
|
contracts_now = contract_states(root, data)
|
|
1095
|
+
if lock is not None:
|
|
1096
|
+
tracking = lock_tracking(root)
|
|
1097
|
+
if not tracking["tracked"]:
|
|
1098
|
+
add("契约锁跟踪", level,
|
|
1099
|
+
f"{LOCK_NAME} 未被父仓 Git 跟踪;CI 无法从父仓 commit 还原锁定版本")
|
|
1100
|
+
elif tracking["consistent"] is False:
|
|
1101
|
+
add("契约锁跟踪", level,
|
|
1102
|
+
f"{LOCK_NAME} 与父仓 HEAD 不一致;请提交锁文件后再跑 CI")
|
|
893
1103
|
if lock is None:
|
|
894
|
-
add("契约锁",
|
|
1104
|
+
add("契约锁", level, f"缺少 {LOCK_NAME};运行 atlas solution lock --update")
|
|
895
1105
|
else:
|
|
896
1106
|
for s in data["members"]:
|
|
897
1107
|
prev = _lock_member(lock, s["name"])
|
|
898
1108
|
cur = member_state(root, s)
|
|
899
1109
|
if prev is None:
|
|
900
|
-
add(f"锁/{s['name']}",
|
|
1110
|
+
add(f"锁/{s['name']}", level, "锁中没有该成员")
|
|
901
1111
|
continue
|
|
1112
|
+
if not prev.get("head"):
|
|
1113
|
+
add(f"锁/{s['name']}", level, "锁中没有 commit,无法复现成员版本")
|
|
902
1114
|
if prev.get("head") != cur.get("head"):
|
|
903
|
-
add(f"锁/{s['name']}",
|
|
1115
|
+
add(f"锁/{s['name']}", level,
|
|
904
1116
|
f"HEAD 漂移:锁定 {str(prev.get('head'))[:12]} → 当前 {str(cur.get('head'))[:12]}")
|
|
905
1117
|
if prev.get("branch") != cur.get("branch"):
|
|
906
|
-
add(f"锁/{s['name']}",
|
|
1118
|
+
add(f"锁/{s['name']}", level,
|
|
907
1119
|
f"分支漂移:锁定 {prev.get('branch')!r} → 当前 {cur.get('branch')!r}")
|
|
908
1120
|
if prev.get("atlas_baseline") != cur.get("atlas_baseline"):
|
|
909
|
-
add(f"锁/{s['name']}",
|
|
1121
|
+
add(f"锁/{s['name']}", level,
|
|
910
1122
|
f"成员 Atlas baseline 漂移:锁定 {str(prev.get('atlas_baseline'))[:12]} → "
|
|
911
1123
|
f"当前 {str(cur.get('atlas_baseline'))[:12]}")
|
|
1124
|
+
if prev.get("path") != s["path"]:
|
|
1125
|
+
add(f"锁/{s['name']}", level,
|
|
1126
|
+
f"锁中 path={prev.get('path')!r} 与清单 {s['path']!r} 不一致")
|
|
1127
|
+
manifest_url = s.get("url") or ""
|
|
1128
|
+
lock_url = prev.get("url") or ""
|
|
1129
|
+
if not manifest_url and not lock_url:
|
|
1130
|
+
if strict:
|
|
1131
|
+
add(f"锁/{s['name']}", "FAIL",
|
|
1132
|
+
"清单与锁都没有 url;新机器 / CI 无法 bootstrap 成员")
|
|
1133
|
+
elif lock_url != manifest_url:
|
|
1134
|
+
add(f"锁/{s['name']}", level,
|
|
1135
|
+
"锁中 url 与清单不一致;重新执行 lock --update 并提交")
|
|
912
1136
|
for c in contracts_now:
|
|
913
1137
|
prev = _lock_contract(lock, c["id"])
|
|
914
1138
|
if prev is None:
|
|
915
|
-
add(f"锁/契约 {c['id']}",
|
|
1139
|
+
add(f"锁/契约 {c['id']}", level, "锁中没有该契约")
|
|
916
1140
|
continue
|
|
917
1141
|
for side in ("producer_sha256", "consumer_sha256"):
|
|
918
1142
|
if prev.get(side) != c[side]:
|
|
919
|
-
add(f"锁/契约 {c['id']}",
|
|
1143
|
+
add(f"锁/契约 {c['id']}", level, f"{side} 漂移(需人工确认跨仓影响)")
|
|
920
1144
|
member_names = {m["name"] for m in data["members"]}
|
|
921
1145
|
contract_ids = {c["id"] for c in contracts_now}
|
|
922
1146
|
for lm in lock.get("members") or []:
|
|
923
1147
|
if lm.get("name") not in member_names:
|
|
924
|
-
add("锁",
|
|
1148
|
+
add("锁", level, f"锁中成员已不在清单: {lm.get('name')}")
|
|
925
1149
|
for lc in lock.get("contracts") or []:
|
|
926
1150
|
if lc.get("id") not in contract_ids:
|
|
927
|
-
add("锁",
|
|
1151
|
+
add("锁", level, f"锁中契约已不在清单: {lc.get('id')}")
|
|
928
1152
|
for c in contracts_now:
|
|
929
1153
|
missing = [side for side in ("producer_sha256", "consumer_sha256")
|
|
930
1154
|
if c[side] == "missing"]
|
|
931
1155
|
if missing:
|
|
932
|
-
add(f"契约 {c['id']}",
|
|
1156
|
+
add(f"契约 {c['id']}", level,
|
|
933
1157
|
"文件缺失:" + "、".join(side.replace("_sha256", "") for side in missing))
|
|
934
1158
|
|
|
935
1159
|
for m in data["members"]:
|
|
936
1160
|
s = member_state(root, m)
|
|
937
1161
|
prefix = f"成员 {s['name']}"
|
|
938
1162
|
if not s["exists"]:
|
|
939
|
-
add(prefix,
|
|
1163
|
+
add(prefix, level, f"路径不存在: {s['path']}")
|
|
940
1164
|
continue
|
|
941
1165
|
if s["escaped"]:
|
|
942
|
-
add(prefix,
|
|
1166
|
+
add(prefix, level, "成员路径 resolve 后逃逸出 solution 根(symlink?)")
|
|
943
1167
|
if not s["git"]:
|
|
944
|
-
add(prefix,
|
|
1168
|
+
add(prefix, level, "不是 git 仓")
|
|
945
1169
|
if not s["atlas_assets"]:
|
|
946
1170
|
add(prefix, "WARN", "未检测到 Atlas 资产(atlas.config.yaml / product/stack-profile.yaml / 结构 meta)")
|
|
947
1171
|
if s["ignored"]:
|
|
948
|
-
add(prefix,
|
|
1172
|
+
add(prefix, level, "成员路径命中 ignore:" + "、".join(s["ignored"]))
|
|
949
1173
|
if s["tracked"]:
|
|
950
|
-
add(prefix,
|
|
1174
|
+
add(prefix, level, f"成员路径已被 solution 仓跟踪({len(s['tracked'])} 条,疑似 gitlink)")
|
|
1175
|
+
if strict and s["git"]:
|
|
1176
|
+
if s["dirty"] is None:
|
|
1177
|
+
add(prefix, "FAIL", "无法判断工作区是否 dirty(git status 失败)")
|
|
1178
|
+
elif s["dirty"]:
|
|
1179
|
+
add(prefix, "FAIL",
|
|
1180
|
+
f"工作区有 {len(s['dirty'])} 处未提交改动;strict 要求成员干净")
|
|
951
1181
|
if s.get("unknown"):
|
|
952
1182
|
add(prefix, "WARN", "成员未知键:" + "、".join(s["unknown"]))
|
|
953
1183
|
|
|
@@ -978,11 +1208,62 @@ def check_solution(root: Path) -> dict:
|
|
|
978
1208
|
add("Trellis packages", "SKIP",
|
|
979
1209
|
"solution 根无 .trellis/config.yaml(Phase 1 不生成;Phase 2)")
|
|
980
1210
|
|
|
981
|
-
|
|
1211
|
+
if any(r["status"] == "FAIL" for r in results):
|
|
1212
|
+
overall = "FAIL"
|
|
1213
|
+
elif any(r["status"] == "WARN" for r in results):
|
|
1214
|
+
overall = "WARN"
|
|
1215
|
+
else:
|
|
1216
|
+
overall = "PASS"
|
|
982
1217
|
return {"solution": data["solution"], "mode": data["mode"],
|
|
983
1218
|
"overall": overall, "checks": results}
|
|
984
1219
|
|
|
985
1220
|
|
|
1221
|
+
def diff_solution(root: Path) -> dict:
|
|
1222
|
+
"""只读对账:每个成员相对锁的提交、diffstat 与工作区改动。"""
|
|
1223
|
+
root = Path(root).resolve()
|
|
1224
|
+
data = load_manifest(root)
|
|
1225
|
+
lock = read_lock(root)
|
|
1226
|
+
members: list[dict] = []
|
|
1227
|
+
for m in data["members"]:
|
|
1228
|
+
path = (root / m["path"]).resolve()
|
|
1229
|
+
prev = _lock_member(lock, m["name"]) or {}
|
|
1230
|
+
entry = {
|
|
1231
|
+
"name": m["name"],
|
|
1232
|
+
"path": m["path"],
|
|
1233
|
+
"git": _is_git(path),
|
|
1234
|
+
"branch": None,
|
|
1235
|
+
"head": None,
|
|
1236
|
+
"locked_head": prev.get("head"),
|
|
1237
|
+
"lock_commit_present": None,
|
|
1238
|
+
"commits": [],
|
|
1239
|
+
"diffstat": [],
|
|
1240
|
+
"staged": [],
|
|
1241
|
+
"unstaged": [],
|
|
1242
|
+
"worktree": [],
|
|
1243
|
+
"worktree_ok": None,
|
|
1244
|
+
}
|
|
1245
|
+
if entry["git"]:
|
|
1246
|
+
entry["branch"] = _branch(path)
|
|
1247
|
+
entry["head"] = _head(path)
|
|
1248
|
+
locked = prev.get("head")
|
|
1249
|
+
if locked:
|
|
1250
|
+
rc, _, _ = _git(path, "cat-file", "-e", f"{locked}^{{commit}}")
|
|
1251
|
+
entry["lock_commit_present"] = rc == 0
|
|
1252
|
+
if rc == 0 and locked != entry["head"]:
|
|
1253
|
+
entry["commits"] = _git_lines(
|
|
1254
|
+
path, "log", "--oneline", "--max-count=50",
|
|
1255
|
+
f"{locked}..HEAD") or []
|
|
1256
|
+
entry["diffstat"] = _git_lines(
|
|
1257
|
+
path, "diff", "--stat", f"{locked}..HEAD") or []
|
|
1258
|
+
entry["staged"] = _git_lines(path, "diff", "--cached", "--stat") or []
|
|
1259
|
+
entry["unstaged"] = _git_lines(path, "diff", "--stat") or []
|
|
1260
|
+
worktree = _status_lines(path)
|
|
1261
|
+
entry["worktree_ok"] = worktree is not None
|
|
1262
|
+
entry["worktree"] = worktree or []
|
|
1263
|
+
members.append(entry)
|
|
1264
|
+
return {"solution": data["solution"], "mode": data["mode"], "members": members}
|
|
1265
|
+
|
|
1266
|
+
|
|
986
1267
|
def _assets_root(root: Path) -> str:
|
|
987
1268
|
config = root / CONFIG_NAME
|
|
988
1269
|
if config.is_file():
|
|
@@ -999,13 +1280,19 @@ def render_status(data: dict) -> str:
|
|
|
999
1280
|
lines = [f"solution: {data['solution']} ({data['mode']})", "members:"]
|
|
1000
1281
|
for s in data["members"]:
|
|
1001
1282
|
head = (s.get("head") or "—")[:12]
|
|
1002
|
-
|
|
1003
|
-
|
|
1283
|
+
dirty_n = s.get("dirty_count")
|
|
1284
|
+
dirty = "clean" if dirty_n == 0 else (f"dirty:{dirty_n}" if dirty_n else "n/a")
|
|
1004
1285
|
ignored = "ignored" if s.get("ignored") else "ok"
|
|
1286
|
+
if s.get("head_drift"):
|
|
1287
|
+
drift = "drift"
|
|
1288
|
+
elif s.get("locked_head"):
|
|
1289
|
+
drift = "locked"
|
|
1290
|
+
else:
|
|
1291
|
+
drift = "no-lock"
|
|
1005
1292
|
lines.append(
|
|
1006
1293
|
f" {s['name']:<16} {s['path']:<20} git={str(s['git']).lower():<5} "
|
|
1007
|
-
f"branch={s.get('branch') or '—':<12} head={head:<12} {dirty:<
|
|
1008
|
-
f"atlas={'yes' if s['atlas_assets'] else 'no':<3} {ignored}")
|
|
1294
|
+
f"branch={s.get('branch') or '—':<12} head={head:<12} {dirty:<8} "
|
|
1295
|
+
f"{drift:<7} atlas={'yes' if s['atlas_assets'] else 'no':<3} {ignored}")
|
|
1009
1296
|
lines.append(f"lock: {'present' if data['lock']['present'] else 'missing'}"
|
|
1010
1297
|
+ (f" ({data['lock']['locked_at']})" if data['lock'].get('locked_at') else ""))
|
|
1011
1298
|
return "\n".join(lines)
|
|
@@ -1016,3 +1303,41 @@ def render_check(data: dict) -> str:
|
|
|
1016
1303
|
for r in data["checks"]:
|
|
1017
1304
|
lines.append(f" [{r['status']}] {r['check']}: {r['detail']}")
|
|
1018
1305
|
return "\n".join(lines)
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
def render_diff(data: dict) -> str:
|
|
1309
|
+
lines = [f"solution diff: {data['solution']} ({data['mode']})"]
|
|
1310
|
+
for m in data["members"]:
|
|
1311
|
+
if not m["git"]:
|
|
1312
|
+
lines.append(f" [{m['name']}] {m['path']} ! 不是 git 仓")
|
|
1313
|
+
continue
|
|
1314
|
+
locked = (m.get("locked_head") or "—")[:12]
|
|
1315
|
+
lines.append(
|
|
1316
|
+
f" [{m['name']}] {m['path']} branch={m.get('branch') or '—'} "
|
|
1317
|
+
f"head={(m.get('head') or '—')[:12]} locked={locked}")
|
|
1318
|
+
if not m.get("locked_head"):
|
|
1319
|
+
lines.append(" lock=—(未锁定,仅显示工作区)")
|
|
1320
|
+
elif m.get("lock_commit_present") is False:
|
|
1321
|
+
lines.append(" ! 锁中 commit 不在本地;请先 fetch 对应成员")
|
|
1322
|
+
elif m["commits"]:
|
|
1323
|
+
lines.append(f" 自锁以来提交 {len(m['commits'])} 条:")
|
|
1324
|
+
lines += [f" {c}" for c in m["commits"]]
|
|
1325
|
+
if m["diffstat"]:
|
|
1326
|
+
lines.append(" 自锁以来 diffstat:")
|
|
1327
|
+
lines += [f" {c}" for c in m["diffstat"]]
|
|
1328
|
+
if m["staged"]:
|
|
1329
|
+
lines.append(" 已暂存:")
|
|
1330
|
+
lines += [f" {c}" for c in m["staged"]]
|
|
1331
|
+
if m["unstaged"]:
|
|
1332
|
+
lines.append(" 未暂存:")
|
|
1333
|
+
lines += [f" {c}" for c in m["unstaged"]]
|
|
1334
|
+
if m["worktree"]:
|
|
1335
|
+
lines.append(f" 工作区 {len(m['worktree'])} 项:")
|
|
1336
|
+
lines += [f" {c}" for c in m["worktree"][:30]]
|
|
1337
|
+
if len(m["worktree"]) > 30:
|
|
1338
|
+
lines.append(f" …(其余 {len(m['worktree']) - 30} 项省略)")
|
|
1339
|
+
if m.get("worktree_ok") is False:
|
|
1340
|
+
lines.append(" ! git status 失败,无法判断工作区")
|
|
1341
|
+
if not any((m["commits"], m["staged"], m["unstaged"], m["worktree"])):
|
|
1342
|
+
lines.append(" clean(相对锁无差异)")
|
|
1343
|
+
return "\n".join(lines)
|
package/package.json
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
atlas solution init --name <名> --member <名>=<路径> [--member ...] [--no-install]
|
|
6
6
|
atlas solution adopt [--name <名>] [--member <名>=<路径> ...]
|
|
7
7
|
atlas solution status [--json]
|
|
8
|
-
atlas solution
|
|
8
|
+
atlas solution diff [--json]
|
|
9
|
+
atlas solution check [--strict] [--json]
|
|
9
10
|
atlas solution lock --update [--json]
|
|
10
11
|
|
|
11
12
|
Phase 1 只做只读整合;unified / 成员代码提交(commit)在 Phase 2。
|
|
13
|
+
`check --strict` 用于 CI:锁缺失 / 未跟踪 / 版本或契约漂移 / 成员 dirty / 缺 URL 判 FAIL。
|
|
12
14
|
契约正文见 `.atlas/shared/solution.md`。
|
|
13
15
|
"""
|
|
14
16
|
from __future__ import annotations
|
|
@@ -85,8 +87,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
85
87
|
p_status = sub.add_parser("status", help="只读聚合成员状态")
|
|
86
88
|
_add_common(p_status)
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
p_diff = sub.add_parser("diff", help="只读对账:成员相对锁的提交/文件改动")
|
|
91
|
+
_add_common(p_diff)
|
|
92
|
+
|
|
93
|
+
p_check = sub.add_parser("check", help="只读检查清单/守卫/锁;--strict 用于 CI 门禁")
|
|
89
94
|
_add_common(p_check)
|
|
95
|
+
p_check.add_argument("--strict", action="store_true",
|
|
96
|
+
help="锁缺失/未跟踪/漂移/dirty/缺 URL 判 FAIL,并返回非零")
|
|
90
97
|
|
|
91
98
|
p_lock = sub.add_parser("lock", help="查看或更新契约锁")
|
|
92
99
|
_add_common(p_lock)
|
|
@@ -174,11 +181,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
174
181
|
else core.render_status(data))
|
|
175
182
|
return 0
|
|
176
183
|
|
|
184
|
+
if args.cmd == "diff":
|
|
185
|
+
data = core.diff_solution(root)
|
|
186
|
+
print(json.dumps(data, ensure_ascii=False, indent=2) if args.json
|
|
187
|
+
else core.render_diff(data))
|
|
188
|
+
return 0
|
|
189
|
+
|
|
177
190
|
if args.cmd == "check":
|
|
178
|
-
data = core.check_solution(root)
|
|
191
|
+
data = core.check_solution(root, strict=args.strict)
|
|
179
192
|
print(json.dumps(data, ensure_ascii=False, indent=2) if args.json
|
|
180
193
|
else core.render_check(data))
|
|
181
|
-
return 0
|
|
194
|
+
return 1 if data["overall"] == "FAIL" else 0
|
|
182
195
|
|
|
183
196
|
if args.cmd == "lock":
|
|
184
197
|
if not args.update:
|
package/shared/gates.md
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
| `validators/validate_adr.py`(2026-10-13 新增) | 架构决策记录 ⇔ MADR 契约 | `[机器]` 编号唯一(无同号撞号)/ frontmatter 合法性(status 枚举)/ 演进链闭环(superseded 必指有效后继)/ 核心章节完整(Context/Decision/Consequences)/ accepted 状态 Decision 内容非空;目录不存在或为空 ⇒ `SKIP` | 编号连续性(跳号合法);日期时序;决策内容工程合理性(语义归人侧审查) | 架构决策落笔后 + 每批收口;**调度者 = `atlas_check`**(三态前置:无 `<资产根>/adr/`(默认 `product/adr/`)⇒ `SKIP`) | `出厂级(本轮实测)`:`tests/test_validate_adr.py` 覆盖四维坏输入变异(同号撞号报 WARN / 状态非法报 WARN / 缺章节报 WARN / 无资产根 adr 报 SKIP / 格式完整报 PASS;RFC-20261026-01 增 override 与非法布局钉) |
|
|
61
61
|
| `validators/validate_walkthrough.py`(M1,`RFC-20261022-01`,2026-10-23) | 走查单确认门的**声明 ⇔ 凭据** | `[机器]` 时空域 = `.trellis/tasks/*/task.json.status ∈ {planning, in_progress}`(已归档不扫;记录缺失 / 不可解析 / status 不在 {planning, in_progress, completed} ⇒ 该任务 `SKIP` 指名,不静默出域);`atlas-apply.md` 三问门判定第 2 问**已写下**「是」⇒ 报告引用的 `product/prd/<domain>-prd.md` 的「用户旅程走查」节须有 `> 已确认:YYYY-MM-DD` 行(受影响域 = 报告内对该路径的引用);缺失 / 形态非法 / 域级 PRD 不存在 ⇒ `FAIL` 指名域与文件;三问小节在但第 2 问**不可解析**(无第 2 问行 / 答句非「是 / 否」开头 / 多行判定不一致)⇒ `WARN` 要求人工核对(不可解析 ≠ 未走到);无 apply 记录 / 第 2 问否 / 无三问小节 ⇒ `SKIP` 带原因;第 2 问是但解析不到域级 PRD 引用 ⇒ `WARN` | 三问判定**本身的语义越轨**(该答「是」的答成「否」——本门锁的是「写下的『是』与确认行的对账」,不是「是」判得对不对);§3.2 第四形态(无需求卡修订)的走查面(归 closeout 宣称 sweep);走查**内容**对不对(语义,用户确认时判) | 需求进 e2e 环前 / 每批收口;**调度者 = `atlas_check`**(纳入 `VALIDATORS`) | `出厂级(本轮实测)`:`tests/test_validate_walkthrough.py` **20 条**(正控 2 / 坏输入 5 / 解析面 WARN 5 / 时空域与三态 7;评审后 +3:未知 status 可见 SKIP / 多行冲突 WARN / 一致多行取值;#45 相对 root 钉 1 条);变异 **M138**(摘确认行存在性判据 ⇒ 一律放行,坏输入钉红)/ **M139**(第 2 问不可解析分支降 `SKIP` ⇒ WARN 钉红)/ **M140**(摘时空域过滤 ⇒ 已归档任务被扫,归档不扫钉红),四段协议含注入 diff、还原逐字节一致 |
|
|
62
62
|
| `scripts/atlas_check.py`(编排,见 2.2) | — | `[机器]` 只聚合,不改判据;每轮向 `.atlas/runs/check-events.jsonl` 追加一行门名/状态/耗时(**观测面,不参与判定**;P2,2026-10-23);`git_dirty` 排除 `.atlas/`(未知为 null);`duration_ms=None` = 未计量或无可计时段(E2E 计整门 wall time,含 reset/probe) | — | 每批收口 | 见 2.2 |
|
|
63
|
-
| `scripts/atlas_solution.py`(solution check,Phase 1,2026-11-04,`RFC-20261104-02`) | `atlas.solution.yaml` ⇔ 成员 git 状态 / Atlas 资产 / 契约锁 | `[机器]` manifest schema(version/mode/成员唯一/路径逃逸);Phase 1 仅 `federated`;成员 git / ignore / gitlink / 非 git;契约文件 sha256 ⇔ lock;solution 层 PRD 骨架 / profile / `.atlas` 存在性;requirements ↔ 成员任务 live 对账(缺任务 / AC 定义行 / 指针 ⇒ WARN);`task create` 只窄写成员 `.trellis/tasks`(--no-start / meta / add-context
|
|
63
|
+
| `scripts/atlas_solution.py`(solution check,Phase 1,2026-11-04,`RFC-20261104-02`) | `atlas.solution.yaml` ⇔ 成员 git 状态 / Atlas 资产 / 契约锁 | `[机器]` manifest schema(version/mode/成员唯一/路径逃逸);Phase 1 仅 `federated`;成员 git / ignore / gitlink / 非 git;契约文件 sha256 ⇔ lock;solution 层 PRD 骨架 / profile / `.atlas` 存在性;requirements ↔ 成员任务 live 对账(缺任务 / AC 定义行 / 指针 ⇒ WARN);`task create` 只窄写成员 `.trellis/tasks`(--no-start / meta / add-context);语义漂移默认 WARN;`--strict` 下锁缺失/未跟踪或与 HEAD 不一致、锁↔清单 url/path 不一致、成员 dirty/无法判定、缺 url、成员/契约漂移 ⇒ FAIL;schema 错误 exit 2 | 跨仓契约语义兼容;成员 PRD 语义;自动领取/自动启动;成员任务内容是否实现正确;unified / baseline v2 / 多根 impact·closeout(Phase 2);成员代码提交(Phase 2);Phase 1 不跑 apply / impact / closeout | `atlas solution check [--strict]`(人工 / CI,独立入口;**不进 `atlas_check`**);`--strict` 且 overall=FAIL 时 exit 1 | `待复核`:`tests/test_atlas_solution.py`(32 条)+ `tests/test_solution_guards.py`(12 条)+ `tests/test_solution_e2e_console.py`(5 条)+ `tests/test_solution_task.py`(16 条,含真实 Trellis 探针可 skip)已绿;变异钉待补,暂不升 `出厂级` |
|
|
64
64
|
|
|
65
65
|
### 2.2 编排检查(`atlas_check.py` 的门行)
|
|
66
66
|
|
package/shared/layout.md
CHANGED
|
@@ -114,4 +114,4 @@ layout:
|
|
|
114
114
|
|
|
115
115
|
- solution 根是独立 git 仓,只跟踪 Atlas 资产、清单、锁与父级 PRD;成员目录 **untracked 且不被任何 ignore 规则覆盖**。
|
|
116
116
|
- 禁止在 solution 根 `.gitignore` / `.ignore` / `.rgignore` / `.git/info/exclude` 命中成员;禁止 `status.showUntrackedFiles=no`;消费者统一 `--untracked-files=all` 并逐成员根过滤。
|
|
117
|
-
- 字段与命令契约见 `shared/solution.md`;Phase 1 只支持 `federated
|
|
117
|
+
- 字段与命令契约见 `shared/solution.md`;Phase 1 只支持 `federated`;`unified` 与成员代码提交属 Phase 2,`import`/`export` 属 Phase 3,多 host / 跨仓图谱等增强属 Phase 4(可选)。
|
package/shared/solution.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# atlas 共享契约 — 多仓方案层(solution,Phase 1)
|
|
2
2
|
|
|
3
|
-
> **状态**:Phase 1(2026-11-04)+ solution task 增量(2026-11-05
|
|
3
|
+
> **状态**:Phase 1(2026-11-04)+ solution task 增量(2026-11-05)+ 可复现锁 / `check --strict` 增量(2026-11-07,`[Unreleased]`)。父级只做只读整合与**窄写成员任务卡**(`.trellis/tasks`);`unified` 与成员代码提交属 Phase 2,`import`/`export` 属 Phase 3,多 host / `targets[]`、跨仓影响面与图谱、成员拆分导出属 Phase 4 可选增强,见源包提案 RFC-20261104-02 / RFC-20261105-02(装配态无 proposals)。
|
|
4
4
|
>
|
|
5
5
|
> 本层不复制 PRD / 域事实 / E2E;它只拥有清单、锁、父级 PRD 与跨仓声明。资产归属的单源是 `atlas.solution.yaml` 的 `members[].assets`。
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<solution 根>/
|
|
11
11
|
├── atlas.config.yaml # 布局(assets_root),由 _support/layout.py 解析
|
|
12
12
|
├── atlas.solution.yaml # 本契约:members / mode / assets / contracts
|
|
13
|
-
├── atlas.solution.lock.json # 成员
|
|
13
|
+
├── atlas.solution.lock.json # 成员 url/branch/commit + 契约指纹;被父仓 Git 跟踪,作为可复现基线
|
|
14
14
|
├── .atlas/ # solution 层 Atlas 装配(Phase 1 只读检查所需)
|
|
15
15
|
├── <assets_root>/ # 父级 PRD / E2E / solution stack-profile
|
|
16
16
|
│ ├── stack-profile.yaml
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
- solution 根是独立 git 仓,只跟踪 Atlas 资产、清单、锁、父级 PRD;成员目录 **untracked 且不被任何 ignore 规则覆盖**。
|
|
24
|
-
-
|
|
24
|
+
- 锁文件必须被父仓 Git 跟踪且与父仓 `HEAD` 一致;否则 `check --strict` 判 `FAIL`(CI 无法还原锁定版本)。
|
|
25
|
+
- 禁止在 solution 根 `.gitignore` / `.ignore` / `.rgignore` / `.git/info/exclude` 命中成员;子目录下的同名 ignore 文件沿成员路径逐级检测。
|
|
25
26
|
- 禁止设置 `status.showUntrackedFiles=no`;所有消费者用 `--untracked-files=all` 并逐成员根过滤。
|
|
26
27
|
|
|
27
28
|
## 2. 清单字段(Phase 1)
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
| `solution` | 是 | 方案名 |
|
|
33
34
|
| `mode` | 是 | Phase 1 仅 `federated`;`unified` 显式拒绝 |
|
|
34
35
|
| `members[].name` | 是 | 成员标识,solution 内唯一 |
|
|
35
|
-
| `members[].path` | 是 | 相对 solution 根;拒绝绝对路径 / `..` / Atlas/Trellis
|
|
36
|
+
| `members[].path` | 是 | 相对 solution 根;拒绝绝对路径 / `..` / Atlas/Trellis 内部目录;若已被父仓跟踪(含 mode 160000)则 init/adopt 直接拒绝 |
|
|
37
|
+
| `members[].url` | 否 | 远端地址;仅 `http/https/ssh/git/file` 或 `user@host:path`;禁止内嵌 userinfo / token,检测到即拒绝写入清单与锁 |
|
|
36
38
|
| `members[].assets` | 是 | Phase 1 仅 `member` |
|
|
37
39
|
| `members[].kind` | 否 | `frontend` / `backend` / `fullstack` / `mobile`;供 solution stack-profile |
|
|
38
40
|
| `contracts[].id` | 否 | 唯一 |
|
|
@@ -47,24 +49,40 @@
|
|
|
47
49
|
|
|
48
50
|
模板:`templates/atlas.solution.yaml`(字段样板;运行期解析以本契约为准,模板不参与判定)。
|
|
49
51
|
|
|
52
|
+
默认模式与 RFC 一致:Phase 1 只接受 `federated`;Phase 2 交付后,绿地项目(无成员资产)恢复默认 `unified`,已有成员资产仍默认 `federated`,`--mode` 可覆盖。
|
|
53
|
+
|
|
50
54
|
## 3. 命令(Phase 1)
|
|
51
55
|
|
|
52
56
|
```bash
|
|
53
|
-
atlas solution init --name <名> --member <名>=<路径> [--member ...] # 一次创建 solution
|
|
57
|
+
atlas solution init --name <名> --member <名>=<路径> [--member ...] # 一次创建 solution 层(清单 / 锁 / 骨架,不迁移成员资产)
|
|
54
58
|
atlas solution adopt [--name <名>] [--member <名>=<路径> ...] # 识别已有成员资产
|
|
55
59
|
atlas solution status # 只读聚合
|
|
56
|
-
atlas solution
|
|
57
|
-
atlas solution
|
|
60
|
+
atlas solution diff # 只读对账:成员相对锁的提交/改动
|
|
61
|
+
atlas solution check [--strict] # 默认 WARN;--strict = CI 门禁
|
|
62
|
+
atlas solution lock --update # 人工刷新锁(拒绝 detached HEAD)
|
|
58
63
|
atlas solution task create --requirement <REQ> [--dry-run|--apply] # 父级需求 → 成员任务卡
|
|
59
64
|
atlas solution task status [--requirement <REQ>] # 只读对账
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
- `init`
|
|
67
|
+
- `init` / `adopt` 写清单前执行 `git ls-files -s`:成员路径已被父仓跟踪(普通文件或 `160000` gitlink)直接拒绝,并给出 `git rm --cached` / 移除 `.gitmodules` 的修复指引;不再降级为 WARN。
|
|
68
|
+
- `init` 只在成员齐全且都不在 detached HEAD 时自动写入首版锁;成员未 clone 时暂不写,避免 `head: null` 的假锁。
|
|
63
69
|
- `adopt` 不移动、不复制成员资产;自动识别直属子目录中「git 仓 + Atlas 资产」的成员。
|
|
64
|
-
- `
|
|
70
|
+
- `diff` 只读对账:按成员输出自锁以来的 commit / diffstat、已暂存 / 未暂存 / 工作区改动;锁中 commit 不在本地时显式提示先 fetch。
|
|
71
|
+
- `check` 的 manifest schema / 路径逃逸是输入错误(exit 2);默认模式下成员非 git、缺 Atlas 资产、被 ignore、被跟踪/gitlink、锁漂移、PRD 骨架未补齐 ⇒ WARN。
|
|
72
|
+
- `check --strict` 把以下升为 `FAIL` 并返回 exit 1:锁缺失、锁未被父仓跟踪或与父仓 `HEAD` 不一致、锁↔清单 `url/path` 不一致、成员 dirty 或 dirty 无法判断、缺 URL、成员/契约版本漂移。适用于 CI;不改变默认人工检查的 WARN 语义。
|
|
65
73
|
- `task create` 默认 dry-run,`--apply` 才写成员 `.trellis/tasks`:固定 `--no-start`(不领取)、用 `--meta solution/requirement/member` 做幂等、写 `solution.md` 指针并 `add-context`;不写代码/资产/PRD,不自动 commit。重复/失败显式报告;`--resume`/`--update` 只处理已有任务。
|
|
66
74
|
- `commit` 入口保留给 Phase 2;Phase 1 调用时显式报「未交付」。
|
|
67
75
|
|
|
76
|
+
### 3.1 已交付 vs 本次新增(`[Unreleased]`)
|
|
77
|
+
|
|
78
|
+
| 能力 | 状态 |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `init` / `adopt` / `status` / `check` / `lock` / `task`(federated) | Phase 1 已交付(2026-11-04/05) |
|
|
81
|
+
| `members[].url`、scheme 白名单、内嵌凭据拒绝 | 本次新增,未发布 |
|
|
82
|
+
| 锁被父仓跟踪 / 与 HEAD 一致、锁↔清单 url/path 对账、dirty 判据、detached 拒绝 | 本次新增,未发布 |
|
|
83
|
+
| `solution diff`(成员相对锁的提交 / diffstat / 工作区对账) | 本次新增,未发布 |
|
|
84
|
+
| `check --strict`(CI 门禁,`overall=FAIL` → exit 1) | 本次新增,未发布 |
|
|
85
|
+
|
|
68
86
|
## 4. 父级 PRD
|
|
69
87
|
|
|
70
88
|
- `prd.md` 是产品级需求源;`solution-prd.md` 是跨仓域级 PRD,必须按 `templates/prd/domain.md` 完整形态落盘:`domain: solution`、`domain_code: SOLUTION`、`AC-SOLUTION-NNN`(三位)、FN/R/AC、§五三列 AC 表、结构类 AC 清单;`prd.md` §五列出 `solution`,README 追溯行 7 列且计数一致。
|
|
@@ -72,17 +90,51 @@ atlas solution task status [--requirement <REQ>] # 只读对
|
|
|
72
90
|
|
|
73
91
|
## 5. 跨仓契约锁
|
|
74
92
|
|
|
75
|
-
-
|
|
76
|
-
- `
|
|
93
|
+
- 锁是**可复现基线**:必须被父仓 Git 跟踪,且与父仓 `HEAD` 一致;`check --strict` 以此作为 CI 判据。
|
|
94
|
+
- `lock --update` 记录成员 `url / path / branch / head(commit)`、member `_meta.json.baseline` 与契约文件 `sha256`。成员处于 detached HEAD(`branch` 为 `HEAD`)时**拒绝写入**,避免锁里出现不可复现的分支名。
|
|
95
|
+
- 锁与清单必须一致:`path` 完全一致;`url` 完全一致(两边都空 ⇒ `--strict` FAIL)。旧锁缺少 `url` 时需重新 `lock --update` 并提交。
|
|
96
|
+
- 成员工作区 dirty,或无法判断(`git status` 失败)⇒ `--strict` FAIL;默认 `check` 只 WARN。
|
|
97
|
+
- 默认 `check` 只对漂移发 WARN,不判断语义兼容;跨仓契约的语义兼容归人工/独立评审。
|
|
77
98
|
- 成员内部改动不改变 solution 根 `git status`;Phase 2 的 baseline/freshness 必须把成员 HEAD + dirty 纳入。
|
|
99
|
+
- URL 安全:只接受 `http/https/ssh/git/file` 或 `user@host:path`;http(s) userinfo、任意形式的密码、token/签名查询参数一律拒绝写入清单与锁(避免凭据落盘)。
|
|
100
|
+
- 父仓只存清单、锁与父级 PRD/骨架;成员代码与成员 Atlas 资产留在成员仓,不迁移(`unified` 属 Phase 2,`import`/`export` 属 Phase 3)。
|
|
101
|
+
- 风险:成员目录是 untracked。在 solution 根执行 `git clean -ffdx` 会删除整个成员工作区及未提交改动;不要把它当作安全清理命令。
|
|
102
|
+
- 路径安全:`members[].path` 逃逸根目录直接输入错误;成员 symlink 指向根外时,契约文件哈希返回 `missing`,**不读取根外文件**。
|
|
103
|
+
|
|
104
|
+
### 5.1 CI 按锁还原(父仓只存清单与锁)
|
|
105
|
+
|
|
106
|
+
CI 不依赖任何自动还原命令:按 `atlas.solution.lock.json` 逐成员 clone + checkout,再跑 strict。
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
set -euo pipefail
|
|
110
|
+
git clone <solution-repo> solution
|
|
111
|
+
cd solution
|
|
112
|
+
git checkout <parent-ref> # 回滚时切到目标父仓 commit,锁随之还原
|
|
113
|
+
|
|
114
|
+
node -e '
|
|
115
|
+
const fs = require("fs"), cp = require("child_process");
|
|
116
|
+
const lock = JSON.parse(fs.readFileSync("atlas.solution.lock.json", "utf8"));
|
|
117
|
+
for (const m of lock.members) {
|
|
118
|
+
if (!m.url || !m.head) throw new Error(`成员 ${m.name} 缺少 url/head`);
|
|
119
|
+
if (!fs.existsSync(m.path)) cp.execFileSync("git", ["clone", "--", m.url, m.path], { stdio: "inherit" });
|
|
120
|
+
cp.execFileSync("git", ["-C", m.path, "fetch", "--all", "--prune"], { stdio: "inherit" });
|
|
121
|
+
cp.execFileSync("git", ["-C", m.path, "-c", "advice.detachedHead=false", "checkout", "--detach", m.head], { stdio: "inherit" });
|
|
122
|
+
}
|
|
123
|
+
'
|
|
124
|
+
atlas solution check --strict
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- 该 checkout 是 detached HEAD,仅用于 CI / 回滚;日常开发在成员仓自己的分支上进行。
|
|
128
|
+
- 锁必须随父仓提交;`check --strict` 会校验锁与父仓 `HEAD` 一致。
|
|
129
|
+
- 锁中 commit 不在本地时,先对相应成员 `fetch`。
|
|
78
130
|
|
|
79
|
-
## 6. Phase 2/3 边界(显式盲区)
|
|
131
|
+
## 6. Phase 2/3/4 边界(显式盲区)
|
|
80
132
|
|
|
81
|
-
- `unified
|
|
82
|
-
- `solution_commit --member
|
|
83
|
-
- `import` / `export
|
|
133
|
+
- `unified`(Phase 2):solution 拥有唯一资产集、成员只提供代码根;需要 baseline v2 + 成员 SHA 向量 + 多根 freshness / impact / closeout。
|
|
134
|
+
- `solution_commit --member`(Phase 2):按成员仓提交代码。
|
|
135
|
+
- `import` / `export`(Phase 3):成员资产迁移;旧源删除,历史归 git。
|
|
84
136
|
- solution 级 Trellis `packages`:Phase 1 不创建 `.trellis/`;若 solution 根已有 `.trellis/config.yaml`,`check` 只做成员 `path` 文本校验(不校验 `git: true`);生成与完整语义校验归 Phase 2。
|
|
85
|
-
-
|
|
137
|
+
- Phase 4(可选增强):多 host / `targets[]`、跨仓影响面与代码图谱、成员拆分导出、更多宿主集成;不在当前 Phase 1–3 的交付范围。
|
|
86
138
|
- 自动领取/自动启动不在本层:`task create` 只创建任务卡;成员仍需 `/trellis:start` 选择任务。
|
|
87
139
|
- 父级 `task create` 是 Phase 1 的唯一窄写例外:只写成员 `.trellis/tasks`(任务卡/指针/context),不写成员代码/资产/PRD。
|
|
88
140
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#
|
|
7
7
|
# Phase 1 只支持 mode: federated(成员各自持有 Atlas 资产)。
|
|
8
8
|
# 成员目录必须 untracked 且不被任何 ignore 规则覆盖;不要在 solution 根 .gitignore 中忽略成员。
|
|
9
|
+
# 成员路径若已被父仓跟踪(含 submodule gitlink),init/adopt 会直接拒绝。
|
|
9
10
|
version: 1
|
|
10
11
|
solution: <方案名>
|
|
11
12
|
mode: federated
|
|
@@ -13,6 +14,8 @@ mode: federated
|
|
|
13
14
|
members:
|
|
14
15
|
- name: <成员标识>
|
|
15
16
|
path: <成员仓相对路径>
|
|
17
|
+
url: <远端地址> # 可选;仅 http/https/ssh/git/file 或 user@host:path
|
|
18
|
+
# 禁止内嵌 userinfo/token;检测到会拒绝写入清单与锁
|
|
16
19
|
assets: member # Phase 1 只允许 member;solution 属 Phase 2 unified
|
|
17
20
|
kind: fullstack # frontend | backend | fullstack | mobile(供 solution stack-profile 使用)
|
|
18
21
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -104,6 +104,26 @@ def test_lock_roundtrip_and_head_drift(tmp_path: Path) -> None:
|
|
|
104
104
|
assert any("HEAD 漂移" in c["detail"] for c in drift["checks"])
|
|
105
105
|
|
|
106
106
|
|
|
107
|
+
def test_diff_reports_commits_since_lock(tmp_path: Path) -> None:
|
|
108
|
+
member = make_repo(tmp_path / "web")
|
|
109
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
110
|
+
install=False)
|
|
111
|
+
core.write_lock(tmp_path, core.load_manifest(tmp_path))
|
|
112
|
+
(member / "new.txt").write_text("new\n", encoding="utf-8")
|
|
113
|
+
git(member, "add", "new.txt")
|
|
114
|
+
git(member, "-c", "user.email=a@b", "-c", "user.name=a",
|
|
115
|
+
"commit", "-qm", "member change")
|
|
116
|
+
entry = core.diff_solution(tmp_path)["members"][0]
|
|
117
|
+
assert entry["head"] != entry["locked_head"]
|
|
118
|
+
assert any("member change" in c for c in entry["commits"])
|
|
119
|
+
assert "自锁以来提交" in core.render_diff({"solution": "demo",
|
|
120
|
+
"mode": "federated",
|
|
121
|
+
"members": [entry]})
|
|
122
|
+
res = run_cli(tmp_path, "--root", str(tmp_path), "diff", "--json")
|
|
123
|
+
assert res.returncode == 0, res.stderr
|
|
124
|
+
assert json.loads(res.stdout)["members"][0]["name"] == "web"
|
|
125
|
+
|
|
126
|
+
|
|
107
127
|
def test_contract_fingerprint_drift(tmp_path: Path) -> None:
|
|
108
128
|
make_repo(tmp_path / "api", {"openapi.yaml": "openapi: 3.0.0\n"})
|
|
109
129
|
make_repo(tmp_path / "web", {"client.ts": "// client\n"})
|
|
@@ -151,6 +171,11 @@ def run_cli(root: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
|
151
171
|
capture_output=True, text=True)
|
|
152
172
|
|
|
153
173
|
|
|
174
|
+
def commit_root(root: Path, *paths: str) -> None:
|
|
175
|
+
git(root, "add", *paths)
|
|
176
|
+
git(root, "-c", "user.email=a@b", "-c", "user.name=a", "commit", "-qm", "root")
|
|
177
|
+
|
|
178
|
+
|
|
154
179
|
def test_init_rejects_duplicate_member_names(tmp_path: Path) -> None:
|
|
155
180
|
make_repo(tmp_path / "web")
|
|
156
181
|
with pytest.raises(core.SolutionError, match="重复"):
|
|
@@ -188,10 +213,113 @@ def test_check_pass_positive(tmp_path: Path) -> None:
|
|
|
188
213
|
(tmp_path / "product" / "prd" / "solution-prd.md").write_text(
|
|
189
214
|
"# solution\n\n无占位符\n", encoding="utf-8")
|
|
190
215
|
core.write_lock(tmp_path, core.load_manifest(tmp_path))
|
|
216
|
+
commit_root(tmp_path, core.MANIFEST_NAME, core.LOCK_NAME)
|
|
191
217
|
result = core.check_solution(tmp_path)
|
|
192
218
|
assert result["overall"] == "PASS", result["checks"]
|
|
193
219
|
|
|
194
220
|
|
|
221
|
+
def test_check_strict_fails_when_lock_untracked_or_stale(tmp_path: Path) -> None:
|
|
222
|
+
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
|
223
|
+
member = make_repo(tmp_path / "web")
|
|
224
|
+
git(member, "remote", "add", "origin", "https://example.com/web.git")
|
|
225
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
226
|
+
install=False)
|
|
227
|
+
result = core.check_solution(tmp_path, strict=True)
|
|
228
|
+
assert result["overall"] == "FAIL"
|
|
229
|
+
assert any("未被父仓 Git 跟踪" in c["detail"] for c in result["checks"])
|
|
230
|
+
|
|
231
|
+
commit_root(tmp_path, core.MANIFEST_NAME, core.LOCK_NAME)
|
|
232
|
+
assert core.check_solution(tmp_path, strict=True)["overall"] != "FAIL"
|
|
233
|
+
|
|
234
|
+
lock_path = tmp_path / core.LOCK_NAME
|
|
235
|
+
lock_path.write_text(lock_path.read_text(encoding="utf-8") + "\n",
|
|
236
|
+
encoding="utf-8")
|
|
237
|
+
stale = core.check_solution(tmp_path, strict=True)
|
|
238
|
+
assert stale["overall"] == "FAIL"
|
|
239
|
+
assert any("与父仓 HEAD 不一致" in c["detail"] for c in stale["checks"])
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_check_strict_fails_on_member_dirty(tmp_path: Path) -> None:
|
|
243
|
+
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
|
244
|
+
member = make_repo(tmp_path / "web")
|
|
245
|
+
git(member, "remote", "add", "origin", "https://example.com/web.git")
|
|
246
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
247
|
+
install=False)
|
|
248
|
+
commit_root(tmp_path, core.MANIFEST_NAME, core.LOCK_NAME)
|
|
249
|
+
(member / "dirty.txt").write_text("dirty\n", encoding="utf-8")
|
|
250
|
+
result = core.check_solution(tmp_path, strict=True)
|
|
251
|
+
assert result["overall"] == "FAIL"
|
|
252
|
+
assert any("未提交改动" in c["detail"] for c in result["checks"])
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_check_strict_fails_without_member_url(tmp_path: Path) -> None:
|
|
256
|
+
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
|
257
|
+
make_repo(tmp_path / "web")
|
|
258
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
259
|
+
install=False)
|
|
260
|
+
commit_root(tmp_path, core.MANIFEST_NAME, core.LOCK_NAME)
|
|
261
|
+
result = core.check_solution(tmp_path, strict=True)
|
|
262
|
+
assert result["overall"] == "FAIL"
|
|
263
|
+
assert any("都没有 url" in c["detail"] for c in result["checks"])
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def test_lock_rejects_detached_head(tmp_path: Path) -> None:
|
|
267
|
+
member = make_repo(tmp_path / "web")
|
|
268
|
+
git(member, "checkout", "--detach", "HEAD")
|
|
269
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
270
|
+
install=False)
|
|
271
|
+
with pytest.raises(core.SolutionError, match="detached HEAD"):
|
|
272
|
+
core.write_lock(tmp_path, core.load_manifest(tmp_path))
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def test_url_rejects_credentials_and_ext_scheme(tmp_path: Path) -> None:
|
|
276
|
+
make_repo(tmp_path / "web")
|
|
277
|
+
with pytest.raises(core.SolutionError, match="内嵌凭据"):
|
|
278
|
+
core.init_solution(
|
|
279
|
+
tmp_path, "demo",
|
|
280
|
+
[("web", "web", "frontend", "https://user:token@example.com/a.git")],
|
|
281
|
+
install=False)
|
|
282
|
+
with pytest.raises(core.SolutionError, match="白名单"):
|
|
283
|
+
core.init_solution(
|
|
284
|
+
tmp_path, "demo",
|
|
285
|
+
[("web", "web", "frontend", "ext::sh")],
|
|
286
|
+
install=False)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def test_contract_symlink_escape_is_missing(tmp_path: Path) -> None:
|
|
290
|
+
outside = tmp_path.parent / f"{tmp_path.name}-secret.yaml"
|
|
291
|
+
outside.write_text("secret\n", encoding="utf-8")
|
|
292
|
+
make_repo(tmp_path / "api", {"openapi.yaml": "openapi: 3.0.0\n"})
|
|
293
|
+
web = make_repo(tmp_path / "web", {"client.ts": "// inside\n"})
|
|
294
|
+
(web / "client.ts").unlink()
|
|
295
|
+
(web / "client.ts").symlink_to(outside)
|
|
296
|
+
core.init_solution(
|
|
297
|
+
tmp_path, "demo",
|
|
298
|
+
[("api", "api", "backend"), ("web", "web", "frontend")],
|
|
299
|
+
install=False,
|
|
300
|
+
contracts=[{"id": "c1", "producer": "api", "producer_path": "openapi.yaml",
|
|
301
|
+
"consumer": "web", "consumer_path": "client.ts"}],
|
|
302
|
+
)
|
|
303
|
+
states = {c["id"]: c for c in core.contract_states(
|
|
304
|
+
tmp_path, core.load_manifest(tmp_path))}
|
|
305
|
+
assert states["c1"]["consumer_sha256"] == "missing"
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def test_cli_check_strict_exit_code(tmp_path: Path) -> None:
|
|
309
|
+
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
|
310
|
+
member = make_repo(tmp_path / "web")
|
|
311
|
+
git(member, "remote", "add", "origin", "https://example.com/web.git")
|
|
312
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
313
|
+
install=False)
|
|
314
|
+
res = run_cli(tmp_path, "--root", str(tmp_path), "check", "--strict")
|
|
315
|
+
assert res.returncode == 1, res.stdout
|
|
316
|
+
assert "FAIL" in res.stdout
|
|
317
|
+
|
|
318
|
+
commit_root(tmp_path, core.MANIFEST_NAME, core.LOCK_NAME)
|
|
319
|
+
res = run_cli(tmp_path, "--root", str(tmp_path), "check", "--strict")
|
|
320
|
+
assert res.returncode == 0, res.stdout
|
|
321
|
+
|
|
322
|
+
|
|
195
323
|
@pytest.mark.skipif(not (PKG_ROOT / "install.py").is_file(),
|
|
196
324
|
reason="副本态(.atlas/)无 install.py;安装器集成只在源包测试")
|
|
197
325
|
def test_init_with_install_skips_trellis_and_uses_solution_profile(tmp_path: Path) -> None:
|
|
@@ -48,7 +48,8 @@ def make_solution(tmp_path: Path) -> Path:
|
|
|
48
48
|
[("web", "web", "frontend"), ("api", "api", "backend")],
|
|
49
49
|
install=False,
|
|
50
50
|
)
|
|
51
|
-
git(tmp_path, "add", "atlas.config.yaml", "atlas.solution.yaml",
|
|
51
|
+
git(tmp_path, "add", "atlas.config.yaml", "atlas.solution.yaml",
|
|
52
|
+
"atlas.solution.lock.json", "product")
|
|
52
53
|
git(tmp_path, "-c", "user.email=a@b", "-c", "user.name=a", "commit", "-qm", "assets")
|
|
53
54
|
return tmp_path
|
|
54
55
|
|
|
@@ -70,7 +71,8 @@ def test_non_ascii_member_path(tmp_path: Path) -> None:
|
|
|
70
71
|
member = make_repo(tmp_path / "web 测试", {"src/a.js": "export const a = 1;\n"})
|
|
71
72
|
core.init_solution(tmp_path, "demo", [("web 测试", "web 测试", "frontend")],
|
|
72
73
|
install=False)
|
|
73
|
-
git(tmp_path, "add", "atlas.config.yaml", "atlas.solution.yaml",
|
|
74
|
+
git(tmp_path, "add", "atlas.config.yaml", "atlas.solution.yaml",
|
|
75
|
+
"atlas.solution.lock.json", "product")
|
|
74
76
|
git(tmp_path, "-c", "user.email=a@b", "-c", "user.name=a", "commit", "-qm", "assets")
|
|
75
77
|
assert console.repo_git_dirty(tmp_path) is False
|
|
76
78
|
(member / "src" / "a.js").write_text("export const a = 2;\n", encoding="utf-8")
|
|
@@ -6,6 +6,8 @@ import importlib.util
|
|
|
6
6
|
import subprocess
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
9
11
|
PKG_ROOT = Path(__file__).resolve().parents[1]
|
|
10
12
|
|
|
11
13
|
|
|
@@ -65,14 +67,13 @@ def test_dotignore_member_warns(tmp_path: Path) -> None:
|
|
|
65
67
|
assert "命中 ignore" in details(result)
|
|
66
68
|
|
|
67
69
|
|
|
68
|
-
def
|
|
70
|
+
def test_gitlink_member_rejected_at_init(tmp_path: Path) -> None:
|
|
69
71
|
make_solution_root(tmp_path)
|
|
70
72
|
make_repo(tmp_path / "web")
|
|
71
73
|
git(tmp_path, "add", "web")
|
|
72
|
-
core.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
assert "已被 solution 仓跟踪" in details(result)
|
|
74
|
+
with pytest.raises(core.SolutionError, match="gitlink|submodule"):
|
|
75
|
+
core.init_solution(tmp_path, "demo", [("web", "web", "frontend")],
|
|
76
|
+
install=False)
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
def test_non_git_member_warns(tmp_path: Path) -> None:
|
|
@@ -121,6 +122,18 @@ def test_common_parent_ignore_warns(tmp_path: Path) -> None:
|
|
|
121
122
|
assert "命中 ignore" in details(core.check_solution(tmp_path))
|
|
122
123
|
|
|
123
124
|
|
|
125
|
+
def test_nested_ignore_in_parent_dir_warns(tmp_path: Path) -> None:
|
|
126
|
+
make_solution_root(tmp_path)
|
|
127
|
+
(tmp_path / "members").mkdir()
|
|
128
|
+
(tmp_path / "members" / ".ignore").write_text("web/\n", encoding="utf-8")
|
|
129
|
+
make_repo(tmp_path / "members" / "web")
|
|
130
|
+
core.init_solution(tmp_path, "demo", [("web", "members/web", "frontend")],
|
|
131
|
+
install=False)
|
|
132
|
+
result = core.check_solution(tmp_path)
|
|
133
|
+
assert "命中 ignore" in details(result)
|
|
134
|
+
assert "members/.ignore" in details(result)
|
|
135
|
+
|
|
136
|
+
|
|
124
137
|
def test_symlink_escape_warns(tmp_path: Path) -> None:
|
|
125
138
|
make_solution_root(tmp_path)
|
|
126
139
|
outside = make_repo(tmp_path.parent / f"{tmp_path.name}-outside")
|