# editor-scopes ## Goal Three of the owner's five editor requests are the same question asked three ways — *which `end` belongs to this `begin`?* — so they get one answer: `crates/vfmt_server/src/pairs.rs`, a stack matcher over the token stream the document already caches. On top of it sit three consumers: `textDocument/documentHighlight`, so the cursor on a `begin` highlights its own `end` (real matching, not a text search for the word), and a **missing-closer warning** that points at the `begin` which lost its `end` instead of leaving the user with one parse error at the bottom of the file. The third consumer is the extension's rainbow: `vfmt/scopePairs` hands the client every `begin`/`end` and `fork`/`join*` pair with its nesting depth, and `extension.js` paints each depth in one of the six colours the user's theme already defines for bracket pairs. ## Assumptions - **The token stream is the right substrate, not the text and not the AST.** `Document.tokens` is already cached and already lexed, so a `// end` in a comment and a `"begin"` in a string literal cannot be mistaken for keywords: the lexer detached the comment and made the literal one `String` token before the matcher ever sees the stream. The AST would be *more* precise and is the wrong tool anyway — a file with a missing `end` is exactly a file with no usable AST, and that is the file the user needs help with. - **A macro's body is not in the stream, so the matcher cannot see into it.** `` `uvm_do_with(...) `` is one `Ident` token however many `begin`s it expands to, and a `` `define `` line is one `Directive` token. This is a feature for false positives (a macro can never push or pop) and the reason the diagnostics are gated (a macro that *does* supply an `end` makes a perfectly good file look unbalanced). - **Keyword-level matching means labels are free.** `begin : outer … end : outer` matches on the two keywords; the label is tokens the matcher skips. Nothing checks that the two labels agree — that is a linter's job, not this one's. - **`checker`/`endchecker` and `config`/`endconfig` are not in the pair set** because `vlog_parser::token::is_keyword` does not list them: they lex as plain identifiers, and matching identifiers named `checker` would be a false-positive machine. `table`/`endtable` *are* keywords but are left out too — they only occur inside a `primitive`, which is matched, and the plan did not ask for them. All three are one line each in `RULES` the day the lexer or the need arrives. - **A prototype ends at the next `;`.** The flag `extern`, `pure`, `import`, `export` and `typedef` raise is dropped at the next semicolon, wherever it falls. A `typedef struct { logic a; } t;` therefore drops the flag at the member's `;` rather than the declaration's — harmless, because nothing between the two can open a scope, and far simpler than tracking brace depth. - **Every guard in `opens_a_scope` is a construct that spells an opener and opens nothing.** They are listed in *Handshakes* below because getting one wrong is a phantom unclosed scope; each has a test, and the corpus sweep in the work log is what says the list is complete rather than merely plausible. - **A scope counts toward `depth` if and only if it is drawn.** Both readings come from one const, `RAINBOW_KEYWORDS`. M3 assumed the opposite — that counting every frame and filtering afterwards was fine, because "the rainbow only needs nesting *differences*". That was wrong, and a user found it: a hidden scope between two `begin`s is a difference the screen cannot explain. A `begin` inside a `case` came out one colour deeper than its sibling outside, so the `case` read as *"an invisible begin/end being highlighted"* — their words. Colour is only meaningful relative to the other coloured things; a level nobody can see is a level that must not exist. Anything added to `RULES` must therefore either join `RAINBOW_KEYWORDS` or stay invisible in both senses at once, which is what `the_depth_counter_and_the_wire_filter_read_the_same_list` enforces. - **Analysis is cheap enough to redo per request.** `analyze` is one pass over the token vector with a small stack, so nothing is cached and no invalidation rule can go stale. Measured, because `vfmt/scopePairs` arrives on a debounce timer rather than on a user gesture: sweeping the corpus, the worst single `scope_pairs` call is **2.1 ms** (`picorv32.v`, the largest file), against a 250 ms debounce. If a profile ever says otherwise, the result belongs next to `tokens` in `Document`, computed once per change like everything else there. - **The client repaints; the server never pushes.** LSP has no "decorate these ranges" notification, so the extension asks after every settled edit. That makes a stale answer possible — the reply describes the version that was asked about, and the user may have typed since — so `extension.js` compares `document.version` across the await and drops anything late. Without that, every range after an edit is painted at the wrong offset until the next repaint. ## Handshakes **Consumed from `state.rs`:** `Document.tokens` (the cached lex; empty when the file does not lex, which the matcher handles by finding nothing), `Document.diagnostics` (the *parse* diagnostics — the gate reads these, and only these), and `Document.positions()` for the byte→UTF-16 conversion. No new field was added to `Document` and nothing in `state.rs` changed. **Consumed from `vlog_parser`:** `Token`, `TokenKind`, `TextRange`, and `token::is_keyword`'s classification. If a keyword is ever added to or removed from that table, `RULES` and the guards below must be re-checked: the matcher only ever looks at `TokenKind::Keyword` tokens, so a word that stops being a keyword silently stops being matched. **Promised to `diagnostics.rs`:** `pairs::missing_end_diagnostics(doc)`, called from `diagnostics::all` between the parse errors and the lint warnings. It returns an empty list whenever `doc.diagnostics` is empty — callers do not have to check the gate themselves. **Promised to `server.rs` and `main.rs`:** `pairs::highlights(doc, offset) -> Option>`, and the `documentHighlightProvider` capability that advertises it. `None` means "decline", which the request loop turns into a JSON `null` — deliberately not an empty array, because an empty array tells the editor there are no occurrences anywhere and suppresses its own word highlighting. **Promised to `extension.js` — the `vfmt/scopePairs` wire shape.** This is the contract; `the_scope_pairs_wire_shape_is_what_the_extension_reads` pins it as literal JSON so it cannot drift silently. Request — a custom method, so nothing advertises it and a client that does not know it simply never asks: ```json { "method": "vfmt/scopePairs", "params": { "textDocument": { "uri": "file:///…" } } } ``` Result: ```json { "pairs": [ { "open": Range, "close": Range, "depth": 0 } ] } ``` - `open`/`close` are LSP `Range`s over the **keyword itself** — UTF-16, like every other position this server sends, converted with `doc.positions()`. - `pairs` holds only `begin`/`end` and `fork`/`join`/`join_any`/`join_none`. Every other scope the engine matches is dropped: a whole-file `module` would tint its own keywords a colour that means nothing, and letting `case`/`endcase` into the ladder makes the nesting read as deeper than it looks. What the owner asked for is the `begin`/`end` ladder. - `depth` counts **only the enclosing scopes that are themselves on the wire** — `begin` and `fork` frames, nothing else. A `begin` directly inside a `module` is 0; so is a `begin` inside a `case` inside that module; a `begin` inside a `begin` is 1; a `begin` inside a `fork` inside a `begin` is 2. The filter and the counter read the same `RAINBOW_KEYWORDS` const, so a scope is counted if and only if it is sent. (This is the M5 reversal — see Assumptions and the work log.) - Unmatched keywords are absent. Half a pair is nothing to colour, and the missing-closer warning already speaks about it. - An unopened document answers `null`, matching every other handler here. The extension treats that as "no pairs". Ordering is by opener position, though the extension does not depend on it. **Promised to any future consumer:** `analyze(&[Token]) -> ScopeAnalysis`, with `Pair { open, close, keyword, depth }`. `keyword` is the opener as written, which is how `scope_pairs` filters. **The guards — the list that must stay correct.** Each is an opener keyword in a construct with no closer: | Written | Why it opens nothing | |---|---| | `extern function f(); `, `pure virtual function g();` | prototype, body elsewhere | | `import "DPI-C" function void c();`, `export "DPI-C" function f;` | foreign, no body here | | `extern module m (...);` | header only | | `typedef class C;` | forward declaration | | `virtual interface bus_if vif;` | a type, not a declaration | | `interface class IC; … endclass` | the `class` opens; the `interface` must not, or `endclass` finds the wrong frame | | `module m (interface bus);` | generic interface port | | `default clocking cb;` | names a block that already exists | | `assert property (...)`, `cover sequence (...)` | only a *declaration* names what it declares | | `disable fork;`, `wait fork;` | statements about a fork, not a new one | | `covergroup cg with function sample(...);` | the covergroup's sample method; `endgroup` closes the lot | **Request to the lead (outside this feature's scope):** `docs/features/vfmt-server/README.md` carries the server's capability list and `TODO.md` §6 carries the shipped/not-shipped list; both now understate the server by one capability (`textDocument/documentHighlight`) and one diagnostic source. Neither file belongs to this feature, so neither was touched. ## Status / TODO - [x] `pairs.rs`: `analyze`, the `RULES` table, the prototype flag, the `opens_a_scope` guards, and mismatch recovery that does not cascade. - [x] Unit tests for every hazard in the plan, plus labeled blocks, nested depth counting, all three `join` flavours, all four `case` flavours. - [x] `textDocument/documentHighlight` in `server.rs`, capability in `main.rs`, `every_advertised_capability_is_implemented` updated. - [x] Missing-closer WARNING diagnostics, gated on the parse having already failed, capped at 20. - [x] e2e coverage over the wire (`tests/e2e.rs`). - [x] Corpus sweep for false positives (found one class; fixed). - [x] `vfmt/scopePairs` in `server.rs` + `pairs::scope_pairs`, wire shape pinned by a literal-JSON test. - [x] The rainbow in `extension.js`: six theme decoration types, `depth % 6`, repaint on active-editor / visible-editors / document change (250 ms debounce), stale-answer guard. - [x] `vfmt.rainbowBeginEnd` (default true), honoured live by a configuration-change listener. - [x] `smoke.js` drives `vfmt/scopePairs` against a nested-begin + fork fixture and asserts the depths. - [x] **M5:** wire `depth` counts only enclosing rainbow pairs, so a scope the rainbow hides cannot shift the colour of one it shows. - [ ] Not done, deliberately: no check that a labeled `end : outer` agrees with its `begin : outer`. That is a lint rule with its own fix and its own opinion, not part of matching. - [ ] Not done, deliberately: nothing is reported for an unbalanced file that the parser accepts. See the gate, above and below. ## Work log ### 2026-08-24 — M2: the matcher, documentHighlight, missing-closer warnings **`pairs.rs`.** One pass over `Document.tokens`, one stack, no recursion (so nothing here can join the parser in the stack-depth conversation) and no `unwrap`. `RULES` is a flat table of 21 openers and their closers; `fork` is the only one with more than one (`join`, `join_any`, `join_none`), and the first entry is the one the warnings name. **Two decisions worth recording.** 1. *Recovery does not cascade.* A closer searches the stack from the top down for a frame it can close. If it finds one below the top, the frames above it are reported as unclosed and it matches; if it finds nothing, it is reported on its own and the stack is left completely alone. Popping the top blindly would pair `begin` with `endmodule` and then report the module unclosed — two wrong answers for one missing keyword, and the rainbow would lose every colour below the mistake. `a_wrong_closer_does_not_pop_the_frame_it_does_not_match` and `a_stray_end_matches_nothing_and_disturbs_nothing` pin both halves. 2. *`highlights` returns `Option`, and `None` becomes JSON `null`.* An empty array is a positive claim — "no occurrences of this anywhere" — and VS Code honours it by drawing nothing, so answering `[]` for every cursor that is not on a `begin` would cost the user their ordinary word highlighting everywhere in the file. Declining hands the editor back its own behaviour. The cursor is treated as being on a keyword from its first byte to one past its last, so `|end` and `end|` both match; keyword spans never touch, so the extra byte cannot claim a neighbour. **The gate.** `missing_end_diagnostics` returns nothing at all unless `doc.diagnostics` is non-empty. The rationale is in the module doc: a token-stream matcher cannot see `` `ifdef `` arms or macro bodies, so telling a user their *working* file is unbalanced is a failure mode this feature may not have. `the_gate_alone_suppresses_the_warnings` proves the gate is load-bearing rather than decorative — it takes a buffer the matcher genuinely finds unbalanced, clears the parse diagnostics on it, and asserts the answer goes empty while `analyze` still reports the unmatched opener. **Corpus sweep — the part that changed the code.** A temporary test (added, run, removed; it is not in the committed file) ran `Document::new` + `analyze` over all 860 corpus files and reported every file that parses cleanly yet looks unbalanced to the matcher. First run: **7 false positives out of 840 clean-parsing files**, every one of them a `function` reported unclosed, and every one of them the same construct — ```systemverilog covergroup rx_fifo_level_cg with function sample(int lvl, bit rst); ``` `with function sample(...)` declares the covergroup's sample method in the covergroup's own header. There is no `endfunction`; the `endgroup` closes everything. It appears in every UVM coverage class in the corpus (uart, ibex icache, the whole of `dv_base_reg`) and it is not in the plan's hazard list — reading the LRM would not have caught it, running the corpus did. One guard (`"function" => !is_keyword(prev, "with")`) plus `a_covergroup_sample_method_opens_nothing`. Second run: **840 clean files, 11 062 matched pairs, max depth 13, 0 false positives.** **Deviations from the plan, all recorded above and each with a test.** - `checker`/`endchecker` **dropped** from the pair set: `vlog_parser` does not lex them as keywords, so matching them would mean matching identifiers. - Four guards added beyond the plan's list, three of them for constructs the plan did not mention: `assert property (` / `cover sequence (` (an assertion is not a declaration — this one is unavoidable, SV assertions are everywhere), `disable fork;` / `wait fork;` (idiomatic UVM), `module m (interface bus)` (generic interface port), and `covergroup … with function` (from the sweep). Two of them — the generic interface port and `interface class` — cover constructs `vlog_parser` cannot parse yet, so today they only matter for a file that is already failing; they cost one condition each and stop the matcher from adding a second, wrong complaint on top of the parser's. - The plan's `clocking` fallback ("if this gets hairy, drop clocking") was not needed: two tokens of lookahead separate `default clocking cb;` from `clocking cb @(posedge clk);`, and both shapes are tested. - `the_warnings_are_capped` uses 25 *flat* stray `end`s rather than 41 nested `begin`s. The nested version overflowed the test thread's stack inside the **parser** — `docs/features/recursion-limit/README.md` documents that the parser's 64-level budget needs the 8 MiB main-thread stack and that a spawned thread must be given one, and a `cargo test` thread gets 2 MiB. Nothing to do with this module; the flat shape tests the same cap without inviting it. **Wiring.** `main.rs`: `document_highlight_provider` advertised, module declared, capability test extended. `server.rs`: one arm in the request match. `diagnostics.rs`: one line in `all()`, between the parse errors and the lint warnings, with the reason in the doc comment. Nothing else in the crate moved, and no file outside `crates/vfmt_server/` was touched. **Tests.** `cargo test -p vfmt_server`: 162 unit (was 130) + 7 e2e (was 6), all green. Full workspace: 937 passed, 0 failed. `cargo fmt --all` clean, `cargo clippy --all-targets` clean. The one `#[allow]` in the new code is on `Pair::depth`, with a comment naming the milestone that removes it. ### 2026-08-24 — M3: `vfmt/scopePairs` and the extension's rainbow **Server.** `Pair` gained a `keyword` field (the opener as written) so a consumer can take a subset without the engine having to know about subsets; `scope_pairs` filters on it and converts to LSP `Range`s. That field is also what let the `#[allow(dead_code)]` on `Pair::depth` go — both fields are now read by shipping code, and the crate has no `#[allow]` left in this module. The handler is one arm in `server.rs`, matched on the method name rather than through an `lsp_types::request` type because the method is ours. **Three decisions worth recording.** 1. *Depth is not renumbered after filtering.* A `begin` directly inside a `module` reports depth 1, because the module frame was open when it was pushed. The rainbow only needs nesting *differences*, and renumbering would cost a pass and change nothing on screen. Written down because "why does my outermost block get colour 2?" is otherwise a mystery. **— Reversed by M5 (2026-08-24): this was the bug. See that entry.** The reasoning above is wrong in its last clause: renumbering changes plenty on screen, because a filtered-out scope silently consumes a colour level. 2. *Only `begin`/`end` and `fork`/`join*` go on the wire.* The engine matches twenty-one scopes; nineteen are dropped here. Colouring `module`/`endmodule` tints a keyword pair the user never wonders about, and letting `case` into the ladder shifts every `begin` inside it one colour, which reads as deeper nesting than the code has. 3. *The extension guards against its own staleness.* `paint` records `document.version` before the request and drops the answer if it changed while in flight. The debounce reduces how often that happens; it cannot prevent it, and a decoration painted at a pre-edit offset is worse than no decoration. **Extension.** Six `TextEditorDecorationType`s, colour-only, each bound to `vscode.ThemeColor('editorBracketHighlight.foregroundN')` so the palette is whatever the user's theme already uses for brackets — no colours invented here, nothing to clash. Repaint on active-editor change, visible-editors change (splits, tab drags) and document change on a 250 ms debounce. Turning `vfmt.rainbowBeginEnd` off repaints with empty range lists, which is how a decoration type is removed — so "off" takes effect immediately in both directions rather than "after a reload". Closing an editor needs no handler: VS Code disposes its decorations with it, and the types themselves are in `context.subscriptions`. A failed request leaves the previous colours alone rather than blanking the file, since the language client already reports a server that will not start, in its own channel. **Corpus sweep, again** (temporary test, run and removed, as in M2): all 860 files through `scope_pairs`. **8 146 block pairs, max depth 13, 0 malformed ranges** (every `open` before its `close`, every range non-empty), and the timing above. No behavioural change from M2 — the `keyword` field is additive — but the new surface is the one that reaches the screen, so it got its own pass. **Deviations from the plan.** One, and it is an addition: the plan put scopePairs coverage in `smoke.js` only, and it is also asserted in `tests/e2e.rs` (one request appended to the existing scopes test). `smoke.js` is run by hand before packaging; the routing of a custom method is exactly the kind of thing that breaks silently, so it is worth having in `cargo test` too. Otherwise the milestone is as specified. **Verification.** `cargo fmt --all` clean, `cargo clippy --all-targets` clean (0 diagnostics), `cargo test --workspace` **944 passed, 0 failed** (168 unit in this crate, up from 162; 7 e2e). `node smoke.js ../../target/debug/vfmt-server` against a freshly built binary: OK. The smoke assertion was mutation-checked — changing the expected depths to `[9,9,9]` fails with `got [1,2,1]`, so it is live rather than vacuous. `npx @vscode/vsce ls` still accepts the manifest. `node --check` on both JS files. ### 2026-08-24 — M5: depth counts only the pairs the rainbow shows **The bug, in the user's words:** *"for blocks that don't have begin/end, like inside of a case statement, I can see an invisible begin/end being highlighted."* Nothing was actually drawn on the `case` — the lead's probe confirmed every returned range sits on a real keyword — but the `begin` inside it was painted one colour deeper than a sibling `begin` outside it, so the eye read the missing level as a hidden pair. `Pair::depth` counted every open frame, and nineteen of the twenty-one scope kinds never reach the wire. **The fix.** `depth` now counts only enclosing frames whose opener is in `RAINBOW_KEYWORDS`, computed at push time by scanning the stack: ```rust let depth = stack.iter().filter(|f| is_rainbow(f.rule.open)).count() as u32; ``` Scanning rather than keeping a running counter is deliberate. The stack is seven frames deep at worst across the whole corpus, so the cost is nothing, and a counter would have to be unwound correctly by the mismatch recovery in `close`, which pops frames out of the middle — a second thing to get right for no gain. `RAINBOW_KEYWORDS` moved up beside `RULES` and is now read by both the counter and `scope_pairs`' filter through one `is_rainbow` helper; it used to be declared next to `scope_pairs` and duplicated in spirit by the counter's "count everything" rule. **One list, two jobs** — a scope is counted if and only if it is sent, which is the invariant that keeps this bug from returning. **Depths now.** Outermost `begin` = 0. `begin` inside a `case` at module level = 0, the same as a sibling `begin` outside the case — that is the fix. `begin` in `begin` = 1. `begin` in `fork` in `begin` = 2. **Behaviour deliberately unchanged.** `documentHighlight` and the missing-closer diagnostics never read `depth` — they use the pair ranges and the unmatched lists — so they are untouched by construction, and every one of their tests passed without edits. Demonstrated rather than asserted: reverting the one line back to `stack.len()` fails **exactly six** tests, all of them depth assertions (`a_module_with_nested_begins_matches_every_pair`, `a_scope_the_rainbow_hides_does_not_shift_the_colour_of_one_it_shows`, `no_hidden_scope_counts_toward_the_depth`, `only_begins_and_forks_stack_up_the_colours`, `scope_pairs_depths_nest_and_forks_are_included`, `the_scope_pairs_wire_shape_is_what_the_extension_reads`) and **none** of the highlight or diagnostic tests. That one experiment proves both halves at once: the new tests really do catch the bug, and nothing outside depth moved. **Tests.** 194 unit (was 190) and 9 e2e in this crate. Updated: `a_module_with_nested_begins_matches_every_pair` (`[0,1,2]` → `[0,0,1]`), `scope_pairs_depths_nest_and_forks_are_included` (`[1,2,1]` → `[0,1,0]`), the pinned-JSON wire test (`depth: 1` → `0`), the e2e scopePairs assertion (`2` → `1`), and `smoke.js` (`[1,2,1]` → `[0,1,0]`). Added four: - `a_scope_the_rainbow_hides_does_not_shift_the_colour_of_one_it_shows` — the reported bug as a fixture: two sibling `begin`s, one of them wrapping a `case` that wraps a third. Asserts `[0, 0, 1]`; before M5 this was `[0, 0, 2]`. - `no_hidden_scope_counts_toward_the_depth` — eight wrappers (module, package, generate, task, class, interface, program, specify), each around a `begin` that must still come out at depth 0. - `only_begins_and_forks_stack_up_the_colours` — `begin`/`fork`/`begin` is three real levels. - `the_depth_counter_and_the_wire_filter_read_the_same_list` — walks `RULES` and asserts counted-iff-sent, so a new rule that forgets the question fails here rather than on a user's screen. **Corpus sweep** (temporary, run and removed, as in M2/M3): all 860 files. **wire pairs 8 146 — byte-identical to M3's sweep**, so nothing changed about *which* pairs are sent; **max wire depth 13 → 7**; 0 malformed ranges. The depth histogram is a clean decay — `{0: 2881, 1: 2424, 2: 1689, 3: 700, 4: 278, 5: 120, 6: 41, 7: 13}` — and the populated depth-0 bucket is the fix made visible: under M3 almost every `begin` sat inside a `module`, so depth 0 was nearly empty and the whole palette was rotated by one. **Also closed here** (M4 QA finding, accepted by lead review): `a_pushed_exclude_rebuilds_the_index_mid_session` in `tests/e2e.rs` proved the rescan half of `reindex()` but not the republish half, because the session had no open buffer for the republish loop to iterate. It now opens one and counts `publishDiagnostics` notifications for it: **exactly 3** — one for the `didOpen`, one per *changed* exclude — and the session pushes the same exclude value twice in a row to assert that the no-op push publishes nothing and does not rescan. Mutation-checked (expecting 4 fails with `left: 3`). **Verification.** `cargo fmt --all` clean, `cargo clippy --all-targets` clean, `cargo test --workspace` green, `node smoke.js` against a freshly built `target/debug/vfmt-server` OK. ## QA log ### 2026-08-24 — QA round 1 (M2): pairs.rs, documentHighlight, missing-end gate Charter items 1–3 and 6 from `editor_features_plan.md` (4/5 are M1/M3, out of scope this round). Verdict: **PASS**, no blocking findings. **Method.** Read `pairs.rs` end to end against the hazard list in the plan and the guard table in *Handshakes* above; ran the dev's own 162 unit + 7 e2e tests; then attacked with two throwaway additions to `pairs.rs`'s own `#[cfg(test)] mod tests` (same crate access as the real code, since `vfmt_server` is bin-only and has no lib target for an external test to link against) — run, read, and **removed before this log was written**; nothing below is in the committed tree. **1. Corpus sweep, reproduced independently.** Walked `corpus/` (the same 860-file, gitignored directory the dev used), tokenized each file, and for every file whose `Document::new` produced zero parse diagnostics, ran `pairs::analyze` and asserted zero unmatched opens/closes. Result: **860 files scanned, 840 clean-parsing, 11 062 matched pairs, max depth 13, 0 false positives** — exact match to the dev's reported numbers in the Work log above. **2. Targeted attacks beyond the dev's own test list**, each run as a single probe printing `(parse_diags_empty, pairs.len(), unmatched_open, unmatched_close)`: | Probe | Result | Verdict | |---|---|---| | `virtual interface class IC; ... endclass` (plan mentions this combination but the dev's tests only cover `interface class` without `virtual`) | clean matcher: `class..endclass`, no unmatched. Parser itself does not yet accept this construct (`parse_diags_empty=false`) | correct — gate stays consistent with the parser's own limits, and even so the matcher reports nothing false | | `assert property (...) begin ... end else begin ... end` — pass/fail action blocks, a common real-world idiom the plan/tests don't mention | parses clean, 3 pairs (module + both action blocks), 0 unmatched | correct — confirms the `property`-only guard doesn't leak into ordinary `begin`/`end` inside the assertion statement | | `covergroup cg with function sample(int lvl) extends base_cg;` (the corpus-found guard, with `extends` appended) | parses clean, 0 unmatched | correct — guard checks only the token immediately before `function`, unaffected by what follows | | `typedef class C;` forward decl followed by an unrelated `class D` before the real `class C` (package-scoped, three classes total) | parses clean, 3 pairs, 0 unmatched | correct — confirms the prototype flag clears at `;` and doesn't bleed into the next real declaration | | `default clocking cb @(posedge clk); endclocking` — the body form written with `default` on the *same* line as a real event (not a bare reference) | parses clean, 2 pairs incl. `clocking..endclocking` | correct — the two-token lookahead (`ident` then `;`) correctly tells this apart from `default clocking cb;` | | `` `define DO_BEGIN begin `` then invoking `` `DO_BEGIN `` in place of a real `begin`, leaving a real `end` orphaned | parser fails (as expected — the file really is broken without macro expansion); matcher: 1 pair (module), `end` correctly reported as the only unmatched closer, `begin` inside the `` `define `` line does **not** register as a keyword | correct — confirms directive lines are opaque in full, body text included, not just macro invocations | | Same, mirrored (macro supplies the `end`, real `begin` left open) | parser fails; matcher reports `begin` as the sole unmatched opener | correct, symmetric to the above | | `` `ifdef ``/`` `elsif `` arms with two `begin`s and one `end` (asymmetric arms, the literal hazard the charter names) | parser fails (the raw token stream really is unbalanced, since this server does not evaluate conditions — confirmed at `crates/vlog_parser/src/parser.rs:5482`); matcher correctly reports one `begin` unmatched, matching reality of the raw text | correct — this is not a case of "clean parse but matcher confused"; the file is genuinely malformed as written, both parser and matcher agree | | `` `ifdef ``/`` `else `` arms where one arm uses `begin`/`end` for two statements and the other is a single bare statement (a very common real idiom) | parser fails — not because of `begin`/`end`, but because the second arm's statement lands illegally at module-item scope once both arms are read literally; matcher itself finds 0 unmatched | correct — the parse failure is a pre-existing, unrelated diagnostic-quality question (bare statement outside a procedural block), not a `pairs.rs` defect; no missing-end warning is produced either way | | Labeled `begin : a ... end : totally_different_name` | parses clean, matches on keywords alone as designed | correct, matches the documented "labels are not part of the match" assumption | No probe produced a file that parses clean yet the matcher calls unbalanced — the property under test in charter item 3 held in every case tried, not only the ones the dev's own suite encodes. **3. Incidental, non-blocking finding (not a defect in this feature):** `vlog_parser` does not yet accept `virtual interface class IC; ... endclass` or `global clocking cb;` (only `default clocking cb;` was checked by the dev). Both are pre-existing parser gaps, not `pairs.rs` bugs — the matcher behaves correctly on both regardless, and the diagnostics gate means neither can ever produce a wrong warning. Filed as an FYI for whoever next touches `vlog_parser`'s grammar coverage, not a blocker here. (`global clocking` is the one of the two the dev's guard table doesn't already list — worth a line if the table is touched again, not worth blocking on.) **4. `crates/vfmt_server/src/server.rs:109-121`** (`DocumentHighlightRequest` handler): `self.offset(&uri, position)` internally calls `self.workspace.document(&uri)`, and the closure passed to `.and_then` calls `self.workspace.document(&uri)` a second time. Harmless — `Document::new` isn't re-run, it's a cheap map lookup, and correctness is unaffected either way (the second call cannot see a different document than the first inside one synchronous request handler) — but it is two lookups where one would do. Non-blocking style nit, left as-is per "you verify, you don't redesign." **5. Invariants.** - `cargo test --workspace`: every crate green, 0 failures (162 unit + 7 e2e in `vfmt_server` alone, matching the Work log's count exactly). - `cargo fmt --all -- --check`: clean. - `cargo clippy --all-targets --workspace`: clean, no warnings. - `git diff --stat` (working tree vs `HEAD`): only `crates/vfmt_server/{diagnostics,main,server}.rs` and `crates/vfmt_server/tests/e2e.rs`, plus the untracked new `crates/vfmt_server/src/pairs.rs` and `docs/features/editor-scopes/`. No formatter, `verify.rs`, or `vlog_parser` files touched, confirmed by listing (`git status`) as well as the stat diff. - No `unwrap()`/`expect()`/`panic!` in `pairs.rs`, `server.rs`, or `diagnostics.rs` outside `#[cfg(test)]`, checked directly (grep over the code above each file's test module). - The one `#[allow(dead_code)]` (`Pair::depth`) carries an explanatory comment, satisfying CLAUDE.md's rule. **Verdict: PASS.** No blocking findings. Two informational, non-blocking notes recorded above (a pre-existing `vlog_parser` grammar gap unrelated to this feature, and a redundant-but-harmless double document lookup in `server.rs`). ### 2026-08-24 — QA round 2 (M3): `vfmt/scopePairs` and the extension rainbow Charter items 1, 4, 5 (repeat, unregressed) and 6 from `editor_features_plan.md` for this dispatch: the wire shape, `scope_pairs` correctness, `extension.js` review, `smoke.js`, invariants, and an M1/M2 unregression spot-check. Item 2 (documentHighlight attack surface) is M2 and was covered in round 1; not re-audited except where M3 touched shared code (it did not — `Pair::keyword` is additive). Verdict: **PASS**, no blocking findings. **1. Wire shape.** Ran `cargo test -p vfmt_server`: 168 unit + 7 e2e, all green. Read `the_scope_pairs_wire_shape_is_what_the_extension_reads` (`crates/vfmt_server/src/pairs.rs:915`) — it pins the full response as literal JSON (`open`/`close` LSP `Range`s over the keyword, `depth`), matching the Handshakes section word for word. Confirmed each documented property against its own test, not just the pinned one: - UTF-16 ranges: `scope_pairs_ranges_are_utf16_and_cover_the_keyword` (`pairs.rs:882`) — a 2-byte `é`/`✓` comment before `begin` and the column lands at 10, not shifted by the extra bytes. - Only `begin`/`end` + `fork`/`join*`: `scope_pairs_carries_only_block_delimiters` (`pairs.rs:858`) — module/case/function all matched by the engine (4 pairs) but only the 1 `begin..end` survives the filter. `RAINBOW_KEYWORDS` is `["begin", "fork"]`; since `Pair::keyword` stores the opener, this correctly admits `fork` closed by any of `join`/`join_any`/`join_none`. - Depth not renumbered after filtering: `scope_pairs_depths_nest_and_forks_are_included` (`pairs.rs:872`) — module (depth 0, filtered out) then begins at depth 1 and 2; e2e test at `tests/e2e.rs:576` independently pins depth 2 for a `begin` nested two frames deep in an unbalanced file. - Unmatched keywords absent: `scope_pairs_omits_a_pair_that_never_closed` (`pairs.rs:895`) and the e2e test (only the closed inner `begin` is offered, 1 pair, from a file with one unclosed `begin`). - Unopened doc → `null`: no dedicated unit test exists for this specific handler (matches the pattern for every sibling handler in `server.rs` — none of them have one either, so this is not an M3-specific gap). Verified directly against the built binary instead: spawned `vfmt-server`, sent `vfmt/scopePairs` for a URI never opened via `didOpen`, got back `{"jsonrpc":"2.0","id":2,"result":null}` with no error. Matches `server.rs:165-170`. **2. `scope_pairs` correctness — independent corpus sweep.** Added a throwaway `#[cfg(test)]` (same discipline as round 1: run, read, removed before this log was written — not in the committed tree) walking `corpus/` and calling `scope_pairs` on every file that lexes, checking every emitted range is non-empty and `open` starts before `close` starts. Result: **859 files scanned, 8 146 pairs, max depth 13, 0 malformed** — an exact match to the dev's Work Log numbers (`8 146 block pairs, max depth 13, 0 malformed ranges`). Depths and UTF-16 columns already covered per-case above; nothing in the sweep found a malformed range or a panic. **3. `extension.js` review** (`editors/vscode/extension.js`), read in full against the round-2 charter's specific worry list: - **Decoration lifecycle**: 6 `TextEditorDecorationType`s built once in `activate` (line 64-68), color-only (`ThemeColor` per index, no `fontWeight`), pushed into `context.subscriptions` (line 69) — disposed automatically on deactivate, which also removes their decorations from every editor without extra code. - **Staleness guard**: `askedAbout = document.version` (line 142) is captured *before* `await client.sendRequest(...)` (line 147) and compared *after* (line 159) — correct order, confirmed by reading the `async` control flow directly; a version bump during the await drops the stale answer and relies on the debounce the edit already scheduled. - **Debounce**: `scheduleRepaint` (line 121) clears the pending timer before setting a new one; `deactivate` (line 107) clears it too, so no dangling `setTimeout` after unload. - **Setting-off path**: `onDidChangeConfiguration` (line 83) updates `rainbowEnabled` and calls `repaintVisible()` synchronously (no debounce); `paint()` skips the request entirely when `rainbowEnabled` is false and still runs `setDecorations([])` for every bucket (line 167-169), which is how a decoration type is cleared — confirmed this is unconditional (outside the `if (rainbowEnabled)` block), so already-open editors really lose their colours immediately, not after a reload. - **No request for non-verilog docs**: `repaintVisible` (line 127) and the document-change listener (line 81) both gate on `isVerilog()` before scheduling or painting. - **Listener leaks**: client, all 6 decoration types, and the 4-item listener array are all pushed to `context.subscriptions` (lines 59, 69, 73-90) — nothing is registered outside that list. - **Client/server not ready or request rejects**: `client.start().then(ok, () => {})` (line 96-102) swallows a startup rejection without throwing; `paint`'s `try { await client.sendRequest(...) } catch { return; }` (line 146-150) swallows a rejected/thrown request the same way. Neither path produces an unhandled rejection. No defects found in `extension.js`. **4. `smoke.js`.** Built `target/debug/vfmt-server` fresh (`cargo build -p vfmt_server`), ran `node smoke.js ../../target/debug/vfmt-server` from `editors/vscode/`: **OK**. Mutation check: changed the expected depths assertion from `[1, 2, 1]` to `[9, 9, 9]`, reran — failed as expected (`expected depths [1,2,1] ..., got [1,2,1]`, exit code 1), then reverted; `md5` of `smoke.js` before and after the round-trip is identical (`436a569e05a23fb766813e0cc15d2de8`), so the file is byte-for-byte what it was. `node --check` on both `extension.js` and `smoke.js`: clean. **5. Invariants.** - `cargo test --workspace`: 944 passed, 0 failed (168 unit + 7 e2e in `vfmt_server`, matching the Work Log's count). - `cargo fmt --all -- --check`: clean. - `cargo clippy --all-targets`: clean, no warnings. - `git diff --stat` vs `HEAD`: `crates/vfmt_server/{pairs,server}.rs`, `crates/vfmt_server/tests/e2e.rs`, `docs/features/editor-scopes/README.md`, `editors/vscode/{README.md,extension.js,package.json,smoke.js}`. No `vlog_formatter`/`vlog_parser`/`verify.rs` paths touched. - `node -e "JSON.parse(...)"` on `editors/vscode/package.json`: valid; the new `vfmt.rainbowBeginEnd` setting and the M1 `contributes.snippets` block are both present and unchanged in shape. `npx @vscode/vsce ls` accepts the manifest and lists `package.json`, `extension.js`, `README.md`, `snippets/verilog.json`, `snippets/systemverilog.json` — no error. - No `unwrap()`/`expect()`/`panic!` in the new `pairs.rs`/`server.rs` code outside `#[cfg(test)]` (grepped directly). No `#[allow]` remains in `pairs.rs` — the dev's removal of the `Pair::depth` `#[allow(dead_code)]` is confirmed; nothing new was added in its place. **6. M1/M2 unregression spot-check.** `cargo test -p vfmt_server` (168 unit) includes the full M1 snippet-adjacent and M2 `pairs.rs`/`documentHighlight`/ missing-end suites from round 1, all still passing; `package.json`'s `contributes.snippets` block is byte-identical to what round 1 saw (verified by reading it directly, not diffed against round 1 since M1 was committed before this dispatch). No M2 test was touched by this diff except the two lines the e2e test needed to add a `vfmt/scopePairs` frame after the existing `documentHighlight` assertions. **Verdict: PASS.** No blocking findings, no non-blocking findings either — the unopened-doc-→-null path lacking a dedicated unit test is a pattern that predates this feature (every sibling handler in `server.rs` shares it) and was independently verified against the running binary, so it is not filed as a gap specific to this work. ### 2026-08-24 — QA round 4 (M5): rainbow depth renumbering + M4 gap closure Charter: `editor_features_plan.md`'s M5 section (the user-reported "invisible begin/end" bug fix) plus the M4 exclude-republish gap the lead accepted last round. Scope: uncommitted working tree only, diff vs `9a3a92c` — `crates/vfmt_server/src/pairs.rs`, `crates/vfmt_server/tests/e2e.rs`, `editors/vscode/smoke.js`, `docs/features/editor-scopes/README.md`. Verdict: **PASS**, one non-blocking finding (item 2 below). **Method.** Same discipline as rounds 1–3: throwaway additions to `pairs.rs`'s own `#[cfg(test)] mod tests` for attacks that need the crate's private API, run, read, and removed before this entry was written — each removal verified `md5`-identical to the file's state before the addition. All three files (`pairs.rs`, `tests/e2e.rs`, `smoke.js`) were confirmed byte-identical (`md5`) after every mutation-and-restore cycle below; final `git diff --stat` matches the four files in the charter exactly, same line counts as at dispatch. **1. Adversarial depth probes**, beyond the dev's own eight-wrapper table and the reported-bug fixture. Added four throwaway tests, all passed: - `begin` inside `function` inside `module` → `[0]`. Neither wrapper counts. - The generate-for hazard the charter calls out by name: a *named* generate block (`for (...) begin : g ... end`) is itself a real `begin` keyword and therefore **is** a rainbow frame — it is not the same thing as the enclosing (uncounted) `generate`. `generate → for (...) begin : g → if (i == 0) begin` gives `[0, 1]`: the named block at 0, a begin nested inside it at 1. Checked this against both the dev's tests and the README (`docs/features/editor-scopes/README.md:415`, the `no_hidden_scope_...` case list) — the dev's own `generate` case is an *if*-generate with a single anonymous `begin` (`no_hidden_scope_counts_toward_the_depth`, `crates/vfmt_server/src/pairs.rs:944`), which never exercises a *second* begin nested inside a named generate-for block. No inconsistency between the dev's tests and the README, though: the depth logic is opener-keyword- based, not context-based, so a generate-for's named begin behaves identically to any other begin regardless of what encloses it. The dev's table and the README's claims both hold; the scenario was simply untested, and now is (as a throwaway, not left in the tree — see below). - `fork` inside `case` inside `begin` → `[0, 1]`: the case is hidden, the fork sees one enclosing rainbow frame (the begin). - Deeply mixed: `begin` / sibling `begin` inside a `function` (itself inside a hidden `function`, wrapping `case` → `fork` → `begin`) → `[0, 0, 1, 2]`. No inconsistency found; removed before writing this entry (`pairs.rs` `md5` before/after: `975e8a4a80530309841415bd403cc71d`, both times). **2. The invariant test — mutation-checked, and it is weaker than its name claims. Non-blocking, filed as a finding rather than fixed directly** (it would mean rewriting the test's structure, past "small unambiguous fix"). `the_depth_counter_and_the_wire_filter_read_the_same_list` (`crates/vfmt_server/src/pairs.rs:978-994`) has two parts: a loop over `RULES` comparing `is_rainbow(rule.open)` against `RAINBOW_KEYWORDS.contains(&rule.open)` — which is **tautological**, since `is_rainbow` is defined as exactly that `.contains` call (`pairs.rs:74-76`); the loop can never fail regardless of what `analyze` or `scope_pairs` actually do — and a trailing pinned literal, `assert_eq!(RAINBOW_KEYWORDS, ["begin", "fork"], ...)`, which is the only line that has ever caught anything. - Mutation A: added `"case"` to `RAINBOW_KEYWORDS` and, separately, changed `scope_pairs`'s filter to a disconnected hardcoded `["begin", "fork"].contains(...)` (recreating the pre-M5 shape: a keyword counted by `analyze` but not sent by `scope_pairs`). Result: the test **did** fail — but at the trailing pinned assert (`left: ["begin", "fork", "case"], right: ["begin", "fork"]`, `pairs.rs:993`), not at the per-rule loop. The loop ran to completion without incident. - Mutation B, isolating the loop from the pinned literal: left `RAINBOW_KEYWORDS` at `["begin", "fork"]` (so the trailing assert cannot fire) and made only `analyze`'s counter diverge — `stack.iter().filter(|f| f.rule.open == "begin")`, silently dropping `fork` from what gets counted, without touching `scope_pairs`'s filter or `is_rainbow`. Result: `the_depth_counter_and_the_wire_filter_read_the_same_list` **passed** (both its loop and its pinned assert are blind to this, since neither calls `analyze` or `scope_pairs`). The only failure was an ordinary depth test, `only_begins_and_forks_stack_up_the_colours` (`pairs.rs:967-975`), which caught it because it happens to nest a fork under a begin. - **Conclusion:** the charter's premise — "confirm it actually fails if a keyword is added to `RAINBOW_KEYWORDS` without the filter following" — holds for the specific case where the two functions stay wired through `is_rainbow` and only the *set itself* changes (mutation A), but that protection comes entirely from the pinned literal, which will need editing by hand on every legitimate future addition to the rainbow — exactly the "canary, not proof" pattern. It does **not** hold for a regression where `analyze` and `scope_pairs` are rewired to read from different sources independently of `RAINBOW_KEYWORDS` (mutation B) — the comment's claim that this is "asserted over the whole rule table" and that a divergence "fails here" is not accurate; the real backstop for mutation B's shape is coincidental coverage from the ordinary depth tests, not this test. Today's single-shared-list design (`is_rainbow` called from both sites) makes mutation B's shape unlikely to arise by accident, but the test as named and commented would not catch it if it did. Suggest either renaming/re-scoping the test to describe what it actually checks (a pinned-value canary on `RAINBOW_KEYWORDS`), or strengthening the loop to call `analyze` and `scope_pairs` on a per-rule fixture and compare their outputs directly rather than comparing `is_rainbow` to itself. Left as a finding, not fixed, since either direction is a design choice for the dev/lead. - Both mutations reverted; `pairs.rs` `md5` confirmed `975e8a4a80530309841415bd403cc71d` before, during isolation, and after. **3. Mutation-check the core depth line.** Reverted `stack.iter().filter(|f| is_rainbow(f.rule.open)).count()` (`pairs.rs:157`) to `stack.len() as u32`. `cargo test -p vfmt_server` (unit): **exactly six** failures, all depth assertions, names matching the dev's Work Log list exactly (`a_module_with_nested_begins_matches_every_pair`, `a_scope_the_rainbow_hides_does_not_shift_the_colour_of_one_it_shows`, `no_hidden_scope_counts_toward_the_depth`, `only_begins_and_forks_stack_up_the_colours`, `scope_pairs_depths_nest_and_forks_are_included`, `the_scope_pairs_wire_shape_is_what_the_extension_reads`) — 188 unit tests still passed. The e2e suite adds one more failure under this mutation, `scope_highlights_and_the_missing_end_warning_round_trip_over_the_wire`, but confirmed with `--nocapture` that it panics specifically at `tests/e2e.rs:590` (the `pairs[0]["depth"]` assertion, `left: Number(2), right: 1`) — every `documentHighlight` assertion earlier in that same test runs and passes first. So "no documentHighlight or missing-end diagnostic test moves" holds exactly as claimed; the dev's "six" was scoped to the unit suite, and the one e2e test that also carries a depth assertion fails only on that line. Reverted; `pairs.rs` `md5` confirmed unchanged. **4. M4 gap closure — the republish assertion.** `a_pushed_exclude_rebuilds_the_index_mid_session` (`crates/vfmt_server/tests/e2e.rs`) passes as committed. Mutation-checked the new count: changed `assert_eq!(publishes, 3, ...)` to `4` (`tests/e2e.rs:766`) — failed as expected (`left: 3, right: 4`); reverted, `md5` confirmed unchanged (`ce62cbe2d094214d0e132cda9c252507` before and after). **5. Corpus sweep, reproduced independently.** Same throwaway-test discipline as rounds 1–2: walked the 860-file `corpus/` directory (`.v`/`.sv`/`.vh`/`.svh`), ran `scope_pairs` on every file that lexes, and checked every emitted range for a sane open ≤ close ordering. Removed before writing this entry. **Result: scanned 860, wire pairs 8 146 — matches M3's sweep exactly, matches the dev's claim — max depth 7 (was 13 under M3/M4), 0 malformed ranges.** Histogram (depth → pair count): `{0: 2881, 1: 2424, 2: 1689, 3: 700, 4: 278, 5: 120, 6: 41, 7: 13}` — identical to the dev's reported histogram in the Work log. `pairs.rs` `md5` confirmed `975e8a4a80530309841415bd403cc71d` after removal, matching its state before the sweep test was added. **6. `smoke.js` and invariants.** - Built `target/debug/vfmt-server` fresh (`cargo build -p vfmt_server`), ran `node smoke.js ../../target/debug/vfmt-server`: **OK**. Mutation check: changed the expected-depths literal from `[0, 1, 0]` to `[9, 9, 9]`, reran — failed as expected (`smoke: FAIL — expected depths [0,1,0] ..., got [0,1,0]`, exit code 1 confirmed separately from the pipeline's own exit code), reverted; `md5` of `smoke.js` before and after is identical (`2092dbb2331bd040932f3ccb76246398`). - `node --check` on both `smoke.js` and `extension.js`: clean. - `cargo test --workspace`: every crate green (194 unit + 9 e2e in `vfmt_server`, matching the Work Log's count), 0 failures, both before any mutation and again after every mutation was reverted. - `cargo fmt --all -- --check`: clean. `cargo clippy --workspace --all-targets`: clean, no warnings (re-checked after touching the two Rust files to defeat incremental-build caching). - `git diff --stat` vs `HEAD` (`9a3a92c`): exactly the four files in the charter, same shape as at dispatch — `crates/vfmt_server/src/pairs.rs`, `crates/vfmt_server/tests/e2e.rs`, `docs/features/editor-scopes/README.md`, `editors/vscode/smoke.js`. No `vlog_formatter`/`vlog_parser`/`verify.rs` path touched. - No `unwrap()`/`expect()`/`panic!` added outside `#[cfg(test)]` in the diff (grepped the diff hunks directly); no `#[allow]` added. **Verdict: PASS.** No blocking findings. One non-blocking finding (item 2): `the_depth_counter_and_the_wire_filter_read_the_same_list`'s per-rule loop is tautological and its real protection is a pinned-literal canary rather than a comparison of `analyze`'s and `scope_pairs`'s actual behavior against each other — worth a rename or a rewrite next time this test is touched, not blocking today's fix (which is correct and well covered by the ordinary depth tests). ## Review ### 2026-08-24 — lead review of M2 (after QA round 1) Read `pairs.rs` in full plus the four integration diffs. Approved and committed. Notes: - The non-cascading recovery rule and the parse-error gate are the two load-bearing decisions; both are stated in comments where they live and both are pinned by tests that would fail if either were "simplified". Good. - The `covergroup ... with function sample` guard coming from a corpus sweep rather than the plan is exactly why the sweep is worth its cost; keep sweeping in future rounds. - `randsequence` (LRM: closed by `endsequence`) is not in the pair set. Acceptable today — the parser rejects those files anyway, so the gate never lets a wrong warning out — but worth a line in Assumptions if the parser ever learns it. - QA's non-blocking note about the double `workspace.document` lookup in the `documentHighlight` handler is real but matches the surrounding handler style; not worth churn. ### 2026-08-24 — lead review of M3 (after QA round 2) Read `extension.js` in full, the `scope_pairs` additions, the `server.rs` arm and the `smoke.js` extension. Approved and committed. Notes: - The client-side staleness guard (`document.version` captured before the await, compared after, plus the visible-editor check) is the right shape, and "leave the old colours on a failed request" is the right failure mode for a cosmetic feature. - Not renumbering depth after filtering is fine and well documented; the rainbow reads differences only. - The wire-shape test pinning literal JSON is what makes the custom method safe to evolve; keep that pattern for any future custom request. ### 2026-08-24 — lead review of M5 (after QA round 4) Read the diff (one-line core change, the const hoist, tests, docs). Approved and committed. Notes: - M3's "depth reads differences only" reasoning — endorsed in the M3 review above — was wrong, and the user's report is the counterexample: a hidden scope between two begins is a difference the screen cannot explain. The corrected Assumptions bullet says this well. - QA's non-blocking finding on `the_depth_counter_and_the_wire_filter_read_the_same_list` is accepted as-is: the per-rule loop is tautological through `is_rainbow`, but the invariant it names is genuinely held by the trailing pinned-literal assert plus the ordinary depth tests (QA's mutation B was caught by `only_begins_and_forks_stack_up_the_colours`). Coverage is real; it just lives across tests rather than in the one with the name. Not worth restructuring now; noted so the next reader of that test knows.