Repository navigation
test: pin what each lint finds on the corpus - #44
Merged
Merged
Conversation
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
marked this pull request as ready for review
September 27, 2026 01:01
5 tasks done
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofcheck_repo(resolve settings, themin_entries/max_entriescontradiction check, parse theDocument, run every lint) moved as-is into a publiccheck_file(config, relative, contents, dir).check_repocalls it. No behavior change: every case and corpus test passes unchanged, and a scratch copy of the golden test that dispatched the lints the waycheck_repodid onmainproduced an identical set.tests/common/corpus.rs: the corpus loader and sidecar types moved out oftests/corpus.rsso both tests can use them. A fixture now also carries its path undertests/corpus/.tests/golden/config.toml: a normal deslag config, one[md.lints.<lint>]table per lint, loaded withConfig::parselike 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 intofixand listed inhelpin the doctrine's order (fix,fix-clippy,fix-fmt,fix-golden,fix-test-output)._typos.toml: skipstests/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.mdupdated (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_tablesfor the settings the run used, the same waydeslag explainfills in defaults. It is output only and is never parsed back; the input isconfig.toml. So if a schema default changes, the header and the body move together. For example,tests/golden/density.txt:Each line records the measurements the lint's verdict compares, not just a pass/fail:
max_size_bytessize_bytes:27146 budget:16384max_emphasisspans:17 percent:1.27(two decimals, not the report's rounded-up figure)repo_layoutproblems:8banned_charscount:6banned_phrasesmatches:1densityitem:361 paragraph:702The record is built by an exhaustive
matchonViolation, 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_layoutthen runs its realcheck, 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. Therepo_layoutfile's header says so. A future lint that reads the disk inherits the same rule.What the test fails on
-/+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, runmake fix-goldenand read the diff.config.toml: "Add a[md.lints.<lint>]table there, with settings under which some fixtures fail it and some pass, then runmake fix-goldenand read the diff."tests/golden/named after no lint.config.tomlholding overrides, since each header states one set of settings for every fixture.I tried the scratch-lint case (not committed): adding a field to
MdLintswith 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 somake fix) runs the test withDESLAG_FIX_GOLDEN=1, which writes the files instead of comparing, the same pattern asfix-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.max_size_bytesvalue = 16384: fails few, keeping the file short. Its records barely move anyway, since fixture bytes are pinned by sha256.max_emphasisfree_spans = 2,max_percent = 1.0: the limits deslag holds its own Markdown to, and the ones the corpus test uses.repo_layoutbanned_charsdensitybanned_phrasesbanthose 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_chars469,banned_phrases221,density279,max_emphasis491,max_size_bytes166,repo_layout2. Together the six files are about 125 KB.On
repo_layout: at the default heading onlycore/rt-agents.md(the one fixture in deslag's layout format) and onemixed/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 inmake cion my machine, against 32.8s fortests/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):test_regression.pycompares 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 --updaterewrites 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.tests/examples.pypairs every check with should-fail and should-pass strings, andtest_check_examples_existdiffs 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.@exampleblocks 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.mddescribes the golden set under Tests, andcheck_fileunder Checking and reporting. The doc was 5 bytes under its 16384-byte budget, so the new text is paid for with cuts. These went: themessageline of the config example; the note thatmax_emphasis'sOverholds theMeasure; "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, sogolden/is a continuation of thetests/line, not a new entry.Left out
Lint behavior worth a look (unchanged here)
Nothing looked like a bug. Two things stood out:
core/midi-bug-report.mdis 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.llm >= 4 * humancheck for the default character groups has little margin: 241llm/fixtures against 57human/, so 241 against a floor of 228.Testing
make ci: exit 0make fix-goldenregenerates with no diff;make helplists it betweenfix-fmtandfix-test-outputmain's per-file dispatch in place ofcheck_filepasses against the committed filescargo clippy --all-targets -- -D warningsReferences
tests/golden/config.tomland a golden file.ACKNOWLEDGEMENTS.md).