Skip to content

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

test: cover per-agent poll scoping and agent context lifecycle

Steven Enamakel5ef831cb5714
diff --git a/crates/openhuman-core/src/integrations/task_sources/periodic_tests.rs b/crates/openhuman-core/src/integrations/task_sources/periodic_tests.rs
index 3fa09a3ec8..ebad54b761 100644
--- a/crates/openhuman-core/src/integrations/task_sources/periodic_tests.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/periodic_tests.rs
@@ -206,3 +206,24 @@ async fn manual_fetch_still_returns_the_explanatory_error() {
assert_eq!(outcome.fetched, 0);
assert_eq!(outcome.routed, 0);
}
+
+#[tokio::test]
+async fn poll_timestamps_are_kept_per_agent_scope() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
+ let agent = |name: &str| {
+ CoreContext::for_test(DomainSet::full(), None).derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::full(),
+ Default::default(),
+ )
+ .session_agent(name),
+ )
+ };
+ let s = source("ts-per-agent-scope-xyz", 1800);
+ CoreContext::scope(agent("ts-agent-a"), async { record_poll(&s.id) }).await;
+ let due_for_a = CoreContext::scope(agent("ts-agent-a"), async { is_due(&s) }).await;
+ let due_for_b = CoreContext::scope(agent("ts-agent-b"), async { is_due(&s) }).await;
+ assert!(!due_for_a, "agent a just polled it");
+ assert!(due_for_b, "agent b's same-id source is a different source");
+}
diff --git a/crates/openhuman-core/src/storage/agents_tests.rs b/crates/openhuman-core/src/storage/agents_tests.rs
index 4e7160e29c..5d7d9d6d94 100644
--- a/crates/openhuman-core/src/storage/agents_tests.rs
+++ b/crates/openhuman-core/src/storage/agents_tests.rs
@@ -59,3 +59,25 @@ async fn without_a_backend_only_the_local_scope_runs() {
assert_eq!(runs[0].0, None);
assert!(for_each_agent("test", || async {}).await.is_empty());
}
+
+#[test]
+fn a_dropped_sibling_context_does_not_hide_a_live_one() {
+ let first = agent_context("agents-test-siblings");
+ let second = agent_context("agents-test-siblings");
+ drop(second);
+ let (_, found) = agent_contexts(None)
+ .into_iter()
+ .find(|(id, _)| id == "agents-test-siblings")
+ .expect("the first context is still live");
+ assert!(Arc::ptr_eq(&found, &first));
+ assert!(context_for("agents-test-siblings").is_some());
+ drop((found, first));
+ assert!(!live_agents().contains(&"agents-test-siblings".to_string()));
+}
+
+#[test]
+fn reset_recorded_forgets_what_was_recorded() {
+ RECORDED.lock().unwrap().insert("agents-test-recorded".into());
+ reset_recorded();
+ assert!(!RECORDED.lock().unwrap().contains("agents-test-recorded"));
+}