@walvka-code/proj-doc-builder 0.0.0-stage → 4.5.2
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 +290 -3
- package/README.zh-CN.md +258 -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 +59 -4
- package/skills/proj-doc-builder/SKILL.md +412 -0
- package/skills/proj-doc-builder/references/audit_script.md +103 -0
- package/skills/proj-doc-builder/references/batch-generation.md +55 -0
- package/skills/proj-doc-builder/references/checklist.md +90 -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 +212 -0
- package/skills/proj-doc-builder/tests/claims.json +76 -0
- package/skills/proj-doc-builder/tests/conftest.py +23 -0
- package/skills/proj-doc-builder/tests/test_claims_registry.py +81 -0
- package/skills/proj-doc-builder/tests/test_claude_doc_index.py +157 -0
- package/skills/proj-doc-builder/tests/test_e2e_fresh_project.py +156 -0
- package/skills/proj-doc-builder/tests/test_link_tools.py +279 -0
- package/skills/proj-doc-builder/tests/test_load_docs.py +353 -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 +812 -0
- package/skills/proj-doc-builder/tests/test_scan_dirs.py +1159 -0
- package/skills/proj-doc-builder/tests/test_stage1_stage2_upgrades.py +395 -0
- package/skills/proj-doc-builder/tests/test_sync_project_docs.py +2169 -0
- package/skills/proj-doc-builder/tests/test_v41_upgrades.py +614 -0
- package/skills/proj-doc-builder/tests/test_v42_upgrades.py +422 -0
- package/skills/proj-doc-builder/tests/test_v43_upgrades.py +198 -0
- package/skills/proj-doc-builder/tests/test_v44_upgrades.py +361 -0
- package/skills/proj-doc-builder/tests/test_v45_upgrades.py +212 -0
- package/skills/proj-doc-builder/tests/test_validate_doc.py +712 -0
- package/skills/proj-doc-builder/tools/_paths.py +39 -0
- package/skills/proj-doc-builder/tools/core/claude_doc_index.py +504 -0
- package/skills/proj-doc-builder/tools/core/compute_link.py +239 -0
- package/skills/proj-doc-builder/tools/core/proj_doc_config.py +460 -0
- package/skills/proj-doc-builder/tools/core/project_docs_contract.py +2725 -0
- package/skills/proj-doc-builder/tools/phase4/__init__.py +82 -0
- package/skills/proj-doc-builder/tools/phase4/cas_storage.py +25 -0
- package/skills/proj-doc-builder/tools/phase4/engine.py +35 -0
- package/skills/proj-doc-builder/tools/phase4/journal.py +29 -0
- package/skills/proj-doc-builder/tools/phase4/platform_handles.py +27 -0
- package/skills/proj-doc-builder/tools/phase4_exit.py +8565 -0
- package/skills/proj-doc-builder/tools/pipeline/gen_docs_from_scaffold.py +789 -0
- package/skills/proj-doc-builder/tools/pipeline/sync_project_docs.py +5531 -0
- package/skills/proj-doc-builder/tools/reader/load_docs.py +654 -0
- package/skills/proj-doc-builder/tools/scan/link_check.py +203 -0
- package/skills/proj-doc-builder/tools/scan/normalize_markers.py +211 -0
- package/skills/proj-doc-builder/tools/scan/scan_dirs.py +2735 -0
- package/skills/proj-doc-builder/tools/validate/validate_doc.py +1911 -0
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Focused tests for the shared project_docs contract."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import copy
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
import project_docs_contract as contract
|
|
13
|
+
|
|
14
|
+
SYNCED_1 = "2026-07-29T12:00:00+08:00"
|
|
15
|
+
SYNCED_2 = "2026-07-30T12:00:00+08:00"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _write_doc(
|
|
19
|
+
path: Path,
|
|
20
|
+
title: str,
|
|
21
|
+
*,
|
|
22
|
+
status: str = "✅",
|
|
23
|
+
synced_at: str | None = SYNCED_1,
|
|
24
|
+
repeated_suffix: bool = False,
|
|
25
|
+
) -> None:
|
|
26
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
marker = ""
|
|
28
|
+
if synced_at is not None:
|
|
29
|
+
marker = f"<!-- Last synced: {synced_at} by proj-doc-builder v4.0 -->"
|
|
30
|
+
if repeated_suffix:
|
|
31
|
+
marker += " by proj-doc-builder v4.0 -->"
|
|
32
|
+
marker += "\n"
|
|
33
|
+
path.write_text(
|
|
34
|
+
f"# {title}\n\n{marker}\n## 状态\n\n{status} 完整\n",
|
|
35
|
+
encoding="utf-8",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _make_docs(tmp_path: Path) -> Path:
|
|
40
|
+
root = tmp_path / "project_docs"
|
|
41
|
+
root.mkdir()
|
|
42
|
+
_write_doc(root / "root.md", "根文档")
|
|
43
|
+
_write_doc(root / "group" / "child.md", "子文档", status="🔶")
|
|
44
|
+
return root
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_valid_manifest_paths_and_depth() -> None:
|
|
48
|
+
assert contract.validate_manifest_relative_path("root.md").as_posix() == "root.md"
|
|
49
|
+
assert contract.validate_manifest_relative_path("a/b.md").as_posix() == "a/b.md"
|
|
50
|
+
assert contract.manifest_path_depth("root.md") == 0
|
|
51
|
+
assert contract.manifest_path_depth("a/b.md") == 1
|
|
52
|
+
assert contract.manifest_path_depth("a/b/c.md") == 2
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.mark.parametrize(
|
|
56
|
+
"value",
|
|
57
|
+
[
|
|
58
|
+
"",
|
|
59
|
+
"/absolute.md",
|
|
60
|
+
"C:/absolute.md",
|
|
61
|
+
"C:relative.md",
|
|
62
|
+
"//server/share.md",
|
|
63
|
+
"bad\x00name.md",
|
|
64
|
+
r"a\b.md",
|
|
65
|
+
".",
|
|
66
|
+
"..",
|
|
67
|
+
"./a.md",
|
|
68
|
+
"a/../b.md",
|
|
69
|
+
"a/./b.md",
|
|
70
|
+
"a//b.md",
|
|
71
|
+
"a/",
|
|
72
|
+
"not-markdown.txt",
|
|
73
|
+
".md",
|
|
74
|
+
"upper.MD",
|
|
75
|
+
"folder/report:meta.md",
|
|
76
|
+
"folder/bad?.md",
|
|
77
|
+
"folder/name./child.md",
|
|
78
|
+
"folder/name /child.md",
|
|
79
|
+
"CON.md",
|
|
80
|
+
"folder/LPT1.log.md",
|
|
81
|
+
"bad\x01name.md",
|
|
82
|
+
],
|
|
83
|
+
)
|
|
84
|
+
def test_invalid_manifest_paths(value: str) -> None:
|
|
85
|
+
with pytest.raises(contract.PathValidationError):
|
|
86
|
+
contract.validate_manifest_relative_path(value)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_casefold_path_conflicts_are_rejected() -> None:
|
|
90
|
+
with pytest.raises(contract.PathConflictError, match="case conflict"):
|
|
91
|
+
contract.ensure_unique_manifest_paths(["Folder/A.md", "folder/a.md"])
|
|
92
|
+
with pytest.raises(contract.PathConflictError, match="duplicate"):
|
|
93
|
+
contract.ensure_unique_manifest_paths(["same.md", "same.md"])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_manifest_symlink_escape_is_rejected(tmp_path: Path) -> None:
|
|
97
|
+
root = tmp_path / "project_docs"
|
|
98
|
+
root.mkdir()
|
|
99
|
+
outside = tmp_path / "outside.md"
|
|
100
|
+
_write_doc(outside, "外部")
|
|
101
|
+
link = root / "escape.md"
|
|
102
|
+
try:
|
|
103
|
+
link.symlink_to(outside)
|
|
104
|
+
except (NotImplementedError, OSError) as exc:
|
|
105
|
+
pytest.skip(f"symlink creation is unavailable: {exc}")
|
|
106
|
+
|
|
107
|
+
with pytest.raises(contract.PathValidationError, match="outside"):
|
|
108
|
+
contract.resolve_manifest_document(root, "escape.md")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_manifest_discovery_rejects_external_directory_link_and_loop(
|
|
112
|
+
tmp_path: Path,
|
|
113
|
+
) -> None:
|
|
114
|
+
root = _make_docs(tmp_path)
|
|
115
|
+
outside = tmp_path / "outside_docs"
|
|
116
|
+
outside.mkdir()
|
|
117
|
+
_write_doc(outside / "secret.md", "外部")
|
|
118
|
+
external_link = root / "external"
|
|
119
|
+
try:
|
|
120
|
+
external_link.symlink_to(outside, target_is_directory=True)
|
|
121
|
+
except (NotImplementedError, OSError) as exc:
|
|
122
|
+
pytest.skip(f"directory symlink creation is unavailable: {exc}")
|
|
123
|
+
|
|
124
|
+
with pytest.raises(contract.PathValidationError, match="symlink or reparse point"):
|
|
125
|
+
contract.build_manifest(root, last_synced=SYNCED_1)
|
|
126
|
+
|
|
127
|
+
external_link.unlink()
|
|
128
|
+
loop = root / "loop"
|
|
129
|
+
loop.symlink_to(root, target_is_directory=True)
|
|
130
|
+
with pytest.raises(contract.PathValidationError, match="symlink or reparse point"):
|
|
131
|
+
contract.build_manifest(root, last_synced=SYNCED_1)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_markdown_link_rules_and_structured_results(tmp_path: Path) -> None:
|
|
135
|
+
root = tmp_path / "project_docs"
|
|
136
|
+
source = root / "a" / "source.md"
|
|
137
|
+
target = root / "b" / "target.md"
|
|
138
|
+
encoded_target = root / "b" / "目标 文档.md"
|
|
139
|
+
_write_doc(source, "源")
|
|
140
|
+
_write_doc(target, "目标")
|
|
141
|
+
_write_doc(encoded_target, "编码目标")
|
|
142
|
+
|
|
143
|
+
content = "\n".join(
|
|
144
|
+
[
|
|
145
|
+
"[extensionless](../b/target)",
|
|
146
|
+
"[encoded](<../b/%E7%9B%AE%E6%A0%87%20%E6%96%87%E6%A1%A3.md?mode=1#part>)",
|
|
147
|
+
"[web](https://example.com/x.md)",
|
|
148
|
+
"[mail](mailto:test@example.com)",
|
|
149
|
+
"[anchor](#section)",
|
|
150
|
+
"[source](../code/tool.py)",
|
|
151
|
+
"[other](../manual.pdf)",
|
|
152
|
+
"[outside](../../../outside.md)",
|
|
153
|
+
"[encoded-outside](%2E%2E/%2E%2E/outside.md)",
|
|
154
|
+
"[encoded-backslash](..%5Cb%5Ctarget.md)",
|
|
155
|
+
"[encoded-nul](../b/target%00.md)",
|
|
156
|
+
"[ads](../b/report:meta.md)",
|
|
157
|
+
"[device](../b/CON.md)",
|
|
158
|
+
"[absolute](/absolute.md)",
|
|
159
|
+
"[bad-percent](../b/%FF.md)",
|
|
160
|
+
]
|
|
161
|
+
)
|
|
162
|
+
links = contract.parse_markdown_links(
|
|
163
|
+
content,
|
|
164
|
+
source_doc=source,
|
|
165
|
+
docs_root=root,
|
|
166
|
+
)
|
|
167
|
+
by_text = {link.text: link for link in links}
|
|
168
|
+
|
|
169
|
+
extensionless = by_text["extensionless"]
|
|
170
|
+
assert extensionless.disposition is contract.LinkDisposition.LOCAL_DOCUMENT
|
|
171
|
+
assert extensionless.project_relative_path == "b/target.md"
|
|
172
|
+
assert extensionless.exists is True
|
|
173
|
+
|
|
174
|
+
encoded = by_text["encoded"]
|
|
175
|
+
assert encoded.disposition is contract.LinkDisposition.LOCAL_DOCUMENT
|
|
176
|
+
assert encoded.project_relative_path == "b/目标 文档.md"
|
|
177
|
+
assert encoded.query == "mode=1"
|
|
178
|
+
assert encoded.fragment == "part"
|
|
179
|
+
assert encoded.exists is True
|
|
180
|
+
|
|
181
|
+
for text in ("web", "mail", "anchor", "source", "other"):
|
|
182
|
+
assert by_text[text].disposition is contract.LinkDisposition.SKIPPED
|
|
183
|
+
for text in (
|
|
184
|
+
"outside",
|
|
185
|
+
"encoded-outside",
|
|
186
|
+
"encoded-backslash",
|
|
187
|
+
"encoded-nul",
|
|
188
|
+
"ads",
|
|
189
|
+
"device",
|
|
190
|
+
"absolute",
|
|
191
|
+
"bad-percent",
|
|
192
|
+
):
|
|
193
|
+
assert by_text[text].disposition is contract.LinkDisposition.INVALID
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_reference_style_and_html_links_are_resolved(tmp_path: Path) -> None:
|
|
197
|
+
root = tmp_path / "project_docs"
|
|
198
|
+
source = root / "refs" / "source.md"
|
|
199
|
+
target = root / "target.md"
|
|
200
|
+
_write_doc(source, "源")
|
|
201
|
+
_write_doc(target, "目标")
|
|
202
|
+
content = "\n".join(
|
|
203
|
+
[
|
|
204
|
+
"[full][target-id]",
|
|
205
|
+
"[collapsed][]",
|
|
206
|
+
"[shortcut]",
|
|
207
|
+
'<a href="../target.md#html">HTML</a>',
|
|
208
|
+
"",
|
|
209
|
+
"[target-id]: ../target.md",
|
|
210
|
+
"[collapsed]: <../target.md?mode=1>",
|
|
211
|
+
"[shortcut]: ../target",
|
|
212
|
+
]
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
links = contract.parse_markdown_links(
|
|
216
|
+
content,
|
|
217
|
+
source_doc=source,
|
|
218
|
+
docs_root=root,
|
|
219
|
+
)
|
|
220
|
+
by_text = {link.text: link for link in links if link.text}
|
|
221
|
+
|
|
222
|
+
assert by_text["full"].project_relative_path == "target.md"
|
|
223
|
+
assert by_text["collapsed"].query == "mode=1"
|
|
224
|
+
assert by_text["shortcut"].project_relative_path == "target.md"
|
|
225
|
+
html = next(link for link in links if link.text == "")
|
|
226
|
+
assert html.project_relative_path == "target.md"
|
|
227
|
+
assert html.fragment == "html"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_link_resolution_rejects_symlink_escape(tmp_path: Path) -> None:
|
|
231
|
+
root = tmp_path / "project_docs"
|
|
232
|
+
root.mkdir()
|
|
233
|
+
source = root / "source.md"
|
|
234
|
+
_write_doc(source, "源")
|
|
235
|
+
outside = tmp_path / "outside.md"
|
|
236
|
+
_write_doc(outside, "外部")
|
|
237
|
+
link = root / "linked.md"
|
|
238
|
+
try:
|
|
239
|
+
link.symlink_to(outside)
|
|
240
|
+
except (NotImplementedError, OSError) as exc:
|
|
241
|
+
pytest.skip(f"symlink creation is unavailable: {exc}")
|
|
242
|
+
|
|
243
|
+
result = contract.resolve_markdown_target(
|
|
244
|
+
"linked.md",
|
|
245
|
+
source_doc=source,
|
|
246
|
+
docs_root=root,
|
|
247
|
+
)
|
|
248
|
+
assert result.disposition is contract.LinkDisposition.INVALID
|
|
249
|
+
assert result.reason == "target-outside-docs-root"
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def test_read_markdown_links_rejects_external_source_before_read(
|
|
253
|
+
tmp_path: Path,
|
|
254
|
+
) -> None:
|
|
255
|
+
root = tmp_path / "project_docs"
|
|
256
|
+
root.mkdir()
|
|
257
|
+
outside = tmp_path / "outside.md"
|
|
258
|
+
outside.write_bytes(b"secret-\xff")
|
|
259
|
+
source = root / "source.md"
|
|
260
|
+
try:
|
|
261
|
+
source.symlink_to(outside)
|
|
262
|
+
except (NotImplementedError, OSError) as exc:
|
|
263
|
+
pytest.skip(f"symlink creation is unavailable: {exc}")
|
|
264
|
+
|
|
265
|
+
with pytest.raises(contract.LinkResolutionError, match="outside"):
|
|
266
|
+
contract.read_markdown_links(source, root)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def test_secure_document_read_rejects_swap_to_external_symlink(
|
|
270
|
+
tmp_path: Path,
|
|
271
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
272
|
+
) -> None:
|
|
273
|
+
root = tmp_path / "project_docs"
|
|
274
|
+
root.mkdir()
|
|
275
|
+
victim = root / "victim.md"
|
|
276
|
+
outside = tmp_path / "outside.md"
|
|
277
|
+
_write_doc(victim, "原始")
|
|
278
|
+
_write_doc(outside, "外部")
|
|
279
|
+
original_resolve = contract.resolve_manifest_document
|
|
280
|
+
swapped = False
|
|
281
|
+
|
|
282
|
+
def swapping_resolve(*args: object, **kwargs: object) -> contract.SafeManifestPath:
|
|
283
|
+
nonlocal swapped
|
|
284
|
+
safe_path = original_resolve(*args, **kwargs)
|
|
285
|
+
if safe_path.relative_path == "victim.md" and not swapped:
|
|
286
|
+
try:
|
|
287
|
+
victim.unlink()
|
|
288
|
+
victim.symlink_to(outside)
|
|
289
|
+
except (NotImplementedError, OSError) as exc:
|
|
290
|
+
pytest.skip(f"symlink creation is unavailable: {exc}")
|
|
291
|
+
swapped = True
|
|
292
|
+
return safe_path
|
|
293
|
+
|
|
294
|
+
monkeypatch.setattr(contract, "resolve_manifest_document", swapping_resolve)
|
|
295
|
+
with pytest.raises(contract.PathValidationError):
|
|
296
|
+
contract.read_project_document(root, "victim.md")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_compute_relative_doc_link_uses_posix_paths(tmp_path: Path) -> None:
|
|
300
|
+
root = _make_docs(tmp_path)
|
|
301
|
+
link = contract.compute_relative_doc_link(
|
|
302
|
+
"group/child.md",
|
|
303
|
+
"root.md",
|
|
304
|
+
root,
|
|
305
|
+
)
|
|
306
|
+
assert link == "../root.md"
|
|
307
|
+
|
|
308
|
+
future_link = contract.compute_relative_doc_link(
|
|
309
|
+
"new/source.md",
|
|
310
|
+
"future/target.md",
|
|
311
|
+
root,
|
|
312
|
+
)
|
|
313
|
+
assert future_link == "../future/target.md"
|
|
314
|
+
with pytest.raises(contract.PathValidationError):
|
|
315
|
+
contract.compute_relative_doc_link(
|
|
316
|
+
"new/source.md",
|
|
317
|
+
"future/target.md",
|
|
318
|
+
root,
|
|
319
|
+
must_exist=True,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def test_last_synced_parser_ignores_repeated_tail(tmp_path: Path) -> None:
|
|
324
|
+
root = tmp_path / "project_docs"
|
|
325
|
+
root.mkdir()
|
|
326
|
+
doc = root / "marker.md"
|
|
327
|
+
_write_doc(doc, "Marker", repeated_suffix=True)
|
|
328
|
+
content = contract.read_utf8(doc)
|
|
329
|
+
assert contract.parse_last_synced_marker(content) == SYNCED_1
|
|
330
|
+
metadata = contract.parse_document_metadata(content, "marker.md")
|
|
331
|
+
assert metadata.title == "Marker"
|
|
332
|
+
assert metadata.status == "✅"
|
|
333
|
+
assert metadata.synced_at == SYNCED_1
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def test_strict_utf8_and_json_reject_corruption(tmp_path: Path) -> None:
|
|
337
|
+
bad_text = tmp_path / "bad.md"
|
|
338
|
+
bad_text.write_bytes(b"valid\xffinvalid")
|
|
339
|
+
with pytest.raises(contract.StrictUtf8Error):
|
|
340
|
+
contract.read_utf8(bad_text)
|
|
341
|
+
|
|
342
|
+
duplicate = tmp_path / "duplicate.json"
|
|
343
|
+
duplicate.write_text('{"a": 1, "a": 2}\n', encoding="utf-8")
|
|
344
|
+
with pytest.raises(contract.JsonContractError, match="duplicate"):
|
|
345
|
+
contract.read_json_strict(duplicate)
|
|
346
|
+
|
|
347
|
+
nonfinite = tmp_path / "nonfinite.json"
|
|
348
|
+
nonfinite.write_text('{"value": NaN}\n', encoding="utf-8")
|
|
349
|
+
with pytest.raises(contract.JsonContractError, match="non-standard"):
|
|
350
|
+
contract.read_json_strict(nonfinite)
|
|
351
|
+
|
|
352
|
+
overflow = tmp_path / "overflow.json"
|
|
353
|
+
overflow.write_text('{"positive": 1e309, "negative": -1e309}\n', encoding="utf-8")
|
|
354
|
+
with pytest.raises(contract.JsonContractError, match="non-finite"):
|
|
355
|
+
contract.read_json_strict(overflow)
|
|
356
|
+
|
|
357
|
+
surrogate = tmp_path / "surrogate.json"
|
|
358
|
+
surrogate.write_text('{"value": "\\ud800"}\n', encoding="utf-8")
|
|
359
|
+
with pytest.raises(contract.JsonContractError, match="surrogate"):
|
|
360
|
+
contract.read_json_strict(surrogate)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def test_atomic_json_is_stable_utf8_and_uses_unique_same_dir_temps(
|
|
364
|
+
tmp_path: Path,
|
|
365
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
366
|
+
) -> None:
|
|
367
|
+
destination = tmp_path / "manifest.json"
|
|
368
|
+
destination.write_text("old", encoding="utf-8")
|
|
369
|
+
real_replace = contract.os.replace
|
|
370
|
+
temporary_paths: list[Path] = []
|
|
371
|
+
|
|
372
|
+
def recording_replace(source: str | Path, target: str | Path) -> None:
|
|
373
|
+
temporary_paths.append(Path(source))
|
|
374
|
+
real_replace(source, target)
|
|
375
|
+
|
|
376
|
+
monkeypatch.setattr(contract.os, "replace", recording_replace)
|
|
377
|
+
contract.atomic_write_json(destination, {"z": 1, "a": "中文"})
|
|
378
|
+
first_content = destination.read_text(encoding="utf-8")
|
|
379
|
+
contract.atomic_write_json(destination, {"a": "中文", "z": 2})
|
|
380
|
+
|
|
381
|
+
assert first_content == '{\n "a": "中文",\n "z": 1\n}\n'
|
|
382
|
+
assert contract.read_json_strict(destination) == {"a": "中文", "z": 2}
|
|
383
|
+
assert len(temporary_paths) == 2
|
|
384
|
+
assert temporary_paths[0] != temporary_paths[1]
|
|
385
|
+
assert all(path.parent == destination.parent for path in temporary_paths)
|
|
386
|
+
assert not list(tmp_path.glob(".manifest.json.*.tmp"))
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
@pytest.mark.skipif(contract.os.name != "posix", reason="permission bits are POSIX-only")
|
|
390
|
+
def test_atomic_write_preserves_existing_file_mode(tmp_path: Path) -> None:
|
|
391
|
+
"""A replacement must keep the destination's permission bits, not silently switch to 0600."""
|
|
392
|
+
target = tmp_path / "doc.md"
|
|
393
|
+
target.write_bytes(b"old\n")
|
|
394
|
+
target.chmod(0o644)
|
|
395
|
+
contract.atomic_write_utf8(target, "new content\n")
|
|
396
|
+
assert target.read_bytes() == b"new content\n"
|
|
397
|
+
assert (target.stat().st_mode & 0o777) == 0o644
|
|
398
|
+
|
|
399
|
+
target.chmod(0o600)
|
|
400
|
+
contract.atomic_write_utf8(target, "again\n")
|
|
401
|
+
assert (target.stat().st_mode & 0o777) == 0o600
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@pytest.mark.skipif(contract.os.name != "posix", reason="permission bits are POSIX-only")
|
|
405
|
+
def test_atomic_write_new_file_uses_umask_correct_mode(tmp_path: Path) -> None:
|
|
406
|
+
"""A brand-new file must respect the process umask, not be locked to mkstemp's 0600."""
|
|
407
|
+
import os as _os
|
|
408
|
+
target = tmp_path / "fresh.md"
|
|
409
|
+
saved = _os.umask(0); _os.umask(saved)
|
|
410
|
+
expected = 0o666 & ~saved
|
|
411
|
+
contract.atomic_write_utf8(target, "hello\n")
|
|
412
|
+
actual = target.stat().st_mode & 0o777
|
|
413
|
+
assert actual != 0o600, "file mode stayed at mkstemp's 0600"
|
|
414
|
+
assert actual == expected
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def test_exclusive_lock_blocks_a_second_owner(tmp_path: Path) -> None:
|
|
418
|
+
lock_path = tmp_path / "manifest.lock"
|
|
419
|
+
with contract.exclusive_lock(lock_path, timeout=1.0):
|
|
420
|
+
with pytest.raises(contract.LockTimeoutError):
|
|
421
|
+
with contract.exclusive_lock(
|
|
422
|
+
lock_path,
|
|
423
|
+
timeout=0.05,
|
|
424
|
+
poll_interval=0.01,
|
|
425
|
+
):
|
|
426
|
+
pass
|
|
427
|
+
with contract.exclusive_lock(lock_path, timeout=0.2):
|
|
428
|
+
pass
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def test_exclusive_lock_rejects_symlink_without_modifying_target(
|
|
432
|
+
tmp_path: Path,
|
|
433
|
+
) -> None:
|
|
434
|
+
target = tmp_path / "target.txt"
|
|
435
|
+
target.write_bytes(b"")
|
|
436
|
+
lock_path = tmp_path / "manifest.lock"
|
|
437
|
+
try:
|
|
438
|
+
lock_path.symlink_to(target)
|
|
439
|
+
except (NotImplementedError, OSError) as exc:
|
|
440
|
+
pytest.skip(f"symlink creation unavailable: {exc}")
|
|
441
|
+
|
|
442
|
+
with pytest.raises(contract.LockError, match="link or reparse point"):
|
|
443
|
+
with contract.exclusive_lock(lock_path, timeout=0.01):
|
|
444
|
+
pass
|
|
445
|
+
|
|
446
|
+
assert target.read_bytes() == b""
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def test_exclusive_lock_repairs_uninitialized_existing_empty_file(
|
|
450
|
+
tmp_path: Path,
|
|
451
|
+
) -> None:
|
|
452
|
+
lock_path = tmp_path / "manifest.lock"
|
|
453
|
+
lock_path.write_bytes(b"")
|
|
454
|
+
|
|
455
|
+
with contract.exclusive_lock(lock_path, timeout=0.1):
|
|
456
|
+
pass
|
|
457
|
+
assert lock_path.read_bytes() == b"\0"
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def test_exclusive_lock_recovers_after_initialization_write_failure(
|
|
461
|
+
tmp_path: Path,
|
|
462
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
463
|
+
) -> None:
|
|
464
|
+
lock_path = tmp_path / "manifest.lock"
|
|
465
|
+
original_write = contract.os.write
|
|
466
|
+
|
|
467
|
+
def fail_write(fd: int, data: bytes) -> int:
|
|
468
|
+
raise OSError("injected initialization failure")
|
|
469
|
+
|
|
470
|
+
monkeypatch.setattr(contract.os, "write", fail_write)
|
|
471
|
+
with pytest.raises(contract.LockError, match="cannot safely open"):
|
|
472
|
+
with contract.exclusive_lock(lock_path, timeout=0.01):
|
|
473
|
+
pass
|
|
474
|
+
assert lock_path.read_bytes() == b""
|
|
475
|
+
|
|
476
|
+
monkeypatch.setattr(contract.os, "write", original_write)
|
|
477
|
+
with contract.exclusive_lock(lock_path, timeout=0.1):
|
|
478
|
+
pass
|
|
479
|
+
assert lock_path.read_bytes() == b"\0"
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def test_build_and_write_manifest_locks_build_and_replace(
|
|
483
|
+
tmp_path: Path,
|
|
484
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
485
|
+
) -> None:
|
|
486
|
+
root = tmp_path / "project_docs"
|
|
487
|
+
root.mkdir()
|
|
488
|
+
destination = root / contract.MANIFEST_FILENAME
|
|
489
|
+
expected_project_root = root.parent.resolve()
|
|
490
|
+
expected_manifest_lock = destination.with_name(destination.name + ".lock")
|
|
491
|
+
events: list[tuple[str, Path]] = []
|
|
492
|
+
expected_manifest = {"schema_version": contract.MANIFEST_SCHEMA_VERSION}
|
|
493
|
+
|
|
494
|
+
@contextmanager
|
|
495
|
+
def recording_project_lock(
|
|
496
|
+
project_root: Path,
|
|
497
|
+
**kwargs: object,
|
|
498
|
+
) -> object:
|
|
499
|
+
assert kwargs == {"timeout": 2.0}
|
|
500
|
+
events.append(("project-lock-enter", Path(project_root)))
|
|
501
|
+
try:
|
|
502
|
+
yield object()
|
|
503
|
+
finally:
|
|
504
|
+
events.append(("project-lock-exit", Path(project_root)))
|
|
505
|
+
|
|
506
|
+
@contextmanager
|
|
507
|
+
def recording_manifest_lock(
|
|
508
|
+
lock_path: Path,
|
|
509
|
+
**kwargs: object,
|
|
510
|
+
) -> object:
|
|
511
|
+
assert kwargs == {"timeout": 2.0}
|
|
512
|
+
events.append(("manifest-lock-enter", Path(lock_path)))
|
|
513
|
+
try:
|
|
514
|
+
yield object()
|
|
515
|
+
finally:
|
|
516
|
+
events.append(("manifest-lock-exit", Path(lock_path)))
|
|
517
|
+
|
|
518
|
+
def recording_build(docs_root: Path, **kwargs: object) -> dict[str, int]:
|
|
519
|
+
assert events == [
|
|
520
|
+
("project-lock-enter", expected_project_root),
|
|
521
|
+
("manifest-lock-enter", expected_manifest_lock),
|
|
522
|
+
]
|
|
523
|
+
assert Path(docs_root) == root
|
|
524
|
+
assert kwargs["last_synced"] == SYNCED_1
|
|
525
|
+
events.append(("build", root))
|
|
526
|
+
return expected_manifest
|
|
527
|
+
|
|
528
|
+
def recording_write(path: Path, value: object) -> Path:
|
|
529
|
+
assert events == [
|
|
530
|
+
("project-lock-enter", expected_project_root),
|
|
531
|
+
("manifest-lock-enter", expected_manifest_lock),
|
|
532
|
+
("build", root),
|
|
533
|
+
]
|
|
534
|
+
assert value is expected_manifest
|
|
535
|
+
events.append(("write", Path(path)))
|
|
536
|
+
return Path(path)
|
|
537
|
+
|
|
538
|
+
monkeypatch.setattr(contract, "project_sync_lock", recording_project_lock)
|
|
539
|
+
monkeypatch.setattr(contract, "exclusive_lock", recording_manifest_lock)
|
|
540
|
+
monkeypatch.setattr(contract, "build_manifest", recording_build)
|
|
541
|
+
monkeypatch.setattr(contract, "atomic_write_json", recording_write)
|
|
542
|
+
|
|
543
|
+
returned = contract.build_and_write_manifest(
|
|
544
|
+
root,
|
|
545
|
+
last_synced=SYNCED_1,
|
|
546
|
+
timeout=2.0,
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
assert returned is expected_manifest
|
|
550
|
+
assert events == [
|
|
551
|
+
("project-lock-enter", expected_project_root),
|
|
552
|
+
("manifest-lock-enter", expected_manifest_lock),
|
|
553
|
+
("build", root),
|
|
554
|
+
("write", destination),
|
|
555
|
+
("manifest-lock-exit", expected_manifest_lock),
|
|
556
|
+
("project-lock-exit", expected_project_root),
|
|
557
|
+
]
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def test_manifest_v2_roundtrip_and_stable_generation(tmp_path: Path) -> None:
|
|
561
|
+
root = _make_docs(tmp_path)
|
|
562
|
+
first = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
563
|
+
second = contract.build_manifest(root, last_synced=SYNCED_2)
|
|
564
|
+
|
|
565
|
+
assert first["schema_version"] == 2
|
|
566
|
+
assert first["producer"] == {
|
|
567
|
+
"name": contract.DEFAULT_PRODUCER_NAME,
|
|
568
|
+
"version": contract.DEFAULT_PRODUCER_VERSION,
|
|
569
|
+
}
|
|
570
|
+
assert first["docs_root"] == "project_docs"
|
|
571
|
+
assert first["total"] == 2
|
|
572
|
+
assert first["depth_counts"] == {"0": 1, "1": 1}
|
|
573
|
+
assert [entry["path"] for entry in first["files"]] == [
|
|
574
|
+
"group/child.md",
|
|
575
|
+
"root.md",
|
|
576
|
+
]
|
|
577
|
+
assert [entry["depth"] for entry in first["files"]] == [1, 0]
|
|
578
|
+
assert first["generation_id"] == second["generation_id"]
|
|
579
|
+
assert (
|
|
580
|
+
contract.compute_generation_id(list(reversed(first["files"])))
|
|
581
|
+
== first["generation_id"]
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
manifest_path = root / contract.MANIFEST_FILENAME
|
|
585
|
+
contract.write_manifest(manifest_path, first, use_lock=False)
|
|
586
|
+
loaded = contract.load_manifest(manifest_path, docs_root=root)
|
|
587
|
+
assert loaded == first
|
|
588
|
+
assert manifest_path.read_bytes().endswith(b"\n")
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def test_manifest_v2_detects_document_and_manifest_hash_tampering(
|
|
592
|
+
tmp_path: Path,
|
|
593
|
+
) -> None:
|
|
594
|
+
root = _make_docs(tmp_path)
|
|
595
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
596
|
+
manifest_path = root / contract.MANIFEST_FILENAME
|
|
597
|
+
contract.atomic_write_json(manifest_path, manifest)
|
|
598
|
+
|
|
599
|
+
(root / "root.md").write_text("# changed\n", encoding="utf-8")
|
|
600
|
+
with pytest.raises(contract.ManifestFileMismatchError):
|
|
601
|
+
contract.load_manifest(manifest_path, docs_root=root)
|
|
602
|
+
assert (
|
|
603
|
+
contract.load_manifest(
|
|
604
|
+
manifest_path,
|
|
605
|
+
docs_root=root,
|
|
606
|
+
verify_files=False,
|
|
607
|
+
)["generation_id"]
|
|
608
|
+
== manifest["generation_id"]
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
tampered = copy.deepcopy(manifest)
|
|
612
|
+
tampered["files"][0]["sha256"] = "0" * 64
|
|
613
|
+
with pytest.raises(
|
|
614
|
+
contract.ManifestValidationError, match="generation_id mismatch"
|
|
615
|
+
):
|
|
616
|
+
contract.validate_manifest_v2(tampered, root, verify_files=False)
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def test_verified_manifest_requires_complete_active_document_set(
|
|
620
|
+
tmp_path: Path,
|
|
621
|
+
) -> None:
|
|
622
|
+
root = _make_docs(tmp_path)
|
|
623
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
624
|
+
extra = root / "extra.md"
|
|
625
|
+
_write_doc(extra, "Extra", status="✅", synced_at=SYNCED_1)
|
|
626
|
+
|
|
627
|
+
with pytest.raises(
|
|
628
|
+
contract.ManifestFileMismatchError,
|
|
629
|
+
match="unregistered active documents",
|
|
630
|
+
):
|
|
631
|
+
contract.validate_manifest_v2(manifest, root, verify_files=True)
|
|
632
|
+
|
|
633
|
+
assert (
|
|
634
|
+
contract.validate_manifest_v2(
|
|
635
|
+
manifest,
|
|
636
|
+
root,
|
|
637
|
+
verify_files=True,
|
|
638
|
+
verify_complete_set=False,
|
|
639
|
+
)["total"]
|
|
640
|
+
== 2
|
|
641
|
+
)
|
|
642
|
+
assert (
|
|
643
|
+
contract.validate_manifest_v2(
|
|
644
|
+
manifest,
|
|
645
|
+
root,
|
|
646
|
+
verify_files=False,
|
|
647
|
+
)["total"]
|
|
648
|
+
== 2
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
manifest_path = root / contract.MANIFEST_FILENAME
|
|
652
|
+
contract.write_manifest(manifest_path, manifest, use_lock=False)
|
|
653
|
+
assert (
|
|
654
|
+
contract.load_manifest(
|
|
655
|
+
manifest_path,
|
|
656
|
+
docs_root=root,
|
|
657
|
+
verify_complete_set=False,
|
|
658
|
+
)["total"]
|
|
659
|
+
== 2
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def test_manifest_v2_verifies_document_metadata(tmp_path: Path) -> None:
|
|
664
|
+
root = _make_docs(tmp_path)
|
|
665
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
666
|
+
|
|
667
|
+
wrong_synced_at = copy.deepcopy(manifest)
|
|
668
|
+
wrong_synced_at["files"][0]["synced_at"] = SYNCED_2
|
|
669
|
+
with pytest.raises(contract.ManifestFileMismatchError, match="synced_at mismatch"):
|
|
670
|
+
contract.validate_manifest_v2(wrong_synced_at, root, verify_files=True)
|
|
671
|
+
contract.validate_manifest_v2(wrong_synced_at, root, verify_files=False)
|
|
672
|
+
|
|
673
|
+
wrong_title = copy.deepcopy(manifest)
|
|
674
|
+
wrong_title["files"][0]["title"] = "伪造标题"
|
|
675
|
+
wrong_title["generation_id"] = contract.compute_generation_id(wrong_title["files"])
|
|
676
|
+
with pytest.raises(contract.ManifestFileMismatchError, match="title mismatch"):
|
|
677
|
+
contract.validate_manifest_v2(wrong_title, root, verify_files=True)
|
|
678
|
+
|
|
679
|
+
invalid_status = copy.deepcopy(manifest)
|
|
680
|
+
invalid_status["files"][0]["status"] = "complete"
|
|
681
|
+
invalid_status["generation_id"] = contract.compute_generation_id(
|
|
682
|
+
invalid_status["files"]
|
|
683
|
+
)
|
|
684
|
+
with pytest.raises(contract.ManifestValidationError, match="status must be one of"):
|
|
685
|
+
contract.validate_manifest_v2(invalid_status, root, verify_files=False)
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def test_manifest_v2_verify_files_false_allows_missing_documents(
|
|
689
|
+
tmp_path: Path,
|
|
690
|
+
) -> None:
|
|
691
|
+
root = _make_docs(tmp_path)
|
|
692
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
693
|
+
(root / "root.md").unlink()
|
|
694
|
+
|
|
695
|
+
contract.validate_manifest_v2(manifest, root, verify_files=False)
|
|
696
|
+
with pytest.raises(contract.PathValidationError, match="cannot be safely resolved"):
|
|
697
|
+
contract.validate_manifest_v2(manifest, root, verify_files=True)
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
def test_manifest_v2_rejects_inconsistent_aggregates(tmp_path: Path) -> None:
|
|
701
|
+
root = _make_docs(tmp_path)
|
|
702
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
703
|
+
|
|
704
|
+
wrong_total = copy.deepcopy(manifest)
|
|
705
|
+
wrong_total["total"] += 1
|
|
706
|
+
with pytest.raises(contract.ManifestValidationError, match="total mismatch"):
|
|
707
|
+
contract.validate_manifest_v2(wrong_total, root)
|
|
708
|
+
|
|
709
|
+
wrong_depths = copy.deepcopy(manifest)
|
|
710
|
+
wrong_depths["depth_counts"] = {"0": 2}
|
|
711
|
+
with pytest.raises(contract.ManifestValidationError, match="depth_counts mismatch"):
|
|
712
|
+
contract.validate_manifest_v2(wrong_depths, root)
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
def test_v1_depth_zero_is_recomputed_in_memory_without_writeback(
|
|
716
|
+
tmp_path: Path,
|
|
717
|
+
) -> None:
|
|
718
|
+
root = _make_docs(tmp_path)
|
|
719
|
+
manifest_path = root / contract.MANIFEST_FILENAME
|
|
720
|
+
v1 = {
|
|
721
|
+
"files": [
|
|
722
|
+
{"path": "root.md", "depth": 0, "title": "根文档", "status": "✅"},
|
|
723
|
+
{
|
|
724
|
+
"path": "group/child.md",
|
|
725
|
+
"depth": 0,
|
|
726
|
+
"title": "子文档",
|
|
727
|
+
"status": "🔶",
|
|
728
|
+
},
|
|
729
|
+
],
|
|
730
|
+
"total": 2,
|
|
731
|
+
"last_synced": SYNCED_1,
|
|
732
|
+
}
|
|
733
|
+
contract.atomic_write_json(manifest_path, v1)
|
|
734
|
+
|
|
735
|
+
with pytest.warns(
|
|
736
|
+
contract.LegacyManifestWarning, match="depth values are untrusted"
|
|
737
|
+
):
|
|
738
|
+
loaded = contract.load_manifest(manifest_path, docs_root=root)
|
|
739
|
+
|
|
740
|
+
by_path = {entry["path"]: entry for entry in loaded["files"]}
|
|
741
|
+
assert loaded["schema_version"] == 1
|
|
742
|
+
assert by_path["root.md"]["depth"] == 0
|
|
743
|
+
assert by_path["group/child.md"]["depth"] == 1
|
|
744
|
+
assert by_path["group/child.md"]["bytes"] > 0
|
|
745
|
+
assert len(by_path["group/child.md"]["sha256"]) == 64
|
|
746
|
+
assert by_path["group/child.md"]["synced_at"] == SYNCED_1
|
|
747
|
+
|
|
748
|
+
on_disk = contract.read_json_strict(manifest_path)
|
|
749
|
+
assert "schema_version" not in on_disk
|
|
750
|
+
assert on_disk["files"][1]["depth"] == 0
|
|
751
|
+
|
|
752
|
+
with pytest.warns(contract.LegacyManifestWarning):
|
|
753
|
+
loaded_again = contract.validate_manifest(loaded, root)
|
|
754
|
+
assert loaded_again["files"] == loaded["files"]
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
@pytest.mark.parametrize("schema_version", [2.0, True, "2", None])
|
|
758
|
+
def test_manifest_schema_version_requires_an_exact_integer(
|
|
759
|
+
tmp_path: Path,
|
|
760
|
+
schema_version: object,
|
|
761
|
+
) -> None:
|
|
762
|
+
root = _make_docs(tmp_path)
|
|
763
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
764
|
+
manifest["schema_version"] = schema_version
|
|
765
|
+
|
|
766
|
+
with pytest.raises(contract.ManifestSchemaError):
|
|
767
|
+
contract.validate_manifest(manifest, root)
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def test_unknown_manifest_schema_fails(tmp_path: Path) -> None:
|
|
771
|
+
root = _make_docs(tmp_path)
|
|
772
|
+
with pytest.raises(contract.ManifestSchemaError, match="unsupported"):
|
|
773
|
+
contract.validate_manifest({"schema_version": 99}, root)
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def test_build_manifest_rejects_non_utf8_document(tmp_path: Path) -> None:
|
|
777
|
+
root = tmp_path / "project_docs"
|
|
778
|
+
root.mkdir()
|
|
779
|
+
(root / "bad.md").write_bytes(b"# title\n\xff")
|
|
780
|
+
with pytest.raises(contract.StrictUtf8Error):
|
|
781
|
+
contract.build_manifest(root, last_synced=SYNCED_1)
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def test_build_manifest_excludes_only_root_quarantine_documents(tmp_path: Path) -> None:
|
|
785
|
+
root = _make_docs(tmp_path)
|
|
786
|
+
_write_doc(root / contract.QUARANTINE_DIRNAME / "receipt" / "old.md", "旧文档")
|
|
787
|
+
_write_doc(root / ".lingma" / "notes.md", "隐藏但活动的文档")
|
|
788
|
+
_write_doc(
|
|
789
|
+
root / "section" / contract.QUARANTINE_DIRNAME / "notes.md",
|
|
790
|
+
"嵌套同名目录仍属活动树",
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
manifest = contract.build_manifest(root, last_synced=SYNCED_1)
|
|
794
|
+
paths = {entry["path"] for entry in manifest["files"]}
|
|
795
|
+
|
|
796
|
+
assert manifest["total"] == 4
|
|
797
|
+
assert ".lingma/notes.md" in paths
|
|
798
|
+
assert "section/.quarantine/notes.md" in paths
|
|
799
|
+
assert all(
|
|
800
|
+
not entry["path"].startswith(contract.QUARANTINE_DIRNAME + "/")
|
|
801
|
+
for entry in manifest["files"]
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
def test_build_manifest_rejects_noncanonical_root_quarantine_name(
|
|
806
|
+
tmp_path: Path,
|
|
807
|
+
) -> None:
|
|
808
|
+
root = _make_docs(tmp_path)
|
|
809
|
+
(root / ".QUARANTINE").mkdir()
|
|
810
|
+
|
|
811
|
+
with pytest.raises(contract.PathValidationError, match="canonical lowercase"):
|
|
812
|
+
contract.build_manifest(root, last_synced=SYNCED_1)
|