docstate 0.2.4__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.4 → docstate-0.2.5}/CHANGELOG.md +6 -0
- {docstate-0.2.4/src/docstate.egg-info → docstate-0.2.5}/PKG-INFO +12 -6
- {docstate-0.2.4 → docstate-0.2.5}/README.md +11 -5
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/__init__.py +1 -1
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/check.py +73 -49
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/config.py +50 -10
- {docstate-0.2.4 → docstate-0.2.5/src/docstate.egg-info}/PKG-INFO +12 -6
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_config.py +13 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_frontmatter.py +23 -4
- {docstate-0.2.4 → docstate-0.2.5}/LICENSE +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/MANIFEST.in +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/README.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/docs/guide.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/docs/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/facts/status.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/basic/templates/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/table/README.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/table/docs/judgments.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/table/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/table/facts/judgments.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/examples/table/templates/judgments.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/pyproject.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/setup.cfg +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/__main__.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/cli.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/errors.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/facts.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/frontmatter.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/render.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/scan.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate/template.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate.egg-info/SOURCES.txt +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate.egg-info/dependency_links.txt +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate.egg-info/entry_points.txt +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate.egg-info/requires.txt +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/src/docstate.egg-info/top_level.txt +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/templates/docstate.schema.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/templates/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/templates/pre-commit.yaml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/templates/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/templates/vale.ini +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/conftest.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-json/docs/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-json/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-json/facts/status.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-json/templates/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-markers/docs/other.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-markers/docs/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-markers/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-markers/facts/status.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/bad-markers/templates/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/README.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/docs/guide.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/docs/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/facts/status.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/basic/templates/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/CHANGELOG.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/README.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/bad.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/docs/design.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/facts/status.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/frontmatter/templates/summary.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/table/docs/status.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/table/docstate.toml +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/table/facts/judgments.json +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/fixtures/table/templates/judgments.md +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_anchors.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_check.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_cli.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_examples.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_render.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_scan.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_template.py +0 -0
- {docstate-0.2.4 → docstate-0.2.5}/tests/test_template_v2.py +0 -0
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.2.4 - 2026-12-06
|
|
4
10
|
|
|
5
11
|
- Add `exclude` to `[check.frontmatter]`. Matched files are removed before any frontmatter check, the same way `[[check.forbidden]].exclude` works.
|
|
@@ -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
|
|
@@ -56,14 +56,14 @@ pipx install docstate
|
|
|
56
56
|
Pin a version:
|
|
57
57
|
|
|
58
58
|
```sh
|
|
59
|
-
pipx install docstate==0.2.
|
|
59
|
+
pipx install docstate==0.2.5
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
Or install from the GitHub tag / release:
|
|
63
63
|
|
|
64
64
|
```sh
|
|
65
|
-
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.
|
|
66
|
-
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.
|
|
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
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
Or install from a checkout:
|
|
@@ -123,7 +123,7 @@ content here is replaced by render
|
|
|
123
123
|
To make drift fail in CI, add two steps:
|
|
124
124
|
|
|
125
125
|
```yaml
|
|
126
|
-
- run: pipx install docstate==0.2.
|
|
126
|
+
- run: pipx install docstate==0.2.5
|
|
127
127
|
- run: docstate check --config docstate.toml --strict
|
|
128
128
|
```
|
|
129
129
|
|
|
@@ -241,6 +241,12 @@ applies_to = ["docs/**/*.md"]
|
|
|
241
241
|
doc = "docs/README.md"
|
|
242
242
|
field = "last_reviewed"
|
|
243
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"
|
|
244
250
|
```
|
|
245
251
|
|
|
246
252
|
Rules:
|
|
@@ -250,7 +256,7 @@ Rules:
|
|
|
250
256
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
251
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.
|
|
252
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.
|
|
253
|
-
- `[[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.
|
|
254
260
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
255
261
|
|
|
256
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.
|
|
@@ -27,14 +27,14 @@ pipx install docstate
|
|
|
27
27
|
Pin a version:
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
-
pipx install docstate==0.2.
|
|
30
|
+
pipx install docstate==0.2.5
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Or install from the GitHub tag / release:
|
|
34
34
|
|
|
35
35
|
```sh
|
|
36
|
-
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.
|
|
37
|
-
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.
|
|
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
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Or install from a checkout:
|
|
@@ -94,7 +94,7 @@ content here is replaced by render
|
|
|
94
94
|
To make drift fail in CI, add two steps:
|
|
95
95
|
|
|
96
96
|
```yaml
|
|
97
|
-
- run: pipx install docstate==0.2.
|
|
97
|
+
- run: pipx install docstate==0.2.5
|
|
98
98
|
- run: docstate check --config docstate.toml --strict
|
|
99
99
|
```
|
|
100
100
|
|
|
@@ -212,6 +212,12 @@ applies_to = ["docs/**/*.md"]
|
|
|
212
212
|
doc = "docs/README.md"
|
|
213
213
|
field = "last_reviewed"
|
|
214
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"
|
|
215
221
|
```
|
|
216
222
|
|
|
217
223
|
Rules:
|
|
@@ -221,7 +227,7 @@ Rules:
|
|
|
221
227
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
222
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.
|
|
223
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.
|
|
224
|
-
- `[[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.
|
|
225
231
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
226
232
|
|
|
227
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)
|
|
@@ -313,19 +315,57 @@ def _parse_freshness_rules(base: Path, raw: object) -> list[FreshnessRule]:
|
|
|
313
315
|
for index, item in enumerate(raw):
|
|
314
316
|
if not isinstance(item, dict):
|
|
315
317
|
fail("CFG_SCHEMA", f"check.freshness[{index}] must be a table")
|
|
316
|
-
_reject_unknown(
|
|
317
|
-
|
|
318
|
-
changelog = _resolve_file(
|
|
319
|
-
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}]"
|
|
320
320
|
)
|
|
321
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}")
|
|
322
360
|
rules.append(
|
|
323
361
|
FreshnessRule(
|
|
324
|
-
doc=
|
|
325
|
-
doc_rel=
|
|
362
|
+
doc=None,
|
|
363
|
+
doc_rel="",
|
|
326
364
|
field=field_name,
|
|
327
|
-
changelog=
|
|
328
|
-
changelog_rel=
|
|
365
|
+
changelog=None,
|
|
366
|
+
changelog_rel="",
|
|
367
|
+
docs=tuple(_expand_check_files(base, patterns, [], exclude)),
|
|
368
|
+
changelog_template=template,
|
|
329
369
|
)
|
|
330
370
|
)
|
|
331
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
|
|
@@ -56,14 +56,14 @@ pipx install docstate
|
|
|
56
56
|
Pin a version:
|
|
57
57
|
|
|
58
58
|
```sh
|
|
59
|
-
pipx install docstate==0.2.
|
|
59
|
+
pipx install docstate==0.2.5
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
Or install from the GitHub tag / release:
|
|
63
63
|
|
|
64
64
|
```sh
|
|
65
|
-
pipx install "git+https://github.com/XinBuilds/docstate.git@v0.2.
|
|
66
|
-
pip install https://github.com/XinBuilds/docstate/releases/download/v0.2.
|
|
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
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
Or install from a checkout:
|
|
@@ -123,7 +123,7 @@ content here is replaced by render
|
|
|
123
123
|
To make drift fail in CI, add two steps:
|
|
124
124
|
|
|
125
125
|
```yaml
|
|
126
|
-
- run: pipx install docstate==0.2.
|
|
126
|
+
- run: pipx install docstate==0.2.5
|
|
127
127
|
- run: docstate check --config docstate.toml --strict
|
|
128
128
|
```
|
|
129
129
|
|
|
@@ -241,6 +241,12 @@ applies_to = ["docs/**/*.md"]
|
|
|
241
241
|
doc = "docs/README.md"
|
|
242
242
|
field = "last_reviewed"
|
|
243
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"
|
|
244
250
|
```
|
|
245
251
|
|
|
246
252
|
Rules:
|
|
@@ -250,7 +256,7 @@ Rules:
|
|
|
250
256
|
- `bom` reports a UTF-8 BOM; `warn` is the default, `ignore` disables it.
|
|
251
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.
|
|
252
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.
|
|
253
|
-
- `[[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.
|
|
254
260
|
- `status_review = "off"` avoids git entirely. When enabled, the directory must be a git repository; untracked files are skipped.
|
|
255
261
|
|
|
256
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.
|
|
@@ -115,3 +115,16 @@ def test_frontmatter_exclude_rejects_parent_paths(tmp_path):
|
|
|
115
115
|
with pytest.raises(DocstateError) as error:
|
|
116
116
|
load_config(config_path)
|
|
117
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")
|
|
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
|