Skip to content

test: pin what each lint finds on the corpus - #44

Merged
webern merged 3 commits into
mainfrom
m/deslag-golden
Sep 27, 2026
Merged

webern merged 3 commits into
mainfrom
m/deslag-golden

Conversation

@webern

@webern webern commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

This adds a golden set: for every lint, a committed file listing each corpus fixture the lint fails, with the numbers its verdict compared. A test reruns the lints over the corpus and fails with a diff when any file no longer matches.

Why: a change to the document layer, the tokenizer, the sentence splitter or a lint's counting can move what a lint finds in hundreds of fixtures, and today the suite still passes as long as each lint fails some fixtures and passes others. Nothing showed what changed. Refactors coming up need to see that exactly. The golden set is a snapshot, not a verdict: it says what deslag does today so a change shows in review. Whether a lint is right about the corpus stays the business of tests/corpus.rs. A change that is not meant to change lint behavior must leave the set as it is.

It also closes a gap: each corpus test proved "fails some, passes some" by hand for the one lint it knew, so a new lint could land without that proof. The golden test enumerates the lints from the config schema, so it cannot forget one.

What changed

  • src/lint/mod.rs: the per-file body of check_repo (resolve settings, the min_entries/max_entries contradiction check, parse the Document, run every lint) moved as-is into a public check_file(config, relative, contents, dir). check_repo calls it. No behavior change: every case and corpus test passes unchanged, and a scratch copy of the golden test that dispatched the lints the way check_repo did on main produced an identical set.
  • tests/common/corpus.rs: the corpus loader and sidecar types moved out of tests/corpus.rs so both tests can use them. A fixture now also carries its path under tests/corpus/.
  • tests/golden/config.toml: a normal deslag config, one [md.lints.<lint>] table per lint, loaded with Config::parse like a user's config (so unknown keys and bad values are hard errors).
  • tests/golden/<lint>.txt: one file per lint, generated.
  • tests/golden.rs: one #[test] that collects every failure and asserts once.
  • Makefile: fix-golden, joined into fix and listed in help in the doctrine's order (fix, fix-clippy, fix-fmt, fix-golden, fix-test-output).
  • _typos.toml: skips tests/golden/*.txt, for the corpus's reason: the files quote other people's repo and file names.
  • docs/design/deslag.asbuilt.md, AGENTS.md, ACKNOWLEDGEMENTS.md updated (details below).

The file format

Plain text, one file per lint, sorted by fixture path so it diffs well on GitHub. The header is printed from MdLints::toml_tables for the settings the run used, the same way deslag explain fills in defaults. It is output only and is never parsed back; the input is config.toml. So if a schema default changes, the header and the body move together. For example, tests/golden/density.txt:

# density: each fixture under tests/corpus/ that it fails, with what it measured there.
# A fixture that passes is not listed. Each is linted alone, in an empty directory.
# tests/golden.rs writes this file with the settings below, from tests/golden/config.toml.
# `make fix-golden` rewrites it; read the diff before committing it.
# fails 279 of 1230: core 8, human 53, llm 92, mixed 126

[md.lints.density]
max_item_chars = 300
max_paragraph_chars = 600

core/den-agents.md item:361 item:632 item:605 item:431 item:565
core/den-classifier-design.md item:312

Each line records the measurements the lint's verdict compares, not just a pass/fail:

Lint Record
max_size_bytes size_bytes:27146 budget:16384
max_emphasis spans:17 percent:1.27 (two decimals, not the report's rounded-up figure)
repo_layout problems:8
banned_chars count:6
banned_phrases matches:1
density each over-long block's kind and length, e.g. item:361 paragraph:702

The record is built by an exhaustive match on Violation, so a new lint does not compile until it says what its golden file records. Line numbers are not recorded, and fixtures that pass are not measured; measuring the whole corpus is a separate job.

Lints that need the disk

One general rule: each fixture is linted alone in an empty directory. repo_layout then runs its real check, finds every listed path missing, and fails every fixture that has the section. A fixture without the section would fail in any directory, so it is left out and counted as passing. The repo_layout file's header says so. A future lint that reads the disk inherits the same rule.

What the test fails on

  • Drift: a golden file differs from what the lint finds now. The message shows a -/+ line diff (capped at 40 lines plus a count), and says that a change not meant to change lint behavior must leave the set alone; if the change is meant, run make fix-golden and read the diff.
  • A lint the schema lists with no table in config.toml: "Add a [md.lints.<lint>] table there, with settings under which some fixtures fail it and some pass, then run make fix-golden and read the diff."
  • A lint with no golden file.
  • A file in tests/golden/ named after no lint.
  • Worded apart from drift: the corpus does not prove a lint, meaning at its settings it fails no fixture or every fixture.
  • config.toml holding overrides, since each header states one set of settings for every fixture.

I tried the scratch-lint case (not committed): adding a field to MdLints with no table fails with the "no settings" message; adding an empty table for it then fails with "The corpus does not prove scratch: ... fails 0 of 1230" and "tests/golden/scratch.txt is missing".

Regenerating

make fix-golden (and so make fix) runs the test with DESLAG_FIX_GOLDEN=1, which writes the files instead of comparing, the same pattern as fix-test-output. It still fails on a missing table or a lint the corpus does not prove. Read the diff before committing it.

Settings, and the measurements behind them

Measured on the in-tree corpus (1230 fixtures) at main = 371cf4e. Each setting splits the corpus. Where a table alone turns a lint on, it runs at its defaults, so a changed default shows up in the set.

Lint Tried (fixtures failed of 1230) Chosen
max_size_bytes 4096: 613, 8192: 355, 16384: 166, 32768: 59 value = 16384: fails few, keeping the file short. Its records barely move anyway, since fixture bytes are pinned by sha256.
max_emphasis (free_spans, max_percent) (2, 1): 491, (5, 2): 336, (10, 5): 173, (0, 1): 604, (2, 0): 558 free_spans = 2, max_percent = 1.0: the limits deslag holds its own Markdown to, and the ones the corpus test uses.
repo_layout heading "Repository layout" (default): 2, "Repository structure": 7, "Project structure": 8, "Layout": 3, "Structure": 3, "File structure": 2, "Directory structure": 0 Defaults. See the note below on why only 2.
banned_chars defaults: 469 Defaults.
density defaults: 279 Defaults.
banned_phrases nothing is banned by default, so it needs a list. Per phrase: "comprehensive" 43, "in order to" 91, "let's" 33, "note that" 133, "production-ready" 2, "please note that" 34 ban those five, allow = ["please note that"]: together 221. Chosen to run each part of the matcher (one word, a row of words, an apostrophe, a hyphen, a match dropped inside an allowed phrase), not as advice. The config says so.

Tallies in the committed files: banned_chars 469, banned_phrases 221, density 279, max_emphasis 491, max_size_bytes 166, repo_layout 2. Together the six files are about 125 KB.

On repo_layout: at the default heading only core/rt-agents.md (the one fixture in deslag's layout format) and one mixed/ README have the section. "Project structure" would list 8 fixtures, but none of them in the lint's format, and a pinned heading would hide a change to the default. I kept the default. It is thin coverage, and easy to revisit.

Speed: the test calls the library on Document::markdown, not the binary. It takes 8.8s in make ci on my machine, against 32.8s for tests/corpus.rs. About 1.1s of that is loading and hashing the corpus, and the rest is the lints, on one thread.

Research

I read how three tools that pin their own behavior do this, and took ideas, not code (credited in ACKNOWLEDGEMENTS.md):

  • docstats (ghchinoy/docstats at d958885, Apache-2.0). test_regression.py compares each sample's metrics against committed JSON (samples/baseline_results.json, samples/expected_findings.json) with a float tolerance of 1e-3, failing with "Drift detected in {file} for {key}: expected X, got Y". baseline_analysis.py --update rewrites the JSON. Taken: a committed zero-drift set, plus one switch that rewrites it instead of comparing. Not taken: JSON keyed by file, which diffs poorly, and the tolerance. We print fixed decimals and compare bytes.
  • proselint (amperser/proselint at dbed789, BSD-3-Clause). tests/examples.py pairs every check with should-fail and should-pass strings, and test_check_examples_exist diffs the set of check modules against the examples both ways ("Some modules lack examples" / "Some examples do not exist"). Taken: the two-way check, here a lint with no table or file, and a file named after no lint. Its paired examples map to "fails some fixtures, passes others", measured on the corpus instead of hand-written strings.
  • remark-lint (remarkjs/remark-lint at ce81d46, MIT). Each rule's JSDoc @example blocks are parsed once (script/info.js), rendered into the package readme (script/pipeline-package.js) and run as the tests (test.js). A rule with no examples just yields no tests. Only the 100% coverage gate catches it, indirectly. Taken: the lesson that a missing proof must fail explicitly. Docs-as-tests does not fit here, since golden files are not docs.

Docs

  • deslag.asbuilt.md describes the golden set under Tests, and check_file under Checking and reporting. The doc was 5 bytes under its 16384-byte budget, so the new text is paid for with cuts. These went: the message line of the config example; the note that max_emphasis's Over holds the Measure; "the guide takes its config paths from the code"; the list of matrix layouts; "a few are not English"; the entry-line detail of the layout corpus test; clap in the intro. The "pure read" paragraph is also shorter. It is now at 16383 bytes.
  • AGENTS.md: the layout is at its 12-entry limit, so golden/ is a continuation of the tests/ line, not a new entry.

Left out

  • The big corpus tier: out of scope until it lands.
  • Threads: the test is single-threaded at ~9s. Splitting the fixtures across threads would cut that to a couple of seconds if suite time starts to matter.
  • Measurements of passing fixtures and line numbers: the set records what each verdict compares, nothing more.

Lint behavior worth a look (unchanged here)

Nothing looked like a bug. Two things stood out:

  • core/midi-bug-report.md is 100.00% emphasized: its only prose is four bold labels, and the rest is HTML comments, which are not prose. That is correct by the lint's definition.
  • The corpus test's llm >= 4 * human check for the default character groups has little margin: 241 llm/ fixtures against 57 human/, so 241 against a floor of 228.

Testing

  • make ci: exit 0
  • make fix-golden regenerates with no diff; make help lists it between fix-fmt and fix-test-output
  • Drift, a missing golden file and a stray file each fail with the messages above (edited files by hand, then restored)
  • A scratch lint added to the schema fails the test with no table, and again with a table but no golden file (not committed)
  • A scratch copy of the test using main's per-file dispatch in place of check_file passes against the committed files
  • Each of the three commits passes cargo clippy --all-targets -- -D warnings

References

The golden set test needs to read the corpus too, so the loader and
the sidecar types move from tests/corpus.rs to tests/common/corpus.rs.
A fixture now also carries its path under tests/corpus/, which the
golden files use to name it. Nothing else changes.
check_repo walked the repo and, for each file, resolved its settings
and ran every lint inline. That part is now check_file, a public
function that check_repo calls, so a caller with a file's bytes can
run exactly what deslag check runs on it. The code moved as it was,
and what deslag prints does not change.
A change to the document layer, the tokenizer or a lint's counting
can move what a lint finds in hundreds of fixtures, and the corpus
tests still pass as long as each lint fails some files and passes
others. Nothing showed what changed.

tests/golden/ now holds a golden file per lint: every fixture the
lint fails, with the numbers its verdict compared, under the settings
in tests/golden/config.toml. tests/golden.rs runs check_file on each
fixture, alone in an empty directory, and fails with a diff when a
file does not match. It also fails when a lint the schema lists has
no settings or no file, when a file is named after no lint, and when
a lint fails no fixture or every one.

make fix-golden rewrites the files, and make fix runs it. Read the
diff before committing it.
@webern webern added ai Primarily authored by AI (whether PR, Issue, Whatever) area/lint Deals with the linting algorithms themselves, how they work. area/build Deals with deslag build, scripts, ci, cd. labels Sep 27, 2026
@webern
webern marked this pull request as ready for review September 27, 2026 01:01
@webern
webern merged commit 71c7de7 into main Sep 27, 2026
2 checks passed
@webern
webern deleted the m/deslag-golden branch September 27, 2026 01:01
webern added a commit that referenced this pull request Sep 27, 2026
## Summary

`docs/design/deslag.asbuilt.md` describes the code as it is. At a2d8ea1
it is 16378 bytes of its 16384 `max_size_bytes`, and it has been within
180 bytes of that budget since #23 (16352). Each of #44, #45 and #47
made room for its new paragraphs by cutting others, and #45 moved the
corpus text out to `corpus.asbuilt.md`. The `deslag-design-docs` skill
says a budget is not raised without the owner, so every change to the
code has had to squeeze the doc.

The budget was also kept by hand: `.agents/deslag.toml` did not select
the doc. Selected at a2d8ea1, it fails `max_emphasis` (20 bold spans,
1.24% of its prose) and `density` (8 paragraphs over 500 characters).

This PR splits the doc the way `corpus.asbuilt.md` already is: one
as-built doc per subsystem, each with its own budget, and every one of
them linted.

- `deslag.asbuilt.md` is now the overview: what deslag is, a run, the
modules at directory level and what calls what, an index of the
subsystem docs, the command line and exit codes, other files, the tests
and the build. Its budget drops from 16384 to 8192, so it cannot grow
back into the place every detail goes.
- `config.asbuilt.md`: the config, glob patterns, the walk and `deslag
explain`.
- `document.asbuilt.md`: the `Document` and frontmatter. It is named for
`src/document/`, the module it holds.
- `lints.asbuilt.md`: checking, marks, one section per lint in
`Lint::ALL` order, reports and `--format`. A new lint is one new
section.

Each subsystem doc opens with its entry points and callers, then its
`src/` tree, then one section per concern. `subsystems:` in each doc's
frontmatter holds `src/` module names, each in exactly one doc: the one
with its detail.

| Doc | Bytes | Budget | `subsystems:` |
|---|---|---|---|
| `deslag.asbuilt.md` | 6786 | 8192 (was 16384) | `cli`, `instructions`
|
| `config.asbuilt.md` | 3889 | 5000 | `config`, `glob`, `explain` |
| `document.asbuilt.md` | 2194 | 3000 | `document`, `parse` |
| `lints.asbuilt.md` | 5884 | 7500 | `lint`, `output` |
| `corpus.asbuilt.md` | 5998 | 8192 | `corpus` (unchanged) |

### Where each old section went

| Section at a2d8ea1 | Now |
|---|---|
| intro, A run | `deslag.asbuilt.md`, as they were |
| Modules | `deslag.asbuilt.md` keeps the tree at directory level and
the paragraph on what calls what; each subsystem doc takes its
file-level lines |
| The document | `document.asbuilt.md`: Blocks; Tokens, sentences and
locations |
| Where a file's budget comes from | `lints.asbuilt.md`: max_size_bytes
|
| The config | `config.asbuilt.md`: The config, and Glob patterns for
the `glob::Pattern` paragraph |
| Frontmatter | `document.asbuilt.md`: Frontmatter |
| Explaining a file | `config.asbuilt.md`: Explaining a file |
| Walking the repo | `config.asbuilt.md`: Walking the repo |
| Checking and reporting | `lints.asbuilt.md`: Checking, Marks, a
section per lint, Reports, --format |
| The command line, Other files, Tests, Build | `deslag.asbuilt.md`, as
they were |

### Commits

1. `docs: split the as-built doc by subsystem`: the text moves as it
was. New text is limited to each subsystem doc's opening sentences, the
overview's index, the section headings, and short descriptions for the
directories in the overview's tree, worded after the layout in
`AGENTS.md`. `README.md` says the overview indexes the subsystem docs.
2. `docs: fix the lint findings in the as-built docs`: 8 paragraphs
split at a sentence end, and 13 of 20 bold spans un-bolded. Each doc
keeps its first two; the sentence that defines each of the others stays.
No sentence is reworded.
3. `docs: correct the as-built docs against the code`: an ellipsis,
U+2026, also ends a sentence (`src/document/sentences.rs:113`); `make
clean` also runs `cargo clean` (`Makefile:98-99`); the trees now name
`parse/mod.rs`, `ACKNOWLEDGEMENTS.md` and `.agents/skills/`; `explain`
is in `subsystems:`, where no doc named it (`src/lib.rs:27`).
4. `test: lint every as-built doc and its subsystems`:
- `.agents/deslag.toml` selects `/docs/design/*.asbuilt.md` in place of
`corpus.asbuilt.md` alone. The glob does not select `deslag.desired.md`,
which is written by hand and stays unlinted, and topic docs stay listed
one by one.
- A selected file with no budget is counted but never size-checked
(`src/lint/max_size_bytes.rs:35-38`). An override on the same glob with
`value = 4096` closes that: a frontmatter budget wins over it, and a doc
that declares none fails at 4 KB.
- `tests/asbuilt.rs` fails when a module under `src/` is named in no
as-built doc's `subsystems:`, or in more than one, so a new module gets
its doc on purpose. It finds the frontmatter with `Document` and reads
it with `serde-saphyr`; no new dependency.

### Nothing lost in the move

A script outside the repo cuts the a2d8ea1 doc into 177 units (each
sentence, code line and heading) and 166 backticked names, and looks for
each in the four new docs, with whitespace and bold markers ignored.
After each commit:

| After commit | Units missing | Names missing |
|---|---|---|
| 1 | 4 | 0 |
| 2 | 4 | 0 |
| 3 | 6 | 0 |
| 4 | 6 | 0 |

The six, each on purpose:

- Three headings, `The document`, `Where a file's budget comes from` and
`Checking and reporting`, replaced by the sections in the table above.
- "Most specific first: the `max_size_bytes` key ..." now opens "A
file's budget comes from, most specific first: ...". Its heading used to
say what it was about; the section is now named for the lint.
- The sentence rule now names the ellipsis (commit 3).
- "`make clean` removes both directories" now adds "and runs `cargo
clean`" (commit 3).

The script proves each unit is somewhere, not that it is in the right
place, so the trees were read by eye.

### Left as it was

- The overview's paragraph on what calls what does not say that
`explain` calls `config`, `glob` and `parse` too. It is not wrong, so it
was not rewritten.
- The tests stay in the overview; no doc owns them yet.
- `corpus.asbuilt.md`, `corpus.md` and their lines in
`.agents/deslag.toml` are untouched; the glob now selects
`corpus.asbuilt.md` in place of its own line.

## Testing

- [x] `make ci`: exit 0
- [x] `deslag check` on the repo: exit 0 with all five as-built docs
selected; `deslag explain docs/design/deslag.desired.md` says it is not
selected.
- [x] A 5149-byte `docs/design/nofm.asbuilt.md` with no frontmatter
fails at 4096 bytes; `deslag explain` shows the frontmatter budget
winning over the override for `lints.asbuilt.md`. File removed after.
- [x] `tests/asbuilt.rs` fails with `parse: in no doc` when `parse` is
dropped from `document.asbuilt.md`, and with `lint: in
corpus.asbuilt.md, lints.asbuilt.md` when `lint` is added to
`corpus.asbuilt.md`, which also shows it reads a YAML block list. Both
reverted.
- [x] The residue script after each commit, as above.

## References

- No issue. Related to #23, #44, #45 and #47, each of which squeezed the
old doc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/build Deals with deslag build, scripts, ci, cd. area/lint Deals with the linting algorithms themselves, how they work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant