forge
Explore
Log in

Don't you dare go Hollow

Close the last two gaps in the window guard, and admit the rest

Browse files at this commit

04265e90b84345b49eb785855fbb3612eeff83a9Ahmet Kaan GümüşParent: edc51b5
  • fix
    • close the last two gaps in the window guard, and admit the rest
Show full message
fix(engine): close the last two gaps in the window guard, and admit the rest

Two coverage gaps closed, one class documented as unmatchable, and a
third failure of this same guard found in the act of closing them.

**A `let` hid a struct literal.** The literal branch skipped any line
starting with `let `, so `let out_us = s.out_us;` was correctly a read
while `let tail = SubClip { in_us: cut, out_us: s.out_us, ..s };` -- a
plausible composer shape, and the shape `sub_clear` and `sub_open_room`
were written in before `set_window` existed -- went through green. The
exclusion is now per-occurrence and keyed on what FOLLOWS the name: `=`
is a local binding, `:` or `,` is a field. A tuple pattern
(`let (a, b) = ..`) is separated from a struct literal by the paren
rather than by the `let`, since the same comma means opposite things in
each.

**The walk skipped a file that never spelled the type.** Its filter was
`text.contains("SubClip")`, which is a name-based guess about which
files can reach the type -- the same mistake the hardcoded pair of file
names was, wearing a derived hat. A glob import and an alias defeat it
exactly as they defeated the list. The filter is gone: the walk now
opens EVERY `.rs` under `crates/` that is not test code, 86 files and
~77,600 lines, and the coverage floor moved with it (141 files and
~116,000 before `/tests/` and `mod tests` are cut).

**And the guard was silently asserting nothing.** While retuning that
floor, a clumsy edit deleted the `found.is_empty()` assertion -- the one
the whole test exists for. For a moment the test reported green while
`found` held a real offender, which is the fourth version of this guard
failing in the one way that looks exactly like success. Found by
instrumenting the walk rather than by reading the diff, which is the
only reason it was found at all. The assertion is back, with a comment
saying that if you retune anything here, check that line still exists.

**The unmatchable class, documented rather than chased.** `*a = *b;`,
`*a = other;`, `std::mem::swap(a, b)`, `a.clone_from(b)` and a macro
like `bump!(s.out_us, by)` all write a caption's window and none of them
spell the field name, so a field matcher returns nothing for all of
them. That is a property of the approach, not an oversight: a helper
that writes the field directly IS caught, and it is specifically the
whole-struct and macro forms that pass. The doc comment now names this
class FIRST, as the most likely route a real composer would take, ahead
of a rename of the fields, a writer inside a test, and a file outside
`crates/`. The five forms are pinned in a test asserted to be MISSED, so
the day one starts matching the test asks which side of the line moved
and the residual-risk list cannot quietly grow a claim the matcher has
not earned.

Guard verification, all from the tip, all red:

- the verifier's one-token `s.out_us += by(s.end(), to);` -> project.rs:5869
- a `let`-bound struct literal in place of `set_window` in `sub_open_room` -> project.rs:5807
- `regroup`'s two lines back to raw assignments -> project.rs:3491-3492
- a composer smuggled into `sweep.rs`, a third module -> sweep.rs:67
- a new module reaching the type by glob import and alias, never spelling it -> zz_glob_alias.rs:4
- clean -> green

`the_window_write_matcher_catches_the_ways_a_composer_hides` now pins
eight forms that must be caught (the five above plus `<<=`, a write
through an indirect `&mut`, and the shorthand), five reads that must not
fire, and five field-less forms asserted to be missed.

