Craft Anything: understand how any software works, and craft your own.
Rust
Changing a setting keeps a test session to its configured engines, and the live browser tests find the installed browser (#479)
Bently09401b6458d4
diff --git a/crates/engine/src/testing.rs b/crates/engine/src/testing.rsindex b3ba6bff..349e62df 100644--- a/crates/engine/src/testing.rs+++ b/crates/engine/src/testing.rs@@ -25,3 +25,11 @@ pub fn session() -> Session {s.settings.engines.only_configured = true;s}++/// A [`session`] that finds the engines this computer has installed, for the `#[ignore]` tests+/// that run a real one (a browser, Ghidra).+pub fn live_session() -> Session {+ let mut s = session();+ s.settings.engines.only_configured = false;+ s+}diff --git a/crates/engine/src/tools/setup_tools.rs b/crates/engine/src/tools/setup_tools.rsindex fd189137..69f500cb 100644--- a/crates/engine/src/tools/setup_tools.rs+++ b/crates/engine/src/tools/setup_tools.rs@@ -503,8 +503,11 @@ pub fn with_setting(settings: &Settings, key: &str, value: Value) -> Result<Settif let Some(slot) = doc.pointer_mut(&pointer) {*slot = value;}- serde_json::from_value(doc)- .map_err(|e| ToolError::invalid(format!("That value doesn't fit {key}: {e}")).with_remediation("Check the type in settings_show."))+ let mut next: Settings = serde_json::from_value(doc)+ .map_err(|e| ToolError::invalid(format!("That value doesn't fit {key}: {e}")).with_remediation("Check the type in settings_show."))?;+ // Not part of the saved settings, so the round trip above drops it: keep this session's.+ next.engines.only_configured = settings.engines.only_configured;+ Ok(next)}fn settings_set(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolError> {@@ -642,5 +645,7 @@ mod tests {assert!(path.starts_with(&dir), "{} is under {}", path.display(), dir.display());assert!(std::fs::read_to_string(&path).unwrap().contains("auto_mode = false"));assert_ne!(dir, crate::settings::config_dir(), "never the computer's own folder");+ assert!(e.session().settings.engines.only_configured, "changing a setting keeps the test session from finding this computer's engines");+ assert_eq!(e.session().settings.ghidra_launcher(), None);}}diff --git a/crates/engine/src/tools/website_tools.rs b/crates/engine/src/tools/website_tools.rsindex d1e86755..78fb8752 100644--- a/crates/engine/src/tools/website_tools.rs+++ b/crates/engine/src/tools/website_tools.rs@@ -1410,7 +1410,7 @@ mod tests {}});// In Clean room, a visitor's view: its evidence says so (#157).- let mut s = crate::testing::session();+ let mut s = crate::testing::live_session();s.settings.deep_mode = false;let e = crate::Engine::new(s);let cli = || crate::CallOptions::new(crate::Caller::Cli).with_consent(crate::Consent::Granted);@@ -1430,7 +1430,7 @@ mod tests {#[test]#[ignore]fn the_browsers_error_page_is_not_captured() {- let e = crate::Engine::new(crate::testing::session());+ let e = crate::Engine::new(crate::testing::live_session());let cli = || crate::CallOptions::new(crate::Caller::Cli).with_consent(crate::Consent::Granted);// Nothing listens on port 1, so the browser shows its own error page.let _ = e.call("web_site_open", json!({"url": "http://127.0.0.1:1/"}), cli());@@ -1503,7 +1503,7 @@ body{margin:0} .d{display:none} @media (min-width:800px){.d{display:block} .p{dilet _ = write!(s, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{page}", page.len());}});- let e = crate::Engine::new(crate::testing::session());+ let e = crate::Engine::new(crate::testing::live_session());let cli = || crate::CallOptions::new(crate::Caller::Cli).with_consent(crate::Consent::Granted);e.call("web_site_open", json!({"url": url}), cli()).unwrap();let dir = tempfile::tempdir().unwrap();