Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(embed): extract core dsn precedence into a testable helper

Steven Enamakelebb7d52e1fb4
diff --git a/crates/openhuman-embed/src/process_sentry.rs b/crates/openhuman-embed/src/process_sentry.rs
index 998bd0d49b..579e6ce4c9 100644
--- a/crates/openhuman-embed/src/process_sentry.rs
+++ b/crates/openhuman-embed/src/process_sentry.rs
@@ -79,9 +79,25 @@ pub fn first_non_blank(candidates: impl IntoIterator<Item = Option<String>>) ->
/// environment of the crate being compiled. `None` gives a client that sends
/// nothing.
pub fn core_dsn(baked_core: Option<&str>, baked_legacy: Option<&str>) -> Option<String> {
- first_non_blank([
+ select_core_dsn(
std::env::var("OPENHUMAN_CORE_SENTRY_DSN").ok(),
std::env::var("OPENHUMAN_SENTRY_DSN").ok(),
+ baked_core,
+ baked_legacy,
+ )
+}
+
+/// The precedence behind [`core_dsn`], with the runtime values passed in:
+/// runtime core, runtime legacy, baked core, baked legacy; blanks skipped.
+fn select_core_dsn(
+ runtime_core: Option<String>,
+ runtime_legacy: Option<String>,
+ baked_core: Option<&str>,
+ baked_legacy: Option<&str>,
+) -> Option<String> {
+ first_non_blank([
+ runtime_core,
+ runtime_legacy,
baked_core.map(str::to_owned),
baked_legacy.map(str::to_owned),
])
diff --git a/crates/openhuman-embed/src/process_sentry_tests.rs b/crates/openhuman-embed/src/process_sentry_tests.rs
index 46e489c62d..0718d45405 100644
--- a/crates/openhuman-embed/src/process_sentry_tests.rs
+++ b/crates/openhuman-embed/src/process_sentry_tests.rs
@@ -252,14 +252,23 @@ fn environment_falls_back_on_blank_or_missing() {
}
#[test]
-fn core_dsn_falls_back_to_the_baked_values_in_order() {
- // Only meaningful when the runtime variables are unset; otherwise the
- // runtime value wins, which `first_non_blank` already covers.
- if std::env::var_os("OPENHUMAN_CORE_SENTRY_DSN").is_none()
- && std::env::var_os("OPENHUMAN_SENTRY_DSN").is_none()
- {
- assert_eq!(core_dsn(Some(" a "), Some("b")).as_deref(), Some("a"));
- assert_eq!(core_dsn(None, Some("b")).as_deref(), Some("b"));
- assert_eq!(core_dsn(Some(" "), None), None);
- }
+fn core_dsn_precedence_is_runtime_then_baked_and_skips_blanks() {
+ let some = |v: &str| Some(v.to_string());
+ assert_eq!(
+ select_core_dsn(some("rc"), some("rl"), Some("bc"), Some("bl")).as_deref(),
+ Some("rc")
+ );
+ assert_eq!(
+ select_core_dsn(some(" "), some("rl"), Some("bc"), Some("bl")).as_deref(),
+ Some("rl")
+ );
+ assert_eq!(
+ select_core_dsn(None, None, Some(" bc "), Some("bl")).as_deref(),
+ Some("bc")
+ );
+ assert_eq!(
+ select_core_dsn(None, None, Some(""), Some("bl")).as_deref(),
+ Some("bl")
+ );
+ assert_eq!(select_core_dsn(None, None, None, Some(" ")), None);
}
diff --git a/crates/openhuman-rpc/README.md b/crates/openhuman-rpc/README.md
index ece78b92b6..56f36193e7 100644
--- a/crates/openhuman-rpc/README.md
+++ b/crates/openhuman-rpc/README.md
@@ -126,7 +126,7 @@ for the hosts that still call them:
- `server::serve(&CoreRuntime, ready_tx, shutdown)` (`server/serve.rs`):
bind and serve an already-built runtime.
- `server::run_server`, `run_server_headless`, `run_server_saas`
- (`server/shims.rs`): build a runtime from the embed `cli` preset and serve it. They do not connect the
+ (`server/shims.rs`): build a runtime and serve it: `run_server` and `run_server_headless` from the embed `cli` preset, `run_server_saas` from the SaaS config through `core::runtime::saas::build`. They do not connect the
TinyHumans backend; `host::desktop` does.
- `server::build_core_http_router(socketio_enabled)` (`server/http/mod.rs`):
the router on its own; root `tests/*.rs` suites use it to make real HTTP
diff --git a/crates/openhuman-rpc/src/server/shims.rs b/crates/openhuman-rpc/src/server/shims.rs
index 065ec6e237..74fbdcfbbd 100644
--- a/crates/openhuman-rpc/src/server/shims.rs
+++ b/crates/openhuman-rpc/src/server/shims.rs
@@ -1,9 +1,12 @@
//! Standalone server entry points, and the build-and-serve step the shared
//! host boot ([`crate::host`]) runs.
//!
-//! Each `run_server*` function is a thin shim over the [`RuntimeBuilder::cli`]
-//! preset: it applies the caller's services and listener, then builds the
-//! runtime and [`serve`](super::serve::serve)s it. The preset carries every
+//! `run_server` and `run_server_headless` are thin shims over the
+//! [`RuntimeBuilder::cli`] preset: each applies the caller's services and
+//! listener, then builds the runtime and [`serve`](super::serve::serve)s it.
+//! `run_server_saas` is separate: it loads a `SaasConfig` and boots through
+//! `core::runtime::saas::build` (a SaaS `CoreBuilder`, not the preset). The
+//! preset carries every
//! domain family, the standalone `HostKind` (CLI or Docker, via
//! `HostKind::detect_standalone`), the `OPENHUMAN_E2E` tool-group switch, and
//! no supplied config (the core discovers the operator's install).