docstate 0.2.3__tar.gz → 0.2.5__tar.gz
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.
- {docstate-0.2.3 → docstate-0.2.5}/CHANGELOG.md +12 -0
- {docstate-0.2.3/src/docstate.egg-info → docstate-0.2.5}/PKG-INFO +23 -7
- {docstate-0.2.3 → docstate-0.2.5}/README.md +22 -6
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/__init__.py +1 -1
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/check.py +73 -49
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/config.py +65 -12
- {docstate-0.2.3 → docstate-0.2.5/src/docstate.egg-info}/PKG-INFO +23 -7
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_config.py +42 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_frontmatter.py +38 -4
- {docstate-0.2.3 → docstate-0.2.5}/LICENSE +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/MANIFEST.in +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/README.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/docs/guide.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/docs/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/facts/status.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/basic/templates/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/table/README.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/table/docs/judgments.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/table/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/table/facts/judgments.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/examples/table/templates/judgments.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/pyproject.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/setup.cfg +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/__main__.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/cli.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/errors.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/facts.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/frontmatter.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/render.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/scan.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate/template.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate.egg-info/SOURCES.txt +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate.egg-info/dependency_links.txt +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate.egg-info/entry_points.txt +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate.egg-info/requires.txt +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/src/docstate.egg-info/top_level.txt +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/templates/docstate.schema.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/templates/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/templates/pre-commit.yaml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/templates/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/templates/vale.ini +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/conftest.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-json/docs/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-json/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-json/facts/status.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-json/templates/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-markers/docs/other.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-markers/docs/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-markers/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-markers/facts/status.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/bad-markers/templates/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/README.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/docs/guide.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/docs/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/facts/status.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/basic/templates/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/CHANGELOG.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/README.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/bad.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/design.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/facts/status.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/frontmatter/templates/summary.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/table/docs/status.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/table/docstate.toml +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/table/facts/judgments.json +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/fixtures/table/templates/judgments.md +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_anchors.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_check.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_cli.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_examples.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_render.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_scan.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_template.py +0 -0
- {docstate-0.2.3 → docstate-0.2.5}/tests/test_template_v2.py +0 -0
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.5 - 2026-12-06
|
|
4
|
+
|
|
5
|
+
- Add `docs` to `[[check.freshness]]`: one rule can cover many documents. The `changelog` path is resolved relative to each document's directory, and a missing changelog is a finding.
|
|
6
|
+
- `doc` and `docs` are mutually exclusive; `exclude` is allowed with `docs`.
|
|
7
|
+
- Used by the vault's third parallel cell: `check-status-lag.mjs` and the docstate freshness rule must report the same stale / missing-changelog document sets.
|
|
8
|
+
|
|
9
|
+
## 0.2.4 - 2026-12-06
|
|
10
|
+
|
|
11
|
+
- Add `exclude` to `[check.frontmatter]`. Matched files are removed before any frontmatter check, the same way `[[check.forbidden]].exclude` works.
|
|
12
|
+
- The vault uses it for the second parallel cell: `check-doc-status.mjs` and the docstate frontmatter rule must report the same missing-status, illegal-status, and BOM document sets.
|
|
13
|
+
|
|
3
14
|
## 0.2.3 - 2026-12-06
|
|
4
15
|
|
|
5
16
|
- Add `docstate check --json`: files, blocks, error/warning counts, and every finding with severity/kind/path/line/field/message.
|
|
6
17
|
- `--strict` still exits 1 only when an error-severity finding exists; warnings remain report-only.
|
|
18
|
+
- Published 0.2.3 to PyPI; `pipx install docstate` now works.
|
|
7
19
|
|
|
8
20
|
## 0.2.2 - 2026-12-06
|
|
9
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstate
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: Generate Markdown blocks from JSON facts and fail when the document drifts
|
|
5
5
|
Author: The docstate authors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -32,6 +32,7 @@ Dynamic: license-file
|
|
|
32
32
|
Generate Markdown blocks from JSON facts, and fail when the document drifts from them.
|
|
33
33
|
|
|
34
34
|
[](https://github.com/XinBuilds/docstate/actions/workflows/test.yml)
|
|
35
|
+
[](https://pypi.org/project/docstate/)
|
|
35
36
|
|
|
36
37
|
`docstate` rewrites the content between two HTML comment markers in your Markdown with values rendered from a JSON file. A second command compares the two and exits non-zero on drift, so stale facts fail CI instead of quietly misleading readers.
|
|
37
38
|
|
|
@@ -46,16 +47,23 @@ Generate Markdown blocks from JSON facts, and fail when the document drifts from
|
|
|
46
47
|
|
|
47
48
|
## Install
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
Install from PyPI:
|
|
50
51
|
|
|
51
52
|
```sh
|
|
52
|
-
pipx install
|
|
53
|
+
pipx install docstate
|
|
53
54
|
```
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
Pin a version:
|
|
56
57
|
|
|
57
58
|
```sh
|
|
58
|
-
|
|
59
|
+
pipx install docstate==0.2.5
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or install from the GitHub tag / release:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.5"
|
|
66
|
+
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.5/docstate-0.2.5-py3-none-any.whl
|
|
59
67
|
```
|
|
60
68
|
|
|
61
69
|
Or install from a checkout:
|
|
@@ -115,7 +123,7 @@ content here is replaced by render
|
|
|
115
123
|
To make drift fail in CI, add two steps:
|
|
116
124
|
|
|
117
125
|
```yaml
|
|
118
|
-
- run: pipx install
|
|
126
|
+
- run: pipx install docstate==0.2.5
|
|
119
127
|
- run: docstate check --config docstate.toml --strict
|
|
120
128
|
```
|
|
121
129
|
|
|
@@ -216,6 +224,7 @@ Findings are printed as `path:line: error[kind:field]: message` or `warning[...]
|
|
|
216
224
|
```toml
|
|
217
225
|
[check.frontmatter]
|
|
218
226
|
files = ["docs/**/*.md"]
|
|
227
|
+
exclude = ["docs/research/**", "docs/README.md"]
|
|
219
228
|
require = ["status", "last_reviewed"]
|
|
220
229
|
status_field = "status"
|
|
221
230
|
status_values = ["draft", "review", "decided", "implemented", "superseded", "archived"]
|
|
@@ -232,15 +241,22 @@ applies_to = ["docs/**/*.md"]
|
|
|
232
241
|
doc = "docs/README.md"
|
|
233
242
|
field = "last_reviewed"
|
|
234
243
|
changelog = "docs/CHANGELOG.md"
|
|
244
|
+
|
|
245
|
+
[[check.freshness]]
|
|
246
|
+
docs = ["projects/*/README.md"]
|
|
247
|
+
exclude = ["projects/legacy/**"]
|
|
248
|
+
field = "last_reviewed"
|
|
249
|
+
changelog = "development/CHANGELOG.md"
|
|
235
250
|
```
|
|
236
251
|
|
|
237
252
|
Rules:
|
|
238
253
|
|
|
254
|
+
- `exclude` removes matched files before any frontmatter check runs. Use it for directories or files that are not required to carry the metadata.
|
|
239
255
|
- `require` fields must exist and be non-empty. `status_values`, when set, rejects other values.
|
|
240
256
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
241
257
|
- An owner declares the authoritative value of a field (for example `project_stage`). Other matched documents may omit the field, but if they set it, the value must match the owner.
|
|
242
258
|
- `status_review` uses git. If the working tree changed a file, it compares the file with `HEAD`; otherwise it compares `HEAD` with `HEAD~1`. If the body changed but both the status field and `updated` stayed the same, it reports `status` (warning by default). If the status changed but `updated` did not, it reports an error.
|
|
243
|
-
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing or
|
|
259
|
+
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing, malformed, or has no changelog. With `docs`, `changelog` is resolved relative to each document's directory and `exclude` filters the matched documents.
|
|
244
260
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
245
261
|
|
|
246
262
|
This is a discipline check, not a semantic verdict. It cannot decide that `status: draft` should have become `decided`; it can only prove the field was not reviewed, is outside the vocabulary, or disagrees with its owner. The status check looks at the working tree or the latest commit, not the whole history.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Generate Markdown blocks from JSON facts, and fail when the document drifts from them.
|
|
4
4
|
|
|
5
5
|
[](https://github.com/XinBuilds/docstate/actions/workflows/test.yml)
|
|
6
|
+
[](https://pypi.org/project/docstate/)
|
|
6
7
|
|
|
7
8
|
`docstate` rewrites the content between two HTML comment markers in your Markdown with values rendered from a JSON file. A second command compares the two and exits non-zero on drift, so stale facts fail CI instead of quietly misleading readers.
|
|
8
9
|
|
|
@@ -17,16 +18,23 @@ Generate Markdown blocks from JSON facts, and fail when the document drifts from
|
|
|
17
18
|
|
|
18
19
|
## Install
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
Install from PyPI:
|
|
21
22
|
|
|
22
23
|
```sh
|
|
23
|
-
pipx install
|
|
24
|
+
pipx install docstate
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
Pin a version:
|
|
27
28
|
|
|
28
29
|
```sh
|
|
29
|
-
|
|
30
|
+
pipx install docstate==0.2.5
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or install from the GitHub tag / release:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.5"
|
|
37
|
+
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.5/docstate-0.2.5-py3-none-any.whl
|
|
30
38
|
```
|
|
31
39
|
|
|
32
40
|
Or install from a checkout:
|
|
@@ -86,7 +94,7 @@ content here is replaced by render
|
|
|
86
94
|
To make drift fail in CI, add two steps:
|
|
87
95
|
|
|
88
96
|
```yaml
|
|
89
|
-
- run: pipx install
|
|
97
|
+
- run: pipx install docstate==0.2.5
|
|
90
98
|
- run: docstate check --config docstate.toml --strict
|
|
91
99
|
```
|
|
92
100
|
|
|
@@ -187,6 +195,7 @@ Findings are printed as `path:line: error[kind:field]: message` or `warning[...]
|
|
|
187
195
|
```toml
|
|
188
196
|
[check.frontmatter]
|
|
189
197
|
files = ["docs/**/*.md"]
|
|
198
|
+
exclude = ["docs/research/**", "docs/README.md"]
|
|
190
199
|
require = ["status", "last_reviewed"]
|
|
191
200
|
status_field = "status"
|
|
192
201
|
status_values = ["draft", "review", "decided", "implemented", "superseded", "archived"]
|
|
@@ -203,15 +212,22 @@ applies_to = ["docs/**/*.md"]
|
|
|
203
212
|
doc = "docs/README.md"
|
|
204
213
|
field = "last_reviewed"
|
|
205
214
|
changelog = "docs/CHANGELOG.md"
|
|
215
|
+
|
|
216
|
+
[[check.freshness]]
|
|
217
|
+
docs = ["projects/*/README.md"]
|
|
218
|
+
exclude = ["projects/legacy/**"]
|
|
219
|
+
field = "last_reviewed"
|
|
220
|
+
changelog = "development/CHANGELOG.md"
|
|
206
221
|
```
|
|
207
222
|
|
|
208
223
|
Rules:
|
|
209
224
|
|
|
225
|
+
- `exclude` removes matched files before any frontmatter check runs. Use it for directories or files that are not required to carry the metadata.
|
|
210
226
|
- `require` fields must exist and be non-empty. `status_values`, when set, rejects other values.
|
|
211
227
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
212
228
|
- An owner declares the authoritative value of a field (for example `project_stage`). Other matched documents may omit the field, but if they set it, the value must match the owner.
|
|
213
229
|
- `status_review` uses git. If the working tree changed a file, it compares the file with `HEAD`; otherwise it compares `HEAD` with `HEAD~1`. If the body changed but both the status field and `updated` stayed the same, it reports `status` (warning by default). If the status changed but `updated` did not, it reports an error.
|
|
214
|
-
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing or
|
|
230
|
+
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing, malformed, or has no changelog. With `docs`, `changelog` is resolved relative to each document's directory and `exclude` filters the matched documents.
|
|
215
231
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
216
232
|
|
|
217
233
|
This is a discipline check, not a semantic verdict. It cannot decide that `status: draft` should have become `decided`; it can only prove the field was not reviewed, is outside the vocabulary, or disagrees with its owner. The status check looks at the working tree or the latest commit, not the whole history.
|
|
@@ -333,58 +333,82 @@ def _status_findings(rule: FrontmatterRule, base: Path) -> list[Finding]:
|
|
|
333
333
|
return findings
|
|
334
334
|
|
|
335
335
|
|
|
336
|
-
def _freshness_findings(rule: FreshnessRule) -> list[Finding]:
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
336
|
+
def _freshness_findings(rule: FreshnessRule, base: Path) -> list[Finding]:
|
|
337
|
+
findings: list[Finding] = []
|
|
338
|
+
targets = [rule.doc] if rule.doc is not None else list(rule.docs)
|
|
339
|
+
for doc in targets:
|
|
340
|
+
doc_rel = doc.relative_to(base).as_posix()
|
|
341
|
+
if rule.doc is not None:
|
|
342
|
+
changelog = rule.changelog
|
|
343
|
+
changelog_rel = rule.changelog_rel
|
|
344
|
+
else:
|
|
345
|
+
changelog = doc.parent / rule.changelog_template
|
|
346
|
+
changelog_rel = changelog.relative_to(base).as_posix()
|
|
347
|
+
frontmatter = _read_frontmatter(doc, doc_rel)
|
|
348
|
+
value = frontmatter.value(rule.field)
|
|
349
|
+
if value is None:
|
|
350
|
+
findings.append(
|
|
351
|
+
Finding(
|
|
352
|
+
kind="freshness",
|
|
353
|
+
path=doc_rel,
|
|
354
|
+
line=1,
|
|
355
|
+
field=rule.field,
|
|
356
|
+
message=f"missing field: {rule.field}",
|
|
357
|
+
)
|
|
347
358
|
)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
359
|
+
continue
|
|
360
|
+
if not DATE_RE.match(value):
|
|
361
|
+
findings.append(
|
|
362
|
+
Finding(
|
|
363
|
+
kind="freshness",
|
|
364
|
+
path=doc_rel,
|
|
365
|
+
line=frontmatter.line(rule.field),
|
|
366
|
+
field=rule.field,
|
|
367
|
+
message=f"date must be YYYY-MM-DD: {value!r}",
|
|
368
|
+
)
|
|
357
369
|
)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
path=rule.changelog_rel,
|
|
371
|
-
line=1,
|
|
372
|
-
field=rule.field,
|
|
373
|
-
message="no dated heading found in changelog",
|
|
370
|
+
continue
|
|
371
|
+
try:
|
|
372
|
+
text = changelog.read_text(encoding="utf-8-sig")
|
|
373
|
+
except FileNotFoundError:
|
|
374
|
+
findings.append(
|
|
375
|
+
Finding(
|
|
376
|
+
kind="freshness",
|
|
377
|
+
path=doc_rel,
|
|
378
|
+
line=frontmatter.line(rule.field),
|
|
379
|
+
field=rule.field,
|
|
380
|
+
message=f"changelog not found: {changelog_rel}",
|
|
381
|
+
)
|
|
374
382
|
)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
continue
|
|
384
|
+
except OSError as exc:
|
|
385
|
+
fail("FILE_READ", f"cannot read changelog: {exc}", path=changelog_rel)
|
|
386
|
+
except UnicodeDecodeError as exc:
|
|
387
|
+
fail("FILE_ENCODING", f"changelog is not UTF-8: {exc}", path=changelog_rel)
|
|
388
|
+
dates = CHANGELOG_DATE_RE.findall(text)
|
|
389
|
+
if not dates:
|
|
390
|
+
findings.append(
|
|
391
|
+
Finding(
|
|
392
|
+
kind="freshness",
|
|
393
|
+
path=changelog_rel,
|
|
394
|
+
line=1,
|
|
395
|
+
field=rule.field,
|
|
396
|
+
message="no dated heading found in changelog",
|
|
397
|
+
)
|
|
385
398
|
)
|
|
386
|
-
|
|
387
|
-
|
|
399
|
+
continue
|
|
400
|
+
newest = max(dates)
|
|
401
|
+
if value < newest:
|
|
402
|
+
findings.append(
|
|
403
|
+
Finding(
|
|
404
|
+
kind="freshness",
|
|
405
|
+
path=doc_rel,
|
|
406
|
+
line=frontmatter.line(rule.field),
|
|
407
|
+
field=rule.field,
|
|
408
|
+
message=f"{value} is older than changelog {newest}",
|
|
409
|
+
)
|
|
410
|
+
)
|
|
411
|
+
return findings
|
|
388
412
|
|
|
389
413
|
|
|
390
414
|
def _anchor_findings(rule: AnchorRule, base: Path) -> list[Finding]:
|
|
@@ -499,7 +523,7 @@ def check_project(config: Config) -> tuple[list[Finding], int, int]:
|
|
|
499
523
|
findings.extend(_frontmatter_findings(config.frontmatter, config.base))
|
|
500
524
|
findings.extend(_status_findings(config.frontmatter, config.base))
|
|
501
525
|
for rule in config.freshness:
|
|
502
|
-
findings.extend(_freshness_findings(rule))
|
|
526
|
+
findings.extend(_freshness_findings(rule, config.base))
|
|
503
527
|
for rule in config.anchors:
|
|
504
528
|
findings.extend(_anchor_findings(rule, config.base))
|
|
505
529
|
for rule in config.forbidden:
|
|
@@ -51,11 +51,13 @@ class FrontmatterRule:
|
|
|
51
51
|
|
|
52
52
|
@dataclass(frozen=True)
|
|
53
53
|
class FreshnessRule:
|
|
54
|
-
doc: Path
|
|
54
|
+
doc: Path | None
|
|
55
55
|
doc_rel: str
|
|
56
56
|
field: str
|
|
57
|
-
changelog: Path
|
|
57
|
+
changelog: Path | None
|
|
58
58
|
changelog_rel: str
|
|
59
|
+
docs: tuple[Path, ...] = ()
|
|
60
|
+
changelog_template: str = ""
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
@dataclass(frozen=True)
|
|
@@ -233,7 +235,17 @@ def _parse_frontmatter_rule(base: Path, raw: object) -> FrontmatterRule:
|
|
|
233
235
|
fail("CFG_SCHEMA", "check.frontmatter must be a table")
|
|
234
236
|
_reject_unknown(
|
|
235
237
|
raw,
|
|
236
|
-
{
|
|
238
|
+
{
|
|
239
|
+
"files",
|
|
240
|
+
"exclude",
|
|
241
|
+
"require",
|
|
242
|
+
"status_field",
|
|
243
|
+
"status_values",
|
|
244
|
+
"bom",
|
|
245
|
+
"status_review",
|
|
246
|
+
"updated_field",
|
|
247
|
+
"owners",
|
|
248
|
+
},
|
|
237
249
|
"check.frontmatter",
|
|
238
250
|
)
|
|
239
251
|
files_raw = raw.get("files")
|
|
@@ -242,7 +254,10 @@ def _parse_frontmatter_rule(base: Path, raw: object) -> FrontmatterRule:
|
|
|
242
254
|
patterns = _list_of_strings(files_raw, "check.frontmatter.files")
|
|
243
255
|
if not patterns:
|
|
244
256
|
fail("CFG_SCHEMA", "check.frontmatter.files must not be empty")
|
|
245
|
-
|
|
257
|
+
exclude = _list_of_strings(raw.get("exclude"), "check.frontmatter.exclude")
|
|
258
|
+
for value in exclude:
|
|
259
|
+
_check_pattern(value, "check.frontmatter.exclude")
|
|
260
|
+
files = _expand_check_files(base, patterns, [], exclude)
|
|
246
261
|
|
|
247
262
|
status_field = _validate_field(raw.get("status_field", "status"), "check.frontmatter.status_field")
|
|
248
263
|
updated_field = _validate_field(raw.get("updated_field", "updated"), "check.frontmatter.updated_field")
|
|
@@ -300,19 +315,57 @@ def _parse_freshness_rules(base: Path, raw: object) -> list[FreshnessRule]:
|
|
|
300
315
|
for index, item in enumerate(raw):
|
|
301
316
|
if not isinstance(item, dict):
|
|
302
317
|
fail("CFG_SCHEMA", f"check.freshness[{index}] must be a table")
|
|
303
|
-
_reject_unknown(
|
|
304
|
-
|
|
305
|
-
changelog = _resolve_file(
|
|
306
|
-
base, item.get("changelog"), suffix=".md", where=f"check.freshness[{index}].changelog"
|
|
318
|
+
_reject_unknown(
|
|
319
|
+
item, {"doc", "docs", "exclude", "field", "changelog"}, f"check.freshness[{index}]"
|
|
307
320
|
)
|
|
308
321
|
field_name = _validate_field(item.get("field"), f"check.freshness[{index}].field")
|
|
322
|
+
has_doc = item.get("doc") is not None
|
|
323
|
+
has_docs = item.get("docs") is not None
|
|
324
|
+
if has_doc == has_docs:
|
|
325
|
+
fail("CFG_SCHEMA", f"check.freshness[{index}] needs exactly one of doc or docs")
|
|
326
|
+
if has_doc:
|
|
327
|
+
if item.get("exclude") is not None:
|
|
328
|
+
fail("CFG_SCHEMA", f"check.freshness[{index}].exclude requires docs")
|
|
329
|
+
doc = _resolve_file(base, item.get("doc"), suffix=".md", where=f"check.freshness[{index}].doc")
|
|
330
|
+
changelog = _resolve_file(
|
|
331
|
+
base, item.get("changelog"), suffix=".md", where=f"check.freshness[{index}].changelog"
|
|
332
|
+
)
|
|
333
|
+
rules.append(
|
|
334
|
+
FreshnessRule(
|
|
335
|
+
doc=doc,
|
|
336
|
+
doc_rel=_relative(base, doc),
|
|
337
|
+
field=field_name,
|
|
338
|
+
changelog=changelog,
|
|
339
|
+
changelog_rel=_relative(base, changelog),
|
|
340
|
+
)
|
|
341
|
+
)
|
|
342
|
+
continue
|
|
343
|
+
patterns = _list_of_strings(item.get("docs"), f"check.freshness[{index}].docs")
|
|
344
|
+
if not patterns:
|
|
345
|
+
fail("CFG_SCHEMA", f"check.freshness[{index}].docs must not be empty")
|
|
346
|
+
exclude = _list_of_strings(item.get("exclude"), f"check.freshness[{index}].exclude")
|
|
347
|
+
for value in exclude:
|
|
348
|
+
_check_pattern(value, f"check.freshness[{index}].exclude")
|
|
349
|
+
template = item.get("changelog")
|
|
350
|
+
if not isinstance(template, str) or not template:
|
|
351
|
+
fail("CFG_SCHEMA", f"check.freshness[{index}].changelog must be a non-empty string")
|
|
352
|
+
pure = PurePosixPath(template)
|
|
353
|
+
if pure.is_absolute() or ".." in pure.parts:
|
|
354
|
+
fail(
|
|
355
|
+
"CFG_PATH",
|
|
356
|
+
f"check.freshness[{index}].changelog must be relative and must not contain '..': {template}",
|
|
357
|
+
)
|
|
358
|
+
if pure.suffix != ".md":
|
|
359
|
+
fail("CFG_SCHEMA", f"check.freshness[{index}].changelog must end with .md: {template}")
|
|
309
360
|
rules.append(
|
|
310
361
|
FreshnessRule(
|
|
311
|
-
doc=
|
|
312
|
-
doc_rel=
|
|
362
|
+
doc=None,
|
|
363
|
+
doc_rel="",
|
|
313
364
|
field=field_name,
|
|
314
|
-
changelog=
|
|
315
|
-
changelog_rel=
|
|
365
|
+
changelog=None,
|
|
366
|
+
changelog_rel="",
|
|
367
|
+
docs=tuple(_expand_check_files(base, patterns, [], exclude)),
|
|
368
|
+
changelog_template=template,
|
|
316
369
|
)
|
|
317
370
|
)
|
|
318
371
|
return rules
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstate
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: Generate Markdown blocks from JSON facts and fail when the document drifts
|
|
5
5
|
Author: The docstate authors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -32,6 +32,7 @@ Dynamic: license-file
|
|
|
32
32
|
Generate Markdown blocks from JSON facts, and fail when the document drifts from them.
|
|
33
33
|
|
|
34
34
|
[](https://github.com/XinBuilds/docstate/actions/workflows/test.yml)
|
|
35
|
+
[](https://pypi.org/project/docstate/)
|
|
35
36
|
|
|
36
37
|
`docstate` rewrites the content between two HTML comment markers in your Markdown with values rendered from a JSON file. A second command compares the two and exits non-zero on drift, so stale facts fail CI instead of quietly misleading readers.
|
|
37
38
|
|
|
@@ -46,16 +47,23 @@ Generate Markdown blocks from JSON facts, and fail when the document drifts from
|
|
|
46
47
|
|
|
47
48
|
## Install
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
Install from PyPI:
|
|
50
51
|
|
|
51
52
|
```sh
|
|
52
|
-
pipx install
|
|
53
|
+
pipx install docstate
|
|
53
54
|
```
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
Pin a version:
|
|
56
57
|
|
|
57
58
|
```sh
|
|
58
|
-
|
|
59
|
+
pipx install docstate==0.2.5
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or install from the GitHub tag / release:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.5"
|
|
66
|
+
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.5/docstate-0.2.5-py3-none-any.whl
|
|
59
67
|
```
|
|
60
68
|
|
|
61
69
|
Or install from a checkout:
|
|
@@ -115,7 +123,7 @@ content here is replaced by render
|
|
|
115
123
|
To make drift fail in CI, add two steps:
|
|
116
124
|
|
|
117
125
|
```yaml
|
|
118
|
-
- run: pipx install
|
|
126
|
+
- run: pipx install docstate==0.2.5
|
|
119
127
|
- run: docstate check --config docstate.toml --strict
|
|
120
128
|
```
|
|
121
129
|
|
|
@@ -216,6 +224,7 @@ Findings are printed as `path:line: error[kind:field]: message` or `warning[...]
|
|
|
216
224
|
```toml
|
|
217
225
|
[check.frontmatter]
|
|
218
226
|
files = ["docs/**/*.md"]
|
|
227
|
+
exclude = ["docs/research/**", "docs/README.md"]
|
|
219
228
|
require = ["status", "last_reviewed"]
|
|
220
229
|
status_field = "status"
|
|
221
230
|
status_values = ["draft", "review", "decided", "implemented", "superseded", "archived"]
|
|
@@ -232,15 +241,22 @@ applies_to = ["docs/**/*.md"]
|
|
|
232
241
|
doc = "docs/README.md"
|
|
233
242
|
field = "last_reviewed"
|
|
234
243
|
changelog = "docs/CHANGELOG.md"
|
|
244
|
+
|
|
245
|
+
[[check.freshness]]
|
|
246
|
+
docs = ["projects/*/README.md"]
|
|
247
|
+
exclude = ["projects/legacy/**"]
|
|
248
|
+
field = "last_reviewed"
|
|
249
|
+
changelog = "development/CHANGELOG.md"
|
|
235
250
|
```
|
|
236
251
|
|
|
237
252
|
Rules:
|
|
238
253
|
|
|
254
|
+
- `exclude` removes matched files before any frontmatter check runs. Use it for directories or files that are not required to carry the metadata.
|
|
239
255
|
- `require` fields must exist and be non-empty. `status_values`, when set, rejects other values.
|
|
240
256
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
241
257
|
- An owner declares the authoritative value of a field (for example `project_stage`). Other matched documents may omit the field, but if they set it, the value must match the owner.
|
|
242
258
|
- `status_review` uses git. If the working tree changed a file, it compares the file with `HEAD`; otherwise it compares `HEAD` with `HEAD~1`. If the body changed but both the status field and `updated` stayed the same, it reports `status` (warning by default). If the status changed but `updated` did not, it reports an error.
|
|
243
|
-
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing or
|
|
259
|
+
- `[[check.freshness]]` reports when a date field is older than the newest dated heading in a changelog, or when the field is missing, malformed, or has no changelog. With `docs`, `changelog` is resolved relative to each document's directory and `exclude` filters the matched documents.
|
|
244
260
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
245
261
|
|
|
246
262
|
This is a discipline check, not a semantic verdict. It cannot decide that `status: draft` should have become `decided`; it can only prove the field was not reviewed, is outside the vocabulary, or disagrees with its owner. The status check looks at the working tree or the latest commit, not the whole history.
|
|
@@ -86,3 +86,45 @@ def test_rejects_symlinked_fact(copy_fixture, tmp_path):
|
|
|
86
86
|
load_config(root / "docstate.toml")
|
|
87
87
|
assert error.value.code == "CFG_PATH"
|
|
88
88
|
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_frontmatter_exclude_filters_matched_files(tmp_path):
|
|
92
|
+
(tmp_path / "docs").mkdir()
|
|
93
|
+
(tmp_path / "docs" / "keep.md").write_text("---\nstatus: draft\n---\n", encoding="utf-8")
|
|
94
|
+
(tmp_path / "docs" / "skip.md").write_text("# no status\n", encoding="utf-8")
|
|
95
|
+
(tmp_path / "README.md").write_text("# readme\n", encoding="utf-8")
|
|
96
|
+
config_path = tmp_path / "docstate.toml"
|
|
97
|
+
config_path.write_text(
|
|
98
|
+
'version = 1\ndialect = "scalar-v1"\n\n[check.frontmatter]\n'
|
|
99
|
+
'files = ["**/*.md"]\nexclude = ["docs/skip.md", "README.md"]\nrequire = ["status"]\n',
|
|
100
|
+
encoding="utf-8",
|
|
101
|
+
)
|
|
102
|
+
config = load_config(config_path)
|
|
103
|
+
assert config.frontmatter is not None
|
|
104
|
+
assert [p.relative_to(tmp_path).as_posix() for p in config.frontmatter.files] == ["docs/keep.md"]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_frontmatter_exclude_rejects_parent_paths(tmp_path):
|
|
108
|
+
(tmp_path / "doc.md").write_text("---\nstatus: draft\n---\n", encoding="utf-8")
|
|
109
|
+
config_path = tmp_path / "docstate.toml"
|
|
110
|
+
config_path.write_text(
|
|
111
|
+
'version = 1\ndialect = "scalar-v1"\n\n[check.frontmatter]\n'
|
|
112
|
+
'files = ["*.md"]\nexclude = ["../outside.md"]\nrequire = ["status"]\n',
|
|
113
|
+
encoding="utf-8",
|
|
114
|
+
)
|
|
115
|
+
with pytest.raises(DocstateError) as error:
|
|
116
|
+
load_config(config_path)
|
|
117
|
+
assert error.value.code == "CFG_PATH"
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_freshness_requires_exactly_one_of_doc_or_docs(tmp_path):
|
|
121
|
+
(tmp_path / "README.md").write_text("---\nlast_reviewed: 2026-12-06\n---\n", encoding="utf-8")
|
|
122
|
+
config_path = tmp_path / "docstate.toml"
|
|
123
|
+
config_path.write_text(
|
|
124
|
+
'version = 1\ndialect = "scalar-v1"\n\n[[check.freshness]]\n'
|
|
125
|
+
'doc = "README.md"\ndocs = ["README.md"]\nfield = "last_reviewed"\nchangelog = "README.md"\n',
|
|
126
|
+
encoding="utf-8",
|
|
127
|
+
)
|
|
128
|
+
with pytest.raises(DocstateError) as error:
|
|
129
|
+
load_config(config_path)
|
|
130
|
+
assert error.value.code == "CFG_SCHEMA"
|
|
@@ -126,25 +126,44 @@ def test_freshness_stale_and_current(tmp_path):
|
|
|
126
126
|
doc = write(tmp_path / "README.md", "---\nlast_reviewed: 2026-11-01\n---\n# doc\n")
|
|
127
127
|
changelog = write(tmp_path / "CHANGELOG.md", "# Log\n\n## 2026-12-06 shipped\n\n## 2026-11-01 started\n")
|
|
128
128
|
stale = FreshnessRule(doc=doc, doc_rel="README.md", field="last_reviewed", changelog=changelog, changelog_rel="CHANGELOG.md")
|
|
129
|
-
findings = _freshness_findings(stale)
|
|
129
|
+
findings = _freshness_findings(stale, tmp_path)
|
|
130
130
|
assert len(findings) == 1
|
|
131
131
|
assert "older than changelog 2026-12-06" in findings[0].message
|
|
132
132
|
|
|
133
133
|
write(doc, "---\nlast_reviewed: 2026-12-06\n---\n# doc\n")
|
|
134
|
-
assert _freshness_findings(stale) == []
|
|
134
|
+
assert _freshness_findings(stale, tmp_path) == []
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
def test_freshness_missing_and_invalid(tmp_path):
|
|
138
138
|
changelog = write(tmp_path / "CHANGELOG.md", "## 2026-12-06 shipped\n")
|
|
139
139
|
doc = write(tmp_path / "README.md", "# no frontmatter\n")
|
|
140
140
|
missing = FreshnessRule(doc=doc, doc_rel="README.md", field="last_reviewed", changelog=changelog, changelog_rel="CHANGELOG.md")
|
|
141
|
-
assert "missing field" in _freshness_findings(missing)[0].message
|
|
141
|
+
assert "missing field" in _freshness_findings(missing, tmp_path)[0].message
|
|
142
142
|
|
|
143
143
|
write(doc, "---\nlast_reviewed: yesterday\n---\n# doc\n")
|
|
144
|
-
invalid = _freshness_findings(missing)[0]
|
|
144
|
+
invalid = _freshness_findings(missing, tmp_path)[0]
|
|
145
145
|
assert "YYYY-MM-DD" in invalid.message
|
|
146
146
|
|
|
147
147
|
|
|
148
|
+
def test_freshness_globs_use_sibling_changelog(tmp_path):
|
|
149
|
+
write(tmp_path / "a" / "README.md", "---\nlast_reviewed: 2026-11-01\n---\n")
|
|
150
|
+
write(tmp_path / "a" / "development" / "CHANGELOG.md", "## 2026-12-06 shipped\n")
|
|
151
|
+
write(tmp_path / "b" / "README.md", "---\nlast_reviewed: 2026-12-06\n---\n")
|
|
152
|
+
write(tmp_path / "b" / "development" / "CHANGELOG.md", "## 2026-12-01 shipped\n")
|
|
153
|
+
write(tmp_path / "c" / "README.md", "---\nlast_reviewed: 2026-12-06\n---\n")
|
|
154
|
+
config_path = write(
|
|
155
|
+
tmp_path / "docstate.toml",
|
|
156
|
+
'version = 1\ndialect = "scalar-v1"\n\n[[check.freshness]]\n'
|
|
157
|
+
'docs = ["*/README.md"]\nfield = "last_reviewed"\nchangelog = "development/CHANGELOG.md"\n',
|
|
158
|
+
)
|
|
159
|
+
config = load_config(config_path)
|
|
160
|
+
findings = _freshness_findings(config.freshness[0], tmp_path)
|
|
161
|
+
assert {(finding.path, finding.message.split(":")[0]) for finding in findings} == {
|
|
162
|
+
("a/README.md", "2026-11-01 is older than changelog 2026-12-06"),
|
|
163
|
+
("c/README.md", "changelog not found"),
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
148
167
|
def test_config_runs_frontmatter_and_freshness(copy_fixture):
|
|
149
168
|
root = copy_fixture("frontmatter")
|
|
150
169
|
config = load_config(root / "docstate.toml")
|
|
@@ -183,3 +202,18 @@ def test_strict_fails_on_error_but_not_warning(tmp_path, capsys):
|
|
|
183
202
|
write(doc, "---\nstatus: review\nupdated: 2026-12-01\n---\n\n<!-- BEGIN GENERATED: summary -->\nok\n<!-- END GENERATED: summary -->\n\ntwo\n")
|
|
184
203
|
assert main(["check", "--config", str(tmp_path / "docstate.toml"), "--strict"]) == 1
|
|
185
204
|
assert "error[status:updated]" in capsys.readouterr().out
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_excluded_file_produces_no_findings(tmp_path):
|
|
208
|
+
(tmp_path / "docs").mkdir()
|
|
209
|
+
write(tmp_path / "docs" / "keep.md", "---\nstatus: draft\n---\n# keep\n")
|
|
210
|
+
write(tmp_path / "docs" / "skip.md", "# no frontmatter\n")
|
|
211
|
+
config_path = tmp_path / "docstate.toml"
|
|
212
|
+
config_path.write_text(
|
|
213
|
+
'version = 1\ndialect = "scalar-v1"\n\n[check.frontmatter]\n'
|
|
214
|
+
'files = ["docs/**/*.md"]\nexclude = ["docs/skip.md"]\nrequire = ["status"]\n'
|
|
215
|
+
'status_values = ["draft", "review"]\n',
|
|
216
|
+
encoding="utf-8",
|
|
217
|
+
)
|
|
218
|
+
config = load_config(config_path)
|
|
219
|
+
assert _frontmatter_findings(config.frontmatter, tmp_path) == []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|