Skip to content

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

test(embed): add process sentry tests

Steven Enamakelc89678888ceb
diff --git a/crates/openhuman-embed/src/process_sentry_tests.rs b/crates/openhuman-embed/src/process_sentry_tests.rs
new file mode 100644
index 0000000000..a84996f57a
--- /dev/null
+++ b/crates/openhuman-embed/src/process_sentry_tests.rs
@@ -0,0 +1,169 @@
+use super::*;
+
+fn event(message: &str, tags: &[(&str, &str)]) -> Event<'static> {
+ let mut event = Event {
+ message: Some(message.to_string()),
+ ..Default::default()
+ };
+ for (key, value) in tags {
+ event.tags.insert((*key).to_string(), (*value).to_string());
+ }
+ event
+}
+
+fn no_user() -> Option<String> {
+ None
+}
+
+fn fixed_user() -> Option<String> {
+ Some("user-123".into())
+}
+
+#[test]
+fn the_chain_is_the_union_of_both_hosts_with_unique_names() {
+ // 19 CLI predicates + 1 shell-only (localhost dev fetch); the shell's other
+ // 11 were already in the CLI chain. `is_transient_backend_api_failure` and
+ // its three siblings were one `||` group in both hosts.
+ assert_eq!(NOISE_FILTERS.len(), 21);
+ let mut names: Vec<_> = NOISE_FILTERS.iter().map(|(name, _)| *name).collect();
+ names.sort_unstable();
+ names.dedup();
+ assert_eq!(names.len(), NOISE_FILTERS.len(), "filter names must be unique");
+}
+
+#[test]
+fn each_known_noise_class_is_dropped() {
+ let cases = [
+ (
+ "localhost-dev-fetch",
+ event("Failed to request http://localhost:1420/index.html: refused", &[]),
+ ),
+ (
+ "transient-provider-http",
+ event(
+ "provider failed",
+ &[("domain", "llm_provider"), ("failure", "non_2xx"), ("status", "503")],
+ ),
+ ),
+ (
+ "fs-limitation",
+ event("write failed (os error 665)", &[]),
+ ),
+ (
+ "max-iterations",
+ event(
+ &format!(
+ "{}: 50",
+ openhuman_core::agent::error::MAX_ITERATIONS_ERROR_PREFIX
+ ),
+ &[],
+ ),
+ ),
+ (
+ "channel-message-404",
+ event(
+ "DELETE /channels/c1/messages/m1 -> 404",
+ &[
+ ("domain", "backend_api"),
+ ("failure", "non_2xx"),
+ ("status", "404"),
+ ("method", "DELETE"),
+ ],
+ ),
+ ),
+ (
+ "session-expired",
+ event("Session expired. Please log in again.", &[("domain", "rpc")]),
+ ),
+ ];
+ for (expected, event) in cases {
+ let name = known_noise(&event);
+ assert!(name.is_some(), "{expected}: not classified as noise");
+ assert!(
+ before_send(event, no_user).is_none(),
+ "{expected}: before_send kept it (classified as {name:?})"
+ );
+ }
+}
+
+#[test]
+fn a_real_error_is_kept_scrubbed_and_attributed() {
+ let mut event = event("upload failed: api_key=sk-abc123", &[("domain", "memory")]);
+ event.server_name = Some("operators-laptop".into());
+ assert_eq!(known_noise(&event), None);
+
+ let kept = before_send(event, fixed_user).expect("a real error reaches Sentry");
+ assert_eq!(kept.server_name, None, "hostname stripped");
+ assert_eq!(kept.message.as_deref(), Some("upload failed: api_key=[REDACTED]"));
+ assert_eq!(kept.user.and_then(|u| u.id).as_deref(), Some("user-123"));
+}
+
+#[test]
+fn a_scope_bound_user_is_not_overwritten() {
+ let mut event = event("boom", &[]);
+ event.user = Some(sentry::User {
+ id: Some("scope-user".into()),
+ ..Default::default()
+ });
+ let kept = before_send(event, fixed_user).expect("kept");
+ assert_eq!(kept.user.and_then(|u| u.id).as_deref(), Some("scope-user"));
+}
+
+#[test]
+fn exception_values_are_scrubbed() {
+ let mut event = event("boom", &[]);
+ event.exception.values.push(sentry::protocol::Exception {
+ value: Some("Authorization: Bearer abc123xyz".into()),
+ ..Default::default()
+ });
+ let kept = before_send(event, no_user).expect("kept");
+ assert_eq!(
+ kept.exception.values[0].value.as_deref(),
+ Some("Authorization: Bearer [REDACTED]")
+ );
+}
+
+#[test]
+fn the_localhost_rule_is_anchored_on_the_dev_proxy_prefix() {
+ assert!(message_is_localhost_dev_fetch_noise(
+ "Failed to request http://127.0.0.1:1420/x: err"
+ ));
+ assert!(!message_is_localhost_dev_fetch_noise(
+ "Failed to request https://api.example.com/x: err"
+ ));
+}
+
+#[test]
+fn release_tags_carry_a_short_sha_when_built_with_one() {
+ assert_eq!(release_tag("1.2.3", None), "[email protected]");
+ assert_eq!(release_tag("1.2.3", Some(" ")), "[email protected]");
+ assert_eq!(
+ release_tag("1.2.3", Some("0123456789abcdef")),
+ "[email protected]+0123456789ab"
+ );
+}
+
+#[test]
+fn the_first_non_blank_candidate_wins() {
+ assert_eq!(
+ first_non_blank([None, Some(" ".into()), Some("https://k@o/1".into())]),
+ Some("https://k@o/1".into())
+ );
+ assert_eq!(first_non_blank([None, Some(String::new())]), None);
+}
+
+#[test]
+fn client_options_wire_the_chain_and_the_transport() {
+ let options = client_options(SentryConfig::new(
+ Some("not a dsn".into()),
+ release_tag("1.0.0", None),
+ "test".into(),
+ ));
+ assert!(options.dsn.is_none(), "an unparsable DSN sends nothing");
+ assert_eq!(options.release.as_deref(), Some("[email protected]"));
+ assert_eq!(options.environment.as_deref(), Some("test"));
+ assert!(!options.send_default_pii);
+ assert!(options.transport.is_some());
+ let before_send = options.before_send.expect("chain installed");
+ assert!(before_send(event("Failed to request http://localhost:1/x: e", &[])).is_none());
+}