Skip to content

test: run the cases in the fast tier and stop pinning the fix counts - #257

Merged
webern merged 7 commits into
mainfrom
m/deslag-testtier
Nov 2, 2026
Merged

webern merged 7 commits into
mainfrom
m/deslag-testtier

Conversation

@webern

@webern webern commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

AI Summary

The 127 case directories under tests/cases/ ran only in the slow binary, so make test-fast never ran them, though they are where every lint's behaviour is pinned. This moves them into the fast tier and removes two costs that did not need to be there.

  • tests/slow/cases.rs is now tests/cases.rs, its own test binary. Its three tests moved with it unchanged. It is one test that spreads the cases over the cores in chunks (on_every_core, now shared in tests/common/mod.rs), collects every failure and names each case. A panic in a case is caught where the case runs and reported as a failure that names it, so it does not hide what the other cases found. make fix-test-output runs --test cases.
  • The diff and update loops no longer run on all 127 cases, which built a repository (or two) for each. They run on a written-out list of 15 in tests/slow/sample.rs. The rule for the list is in its doc comment: a failing case for each lint, because --diff narrows a report per kind of finding; one case for each section but Markdown (Rust, C++, TOML); one case with an allow entry; one case whose config deslag refuses (exit 2). A test checks that every entry exists, that every lint has its <lint>/broken entry, that each broken entry exits 1, that the Rust, C++ and TOML entries have their section in the config, that the allow entry has an allow, that the refusal exits 2, and that no entry is listed twice. A new lint, or a lost or changed entry, fails it. The update loop's >= 40 floor and the diff loop's > 20 floor are gone. A failure in the update loop names the case as <lint>/<case>, as the diff loop does.
  • The corpus fix test no longer pins FIXED, FIXED_WHOLE and LEFT_BY_REASON, which every correct change to the corpus or to fix moved, and whose assert summed the constants and not what was counted. It keeps its per-file checks and the second-run idempotence, checks per file and in total that what was fixed plus what was left equals what was banned, from what the run counted, and floors both counts above zero so it cannot pass inert. The tally still prints.
  • Facts changed to match: the layout block of tests/AGENTS.md, the comment on the slow binary in Cargo.toml, the doc comment of tests/slow/main.rs, and the comment on fix-test-output.

Nothing else changed. No .stderr, .json, golden or corpus file moved. The test-doctrine skill is unchanged. This PR resolves neither the golden-file question nor the library-oracle corpus tests.

Decided on the maintainer's behalf

  1. The cases leave the slow binary and become their own fast-tier binary. Reason: the directory a test is written in sets its tier, and the cases are what pins each lint's behaviour, so an agent iterating on a lint should see them without waiting for ci-fast. This reverses the cases part of the earlier split that put cases, corpus, diff and update in one slow binary.
  2. The cases stay one test, chunked over the cores, not one test per case. Reason: a test per case needs a custom harness with a new dependency (libtest-mimic) or generated code, which is not worth it for 127 directories that already report each failure by name.
  3. The diff and update loops run on a written-out list, not on a discovered one. Reason: what those loops check does not depend on which lint wrote the case, and the list keeps their cost fixed as cases are added. The test on the list is what makes a new lint, a renamed case or a case of the wrong kind fail loudly. A later change that deletes a listed case swaps the entry.
  4. The fix test drops its three constants and asserts a sum of what it counted, with floors. Reason: the constants moved with every correct corpus or fix change, and the doctrine allows a floor and rejects an exact tally. The sum holds on every fixture, per file and in total.
  5. The test-doctrine skill stays as it is; only the facts that name the old layout changed. Reason: it is owner-written guidance and still describes the layout correctly.
  6. No tier target moved. The doctrine's "a few seconds" and the earlier "under 10 s" for the fast tier stand. Reason: the fast tier's gain was measured at 6.6 to 9.5 s CPU on a machine at load 14 to 90, and about 5 s on a quiet one, so the 6 s line is taken as met, and the cost is accepted for every lint's behaviour being pinned in the fast tier. The cost is the 254 deslag process spawns and temp copies (two runs per case), not the threading: capping the threads at 1, 4, 8 or 16 moved it by under 2 s. tests/golden.rs (7 s) and tests/allow.rs (11 s) are not touched.

