The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(config): cover ephemeral route reapply and change logging
Steven Enamakeldf24589b8384
diff --git a/crates/openhuman-core/src/config/schema/ephemeral_route_tests.rs b/crates/openhuman-core/src/config/schema/ephemeral_route_tests.rsindex 46de5ee193..03b782c99e 100644--- a/crates/openhuman-core/src/config/schema/ephemeral_route_tests.rs+++ b/crates/openhuman-core/src/config/schema/ephemeral_route_tests.rs@@ -2,6 +2,44 @@ use super::*;use crate::config::Config;+#[derive(Clone, Default)]+struct Capture(std::sync::Arc<std::sync::Mutex<Vec<u8>>>);++impl Capture {+ fn text(&self) -> String {+ String::from_utf8(self.0.lock().unwrap().clone()).unwrap()+ }+}++impl std::io::Write for Capture {+ fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {+ self.0.lock().unwrap().extend_from_slice(bytes);+ Ok(bytes.len())+ }++ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+}++impl<'a> tracing_subscriber::fmt::MakeWriter<'a> for Capture {+ type Writer = Self;++ fn make_writer(&'a self) -> Self::Writer {+ self.clone()+ }+}++fn capture_logs() -> (Capture, tracing::subscriber::DefaultGuard) {+ let capture = Capture::default();+ let subscriber = tracing_subscriber::fmt()+ .with_writer(capture.clone())+ .with_ansi(false)+ .with_max_level(tracing::Level::TRACE)+ .finish();+ (capture, tracing::subscriber::set_default(subscriber))+}+/// A config with a model resolved for the call, as `agent_chat` leaves it after/// applying `model_override`.fn config_with_model(model: &str) -> Config {@@ -170,6 +208,49 @@ fn apply_twice_leaves_one_entry() {assert_eq!(entries[0].endpoint, "http://127.0.0.1:9999/openai");}+#[test]+fn reapplying_the_same_route_is_a_no_op() {+ let mut config = config_with_model("x/y");+ apply(&mut config, route());+ let before = config.clone();+ let (logs, _guard) = capture_logs();++ apply(&mut config, route());++ assert_eq!(config, before);+ assert!(!logs.text().contains("INFO"));+}++#[test]+fn a_changed_route_is_applied_and_logged_once() {+ let mut config = config_with_model("x/y");+ apply(&mut config, route());+ let (logs, _guard) = capture_logs();+ let changed = EphemeralRoute {+ endpoint: "http://127.0.0.1:9999/openai".into(),+ api_key: "mdl-other".into(),+ headers: Vec::new(),+ };++ apply(&mut config, changed.clone());++ assert_eq!(config.ephemeral_route, Some(changed));+ assert_eq!(+ config+ .cloud_providers+ .iter()+ .find(|entry| entry.slug == EPHEMERAL_ROUTE_SLUG)+ .map(|entry| entry.endpoint.as_str()),+ Some("http://127.0.0.1:9999/openai")+ );+ let info_lines: Vec<_> = logs+ .text()+ .lines()+ .filter(|line| line.contains("INFO") && line.contains("[config][ephemeral-route]"))+ .collect();+ assert_eq!(info_lines.len(), 1, "expected one info log: {info_lines:?}");+}+#[test]fn the_route_cannot_be_serialized_into_a_config_file() {// The containment the whole design rests on: there is no field on the wire