No production code changed: this is the `#[cfg(test)]` module only, and
all eight composers still route through `set_window`.
crates/engine/src/project.rsmodified+110 -23
@@ -10790,6 +10790,11 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10790 continue;10790 continue;
10791 }10791 }
10792 let is_binding = line.starts_with("let ");10792 let is_binding = line.starts_with("let ");
10793+ // `let (a, b) = ..` is a tuple pattern, not a struct literal: the
10794+ // commas there bind names. `let half = SubClip { frames: n, in_us,
10795+ // out_us, ..s };` is the opposite -- the same commas are shorthand
10796+ // fields -- and what separates them is the paren, not the `let`.
10797+ let tuple_pattern = line.starts_with("let (");
10793 for field in FIELDS {10798 for field in FIELDS {
10794 let access = format!(".{field}");10799 let access = format!(".{field}");
10795 if let Some(at) = line.find(&access) {10800 if let Some(at) = line.find(&access) {
@@ -10802,12 +10807,18 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10802 continue;10807 continue;
10803 }10808 }
10804 }10809 }
10805- // A bare name: a literal field, a shorthand, or a binding.10810+ // A bare name: a literal field, a shorthand, or a local
10806- // Skipped when a `.` or an identifier character precedes it --10811+ // binding. Skipped when a `.` or an identifier character
10807- // that is a read, not a field being set.10812+ // precedes it -- that is a read, not a field being set.
10808- if is_binding {10813+ //
10809- continue;10814+ // The `let` exclusion is per-occurrence and keyed on what
10810- }10815+ // FOLLOWS, not on the line. `let out_us = s.out_us;` names a
10816+ // local, so the `=` form is skipped; but `let tail = SubClip {
10817+ // in_us: cut, out_us: s.out_us, ..s };` is a struct literal
10818+ // behind a `let`, and an earlier version of this matcher
10819+ // skipped the whole line for being a `let` -- so that shape,
10820+ // which is exactly what a plausible composer looks like, went
10821+ // through green. Keyed on the follower, a `let` hides nothing.
10811 for (at, _) in line.match_indices(field) {10822 for (at, _) in line.match_indices(field) {
10812 let preceded_by_name = line[..at]10823 let preceded_by_name = line[..at]
10813 .chars()10824 .chars()
@@ -10817,7 +10828,10 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10817 continue;10828 continue;
10818 }10829 }
10819 let after = line[at + field.len()..].trim_start();10830 let after = line[at + field.len()..].trim_start();
10820- if after.starts_with(':') || after.starts_with(',') || after.starts_with('=') {10831+ let sets_a_field = after.starts_with(':')
10832+ || (after.starts_with(',') && !tuple_pattern);
10833+ let names_a_local = after.starts_with('=') && !after[1..].starts_with('=');
10834+ if sets_a_field || (names_a_local && !is_binding) {
10821 found.push((n + 1, line.to_owned()));10835 found.push((n + 1, line.to_owned()));
10822 break;10836 break;
10823 }10837 }
@@ -10848,12 +10862,33 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10848 /// door's public shape rather than a bound, and the wrong size for this10862 /// door's public shape rather than a bound, and the wrong size for this
10849 /// lane -- so the guard stands here with its limits written down instead.10863 /// lane -- so the guard stands here with its limits written down instead.
10850 ///10864 ///
10851- /// Residual risk, concretely: a write through a helper taking10865+ /// **Residual risk, by class, most likely first.** These are not all
10852- /// `&mut SubClip` that assigns by a form the matcher cannot see; a10866+ /// equally hypothetical; the first is the one a real composer would reach
10853- /// macro-mediated write; a `.rs` under `crates/` the walk does not reach;10867+ /// for, and it is the one this matcher cannot see at all:
10854- /// and -- the sharpest one -- renaming the fields themselves, since the10868+ ///
10855- /// matcher keys on the literal strings `in_us`/`out_us` and would then10869+ /// 1. **Field-less writes.** `*a = *b;`, `*a = other;`,
10856- /// match nothing at all while still passing.10870+ /// `std::mem::swap(a, b)`, `a.clone_from(b)`, and any macro that
10871+ /// expands to a field write (`bump!(s.out_us, by)`). None of these ever
10872+ /// spell `in_us` or `out_us` on the line, so `window_writes` returns
10873+ /// nothing for all of them. A *helper* that writes the field directly IS
10874+ /// caught; it is specifically the whole-struct and macro forms that go
10875+ /// through. This is the class most likely to be used, and it is
10876+ /// unmatched by construction rather than by oversight.
10877+ /// 2. **A rename.** The matcher keys on the literal strings `in_us` and
10878+ /// `out_us`. Renaming the fields silences it entirely while it stays
10879+ /// green -- the sharpest failure here, because the guard is supposed to
10880+ /// be the thing that notices a rule drifting.
10881+ /// 3. **A writer inside a test.** `/tests/` paths and `mod tests` blocks
10882+ /// are cut. A test cannot produce a file a user loses, so the line is
10883+ /// drawn there deliberately, not by omission.
10884+ /// 4. **A file the walk does not reach**: a path outside `crates/`, or one
10885+ /// under a directory named `target`, `.git` or `vendor`.
10886+ ///
10887+ /// What the matcher DOES now cover, after four rounds of it not doing so:
10888+ /// every assignment operator; struct-literal fields and the shorthand form,
10889+ /// including behind a `let`; writes through an indirect `&mut`; and every
10890+ /// `.rs` under `crates/` with no filter on what the file contains, so a
10891+ /// glob import or a type alias can no longer hide a module.
10857 #[test]10892 #[test]
10858 fn every_window_write_outside_set_window_is_named() {10893 fn every_window_write_outside_set_window_is_named() {
10859 // `CARGO_MANIFEST_DIR`, not `file!()`: a test runs with the WORKSPACE10894 // `CARGO_MANIFEST_DIR`, not `file!()`: a test runs with the WORKSPACE
@@ -10928,18 +10963,29 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10928 }10963 }
10929 }10964 }
10930 }10965 }
10931- // A floor, not a census: the walk filters to files that can NAME10966+ // A floor, not a census: the walk now opens EVERY `.rs` under
10932- // `SubClip`, which today is 20 of them and ~39,000 lines. The point is10967+ // `crates/` that is not test code -- 86 files and ~77,600 lines today,
10933- // only to catch a walk rooted in the wrong place, which reads a file10968+ // which is 141 files and ~116,000 before `/tests/` and `mod tests` are
10934- // or two. The `seen_app` half is the one that matters: the two-file10969+ // cut. The point is only to catch a walk rooted in the wrong place,
10935- // version of this guard read `project.rs` and `edith.rs` and was10970+ // which reads a file or two.
10936- // silently certifying a claim about the app it had never opened.10971+ // The `seen_app` half is the one that matters: the two-file version of
10972+ // this guard read `project.rs` and `edith.rs` and was silently
10973+ // certifying a claim about the app it had never opened, and the
10974+ // `contains("SubClip")` filter that came next
10975+ // was the same mistake wearing a derived hat -- a file that reached
10976+ // the type by glob import or alias was never opened either.
10937 assert!(10977 assert!(
10938- lines > 20_000 && files >= 10 && seen_app,10978+ lines > 70_000 && files >= 80 && seen_app,
10939 "the walk read {lines} lines in {files} files (app reached: \10979 "the walk read {lines} lines in {files} files (app reached: \
10940 {seen_app}) -- it is not covering the workspace, and a guard that \10980 {seen_app}) -- it is not covering the workspace, and a guard that \
10941 reads nothing is worse than no guard because it reads as one"10981 reads nothing is worse than no guard because it reads as one"
10942 );10982 );
10983+ // The assertion this whole test exists for. It was DELETED by a clumsy
10984+ // edit while the coverage floor above was being retuned, and for a
10985+ // moment the test reported green while `found` held a real offender --
10986+ // the fourth version of this guard failing in the one way that looks
10987+ // exactly like success. If you retune anything here, check this line
10988+ // still exists.
10943 assert!(10989 assert!(
10944 found.is_empty(),10990 found.is_empty(),
10945 "a caption window is written outside set_window:\n {}",10991 "a caption window is written outside set_window:\n {}",
@@ -10947,12 +10993,17 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10947 );10993 );
10948 }10994 }
10949 10995
10950- /// The blind spot, pinned as a case. Every one of these is a write, and10996+ /// The blind spot, pinned as cases. Every one of these is a write, and the
10951- /// the guard exists because its first two versions caught none of them --10997+ /// guard exists because each of its earlier versions caught none of them --
10952 /// `s.out_us += by(...)` being a one-token edit that made it green while a10998 /// `s.out_us += by(...)` being a one-token edit that made it green while a
10953 /// grouped caption really did grow past the ceiling. A matcher that has10999 /// grouped caption really did grow past the ceiling. A matcher that has
10954 /// quietly stopped matching is the failure mode that looks most like a11000 /// quietly stopped matching is the failure mode that looks most like a
10955 /// pass, so it gets its own test rather than a comment.11001 /// pass, so it gets its own test rather than a comment.
11002+ ///
11003+ /// The last group is the opposite: the field-less forms that are a write
11004+ /// and that this matcher CANNOT see. They are asserted to be missed, on
11005+ /// purpose, so that the day someone can match them the test says so --
11006+ /// and so nobody reads this file as claiming more than it does.
10956 #[test]11007 #[test]
10957 fn the_window_write_matcher_catches_the_ways_a_composer_hides() {11008 fn the_window_write_matcher_catches_the_ways_a_composer_hides() {
10958 for (what, code) in [11009 for (what, code) in [
@@ -10971,6 +11022,15 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10971 " out.push(SubClip { in_us: 0, out_us: 1, ..s });",11022 " out.push(SubClip { in_us: 0, out_us: 1, ..s });",
10972 ),11023 ),
10973 ("the shorthand form", " SubClip { in_us, out_us, ..s }"),11024 ("the shorthand form", " SubClip { in_us, out_us, ..s }"),
11025+ (
11026+ "a struct literal behind a `let`, which the old line-wide `let` \
11027+ exclusion skipped whole",
11028+ " let tail = SubClip { in_us: cut, out_us: s.out_us, ..s };",
11029+ ),
11030+ (
11031+ "a struct literal behind a `let` using the shorthand too",
11032+ " let half = SubClip { frames: n, in_us, out_us, ..s };",
11033+ ),
10974 ] {11034 ] {
10975 assert!(11035 assert!(
10976 !window_writes(code).is_empty(),11036 !window_writes(code).is_empty(),
@@ -10990,6 +11050,26 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10990 "the matcher flags a read as a write: {quiet:?}"11050 "the matcher flags a read as a write: {quiet:?}"
10991 );11051 );
10992 }11052 }
11053+ // The class this matcher CANNOT see, asserted as missed. Each of these
11054+ // really does write a caption's window and none of them spell the field
11055+ // name, so a field matcher returns nothing -- that is a property of the
11056+ // approach, not a bug to be fixed here, and the test exists so the
11057+ // doc comment's residual-risk list cannot quietly grow a claim this
11058+ // matcher has not earned. If one of these ever starts matching, this
11059+ // test fails and asks which side of the line moved.
11060+ for unmatchable in [
11061+ " *a = *b;",
11062+ " *a = other;",
11063+ " std::mem::swap(a, b);",
11064+ " a.clone_from(b);",
11065+ " bump!(s.out_us, by);",
11066+ ] {
11067+ assert!(
11068+ window_writes(unmatchable).is_empty(),
11069+ "the matcher now matches a field-less form it documented as \
11070+ unmatched -- update the residual-risk list too: {unmatchable:?}"
11071+ );
11072+ }
10993 }11073 }
10994 11074
10995 /// Every `.rs` under the workspace, paired with its text. Recursive11075 /// Every `.rs` under the workspace, paired with its text. Recursive
@@ -11014,9 +11094,16 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() {
11014 if !skip {11094 if !skip {
11015 stack.push(path);11095 stack.push(path);
11016 }11096 }
11097+ // EVERY `.rs`, with no filter on what it contains. The filter
11098+ // that was here (`text.contains("SubClip")`) was a name-based
11099+ // guess about which files can reach the type, and a glob import
11100+ // or a type alias defeats it exactly as it defeats a
11101+ // hardcoded file list: a new module holding the struct behind
11102+ // `use engine::project::*;` was never opened, and stayed green.
11103+ // The scan is text-only and the tree is small, so the honest
11104+ // thing costs nothing here.
11017 } else if path.extension().is_some_and(|e| e == "rs")11105 } else if path.extension().is_some_and(|e| e == "rs")
11018 && let Ok(text) = std::fs::read_to_string(&path)11106 && let Ok(text) = std::fs::read_to_string(&path)
11019- && text.contains("SubClip")
11020 {11107 {
11021 out.push((path, text));11108 out.push((path, text));
11022 }11109 }