Timings

CPU seconds (user+sys, /usr/bin/time -l, children included), fast profile, builds warm. Other builds were running on the machine, so sys time is inflated and noisy; wall time is not comparable and is not given. Two measurements: the first at load 60 to 90, the second at load 14 to 75.

Measure main (first) head (first) main (second) head (second)
Fast tier 38.2 (24.9+13.3) 47.8 (29.5+18.3) 38.6, 38.9, 39.4 45.2, 48.1, 46.0
Fast-tier delta +9.6 +6.6 to +9.5
Cases binary (3 tests) not in the fast tier 6.7 not in the fast tier 6.7 (3.3+3.3), three runs
Cases test, alone 5.1 (serial, in slow) 6.7 4.7 (serial, in slow)
Diff loop 72.8 (26.9+45.9) 8.7 (3.5+5.2) 79.5 (27.2+52.3) 8.7, 10.4 under load
Update loop 6.1 (3.4+2.6) 1.0 (0.6+0.4) 5.2 (3.0+2.2) 1.0
Fix test 33.8 37.4 35.6 40.9, 39.1
Slow binary, whole 251.0 (135.1+115.9) 143.7 (100.3+43.3) 232, 238.8 138.9

The fix test's difference is load, not code: the test costs the same, since unpinning its counts saves none of its work. The cases test costs more than it did serially because threads add sys time; a quiet-machine run of the fast tier gained about 5 s.

Mutation checks

Each run in a scratch copy, never committed.

  1. One byte of tests/cases/density/broken.stderr changed: make test-fast exit 2, density/broken: stderr differs from line 1.
  2. A lint's advice reworded in src/lint/density.rs: make test-fast exit 2, six density cases named.
  3. verbs_nothing/broken dropped from the sample list: the list's test fails, verbs_nothing has no entry in the sample ... Add verbs_nothing/broken.
  4. fix skips counting one left character: the fix test fails at the per-file sum, naming llm/mabel-dev--opteryx/IMPLEMENTATION_SUMMARY.md.
  5. A second fix that edits a file: the fix test fails, a second fix changed a file.

From a review of the diff:

  1. density/zero_limit renamed: the list's test fails and names it.
  2. max_emphasis/broken swapped for max_emphasis/clean: fails, max_emphasis has no entry in the sample.
  3. The test side skips one counted left reason: the total assert fails (7290 against 7423).
  4. A fix that leaves the first edit of a file on its first sight: a second fix changed a file.
  5. A fix tally that returns nothing: fix fixed nothing in the corpus (the floor).
  6. A panic injected in verbs_nothing/broken with a stale banned_chars/broken.stderr: before, only boom-last printed and the stderr difference was lost; after, both banned_chars/broken: stderr differs and verbs_nothing/broken: panicked: boom-last print.
  7. The verbs_nothing/broken case replaced by the contents of a passing case: the sample test fails, verbs_nothing/broken exits 0 where 1 is expected.

Testing

  • make ci-fast: exit 0
  • make test: exit 0
  • make test-tools: exit 0
  • Rebased onto eb5961f. One conflict, in tests/slow/corpus.rs, where the fix test's pinned counts (moved on main by the frontmatter fixes) are deleted as before; make ci-fast and make test pass again, and the sample test, the diff loop and the update loop pass against the new cases.

References

None.

@webern webern added the ai Primarily authored by AI (whether PR, Issue, Whatever) label Nov 2, 2026
The cases are what pins each lint's behavior, but they ran only in the
slow binary, so `make test-fast` never ran them. Move them to
`tests/cases.rs`, a binary of its own, so the fast tier runs them.

