From ccff9efebbfa08eca407286f2c8a73caef452ad4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 22:46:38 -0800 Subject: [PATCH] Plug-ins: tests fail on a grants read error, check the replaced-file callback ran, and release held loads first - The grant test accepts only a missing grants file as an empty list; any other read error fails it. - The same-stamp replacement test asserts that the callback rewrote the file before it checks that nothing installed. - The loader's ordering test binds the job senders after `loads`, so a failing assertion releases the held jobs before `loads` waits on them under the manual clock. --- crates/engine/src/tests/plugins.rs | 12 +++++++++++- crates/plugins/src/loader.rs | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/plugins.rs b/crates/engine/src/tests/plugins.rs index eec1ca7065..2ee0970238 100644 --- a/crates/engine/src/tests/plugins.rs +++ b/crates/engine/src/tests/plugins.rs @@ -2164,17 +2164,22 @@ fn a_stored_file_replaced_with_the_same_stamp_while_it_loaded_is_skipped() { let (folder, path) = store_with(&format!("plugin-background-replaced{n}"), &id); std::fs::File::options().write(true).open(&path).unwrap().set_modified(modified).unwrap(); let replaced = path.clone(); + // Set once the file holds other bytes with the old stamp, so the case reaches the check. + let rewritten = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); + let done = rewritten.clone(); *crate::store::AFTER_STORED_LOAD.lock().unwrap_or_else(|e| e.into_inner()) = Some(std::sync::Arc::new(move |p: &std::path::Path| { if p == replaced { let mut bytes = std::fs::read(p).unwrap(); bytes.reverse(); std::fs::write(p, &bytes).unwrap(); std::fs::File::options().write(true).open(p).unwrap().set_modified(modified).unwrap(); + done.store(true, std::sync::atomic::Ordering::SeqCst); } })); let mut s = session(); s.attach_plugin_store(folder.0.clone()); let installed = vectorcraft_plugins::registry::remove(&id); + assert!(rewritten.load(std::sync::atomic::Ordering::SeqCst), "the file was not replaced while it loaded ({n})"); assert!(!installed, "the module installed from a file that no longer holds it ({n})"); } } @@ -2494,7 +2499,12 @@ fn a_grant_put_back_for_a_module_that_did_not_install_is_removed_again() { crate::store::AFTER_GRANTS_READ.set(None); let source = vectorcraft_plugins::registry::get(id).and_then(|p| p.source().map(str::to_string)); assert!(vectorcraft_plugins::registry::remove(id)); - let listed: Vec = std::fs::read(&grants).ok().map(|b| serde_json::from_slice(&b).unwrap()).unwrap_or_default(); + // A grants file that went away holds no grant; one still there must read as a list. + let listed: Vec = match std::fs::read(&grants) { + Ok(b) => serde_json::from_slice(&b).unwrap(), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => vec![], + Err(e) => panic!("the grants file could not be read: {e}"), + }; assert_eq!(source, None, "the later module replaced the one installed elsewhere"); assert!(listed.iter().all(|e| e["id"] != id), "the grant put back stayed in the store: {listed:?}"); } diff --git a/crates/plugins/src/loader.rs b/crates/plugins/src/loader.rs index 0c4e81c3c5..955d2274c4 100644 --- a/crates/plugins/src/loader.rs +++ b/crates/plugins/src/loader.rs @@ -523,13 +523,16 @@ mod tests { } let (_, clock) = manual(); let mut loads = Loads::start_with(jobs, 3, LOAD_DEADLINE, clock); + // Bound after `loads`, so a failing assertion drops the senders first: the held jobs then + // return, and dropping `loads` does not wait on them while the test clock stands still. + let release = go; for _ in 0..3 { recv_soon(&starts); } // Each job is let go only once the one after it has finished. let mut finished = Vec::new(); for v in (0..3).rev() { - go[v].send(()).unwrap(); + release[v].send(()).unwrap(); let done = recv_soon(&loads.results.lock().unwrap()); finished.push(done.0); loads.record(done);