@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,120 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Tests for exact, idempotent Last synced marker normalization."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
import normalize_markers as normalizer
|
|
11
|
+
|
|
12
|
+
BAD = (
|
|
13
|
+
"<!-- Last synced: 2026-07-23T16:32:05+08:00 "
|
|
14
|
+
"by proj-doc-builder v4.0 --> v3.1 -->"
|
|
15
|
+
)
|
|
16
|
+
GOOD = "<!-- Last synced: 2026-07-23T16:32:05+08:00 " "by proj-doc-builder v4.0 -->"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _write(path: Path, text: str) -> None:
|
|
20
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
21
|
+
path.write_text(text, encoding="utf-8")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_normalize_only_exact_historical_tail() -> None:
|
|
25
|
+
content = "\n".join(
|
|
26
|
+
[
|
|
27
|
+
"# Doc",
|
|
28
|
+
BAD,
|
|
29
|
+
"自由文本 v3.1 --> 不应改变",
|
|
30
|
+
"<!-- Last synced: malformed --> other -->",
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
normalized, changes = normalizer.normalize_marker_content(content, path="a.md")
|
|
34
|
+
assert GOOD in normalized
|
|
35
|
+
assert BAD not in normalized
|
|
36
|
+
assert "自由文本 v3.1 --> 不应改变" in normalized
|
|
37
|
+
assert "<!-- Last synced: malformed --> other -->" in normalized
|
|
38
|
+
assert changes == [
|
|
39
|
+
{
|
|
40
|
+
"path": "a.md",
|
|
41
|
+
"line": 2,
|
|
42
|
+
"before": BAD,
|
|
43
|
+
"after": GOOD,
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_normalization_preserves_crlf() -> None:
|
|
49
|
+
content = f"# Doc\r\n{BAD}\r\nnext\r\n"
|
|
50
|
+
normalized, changes = normalizer.normalize_marker_content(content)
|
|
51
|
+
assert changes
|
|
52
|
+
assert normalized == f"# Doc\r\n{GOOD}\r\nnext\r\n"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_normalization_is_idempotent() -> None:
|
|
56
|
+
once, changes = normalizer.normalize_marker_content(BAD)
|
|
57
|
+
twice, second_changes = normalizer.normalize_marker_content(once)
|
|
58
|
+
assert changes
|
|
59
|
+
assert once == GOOD
|
|
60
|
+
assert twice == once
|
|
61
|
+
assert second_changes == []
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_collect_excludes_quarantine_and_apply_is_explicit(tmp_path: Path) -> None:
|
|
65
|
+
root = tmp_path / "project_docs"
|
|
66
|
+
_write(root / "bad.md", f"# Bad\n{BAD}\n")
|
|
67
|
+
_write(root / "ok.md", f"# OK\n{GOOD}\n")
|
|
68
|
+
_write(root / ".quarantine" / "receipt" / "old.md", f"# Old\n{BAD}\n")
|
|
69
|
+
|
|
70
|
+
changes = normalizer.collect_marker_changes(root)
|
|
71
|
+
assert [(change.path, change.line) for change in changes] == [("bad.md", 2)]
|
|
72
|
+
assert BAD in (root / "bad.md").read_text(encoding="utf-8")
|
|
73
|
+
|
|
74
|
+
assert normalizer.apply_marker_changes(root, changes) == ["bad.md"]
|
|
75
|
+
assert GOOD in (root / "bad.md").read_text(encoding="utf-8")
|
|
76
|
+
assert normalizer.collect_marker_changes(root) == []
|
|
77
|
+
assert BAD in (root / ".quarantine" / "receipt" / "old.md").read_text(
|
|
78
|
+
encoding="utf-8"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_apply_rejects_concurrent_change(tmp_path: Path) -> None:
|
|
83
|
+
root = tmp_path / "project_docs"
|
|
84
|
+
path = root / "bad.md"
|
|
85
|
+
_write(path, f"# Bad\n{BAD}\n")
|
|
86
|
+
changes = normalizer.collect_marker_changes(root)
|
|
87
|
+
path.write_text("# changed concurrently\n", encoding="utf-8")
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
normalizer.apply_marker_changes(root, changes)
|
|
91
|
+
except normalizer.MarkerNormalizationError as exc:
|
|
92
|
+
assert "已变化" in str(exc)
|
|
93
|
+
else: # pragma: no cover
|
|
94
|
+
raise AssertionError("concurrent modification must fail")
|
|
95
|
+
assert path.read_text(encoding="utf-8") == "# changed concurrently\n"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_collect_rejects_inventory_to_read_symlink_swap(
|
|
99
|
+
tmp_path: Path,
|
|
100
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
101
|
+
) -> None:
|
|
102
|
+
root = tmp_path / "project_docs"
|
|
103
|
+
victim = root / "a.md"
|
|
104
|
+
replacement = root / "b.md"
|
|
105
|
+
_write(victim, f"# A\n{BAD}\n")
|
|
106
|
+
_write(replacement, f"# B\n{GOOD}\n")
|
|
107
|
+
original_discover = normalizer.discover_documents
|
|
108
|
+
|
|
109
|
+
def swapping_discover(project_docs: Path) -> list[tuple[str, Path]]:
|
|
110
|
+
documents = original_discover(project_docs)
|
|
111
|
+
try:
|
|
112
|
+
victim.unlink()
|
|
113
|
+
victim.symlink_to(replacement)
|
|
114
|
+
except (NotImplementedError, OSError) as exc:
|
|
115
|
+
pytest.skip(f"symlink unavailable: {exc}")
|
|
116
|
+
return documents
|
|
117
|
+
|
|
118
|
+
monkeypatch.setattr(normalizer, "discover_documents", swapping_discover)
|
|
119
|
+
with pytest.raises(normalizer.ProjectDocsContractError):
|
|
120
|
+
normalizer.collect_marker_changes(root)
|