From f6f8156c32a8eefc36c859ae8ab0e27ea26daddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 13 Aug 2026 10:29:35 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(tests):=20a=20card's=20body?= =?UTF-8?q?=20ends=20where=20the=20card=20does?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `every_card_closes_without_the_keyboard` read a card's source "up to the next `\n fn `" out of every source file joined end to end -- and these methods are `pub(crate) fn`, which that cut matches none of. So each body ran tens of thousands of characters past its own end, through the rest of its file and into the next one: `mix_card`'s scrim could stop closing the card and the guard still passed, on five other cards' `close_card` calls downstream of it. Two helpers in the tests' own module now, because a slice that starts at `ui_source()` spills by construction and there are 42 seams to spill at: `source_from` cuts inside the one file its needle is in, and `fn_body` ends a method at the ` }` at the impl's own indent. The inspector's occlusion rule reuses the first; the concatenation keeps its old job of answering whether a line is written anywhere, and says so. --- crates/app/src/tests/editing.rs | 16 +++------------- crates/app/src/tests/layout.rs | 6 +----- crates/app/src/tests/mod.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 616f8d2..4213a7b 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -839,16 +839,6 @@ fn every_action_is_reachable_without_the_keyboard() { /// the day it is added, which is the only way the two stay in step. #[test] fn every_card_closes_without_the_keyboard() { - let source = ui_source(); - let source = source.as_str(); - // A fn's source, up to the next one: enough of a body to scan. - let body = |name: &str| -> &str { - let at = source - .find(&format!("fn {name}(")) - .unwrap_or_else(|| panic!("no fn {name} in main.rs")); - let rest = &source[at..]; - &rest[..rest[1..].find("\n fn ").map_or(rest.len(), |e| e + 1)] - }; for card in [ "keys_overlay", "export_card", @@ -858,7 +848,7 @@ fn every_card_closes_without_the_keyboard() { "mix_card", "silence_card", ] { - let src = body(card); + let src = fn_body(card); assert!( src.contains("this.close_card()"), "{card}'s scrim swallows the press without closing the card: \ @@ -873,8 +863,8 @@ fn every_card_closes_without_the_keyboard() { // ...and every state that makes the window modal is a state that press // clears. `exporting()` is not one of them: a running export is a job // with a cancel button, not a card with a scrim. - let close = body("close_card"); - for field in body("modal").split("self.").skip(1).filter_map(|rest| { + let close = fn_body("close_card"); + for field in fn_body("modal").split("self.").skip(1).filter_map(|rest| { let name: String = rest .chars() .take_while(|c| c.is_alphanumeric() || *c == '_') diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index eed39e7..0bd583a 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -147,11 +147,7 @@ fn an_inspector_section_occludes_no_timeline() { // Whichever file the root render has come to live in, from the impl to the // end of it -- found rather than named, so moving the root does not quietly // leave this rule reading a file the render is no longer in. - let render = source_files() - .iter() - .map(|path| std::fs::read_to_string(path).expect("a source file")) - .find_map(|text| text.find("impl Render for Player").map(|at| text[at..].to_string())) - .expect("the root render"); + let render = source_from("impl Render for Player"); for card in [ "eq_card", "color_card", "speed_card", "silence_card", "mix_card", ] { diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 98d0c55..268a0aa 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -77,6 +77,11 @@ use std::time::{Duration, Instant}; /// and a scan that names its files passes a rule by simply not looking where /// the code went. So the files are found rather than listed: every `.rs` under /// `src/`, read at run time. +/// +/// For asking *whether* a line is written anywhere. Never slice it: the files +/// are joined end to end, so a cut that runs to "the next `fn`" runs out of +/// the file it started in and reads the following one as more of the same +/// ([`source_from`]). fn ui_source() -> String { source_files() .iter() @@ -84,6 +89,32 @@ fn ui_source() -> String { .collect() } +/// The one file `needle` is written in, from the needle to the end of *that* +/// file. Every scan that slices starts here, because the alternative is +/// slicing [`ui_source()`]: 42 files with 42 seams between them, and the last +/// fn of any of them -- `silence_card` in `ui/cards.rs` -- read as running on +/// into the file that happens to follow it. The file is found and not named, +/// so the code may move house without this going blind. +fn source_from(needle: &str) -> String { + source_files() + .iter() + .map(|path| std::fs::read_to_string(path).expect("a source file")) + .find_map(|text| text.find(needle).map(|at| text[at..].to_string())) + .unwrap_or_else(|| panic!("no {needle} in the window's source")) +} + +/// One method's body: from its `fn` line to the ` }` that closes it. The +/// brace at the impl's own indent is where a method ends and nothing inside +/// one is written that far out -- which the old cut, "up to the next +/// `\n fn `", was not: these methods are `pub(crate) fn`, so it matched +/// none of them and read every card's body as running to the end of the +/// window instead. +fn fn_body(name: &str) -> String { + let text = source_from(&format!("fn {name}(")); + let end = text.find("\n }\n").map_or(text.len(), |at| at + "\n }\n".len()); + text[..end].to_string() +} + /// One named file of that source, for the scans about a single region. fn src_text(rel: &str) -> String { std::fs::read_to_string(src_dir().join(rel)).expect("a source file")