Skip to content

test: merge the copied section tests and count reads in place of timing the C++ lexer - #260

Merged
webern merged 10 commits into
m/deslag-testtierfrom
m/deslag-testdedup
Nov 2, 2026
Merged

webern merged 10 commits into
m/deslag-testtierfrom
m/deslag-testdedup

Conversation

@webern

@webern webern commented Nov 2, 2026

Copy link
Copy Markdown
Owner

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

  • make ci-fast: exit 0
  • make test: exit 0
  • make test-tools: exit 0
  • make check-deslag: exit 0
  • make check-fmt: exit 0

References

webern added 10 commits November 2, 2026 18:16
tests/rust_section.rs, toml_section.rs and cpp_section.rs held the
same tests with the data changed, 45 in all. tests/sections.rs lists
the sections in one table, with every expected message written out
in its row, and has one test over the table for each rule the three
shared. A rule only one language has stays its own test: TOML has no
doc comment surface, the fix of TOML leaves a string alone and the
TOML section reads only files ending in .toml, and C++ reads eight
extensions.

A test over a table passes when a row is missing, so one test checks
that the table has a row for each section the config schema names
except md.

Two fewer test binaries: building the three took 5.4 s of CPU, and
building one takes 2.0 s. Running them takes about the same.

Nothing is dropped but copies. The rust and cpp tests that no two
sections select one file are covered by the toml copy, which writes
a file for all three sections. The md glob test, which was in the
rust file only, is kept once.
Each lint puts the config message into its own report, so each keeps
its custom_message case; those stay. These three checked the same
thing a second time:

- tests/unit.rs a_config_message_replaces_the_advice used the config
  and file of tests/cases/max_size_bytes/custom_message. That case's
  .stderr holds the whole report, so it also pins that the default
  advice is gone.
- the one-possessive half of the report test in
  src/lint/possessive_own.rs is pinned by
  tests/cases/possessive_own/custom_message.
- the one-negation half of the report test in src/lint/not_at_all.rs
  is pinned by tests/cases/not_at_all/custom_message.

The first half of each report test, the count, the places and the
default advice, stays.
sentence_lengths_by_label is ignored, checks nothing and only prints
tables for issue 33, which is closed. It goes with the helpers only
it used: the length and spread functions, the table printer and the
abbreviation list.

It pins nothing, so no test survives it. every_category_is_well_stocked
stays: it is the floor that keeps the ratio tests from passing on an
empty category.
- instructions.rs update_md_meets_its_budget read the budget of
  src/instructions/update.md from .agents/deslag.toml and ran the
  lints on the file. make check-deslag runs deslag on this repo with
  that config, so it holds update.md to the same budget and the same
  lints, as it holds every file.
- allow.rs the_acknowledgements_credit_the_two_designs_the_entry_takes
  searched ACKNOWLEDGEMENTS.md for words. It pinned no behavior. Its
  helper goes with it.

The other tests that read a file of this repo stay: each one has that
file as its subject, so a fixture would test nothing.
The linear-time test for directives that open a raw string read the
clock and failed above two seconds, which depends on the machine and
its load. In a test build the scanner now counts the bytes it reads,
in at and in the slice search of raw_string that does not go through
at, and the test bounds the count at 32 times the source length.

The limit is argued in a comment from the code and not found by
running it. A scan that reads the rest of the file again for each
directive reads on the order of the source length for every line, far
over the bound. The sources are 10,000 lines instead of 100,000,
since the count does not need a large input to tell linear from
quadratic.

A second test of 10,000 plain directives is added. In the first
source one raw string swallows the file, so the scan meets one
directive; the second meets 10,000.

This was the one read of the clock in src and tests.
- frozen.rs the_hash_is_fnv_1a_64 tested the hash helper. Any change
  to frozen::hash fails no_frozen_config_is_edited_and_each_has_a_line_in_hashes,
  which compares it with the hashes in the repo.
- instructions.rs lints_turned_on_reads_every_section tested a helper.
  If lints_turned_on breaks, the checks that compare a config's lints
  with the lints there are fail: the heading check and the one that
  compares the whole config's lints with lint_names.
- the Tag::ALL.len() == 13 assertion in src/tag/types.rs. The type of
  the array, [Tag; 13], already says it.

The test that every schema property has a since in since.rs stays.
It keeps the check for every property from passing on an empty list.
The read counter counted `at` and the `)` search of `raw_string`, but
code that sliced `self.bytes` directly was not counted. A rescan of the
rest of the file in `directive`, written that way, passed both
linear-time tests.

`Scanner` now holds a `Reader` in its own module. The bytes are private
to it, and 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 now refuses a read that skips the counter.

The bound of 32 reads for each byte is unchanged. Its comment now counts
the one extra read of the bytes that were indexed before.
`#[rustfmt::skip]` on `Row` and `ROWS` kept `tests/sections.rs` at 600
lines by leaving 38 lines over 100 columns, the longest 241. The 600
lines were a size guide. The rows are easier to read formatted, so the
file is now what rustfmt leaves, 704 lines.
Three tests took `ROWS[1]` or `ROWS[2]`, so reordering the table would
have swapped the language they test. They now ask `row("toml")` or
`row("cpp")`, which panics if the table has no such row.
…chema

The merged schema test checked only `surfaces = ["comment"]` and
`density`. The tests it replaced also fitted both surfaces, a table of
`banned_chars` groups and an override. Each row now has that config
checked by `toml_misfit` too, with `doc_comment` left out for `toml`,
which has none.
@webern webern added the ai Primarily authored by AI (whether PR, Issue, Whatever) label Nov 2, 2026
@webern
webern added this pull request to stack #261 November 2, 2026 18:45
@webern
webern marked this pull request as ready for review November 2, 2026 18:49
@webern

webern commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

CI is green on fb6a51b (runs 41503536723, 41503536771 and 41503537461). This PR is stacked on #257 (stack 261) and shows only its own diff until #257 merges.

Decided on the maintainer's behalf: the repo-state tests stay, apart from two. The plan had moved them out; this PR keeps every test whose subject is the repo file it reads, on the 2026-10-24 tier decisions and #215, and deletes only the update.md budget test, which make check-deslag already enforces, and the acknowledgements grep, which pinned wording and no behaviour. The other choice recorded in the body: the 600-line cap on the merged section table was lifted so rustfmt formats it (723 lines) instead of 38 lines over 100 columns under a format skip.

@webern
webern merged commit 7f2062b into main Nov 2, 2026
10 checks passed
@webern
webern deleted the m/deslag-testdedup branch November 2, 2026 21:00
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