@walvka-code/proj-doc-builder 0.0.0-stage → 4.0.0
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/LICENSE +21 -0
- package/README.md +271 -2
- package/README.zh-CN.md +240 -0
- package/cordis.patch.yml +8 -0
- package/icon.svg +11 -0
- package/index.js +164 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -4
- package/skills/proj-doc-builder/SKILL.md +350 -0
- package/skills/proj-doc-builder/references/audit_script.md +96 -0
- package/skills/proj-doc-builder/references/checklist.md +80 -0
- package/skills/proj-doc-builder/references/exclusions.md +79 -0
- package/skills/proj-doc-builder/references/linking.md +83 -0
- package/skills/proj-doc-builder/references/migration.md +32 -0
- package/skills/proj-doc-builder/references/phase4.md +200 -0
- package/skills/proj-doc-builder/references/templates.md +172 -0
- package/skills/proj-doc-builder/tests/__pycache__/conftest.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_claude_doc_index.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_link_tools.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_load_docs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_normalize_markers.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_phase4_exit.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_project_docs_contract.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_scan_dirs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_sync_project_docs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/conftest.py +11 -0
- package/skills/proj-doc-builder/tests/test_claude_doc_index.py +157 -0
- package/skills/proj-doc-builder/tests/test_link_tools.py +279 -0
- package/skills/proj-doc-builder/tests/test_load_docs.py +248 -0
- package/skills/proj-doc-builder/tests/test_normalize_markers.py +120 -0
- package/skills/proj-doc-builder/tests/test_phase4_exit.py +3895 -0
- package/skills/proj-doc-builder/tests/test_project_docs_contract.py +781 -0
- package/skills/proj-doc-builder/tests/test_scan_dirs.py +1159 -0
- package/skills/proj-doc-builder/tests/test_sync_project_docs.py +2169 -0
- package/skills/proj-doc-builder/tests/test_validate_doc.py +555 -0
- package/skills/proj-doc-builder/tools/__pycache__/claude_doc_index.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/compute_link.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/link_check.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/load_docs.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/normalize_markers.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/phase4_exit.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/project_docs_contract.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/scan_dirs.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/sync_project_docs.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/claude_doc_index.py +298 -0
- package/skills/proj-doc-builder/tools/compute_link.py +233 -0
- package/skills/proj-doc-builder/tools/link_check.py +152 -0
- package/skills/proj-doc-builder/tools/load_docs.py +380 -0
- package/skills/proj-doc-builder/tools/normalize_markers.py +205 -0
- package/skills/proj-doc-builder/tools/phase4/__init__.py +57 -0
- package/skills/proj-doc-builder/tools/phase4/cas_storage.py +18 -0
- package/skills/proj-doc-builder/tools/phase4/engine.py +20 -0
- package/skills/proj-doc-builder/tools/phase4/journal.py +22 -0
- package/skills/proj-doc-builder/tools/phase4/platform_handles.py +20 -0
- package/skills/proj-doc-builder/tools/phase4_exit.py +8459 -0
- package/skills/proj-doc-builder/tools/project_docs_contract.py +2318 -0
- package/skills/proj-doc-builder/tools/scan_dirs.py +2405 -0
- package/skills/proj-doc-builder/tools/sync_project_docs.py +3639 -0
- package/skills/proj-doc-builder/tools/validate_doc.py +1299 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Focused tests for ``tools/validate_doc.py``."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
import validate_doc as validator
|
|
12
|
+
|
|
13
|
+
STANDARD_OVERVIEW = (
|
|
14
|
+
"本目录属于测试子系统中的算法模块。"
|
|
15
|
+
"它接收上游协议层输入并调用核心实现完成确定性处理。"
|
|
16
|
+
"结果输出给下游测试组件,且与相邻适配器目录协作。"
|
|
17
|
+
)
|
|
18
|
+
STANDARD_ROLE = (
|
|
19
|
+
"本目录位于测试子系统的数据层,作为算法模块接收上游协议栈传入的测试向量。"
|
|
20
|
+
"它依赖核心接口完成处理,并把输出结果传递给下游验证组件,同时与同级适配器"
|
|
21
|
+
"协作保持数据格式一致。"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _write(path: Path, content: str) -> None:
|
|
26
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
path.write_text(content, encoding="utf-8")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _standard_document(*, overview: str = STANDARD_OVERVIEW) -> str:
|
|
31
|
+
return f"""# module — 标准测试模块
|
|
32
|
+
|
|
33
|
+
**导航**: src > **module**
|
|
34
|
+
|
|
35
|
+
## 概述
|
|
36
|
+
|
|
37
|
+
{overview}
|
|
38
|
+
|
|
39
|
+
## 文件清单
|
|
40
|
+
|
|
41
|
+
| 文件 | 用途 | 关键内容 |
|
|
42
|
+
|------|------|---------|
|
|
43
|
+
| `__init__.py` | 包入口 | 导出公共接口 |
|
|
44
|
+
| `core.py` | 核心实现 | 定义执行流程 |
|
|
45
|
+
|
|
46
|
+
## 关键符号
|
|
47
|
+
|
|
48
|
+
| 符号 | 类型 | 定义位置 | 说明 |
|
|
49
|
+
|------|------|---------|------|
|
|
50
|
+
| `PublicApi` | class | `core.py:L10` | 公共接口 |
|
|
51
|
+
| `run_case` | function | `core.py:L20` | 执行用例 |
|
|
52
|
+
| `DEFAULT_MODE` | constant | `core.py:L5` | 默认模式 |
|
|
53
|
+
|
|
54
|
+
## 子目录
|
|
55
|
+
|
|
56
|
+
| 子目录 | 用途 | 文档 |
|
|
57
|
+
|--------|------|------|
|
|
58
|
+
| `child/` | 子模块实现 | [child.md](module/child.md) |
|
|
59
|
+
|
|
60
|
+
## 依赖关系
|
|
61
|
+
|
|
62
|
+
| 方向 | 模块 | 关系 | 文档 |
|
|
63
|
+
|------|------|------|------|
|
|
64
|
+
| ⬆ 上游 | parent | 依赖父模块提供的核心接口定义 | [parent.md](parent.md) |
|
|
65
|
+
|
|
66
|
+
## 系统角色
|
|
67
|
+
|
|
68
|
+
{STANDARD_ROLE}
|
|
69
|
+
|
|
70
|
+
## 状态
|
|
71
|
+
|
|
72
|
+
✅ 完整 — 标准模块已经实现。
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _make_standard_tree(
|
|
77
|
+
tmp_path: Path,
|
|
78
|
+
*,
|
|
79
|
+
overview: str = STANDARD_OVERVIEW,
|
|
80
|
+
) -> tuple[Path, Path, Path, Path]:
|
|
81
|
+
project_root = tmp_path / "project"
|
|
82
|
+
docs_root = project_root / "project_docs"
|
|
83
|
+
source_dir = project_root / "src" / "module"
|
|
84
|
+
source_dir.mkdir(parents=True)
|
|
85
|
+
(source_dir / "child").mkdir()
|
|
86
|
+
_write(source_dir / "__init__.py", "# -*- coding: utf-8 -*-\n")
|
|
87
|
+
_write(
|
|
88
|
+
source_dir / "core.py",
|
|
89
|
+
"# -*- coding: utf-8 -*-\n"
|
|
90
|
+
"DEFAULT_MODE = 'test'\n\n"
|
|
91
|
+
"class PublicApi:\n"
|
|
92
|
+
" pass\n\n"
|
|
93
|
+
"def run_case():\n"
|
|
94
|
+
" pass\n",
|
|
95
|
+
)
|
|
96
|
+
_write(docs_root / "src" / "parent.md", "# parent\n")
|
|
97
|
+
_write(docs_root / "src" / "module" / "child.md", "# child\n")
|
|
98
|
+
doc_path = docs_root / "src" / "module.md"
|
|
99
|
+
_write(doc_path, _standard_document(overview=overview))
|
|
100
|
+
return project_root, docs_root, source_dir, doc_path
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _validate_standard(
|
|
104
|
+
project_root: Path,
|
|
105
|
+
docs_root: Path,
|
|
106
|
+
source_dir: Path,
|
|
107
|
+
doc_path: Path,
|
|
108
|
+
**kwargs: object,
|
|
109
|
+
) -> dict:
|
|
110
|
+
return validator.validate_doc(
|
|
111
|
+
doc_path,
|
|
112
|
+
source_dir,
|
|
113
|
+
project_docs_dir=docs_root,
|
|
114
|
+
project_root=project_root,
|
|
115
|
+
**kwargs,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _check(result: dict, check_id: int) -> dict:
|
|
120
|
+
return next(item for item in result["checks"] if item["id"] == check_id)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_standard_profile_passes_exact_inventory_links_and_content(
|
|
124
|
+
tmp_path: Path,
|
|
125
|
+
) -> None:
|
|
126
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
127
|
+
|
|
128
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
129
|
+
|
|
130
|
+
assert result["profile"] == validator.PROFILE_STANDARD
|
|
131
|
+
assert result["qualified"] is True
|
|
132
|
+
assert result["ok"] is True
|
|
133
|
+
assert result["failed"] == 0
|
|
134
|
+
assert result["critical_failed"] == 0
|
|
135
|
+
assert len(result["checks"]) == 9
|
|
136
|
+
assert _check(result, 1)["result"] == "PASS"
|
|
137
|
+
assert _check(result, 4)["result"] == "PASS"
|
|
138
|
+
assert _check(result, 9)["result"] == "PASS"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@pytest.mark.parametrize(
|
|
142
|
+
"overview, sentence_count",
|
|
143
|
+
[
|
|
144
|
+
("本目录属于测试模块。它向下游输出结果。", 2),
|
|
145
|
+
(
|
|
146
|
+
"本目录属于测试模块。它接收输入。它执行处理。它输出结果。它记录状态。",
|
|
147
|
+
5,
|
|
148
|
+
),
|
|
149
|
+
],
|
|
150
|
+
)
|
|
151
|
+
def test_standard_overview_requires_three_to_four_sentences(
|
|
152
|
+
tmp_path: Path,
|
|
153
|
+
overview: str,
|
|
154
|
+
sentence_count: int,
|
|
155
|
+
) -> None:
|
|
156
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(
|
|
157
|
+
tmp_path,
|
|
158
|
+
overview=overview,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
162
|
+
|
|
163
|
+
overview_check = _check(result, 2)
|
|
164
|
+
assert overview_check["result"] == "FAIL"
|
|
165
|
+
assert f"{sentence_count} 句话" in overview_check["detail"]
|
|
166
|
+
assert overview_check["severity"] == "advisory"
|
|
167
|
+
assert result["critical_failed"] == 0
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_standard_role_and_dependency_must_be_substantive(tmp_path: Path) -> None:
|
|
171
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
172
|
+
content = doc_path.read_text(encoding="utf-8")
|
|
173
|
+
content = content.replace(
|
|
174
|
+
STANDARD_ROLE,
|
|
175
|
+
"这里记录了一段长度足够但没有架构位置和协作含义的普通说明文字,"
|
|
176
|
+
"只是反复描述当前目录已经存在并包含若干内容,不说明实际数据关系。",
|
|
177
|
+
).replace(
|
|
178
|
+
"依赖父模块提供的核心接口定义",
|
|
179
|
+
"待补充",
|
|
180
|
+
)
|
|
181
|
+
_write(doc_path, content)
|
|
182
|
+
|
|
183
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
184
|
+
|
|
185
|
+
role_check = _check(result, 3)
|
|
186
|
+
dependency_check = _check(result, 9)
|
|
187
|
+
assert role_check["result"] == "FAIL"
|
|
188
|
+
assert "所属子系统、协议层或模块" in role_check["detail"]
|
|
189
|
+
assert dependency_check["result"] == "FAIL"
|
|
190
|
+
assert "关系说明不够具体" in dependency_check["detail"]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_placeholder_profile_does_not_require_three_symbols_or_long_role(
|
|
194
|
+
tmp_path: Path,
|
|
195
|
+
) -> None:
|
|
196
|
+
project_root = tmp_path / "project"
|
|
197
|
+
docs_root = project_root / "project_docs"
|
|
198
|
+
source_dir = project_root / "src" / "empty"
|
|
199
|
+
source_dir.mkdir(parents=True)
|
|
200
|
+
_write(source_dir / "__init__.py", "# -*- coding: utf-8 -*-\n")
|
|
201
|
+
_write(docs_root / "src.md", "# src\n")
|
|
202
|
+
doc_path = docs_root / "src" / "empty.md"
|
|
203
|
+
_write(
|
|
204
|
+
doc_path,
|
|
205
|
+
"""# empty — 占位包
|
|
206
|
+
|
|
207
|
+
**导航**: src > **empty**
|
|
208
|
+
|
|
209
|
+
## 概述
|
|
210
|
+
|
|
211
|
+
本目录当前为占位。待后续实现。
|
|
212
|
+
|
|
213
|
+
## 文件清单
|
|
214
|
+
|
|
215
|
+
| 文件 | 用途 |
|
|
216
|
+
|------|------|
|
|
217
|
+
| `__init__.py` | 包初始化文件 |
|
|
218
|
+
|
|
219
|
+
## 系统角色
|
|
220
|
+
|
|
221
|
+
> 参见 [父目录文档](../src.md)。
|
|
222
|
+
|
|
223
|
+
## 状态
|
|
224
|
+
|
|
225
|
+
⬜ 占位 — 目录已建立,待实现。
|
|
226
|
+
""",
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
result = validator.validate_doc(
|
|
230
|
+
doc_path,
|
|
231
|
+
source_dir,
|
|
232
|
+
project_docs_dir=docs_root,
|
|
233
|
+
project_root=project_root,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
assert result["profile"] == validator.PROFILE_PLACEHOLDER
|
|
237
|
+
assert result["qualified"] is True
|
|
238
|
+
assert _check(result, 2)["result"] == "PASS"
|
|
239
|
+
assert _check(result, 3)["result"] == "PASS"
|
|
240
|
+
assert _check(result, 6)["result"] == "N/A"
|
|
241
|
+
assert _check(result, 9)["result"] == "N/A"
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_file_manifest_reports_missing_extra_and_duplicate_rows(tmp_path: Path) -> None:
|
|
245
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
246
|
+
content = doc_path.read_text(encoding="utf-8")
|
|
247
|
+
content = content.replace(
|
|
248
|
+
"| `core.py` | 核心实现 | 定义执行流程 |",
|
|
249
|
+
"| `ghost.py` | 错误条目 | 不存在 |\n" "| `ghost.py` | 重复错误条目 | 不存在 |",
|
|
250
|
+
)
|
|
251
|
+
_write(doc_path, content)
|
|
252
|
+
|
|
253
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
254
|
+
|
|
255
|
+
file_check = _check(result, 1)
|
|
256
|
+
assert file_check["result"] == "FAIL"
|
|
257
|
+
assert "遗漏文件: core.py" in file_check["detail"]
|
|
258
|
+
assert "多余文件: ghost.py" in file_check["detail"]
|
|
259
|
+
assert "重复文件: ghost.py" in file_check["detail"]
|
|
260
|
+
assert result["critical_failed"] >= 1
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_subdirectory_manifest_requires_exact_existing_markdown_target(
|
|
264
|
+
tmp_path: Path,
|
|
265
|
+
) -> None:
|
|
266
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
267
|
+
content = doc_path.read_text(encoding="utf-8").replace(
|
|
268
|
+
"[child.md](module/child.md)",
|
|
269
|
+
"[wrong.md](parent.md)",
|
|
270
|
+
)
|
|
271
|
+
_write(doc_path, content)
|
|
272
|
+
|
|
273
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
274
|
+
|
|
275
|
+
subdir_check = _check(result, 4)
|
|
276
|
+
assert subdir_check["result"] == "FAIL"
|
|
277
|
+
assert "链接目标错误" in subdir_check["detail"]
|
|
278
|
+
assert "src/module/child.md" in subdir_check["detail"]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def test_unsafe_markdown_link_is_a_critical_error(tmp_path: Path) -> None:
|
|
282
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
283
|
+
content = doc_path.read_text(encoding="utf-8").replace(
|
|
284
|
+
STANDARD_ROLE,
|
|
285
|
+
STANDARD_ROLE + " [越界链接](../../../outside.md)",
|
|
286
|
+
)
|
|
287
|
+
_write(doc_path, content)
|
|
288
|
+
|
|
289
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
290
|
+
|
|
291
|
+
assert result["qualified"] is False
|
|
292
|
+
assert result["critical"] is True
|
|
293
|
+
assert result["critical_failed"] >= 1
|
|
294
|
+
assert result["error_code"] == "unsafe-markdown-link"
|
|
295
|
+
assert "target-outside-docs-root" in result["error"]
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def test_document_and_source_paths_cannot_escape_trusted_roots(tmp_path: Path) -> None:
|
|
299
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
300
|
+
outside_doc = tmp_path / "outside.md"
|
|
301
|
+
_write(outside_doc, _standard_document())
|
|
302
|
+
outside_source = tmp_path / "outside-source"
|
|
303
|
+
outside_source.mkdir()
|
|
304
|
+
|
|
305
|
+
escaped_doc = validator.validate_doc(
|
|
306
|
+
outside_doc,
|
|
307
|
+
source_dir,
|
|
308
|
+
project_docs_dir=docs_root,
|
|
309
|
+
project_root=project_root,
|
|
310
|
+
)
|
|
311
|
+
escaped_source = validator.validate_doc(
|
|
312
|
+
doc_path,
|
|
313
|
+
outside_source,
|
|
314
|
+
project_docs_dir=docs_root,
|
|
315
|
+
project_root=project_root,
|
|
316
|
+
)
|
|
317
|
+
unbounded_doc = validator.validate_doc(outside_doc, source_dir)
|
|
318
|
+
|
|
319
|
+
assert escaped_doc["error_code"] == "path-or-input-error"
|
|
320
|
+
assert "越界" in escaped_doc["error"]
|
|
321
|
+
assert escaped_source["error_code"] == "path-or-input-error"
|
|
322
|
+
assert "越过项目根目录" in escaped_source["error"]
|
|
323
|
+
assert unbounded_doc["error_code"] == "path-or-input-error"
|
|
324
|
+
assert "project_docs" in unbounded_doc["error"]
|
|
325
|
+
assert escaped_doc["critical_failed"] == 1
|
|
326
|
+
assert escaped_source["critical_failed"] == 1
|
|
327
|
+
assert unbounded_doc["critical_failed"] == 1
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def test_validate_index_doc_against_root(tmp_path: Path) -> None:
|
|
331
|
+
project_root = tmp_path / "project"
|
|
332
|
+
docs_root = project_root / "project_docs"
|
|
333
|
+
docs_root.mkdir(parents=True)
|
|
334
|
+
(project_root / "main.py").write_text("def main():\n pass\n", encoding="utf-8")
|
|
335
|
+
(project_root / "src").mkdir()
|
|
336
|
+
(docs_root / "src.md").write_text("# src\n", encoding="utf-8")
|
|
337
|
+
|
|
338
|
+
index_content = """# index — 项目全息总览
|
|
339
|
+
|
|
340
|
+
**导航**: **项目全息总览**
|
|
341
|
+
|
|
342
|
+
## 概述
|
|
343
|
+
|
|
344
|
+
系统提供统一端到端量化分析与自动交易能力。
|
|
345
|
+
微内核分层架构解耦数据采集、因子计算与执行撮合。
|
|
346
|
+
通过统一事件总线调度全链路生命周期并交付研报。
|
|
347
|
+
|
|
348
|
+
## 文件清单
|
|
349
|
+
|
|
350
|
+
| 文件 | 用途 | 关键内容 |
|
|
351
|
+
|---|---|---|
|
|
352
|
+
| `main.py` | 统一主入口 | `main` |
|
|
353
|
+
|
|
354
|
+
## 子目录
|
|
355
|
+
|
|
356
|
+
| 子目录 | 用途 | 文档 |
|
|
357
|
+
|---|---|---|
|
|
358
|
+
| `src/` | 核心源码 | [src.md](src.md) |
|
|
359
|
+
|
|
360
|
+
## 关键符号
|
|
361
|
+
|
|
362
|
+
| 符号 | 类型 | 定义位置 | 说明 |
|
|
363
|
+
|---|---|---|---|
|
|
364
|
+
| `main` | function | `main.py:L1` | 启动入口 |
|
|
365
|
+
|
|
366
|
+
## 依赖关系
|
|
367
|
+
|
|
368
|
+
| 方向 | 模块 | 关系 | 文档 |
|
|
369
|
+
|---|---|---|---|
|
|
370
|
+
| ⬇ 下游 | `src` | 驱动核心计算流水线 | [src.md](src.md) |
|
|
371
|
+
|
|
372
|
+
## 系统角色
|
|
373
|
+
|
|
374
|
+
本模块作为系统的顶层总控与架构拓扑中枢,统一调用底层微内核、数据中台、动态研判与交易执行交付子系统,为下游提供统一服务接口。
|
|
375
|
+
|
|
376
|
+
## 状态
|
|
377
|
+
|
|
378
|
+
✅ 完整
|
|
379
|
+
"""
|
|
380
|
+
index_doc = docs_root / "index.md"
|
|
381
|
+
_write(index_doc, index_content)
|
|
382
|
+
|
|
383
|
+
result = validator.validate_doc(
|
|
384
|
+
index_doc,
|
|
385
|
+
project_root,
|
|
386
|
+
project_docs_dir=docs_root,
|
|
387
|
+
project_root=project_root,
|
|
388
|
+
)
|
|
389
|
+
assert result["qualified"] is True
|
|
390
|
+
assert result["failed"] == 0
|
|
391
|
+
assert result["critical_failed"] == 0
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def test_symbol_table_rejects_hallucinated_symbol(tmp_path: Path) -> None:
|
|
396
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
397
|
+
content = doc_path.read_text(encoding="utf-8").replace(
|
|
398
|
+
"| `PublicApi` | class | `core.py:L10` | 公共接口 |",
|
|
399
|
+
"| `HallucinatedClass` | class | `core.py:L10` | 虚构的类 |",
|
|
400
|
+
)
|
|
401
|
+
_write(doc_path, content)
|
|
402
|
+
|
|
403
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
404
|
+
symbol_check = _check(result, 6)
|
|
405
|
+
assert symbol_check["result"] == "FAIL"
|
|
406
|
+
assert "未在 core.py 的 AST 定义中找到" in symbol_check["detail"]
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def test_banned_boilerplate_phrases(tmp_path: Path) -> None:
|
|
410
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(tmp_path)
|
|
411
|
+
content = doc_path.read_text(encoding="utf-8").replace(
|
|
412
|
+
"定义执行流程",
|
|
413
|
+
"核心业务逻辑与基础设施功能",
|
|
414
|
+
)
|
|
415
|
+
_write(doc_path, content)
|
|
416
|
+
|
|
417
|
+
result = _validate_standard(project_root, docs_root, source_dir, doc_path)
|
|
418
|
+
banned_check = _check(result, 7)
|
|
419
|
+
assert banned_check["result"] == "FAIL"
|
|
420
|
+
assert "核心业务逻辑与基础设施功能" in banned_check["detail"]
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def test_missing_and_invalid_utf8_documents_return_complete_stable_results(
|
|
425
|
+
tmp_path: Path,
|
|
426
|
+
) -> None:
|
|
427
|
+
project_root = tmp_path / "project"
|
|
428
|
+
docs_root = project_root / "project_docs"
|
|
429
|
+
docs_root.mkdir(parents=True)
|
|
430
|
+
source_dir = project_root / "src" / "module"
|
|
431
|
+
source_dir.mkdir(parents=True)
|
|
432
|
+
missing = docs_root / "src" / "missing.md"
|
|
433
|
+
bad_utf8 = docs_root / "src" / "bad.md"
|
|
434
|
+
bad_utf8.parent.mkdir(parents=True)
|
|
435
|
+
bad_utf8.write_bytes(b"# title\n\xff")
|
|
436
|
+
|
|
437
|
+
missing_result = validator.validate_doc(
|
|
438
|
+
missing,
|
|
439
|
+
source_dir,
|
|
440
|
+
project_docs_dir=docs_root,
|
|
441
|
+
project_root=project_root,
|
|
442
|
+
)
|
|
443
|
+
bad_result = validator.validate_doc(
|
|
444
|
+
bad_utf8,
|
|
445
|
+
source_dir,
|
|
446
|
+
project_docs_dir=docs_root,
|
|
447
|
+
project_root=project_root,
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
expected_keys = {
|
|
451
|
+
"schema_version",
|
|
452
|
+
"file",
|
|
453
|
+
"source_dir",
|
|
454
|
+
"requested_profile",
|
|
455
|
+
"profile",
|
|
456
|
+
"checks",
|
|
457
|
+
"passed",
|
|
458
|
+
"failed",
|
|
459
|
+
"na",
|
|
460
|
+
"critical_failed",
|
|
461
|
+
"critical",
|
|
462
|
+
"qualified",
|
|
463
|
+
"ok",
|
|
464
|
+
"error_code",
|
|
465
|
+
"error",
|
|
466
|
+
"errors",
|
|
467
|
+
}
|
|
468
|
+
assert set(missing_result) == expected_keys
|
|
469
|
+
assert set(bad_result) == expected_keys
|
|
470
|
+
assert len(missing_result["checks"]) == 9
|
|
471
|
+
assert len(bad_result["checks"]) == 9
|
|
472
|
+
assert missing_result["na"] == 9
|
|
473
|
+
assert bad_result["na"] == 9
|
|
474
|
+
assert missing_result["error_code"] == "document-not-found"
|
|
475
|
+
assert bad_result["error_code"] == "invalid-utf8"
|
|
476
|
+
assert missing_result["qualified"] is False
|
|
477
|
+
assert bad_result["qualified"] is False
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def test_cli_json_is_pure_and_missing_file_exits_critical(
|
|
481
|
+
tmp_path: Path,
|
|
482
|
+
capsys: pytest.CaptureFixture[str],
|
|
483
|
+
) -> None:
|
|
484
|
+
project_root = tmp_path / "project"
|
|
485
|
+
docs_root = project_root / "project_docs"
|
|
486
|
+
docs_root.mkdir(parents=True)
|
|
487
|
+
source_dir = project_root / "src" / "module"
|
|
488
|
+
source_dir.mkdir(parents=True)
|
|
489
|
+
missing = docs_root / "src" / "missing.md"
|
|
490
|
+
|
|
491
|
+
exit_code = validator.main(
|
|
492
|
+
[
|
|
493
|
+
str(missing),
|
|
494
|
+
"--source-dir",
|
|
495
|
+
str(source_dir),
|
|
496
|
+
"--project-docs",
|
|
497
|
+
str(docs_root),
|
|
498
|
+
"--project-root",
|
|
499
|
+
str(project_root),
|
|
500
|
+
"--json",
|
|
501
|
+
]
|
|
502
|
+
)
|
|
503
|
+
captured = capsys.readouterr()
|
|
504
|
+
payload = json.loads(captured.out)
|
|
505
|
+
|
|
506
|
+
assert exit_code == validator.EXIT_CRITICAL_ERROR
|
|
507
|
+
assert payload["error_code"] == "document-not-found"
|
|
508
|
+
assert payload["qualified"] is False
|
|
509
|
+
assert captured.err == ""
|
|
510
|
+
assert captured.out.lstrip().startswith("{")
|
|
511
|
+
assert captured.out.rstrip().endswith("}")
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def test_cli_exit_policy_distinguishes_advisory_strict_and_critical(
|
|
515
|
+
tmp_path: Path,
|
|
516
|
+
capsys: pytest.CaptureFixture[str],
|
|
517
|
+
) -> None:
|
|
518
|
+
project_root, docs_root, source_dir, doc_path = _make_standard_tree(
|
|
519
|
+
tmp_path,
|
|
520
|
+
overview="本目录属于测试模块。它向下游输出结果。",
|
|
521
|
+
)
|
|
522
|
+
args = [
|
|
523
|
+
str(doc_path),
|
|
524
|
+
"--source_dir",
|
|
525
|
+
str(source_dir),
|
|
526
|
+
"--project-docs",
|
|
527
|
+
str(docs_root),
|
|
528
|
+
"--project-root",
|
|
529
|
+
str(project_root),
|
|
530
|
+
"--json",
|
|
531
|
+
]
|
|
532
|
+
|
|
533
|
+
advisory_exit = validator.main(args)
|
|
534
|
+
advisory_output = capsys.readouterr()
|
|
535
|
+
strict_exit = validator.main([*args, "--strict"])
|
|
536
|
+
strict_output = capsys.readouterr()
|
|
537
|
+
|
|
538
|
+
assert advisory_exit == validator.EXIT_OK
|
|
539
|
+
assert strict_exit == validator.EXIT_VALIDATION_FAILED
|
|
540
|
+
assert json.loads(advisory_output.out)["failed"] == 1
|
|
541
|
+
assert json.loads(strict_output.out)["failed"] == 1
|
|
542
|
+
assert advisory_output.err == ""
|
|
543
|
+
assert strict_output.err == ""
|
|
544
|
+
|
|
545
|
+
content = doc_path.read_text(encoding="utf-8").replace(
|
|
546
|
+
"| `core.py` | 核心实现 | 定义执行流程 |",
|
|
547
|
+
"| `ghost.py` | 错误条目 | 不存在 |",
|
|
548
|
+
)
|
|
549
|
+
_write(doc_path, content)
|
|
550
|
+
critical_exit = validator.main(args)
|
|
551
|
+
critical_output = capsys.readouterr()
|
|
552
|
+
|
|
553
|
+
assert critical_exit == validator.EXIT_VALIDATION_FAILED
|
|
554
|
+
assert json.loads(critical_output.out)["critical_failed"] >= 1
|
|
555
|
+
assert critical_output.err == ""
|
|
Binary file
|
|
Binary file
|
|
Binary file
|