The cases are spread over the cores in chunks, as the corpus tests
spread their fixtures, and the failures are collected and each named.
`on_every_core` moves to the shared test helpers for this.
`make fix-test-output` now runs `--test cases`.
The two loops built a repository for every case, 116 of them at once in
the diff loop, and what they check does not depend on which lint wrote
the case. Run them on a list of 15 cases in `tests/slow/sample.rs`: a
failing case for each lint, one for each section but Markdown, one with
an `allow` entry and one whose config deslag refuses.

A test checks that each entry exists and that every lint has its
`broken` entry, so a new lint or a lost entry fails. The update loop's
floor on the number of cases goes with the discovery it counted.
The corpus fix test pinned how many characters fix changes and leaves,
and for what reason, so it failed on every corpus or fix change that
was correct. Its final sum added up the pinned constant, not what the
test counted.

Check from what the test counted instead: each file's characters are
all fixed or left, so are the corpus's, and neither count is zero. The
per-file checks and the second run that changes nothing stay.
A panic in one chunk of the cases test was resumed when the chunk was
joined, so the failures the other chunks had collected were lost and
the message named no case. Catch the panic where the case runs and
report it as a failure that starts with the case name, like the
others.
Ten cases of the sample are called broken, so a failure in the update
loop said "broken" without the lint. Print the path of the case, as
the diff loop does.
The sample test only checked that an entry is a case directory. Check
that each broken case exits 1, that the Rust, C++ and TOML cases have
their section in the config, that the allow case has an allow entry,
that zero_limit is refused with exit 2, and that no entry is listed
twice. Each entry is written out. Without this, a sample whose cases
all stopped failing would pass the diff and update loops inert.
@webern
webern force-pushed the m/deslag-testtier branch from ff32f71 to ee8ca5b Compare November 2, 2026 16:58
@webern
webern marked this pull request as ready for review November 2, 2026 17:03
@webern

webern commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

CI is green on ee8ca5b (runs 41486636078, 41486636082 and 41486636248), after the rebase onto eb5961f.

Decided on the maintainer's behalf: the cases leave the slow binary they were assigned to on 2026-10-24 and run in the fast tier as their own binary. The reason is that every lint's behaviour is pinned by the cases, and an agent iterating on a lint got no signal from them until ci-fast. The cost is about 5 s of CPU per make test-fast on a quiet machine, measured at 6.6 to 9.5 s on a machine at load 14 to 90, which is taken as meeting the 6 s line in the plan. The diff and update loops run on a written-out sample of 15 cases instead of every case, which is where the slow tier's time went.

