From 76832c7d62f922187be816f29e18465c1df0bae9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 00:59:11 +0000 Subject: [PATCH 01/12] chore(vendor): bump agent-browser, agent-desktop, tinybus and tinyinference Update the pinned submodule commits for the four vendored dependencies to their latest revisions. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- vendor/agent-browser | 2 +- vendor/agent-desktop | 2 +- vendor/tinybus | 2 +- vendor/tinyinference | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/agent-browser b/vendor/agent-browser index 11303656a..9a749e47a 160000 --- a/vendor/agent-browser +++ b/vendor/agent-browser @@ -1 +1 @@ -Subproject commit 11303656ac6121f56bceb9769339085ef004d339 +Subproject commit 9a749e47aa872315db661cb00ff27e909bdce2e4 diff --git a/vendor/agent-desktop b/vendor/agent-desktop index 72f8af2f2..b8d538c03 160000 --- a/vendor/agent-desktop +++ b/vendor/agent-desktop @@ -1 +1 @@ -Subproject commit 72f8af2f2bfb08a691fd374b6f2163061b83ea3c +Subproject commit b8d538c038872c72dbf7ae42e002d6fa03a3e599 diff --git a/vendor/tinybus b/vendor/tinybus index aa36051e2..e5f1cd2d2 160000 --- a/vendor/tinybus +++ b/vendor/tinybus @@ -1 +1 @@ -Subproject commit aa36051e2d384b09a1fb7871758fcf22c2a7e709 +Subproject commit e5f1cd2d2a7b905ee82410a61219292ca8a85c1f diff --git a/vendor/tinyinference b/vendor/tinyinference index 02c01b72f..c29d5118e 160000 --- a/vendor/tinyinference +++ b/vendor/tinyinference @@ -1 +1 @@ -Subproject commit 02c01b72f70cd3747304b2a5a696b52a49fdd4fd +Subproject commit c29d5118eddfa12b83c266d7d5f07f6918dc3787 From 0d58f773295cc9b07527a5f10bc2ab2ebbd7ffc7 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:03:38 +0000 Subject: [PATCH 02/12] chore(vendor): bump agent-browser, agent-desktop, tinybus and tinyinference Update the pinned submodule commits for the four vendored dependencies to their latest revisions. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- vendor/agent-browser | 2 +- vendor/agent-desktop | 2 +- vendor/tinybus | 2 +- vendor/tinyinference | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/agent-browser b/vendor/agent-browser index 9a749e47a..11303656a 160000 --- a/vendor/agent-browser +++ b/vendor/agent-browser @@ -1 +1 @@ -Subproject commit 9a749e47aa872315db661cb00ff27e909bdce2e4 +Subproject commit 11303656ac6121f56bceb9769339085ef004d339 diff --git a/vendor/agent-desktop b/vendor/agent-desktop index b8d538c03..72f8af2f2 160000 --- a/vendor/agent-desktop +++ b/vendor/agent-desktop @@ -1 +1 @@ -Subproject commit b8d538c038872c72dbf7ae42e002d6fa03a3e599 +Subproject commit 72f8af2f2bfb08a691fd374b6f2163061b83ea3c diff --git a/vendor/tinybus b/vendor/tinybus index e5f1cd2d2..aa36051e2 160000 --- a/vendor/tinybus +++ b/vendor/tinybus @@ -1 +1 @@ -Subproject commit e5f1cd2d2a7b905ee82410a61219292ca8a85c1f +Subproject commit aa36051e2d384b09a1fb7871758fcf22c2a7e709 diff --git a/vendor/tinyinference b/vendor/tinyinference index c29d5118e..02c01b72f 160000 --- a/vendor/tinyinference +++ b/vendor/tinyinference @@ -1 +1 @@ -Subproject commit c29d5118eddfa12b83c266d7d5f07f6918dc3787 +Subproject commit 02c01b72f70cd3747304b2a5a696b52a49fdd4fd From 66f4b0f1214e8d29b57201938748c7aa0586ff95 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:06:49 +0000 Subject: [PATCH 03/12] feat(tinycomputer): add live browser egress tests behind a build flag Wire up a build script and gate a new live browser egress test module behind the live_module_browser_egress_tests cfg so the tests only compile when explicitly requested. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinycomputer/Cargo.toml | 1 + crates/tinycomputer/build.rs | 7 ++ .../browser_egress_live_tests.rs | 103 ++++++++++++++++++ crates/tinycomputer/src/tinybus_module/mod.rs | 4 + 4 files changed, 115 insertions(+) create mode 100644 crates/tinycomputer/build.rs create mode 100644 crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs diff --git a/crates/tinycomputer/Cargo.toml b/crates/tinycomputer/Cargo.toml index 1a85edc6d..10aefe96b 100644 --- a/crates/tinycomputer/Cargo.toml +++ b/crates/tinycomputer/Cargo.toml @@ -6,6 +6,7 @@ rust-version.workspace = true license.workspace = true repository.workspace = true description = "Native desktop automation — accessibility-tree observation and interaction — as an installable TinyBus module." +build = "build.rs" documentation = "https://docs.rs/tinycomputer" readme = "../../README.md" keywords = ["tinybus", "module", "accessibility", "automation", "desktop"] diff --git a/crates/tinycomputer/build.rs b/crates/tinycomputer/build.rs new file mode 100644 index 000000000..d541d74cf --- /dev/null +++ b/crates/tinycomputer/build.rs @@ -0,0 +1,7 @@ +fn main() { + println!("cargo:rustc-check-cfg=cfg(live_module_browser_egress_tests)"); + println!("cargo:rerun-if-env-changed=TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS"); + if std::env::var_os("TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS").is_some() { + println!("cargo:rustc-cfg=live_module_browser_egress_tests"); + } +} diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs new file mode 100644 index 000000000..b493ab548 --- /dev/null +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -0,0 +1,103 @@ +//! Opt-in real-Chromium coverage through the loaded TinyComputer module. +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}}; +use std::time::Duration; + +use tinybus::{Connection, broker::Broker, module::ModuleHost, transport::memory::MemoryBus}; +use tinycomputer_bus::{DesktopResponse, browser_egress::{self, BrowserEgressConsumeRequest, BrowserEgressDecision, BrowserEgressGrant, BrowserEgressTarget, BrowserEgressValidateRequest}, names}; + +#[derive(Clone)] +struct EgressHost { + allowed: Arc, + allowed_address: String, + observations: Arc>>, +} + +#[tinybus::interface(name = "ai.tinyhumans.tinycomputer.BrowserEgressHost")] +impl EgressHost { + async fn authorize(&self, request: BrowserEgressTarget) -> tinybus::Result { + let allow = self.allowed.load(Ordering::SeqCst); + self.observations.lock().unwrap().push(format!("authorize:{}:{}:{}:{}", request.policy_id, request.expected_generation, request.hostname, request.port)); + Ok(BrowserEgressGrant { + generation: request.expected_generation, + authorization: if allow { "fixture-lease" } else { "denied-after-policy-change" }.into(), + addresses: if allow { vec![self.allowed_address.clone()] } else { Vec::new() }, + }) + } + + async fn consume(&self, request: BrowserEgressConsumeRequest) -> tinybus::Result { + self.observations.lock().unwrap().push(format!("consume:{}", request.address)); + Ok(BrowserEgressDecision { allowed: self.allowed.load(Ordering::SeqCst) && request.address == self.allowed_address }) + } + + async fn validate(&self, request: BrowserEgressValidateRequest) -> tinybus::Result { + self.observations.lock().unwrap().push(format!("validate:{}", request.authorization)); + Ok(BrowserEgressDecision { allowed: self.allowed.load(Ordering::SeqCst) && request.authorization == "fixture-lease" }) + } +} + +async fn serve_fixture(listener: tokio::net::TcpListener, expected: &'static [u8]) { + let (mut stream, _) = listener.accept().await.expect("authorized Chromium socket arrives"); + let mut request = [0_u8; 4096]; + let _ = tokio::io::AsyncReadExt::read(&mut stream, &mut request).await; + assert!(String::from_utf8_lossy(&request).contains("GET /")); + let response = [b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ".as_slice(), expected.len().to_string().as_bytes(), b"\r\nConnection: close\r\n\r\n".as_slice(), expected].concat(); + let _ = tokio::io::AsyncWriteExt::write_all(&mut stream, &response).await; +} + +fn successful_data(reply: &DesktopResponse) -> &serde_json::Value { + assert!(reply.ok, "{} failed: {:?}", reply.command, reply.error); + reply.data.as_ref().expect("successful response has data") +} + +#[tokio::test] +async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() -> tinybus::Result<()> { + let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let port = allowed_listener.local_addr()?.port(); + let denied_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; + let allowed_address = allowed_listener.local_addr()?.to_string(); + let allowed_server = tokio::spawn(serve_fixture(allowed_listener, b"allowed fixture")); + + let bus = MemoryBus::new(); + let broker = Broker::new(); + let broker_task = broker.spawn(bus.clone()); + let host_connection = Connection::connect(bus.connect().await?).await?; + let allowed = Arc::new(AtomicBool::new(true)); + let observations = Arc::new(Mutex::new(Vec::new())); + host_connection.serve_at(browser_egress::OBJECT_PATH.try_into()?, EgressHost { allowed: allowed.clone(), allowed_address: allowed_address.clone(), observations: observations.clone() }).await?; + host_connection.request_name(browser_egress::INTERFACE).await?; + + let module_host = ModuleHost::new(broker); + let module = crate::linked_module().expect("linked module manifest is valid"); + module_host.attach_linked_with_config(module, serde_json::json!({ + "browser": { + "executable": "/snap/bin/chromium", + "egress": {"policy_id": "fixture-policy", "generation": 41} + } + })).expect("TinyComputer module loads through ModuleHost"); + let client = Connection::connect(bus.connect().await?).await?; + let proxy = client.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE)?; + + let opened: DesktopResponse = proxy.call(names::methods::OPEN_SESSION, (serde_json::json!({"headless": true}),)).await?; + let session = successful_data(&opened)["id"].clone(); + let url = format!("http://fixture.test:{port}/allowed"); + let navigated: DesktopResponse = proxy.call(names::methods::NAVIGATE, (serde_json::json!({"session": session, "request": {"url": url}}),)).await?; + assert!(navigated.ok, "authorized navigation failed: {:?}", navigated.error); + allowed_server.await.expect("fixture server completed"); + + // Simulate DNS rebinding and a policy refresh: the same fixture hostname now + // maps to a different local socket, but the host denies its new resolution. + allowed.store(false, Ordering::SeqCst); + let denied_url = format!("http://fixture.test:{port}/after-policy-change"); + let denied: DesktopResponse = proxy.call(names::methods::NAVIGATE, (serde_json::json!({"session": session, "request": {"url": denied_url}}),)).await?; + assert!(!denied.ok, "navigation after host policy denial unexpectedly succeeded"); + assert!(tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()).await.is_err(), "denied rebound socket received a connection"); + + let calls = observations.lock().unwrap(); + assert!(calls.iter().any(|call| call == &format!("consume:{allowed_address}")), "host did not consume the exact returned socket: {calls:?}"); + assert_eq!(calls.iter().filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")).count(), 2, "both real Chromium requests must reach the host authorizer: {calls:?}"); + assert!(!calls.iter().any(|call| call == &format!("consume:{}", denied_listener.local_addr()?)), "denied socket was consumed: {calls:?}"); + broker_task.abort(); + Ok(()) +} diff --git a/crates/tinycomputer/src/tinybus_module/mod.rs b/crates/tinycomputer/src/tinybus_module/mod.rs index 62dfdc093..2fe7786a3 100644 --- a/crates/tinycomputer/src/tinybus_module/mod.rs +++ b/crates/tinycomputer/src/tinybus_module/mod.rs @@ -106,5 +106,9 @@ tinybus_module::module_export_optional_static! { #[path = "static_link_tests.rs"] mod static_link_tests; +#[cfg(all(test, feature = "static-link", live_module_browser_egress_tests))] +#[path = "browser_egress_live_tests.rs"] +mod browser_egress_live_tests; + #[cfg(test)] mod tinybus_module_tests; From 12100c93a44a878803e6a577f67f91646f7991ac Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:08:06 +0000 Subject: [PATCH 04/12] test(tinycomputer): align live browser egress test with current bus API Update the live Chromium egress test to use the browser interface names and the current navigate request shape, and tighten the host authorizer to only grant the fixture hostname and port. The authorize call count assertion is relaxed to at least two since Chromium may issue extra requests, and the denied socket check now compares against the listener's address directly. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- crates/tinycomputer/build.rs | 2 + .../browser_egress_live_tests.rs | 180 ++++++++++++++---- 2 files changed, 150 insertions(+), 32 deletions(-) diff --git a/crates/tinycomputer/build.rs b/crates/tinycomputer/build.rs index d541d74cf..4921ca4e3 100644 --- a/crates/tinycomputer/build.rs +++ b/crates/tinycomputer/build.rs @@ -1,3 +1,5 @@ +//! Declares the opt-in compile-time gate for local live Chromium tests. + fn main() { println!("cargo:rustc-check-cfg=cfg(live_module_browser_egress_tests)"); println!("cargo:rerun-if-env-changed=TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS"); diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index b493ab548..cdb4814e8 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -1,11 +1,22 @@ //! Opt-in real-Chromium coverage through the loaded TinyComputer module. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}}; +use std::sync::{ + Arc, Mutex, + atomic::{AtomicBool, Ordering}, +}; use std::time::Duration; use tinybus::{Connection, broker::Broker, module::ModuleHost, transport::memory::MemoryBus}; -use tinycomputer_bus::{DesktopResponse, browser_egress::{self, BrowserEgressConsumeRequest, BrowserEgressDecision, BrowserEgressGrant, BrowserEgressTarget, BrowserEgressValidateRequest}, names}; +use tinycomputer_bus::{ + DesktopResponse, + browser::names as browser_names, + browser_egress::{ + self, BrowserEgressConsumeRequest, BrowserEgressDecision, BrowserEgressGrant, + BrowserEgressTarget, BrowserEgressValidateRequest, + }, + names, +}; #[derive(Clone)] struct EgressHost { @@ -17,32 +28,78 @@ struct EgressHost { #[tinybus::interface(name = "ai.tinyhumans.tinycomputer.BrowserEgressHost")] impl EgressHost { async fn authorize(&self, request: BrowserEgressTarget) -> tinybus::Result { - let allow = self.allowed.load(Ordering::SeqCst); - self.observations.lock().unwrap().push(format!("authorize:{}:{}:{}:{}", request.policy_id, request.expected_generation, request.hostname, request.port)); + let allow = self.allowed.load(Ordering::SeqCst) + && request.hostname == "fixture.test" + && request.port + == self + .allowed_address + .rsplit(':') + .next() + .and_then(|port| port.parse().ok()) + .unwrap_or_default(); + self.observations.lock().unwrap().push(format!( + "authorize:{}:{}:{}:{}", + request.policy_id, request.expected_generation, request.hostname, request.port + )); Ok(BrowserEgressGrant { generation: request.expected_generation, - authorization: if allow { "fixture-lease" } else { "denied-after-policy-change" }.into(), - addresses: if allow { vec![self.allowed_address.clone()] } else { Vec::new() }, + authorization: if allow { + "fixture-lease" + } else { + "denied-after-policy-change" + } + .into(), + addresses: if allow { + vec![self.allowed_address.clone()] + } else { + Vec::new() + }, }) } - async fn consume(&self, request: BrowserEgressConsumeRequest) -> tinybus::Result { - self.observations.lock().unwrap().push(format!("consume:{}", request.address)); - Ok(BrowserEgressDecision { allowed: self.allowed.load(Ordering::SeqCst) && request.address == self.allowed_address }) + async fn consume( + &self, + request: BrowserEgressConsumeRequest, + ) -> tinybus::Result { + self.observations + .lock() + .unwrap() + .push(format!("consume:{}", request.address)); + Ok(BrowserEgressDecision { + allowed: self.allowed.load(Ordering::SeqCst) && request.address == self.allowed_address, + }) } - async fn validate(&self, request: BrowserEgressValidateRequest) -> tinybus::Result { - self.observations.lock().unwrap().push(format!("validate:{}", request.authorization)); - Ok(BrowserEgressDecision { allowed: self.allowed.load(Ordering::SeqCst) && request.authorization == "fixture-lease" }) + async fn validate( + &self, + request: BrowserEgressValidateRequest, + ) -> tinybus::Result { + self.observations + .lock() + .unwrap() + .push(format!("validate:{}", request.authorization)); + Ok(BrowserEgressDecision { + allowed: self.allowed.load(Ordering::SeqCst) + && request.authorization == "fixture-lease", + }) } } async fn serve_fixture(listener: tokio::net::TcpListener, expected: &'static [u8]) { - let (mut stream, _) = listener.accept().await.expect("authorized Chromium socket arrives"); + let (mut stream, _) = listener + .accept() + .await + .expect("authorized Chromium socket arrives"); let mut request = [0_u8; 4096]; let _ = tokio::io::AsyncReadExt::read(&mut stream, &mut request).await; assert!(String::from_utf8_lossy(&request).contains("GET /")); - let response = [b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ".as_slice(), expected.len().to_string().as_bytes(), b"\r\nConnection: close\r\n\r\n".as_slice(), expected].concat(); + let response = [ + b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ".as_slice(), + expected.len().to_string().as_bytes(), + b"\r\nConnection: close\r\n\r\n".as_slice(), + expected, + ] + .concat(); let _ = tokio::io::AsyncWriteExt::write_all(&mut stream, &response).await; } @@ -52,7 +109,8 @@ fn successful_data(reply: &DesktopResponse) -> &serde_json::Value { } #[tokio::test] -async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() -> tinybus::Result<()> { +async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() +-> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); let denied_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; @@ -65,39 +123,97 @@ async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch let host_connection = Connection::connect(bus.connect().await?).await?; let allowed = Arc::new(AtomicBool::new(true)); let observations = Arc::new(Mutex::new(Vec::new())); - host_connection.serve_at(browser_egress::OBJECT_PATH.try_into()?, EgressHost { allowed: allowed.clone(), allowed_address: allowed_address.clone(), observations: observations.clone() }).await?; - host_connection.request_name(browser_egress::INTERFACE).await?; + host_connection + .serve_at( + browser_egress::OBJECT_PATH.try_into()?, + EgressHost { + allowed: allowed.clone(), + allowed_address: allowed_address.clone(), + observations: observations.clone(), + }, + ) + .await?; + host_connection + .request_name(browser_egress::INTERFACE) + .await?; let module_host = ModuleHost::new(broker); let module = crate::linked_module().expect("linked module manifest is valid"); - module_host.attach_linked_with_config(module, serde_json::json!({ - "browser": { - "executable": "/snap/bin/chromium", - "egress": {"policy_id": "fixture-policy", "generation": 41} - } - })).expect("TinyComputer module loads through ModuleHost"); + module_host + .attach_linked_with_config( + module, + serde_json::json!({ + "browser": {"egress": {"policy_id": "fixture-policy", "generation": 41}} + }), + ) + .expect("TinyComputer module loads through ModuleHost"); let client = Connection::connect(bus.connect().await?).await?; let proxy = client.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE)?; - let opened: DesktopResponse = proxy.call(names::methods::OPEN_SESSION, (serde_json::json!({"headless": true}),)).await?; + let opened: DesktopResponse = proxy + .call( + browser_names::methods::OPEN_SESSION, + (serde_json::json!({"headless": true}),), + ) + .await?; let session = successful_data(&opened)["id"].clone(); let url = format!("http://fixture.test:{port}/allowed"); - let navigated: DesktopResponse = proxy.call(names::methods::NAVIGATE, (serde_json::json!({"session": session, "request": {"url": url}}),)).await?; - assert!(navigated.ok, "authorized navigation failed: {:?}", navigated.error); + let navigated: DesktopResponse = proxy + .call( + browser_names::methods::NAVIGATE, + (serde_json::json!({"session": session, "url": url}),), + ) + .await?; + assert!( + navigated.ok, + "authorized navigation failed: {:?}", + navigated.error + ); allowed_server.await.expect("fixture server completed"); // Simulate DNS rebinding and a policy refresh: the same fixture hostname now // maps to a different local socket, but the host denies its new resolution. allowed.store(false, Ordering::SeqCst); let denied_url = format!("http://fixture.test:{port}/after-policy-change"); - let denied: DesktopResponse = proxy.call(names::methods::NAVIGATE, (serde_json::json!({"session": session, "request": {"url": denied_url}}),)).await?; - assert!(!denied.ok, "navigation after host policy denial unexpectedly succeeded"); - assert!(tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()).await.is_err(), "denied rebound socket received a connection"); + let denied: DesktopResponse = proxy + .call( + browser_names::methods::NAVIGATE, + (serde_json::json!({"session": session, "url": denied_url}),), + ) + .await?; + assert!( + !denied.ok, + "navigation after host policy denial unexpectedly succeeded" + ); + assert!( + tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()) + .await + .is_err(), + "denied rebound socket received a connection" + ); let calls = observations.lock().unwrap(); - assert!(calls.iter().any(|call| call == &format!("consume:{allowed_address}")), "host did not consume the exact returned socket: {calls:?}"); - assert_eq!(calls.iter().filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")).count(), 2, "both real Chromium requests must reach the host authorizer: {calls:?}"); - assert!(!calls.iter().any(|call| call == &format!("consume:{}", denied_listener.local_addr()?)), "denied socket was consumed: {calls:?}"); + assert!( + calls + .iter() + .any(|call| call == &format!("consume:{allowed_address}")), + "host did not consume the exact returned socket: {calls:?}" + ); + assert!( + calls + .iter() + .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) + .count() + >= 2, + "both real Chromium requests must reach the host authorizer: {calls:?}" + ); + let denied_address = denied_listener.local_addr()?.to_string(); + assert!( + !calls + .iter() + .any(|call| call == &format!("consume:{denied_address}")), + "denied socket was consumed: {calls:?}" + ); broker_task.abort(); Ok(()) } From f2170e061a83fd000bd43278cab0091bf23177f5 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:08:15 +0000 Subject: [PATCH 05/12] test(tinybus): annotate port parse type in browser egress live tests Add an explicit u16 turbofish to the port parse call so the inferred type is unambiguous. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index cdb4814e8..58aaeb008 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -35,7 +35,7 @@ impl EgressHost { .allowed_address .rsplit(':') .next() - .and_then(|port| port.parse().ok()) + .and_then(|port| port.parse::().ok()) .unwrap_or_default(); self.observations.lock().unwrap().push(format!( "authorize:{}:{}:{}:{}", From 9505180825dcd38067cb5c18a3c9bf3c70fde6e7 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:09:04 +0000 Subject: [PATCH 06/12] test(browser_egress): assert session launch and drop headless flag The live egress test now checks that opening a session reports launched as true, and it no longer passes a headless option when opening the session. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 58aaeb008..b25e0fd42 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -153,10 +153,11 @@ async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch let opened: DesktopResponse = proxy .call( browser_names::methods::OPEN_SESSION, - (serde_json::json!({"headless": true}),), + (serde_json::json!({}),), ) .await?; let session = successful_data(&opened)["id"].clone(); + assert_eq!(successful_data(&opened)["launched"], true); let url = format!("http://fixture.test:{port}/allowed"); let navigated: DesktopResponse = proxy .call( From 2c04c85b7d778931f3818c6be622a84aa56cae3e Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:17:19 +0000 Subject: [PATCH 07/12] test(browser_egress): tighten live chromium egress assertions Rename the live Chromium test to match the live_ prefix convention and bound the fixture server wait with a ten second timeout so a hung task fails instead of blocking. The authorizer assertion now compares the count before and after the policy change rather than requiring at least two calls, and the rebinding wording is corrected to describe a policy refresh. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests.rs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index b25e0fd42..084f0b0ab 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -109,7 +109,7 @@ fn successful_data(reply: &DesktopResponse) -> &serde_json::Value { } #[tokio::test] -async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() +async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let port = allowed_listener.local_addr()?.port(); @@ -170,10 +170,19 @@ async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch "authorized navigation failed: {:?}", navigated.error ); - allowed_server.await.expect("fixture server completed"); + tokio::time::timeout(Duration::from_secs(10), allowed_server) + .await + .expect("authorized fixture server completes within ten seconds") + .expect("fixture server task completes"); - // Simulate DNS rebinding and a policy refresh: the same fixture hostname now - // maps to a different local socket, but the host denies its new resolution. + let authorizations_before_policy_change = observations + .lock() + .unwrap() + .iter() + .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) + .count(); + // Simulate a policy refresh: the host changes from granting the fixture + // socket to denying requests for the same hostname. allowed.store(false, Ordering::SeqCst); let denied_url = format!("http://fixture.test:{port}/after-policy-change"); let denied: DesktopResponse = proxy @@ -190,7 +199,7 @@ async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()) .await .is_err(), - "denied rebound socket received a connection" + "denied policy-change socket received a connection" ); let calls = observations.lock().unwrap(); @@ -200,13 +209,13 @@ async fn real_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .any(|call| call == &format!("consume:{allowed_address}")), "host did not consume the exact returned socket: {calls:?}" ); - assert!( - calls + let authorizations_after_policy_change = calls .iter() .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) - .count() - >= 2, - "both real Chromium requests must reach the host authorizer: {calls:?}" + .count(); + assert!( + authorizations_after_policy_change > authorizations_before_policy_change, + "the post-change request did not reach the host authorizer: {calls:?}" ); let denied_address = denied_listener.local_addr()?.to_string(); assert!( From 7c3f6cc71c855fef1768c47450f810c898f7b96a Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:17:45 +0000 Subject: [PATCH 08/12] style(tinycomputer): fix indentation in browser egress live test Reindent the chained iterator calls in the policy change assertion so the continuation lines align with the surrounding code. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 084f0b0ab..66c41916f 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -210,9 +210,9 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch "host did not consume the exact returned socket: {calls:?}" ); let authorizations_after_policy_change = calls - .iter() - .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) - .count(); + .iter() + .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) + .count(); assert!( authorizations_after_policy_change > authorizations_before_policy_change, "the post-change request did not reach the host authorizer: {calls:?}" From af91ba0eb0715cb1d51288f502ce6645a1e9a166 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:19:58 +0000 Subject: [PATCH 09/12] docs(test): document live browser egress switch Co-authored-by: Medulla --- .env.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.env.example b/.env.example index 975167587..a8d5318e0 100644 --- a/.env.example +++ b/.env.example @@ -118,3 +118,6 @@ TINYCOMPUTER_LAB_SELF_EMAIL= # TINYCOMPUTER_LIVE_BROWSER=1 # Compile and run the linked browser egress tests against installed Chromium. # TINYCOMPUTER_LIVE_BROWSER_TESTS=1 +# Compile and run TinyComputer's module-path egress test against installed Chromium +# using only local fixture listeners: +# TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS=1 cargo test --manifest-path crates/tinycomputer/Cargo.toml -p tinycomputer --lib --features static-link live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy -- --exact --nocapture From 81d73905488d63ebe3790c3c29bd34b5e0b5d896 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:21:20 +0000 Subject: [PATCH 10/12] test(browser_egress): assert denied navigation never dials the allowed socket The live Chromium egress test now keeps the fixture listener open after the first response and counts any further connections, so a policy-denied navigation that still reaches the previously allowed socket is caught instead of passing silently. The fixture also serves a minimal HTML document and signals via a oneshot channel once its response is written, letting the test wait on the actual request rather than on the server task finishing. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests.rs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 66c41916f..1036d4cf2 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -3,7 +3,7 @@ use std::sync::{ Arc, Mutex, - atomic::{AtomicBool, Ordering}, + atomic::{AtomicBool, AtomicUsize, Ordering}, }; use std::time::Duration; @@ -85,7 +85,12 @@ impl EgressHost { } } -async fn serve_fixture(listener: tokio::net::TcpListener, expected: &'static [u8]) { +async fn serve_fixture( + listener: tokio::net::TcpListener, + expected: &'static [u8], + extra_connections: Arc, + served: tokio::sync::oneshot::Sender<()>, +) { let (mut stream, _) = listener .accept() .await @@ -101,6 +106,11 @@ async fn serve_fixture(listener: tokio::net::TcpListener, expected: &'static [u8 ] .concat(); let _ = tokio::io::AsyncWriteExt::write_all(&mut stream, &response).await; + let _ = served.send(()); + while let Ok((stream, _)) = listener.accept().await { + extra_connections.fetch_add(1, Ordering::SeqCst); + drop(stream); + } } fn successful_data(reply: &DesktopResponse) -> &serde_json::Value { @@ -115,7 +125,14 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch let port = allowed_listener.local_addr()?.port(); let denied_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; let allowed_address = allowed_listener.local_addr()?.to_string(); - let allowed_server = tokio::spawn(serve_fixture(allowed_listener, b"allowed fixture")); + let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); + let (served_tx, served_rx) = tokio::sync::oneshot::channel(); + let allowed_server = tokio::spawn(serve_fixture( + allowed_listener, + b"allowed fixture", + extra_allowed_connections.clone(), + served_tx, + )); let bus = MemoryBus::new(); let broker = Broker::new(); @@ -170,10 +187,10 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch "authorized navigation failed: {:?}", navigated.error ); - tokio::time::timeout(Duration::from_secs(10), allowed_server) + tokio::time::timeout(Duration::from_secs(10), served_rx) .await - .expect("authorized fixture server completes within ten seconds") - .expect("fixture server task completes"); + .expect("authorized Chromium request reaches the fixture within ten seconds") + .expect("authorized fixture reports its response"); let authorizations_before_policy_change = observations .lock() @@ -181,6 +198,8 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .iter() .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) .count(); + let extra_connections_before_policy_change = + extra_allowed_connections.load(Ordering::SeqCst); // Simulate a policy refresh: the host changes from granting the fixture // socket to denying requests for the same hostname. allowed.store(false, Ordering::SeqCst); @@ -201,6 +220,11 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .is_err(), "denied policy-change socket received a connection" ); + assert_eq!( + extra_allowed_connections.load(Ordering::SeqCst), + extra_connections_before_policy_change, + "policy-denied navigation connected to the previously allowed socket" + ); let calls = observations.lock().unwrap(); assert!( @@ -225,5 +249,6 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch "denied socket was consumed: {calls:?}" ); broker_task.abort(); + allowed_server.abort(); Ok(()) } From 2201c9a4b3a920c40ac546fafa7419c58901065f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:21:27 +0000 Subject: [PATCH 11/12] test(browser_egress): reflow an over-wrapped assertion binding Collapse a two-line let binding back onto a single line so the live chromium egress test matches the surrounding formatting. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 1036d4cf2..e466eebbe 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -198,8 +198,7 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .iter() .filter(|call| call.starts_with("authorize:fixture-policy:41:fixture.test:")) .count(); - let extra_connections_before_policy_change = - extra_allowed_connections.load(Ordering::SeqCst); + let extra_connections_before_policy_change = extra_allowed_connections.load(Ordering::SeqCst); // Simulate a policy refresh: the host changes from granting the fixture // socket to denying requests for the same hostname. allowed.store(false, Ordering::SeqCst); From 202694680a20a0fd0ce196e0064e033bd27a279c Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Thu, 22 Oct 2026 01:29:38 +0000 Subject: [PATCH 12/12] docs(test): qualify live browser egress test filter Co-authored-by: Medulla --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a8d5318e0..ae778e276 100644 --- a/.env.example +++ b/.env.example @@ -120,4 +120,4 @@ TINYCOMPUTER_LAB_SELF_EMAIL= # TINYCOMPUTER_LIVE_BROWSER_TESTS=1 # Compile and run TinyComputer's module-path egress test against installed Chromium # using only local fixture listeners: -# TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS=1 cargo test --manifest-path crates/tinycomputer/Cargo.toml -p tinycomputer --lib --features static-link live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy -- --exact --nocapture +# TINYCOMPUTER_LIVE_BROWSER_EGRESS_TESTS=1 cargo test --manifest-path crates/tinycomputer/Cargo.toml -p tinycomputer --lib --features static-link tinybus_module::browser_egress_live_tests::live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy -- --exact --nocapture