@webern
webern added this pull request to stack #261 November 2, 2026 18:45
@webern
webern merged commit b5c182e into main Nov 2, 2026
10 checks passed
@webern
webern deleted the m/deslag-testtier branch November 2, 2026 21:00
webern added a commit that referenced this pull request Nov 2, 2026
…ng the C++ lexer (#260)

This builds on #257 and shows only its own diff until #257 merges. This
PR resolves neither the golden-file question nor the library-oracle
corpus tests.

## AI Summary

Three test files were copies of one another, one test measured elapsed
time, and a few tests checked things that something else already breaks
on. This removes the copies and puts a counter where the clock was. No
`.stderr`, `.json`, golden or corpus file changes, and no case is
deleted.

### The section tests are one table

`tests/rust_section.rs`, `tests/toml_section.rs` and
`tests/cpp_section.rs` (45 tests, each file a copy of the others with
the language changed) are now `tests/sections.rs`: one written-out
table, `ROWS`, with a row per code section, and one test over it per
rule. A rule only one language has is its own test: TOML refuses
`doc_comment`, C++ reads eight extensions, TOML's fix leaves a string
and keeps CRLF. `the_md_section_keeps_any_glob` is kept once.

A test that loops over the list it pins passes when an entry goes (#197,
#240). So `the_table_has_a_row_for_each_code_section` compares the
table's names with the sections the config schema names, minus `md`, in
both directions. Each row's expected messages are written out, never
formatted from the name. A test picks its row by name (`row("cpp")`), so
reordering the table cannot swap languages.

### Tests and assertions deleted, and what still pins each

- `a_config_message_replaces_the_advice` (`tests/unit.rs`): the case
`tests/cases/max_size_bytes/custom_message`, whose `.stderr` is the
whole report and so shows the advice gone.
- The one-possessive half of
`the_report_names_the_count_the_places_and_the_advice`
(`possessive_own.rs`) and the one-negation half of the same-named test
in `not_at_all.rs`: the cases `possessive_own/custom_message` and
`not_at_all/custom_message`.
- `sentence_lengths_by_label` and its helpers (`tests/slow/corpus.rs`):
an ignored test that printed a spread and checked nothing.
`every_category_is_well_stocked` stays.
- `update_md_meets_its_budget` (`tests/instructions.rs`): `make
check-deslag` holds `src/instructions/update.md` to the same budget, as
it holds every file.
- `the_acknowledgements_credit_the_two_designs_the_entry_takes`
(`tests/allow.rs`): it grepped the wording of `ACKNOWLEDGEMENTS.md` and
checked no behaviour. Nothing pins it now.
- `the_hash_is_fnv_1a_64` (`tests/frozen.rs`):
`no_frozen_config_is_edited_and_each_has_a_line_in_hashes` fails on any
change to `frozen::hash`.
- `lints_turned_on_reads_every_section` (`tests/instructions.rs`):
`each_lint_section_turns_on_its_lint_alone` and
`the_lints_tables_together_are_valid`. This was the only test that used
a non-`md` section. The survivors catch an empty set, ignored overrides
and ignored section-level lints, but not a reader that looks only at
`md`.
- `assert_eq!(Tag::ALL.len(), 13)` (`src/tag/types.rs`, an assertion):
the type `[Tag; 13]` says it.

Kept on purpose: the ten `custom_message` cases and their `.json` files
(each lint substitutes its own placeholders in its own code),
`tests/emphasis.rs`, `tests/since.rs`, `stamp.rs`, `phrases.rs`, the
guide and README tests in `instructions.rs`, `src/lint/mod.rs` and the
88 tests in `src/config/edit/`.

### The C++ lexer's clock is a read counter

One test in `src/document/cpp.rs` timed the lexer with `Instant`, so it
could fail on a slow machine and prove nothing on a fast one. It now
counts reads. `Scanner` holds a `Reader` in its own module, whose bytes
are private. Every read goes through `at`, `byte`, `slice`, `has_at` or
`find`, which count what they hand out in a test build and do nothing
more otherwise. The compiler refuses code that reads the source without
the counter, so a rescan written as a direct slice scan cannot hide.

The bound is 32 reads per byte, argued from the code in the comment on
`MOST_READS_PER_BYTE`, not found by running it. A lexeme start makes at
most 11 reads and steps over a byte; each loop in a lexeme makes at most
2 reads per byte; a blank after a backslash costs at most 6 more; a `<`
with no `>` costs 2 more. That is under 21. In a raw string, `find`
counts each byte once and the check after each `)` reads the delimiter
(at most 16 bytes) and the quote, so under 18. A rescan of the file per
directive reads the source length per line, far over any such constant.
Two tests feed it: 10,000 `#define X R"(a` lines and 10,000 `#define X
1` lines. The first has one directive in effect (the first raw string
swallows the file), so the second is the one that sees a per-directive
rescan.

### Before and after

| | Before | After |
|---|---|---|
| Fast-tier test binaries | 27 | 25 |
| Fast-tier tests | 1,299 | 1,268 |
| Section tests | 45 in 3 binaries | 18 in 1 binary |
| Run CPU | equal | equal |
| Clean-build CPU | unchanged | unchanged |
| CPU to rebuild after an edit | | about 2.8 s less (a review of the
diff measured it) |

The saving is two fewer test binaries to link, not a faster run. CPU per
binary is within noise on a loaded machine.

### Decided on the maintainer's behalf

1. The three section files become one table, with the row-per-section
test. Why: one rule in three copies drifts, and two fewer binaries
build.
2. The ten `custom_message` cases stay, and the three copies of them go.
Why: each lint substitutes its own placeholders in its own code, so each
case pins other code; the three deleted checks pinned only what a case
already shows.
3. `sentence_lengths_by_label` goes and `every_category_is_well_stocked`
stays. Why: the first prints and checks nothing; the second keeps the
ratio tests from passing on an empty category, and the corpus loads
once, so it saves no CPU.
4. Repo-state tests stay except two. Why: each reads a repo file because
that file is its subject, and a fixture would test nothing.
`update_md_meets_its_budget` is held by `make check-deslag` and the
acknowledgements test checked wording only.
5. The clock becomes a read counter, bounded by a constant argued from
the code. Why: a rescan per directive is orders of magnitude over any
small constant, and a count does not depend on the machine.
6. Three tests of helpers go. Why: each helper's tests elsewhere fail
first if it breaks.
7. `src/config/edit/` tests stay. Why: each refusal pins that `deslag
update` never writes a config it cannot edit safely.
8. The 600-line size guide for `tests/sections.rs` is lifted:
`#[rustfmt::skip]` kept it at 600 lines by leaving 38 lines over 100
columns, the longest 241. The table is formatted by rustfmt and the file
is 723 lines. Why: unreadable rows are worse than a longer file.
9. The counter bound is 32 reads per byte. Why: the argued worst cases
are under 21 for non-raw text and under 18 for a raw string, and the
worst measured were 7.0 and 17.98, so 32 leaves room without letting a
rescan through.

### Tests

Each mutation was made in a scratch copy and not committed.

- The `cpp` row dropped: `the_table_has_a_row_for_each_code_section`
fails, left `["rust","toml"]`, right `["cpp","rust","toml"]`.
- "selects it" reworded in `src/config/mod.rs`:
`a_file_that_two_sections_select_is_an_error_that_names_both` fails and
names the row.
- `max_size_bytes.rs` and then `possessive_own.rs` stop replacing
`{path}`: `tests/cases.rs` fails on each `custom_message` case.
- An unterminated raw string made to give up, so each opening searches
to the end: the counter fails at 750,565,002 reads of 150,000 bytes.
- `directive` reads the rest of the file again through `at`:
`many_plain_directives_are_read_in_linear_time` fails at 600,570,002
reads of 120,000 bytes, while the raw-string test passes.
- `directive` scans the rest of the file with a direct slice,
`self.bytes[after_hash..]`, counting newlines. This passed both tests
before the `Reader`. It no longer compiles, because the bytes are
private. The same scan through the reader's `slice` fails
`many_plain_directives_are_read_in_linear_time` at 600,590,005 reads of
120,000 bytes.
- `frozen::hash` with another multiplier:
`no_frozen_config_is_edited_and_each_has_a_line_in_hashes` fails.
- `lints_turned_on` returns an empty set:
`each_lint_section_turns_on_its_lint_alone` and
`the_lints_tables_together_are_valid` fail.
- `update.md` grown past its budget: `make check-deslag` exits 2 with
"src/instructions/update.md is 1884, which is larger than 1585 bytes".

The schema-fit test checks, for every row, `surfaces = ["doc_comment",
"comment"]` (`["comment"]` for `toml`), a `banned_chars` groups table
and an override, as the three replaced tests did, and an unknown surface
is refused.

## Testing

- [x] `make ci-fast`: exit 0
- [x] `make test`: exit 0
- [x] `make test-tools`: exit 0
- [x] `make check-deslag`: exit 0
- [x] `make check-fmt`: exit 0

## References

- Builds on #257.
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant