Skip to content

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

test(memory): inline pre-turn arguments in prefetch tests

Steven Enamakelf5a96839e478
diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
index f9a44083d9..cbd5d69e6f 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
@@ -327,24 +327,33 @@ async fn slow_engine_results_survive_the_manual_pre_turn_cutoff() {
.unwrap();
crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());
let identity = MemoryIdentity::agent("a").resolve(&config);
- let input = |index| PreTurnInput {
- thread_id: "slow".into(),
- turn_index: index,
- user_text: "what is my favourite colour?".into(),
- in_prompt_from: 0,
- at: chrono::Utc::now(),
- resumed_after_compaction: false,
- observed_actor: None,
+ let input = |index| (
+ "slow".to_string(),
+ index,
+ "what is my favourite colour?".to_string(),
+ 0,
+ chrono::Utc::now(),
+ false,
+ None,
+ );
+ let pre_turn = |config, identity, input: (String, u32, String, u32, chrono::DateTime<chrono::Utc>, bool, Option<tinymemory_api::ObservedActor>)| {
+ let (thread, index, text, in_prompt_from, at, resumed, observed_actor) = input;
+ super::pre_turn(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config,
+ identity,
+ thread,
+ index,
+ text,
+ in_prompt_from,
+ at,
+ resumed,
+ observed_actor,
+ None,
+ )
};
let config = Arc::new(config);
- assert!(pre_turn(
- &crate::core::runtime::DispatchCtx::ambient(),
- config.clone(),
- identity.clone(),
- input(0),
- None
- )
- .is_none());
+ assert!(pre_turn(config.clone(), identity.clone(), input(0)).is_none());
// Even after the old one-millisecond cutoff, the pack remains owned by
// the background worker instead of being discarded by the live turn.
tokio::time::sleep(Duration::from_millis(5)).await;
@@ -353,27 +362,14 @@ async fn slow_engine_results_survive_the_manual_pre_turn_cutoff() {
assert!(completed(&cache, &key).is_none());
release.add_permits(100);
drain(&cache, &key).await;
- let pack = pre_turn(
- &crate::core::runtime::DispatchCtx::ambient(),
- config.clone(),
- identity.clone(),
- input(2),
- None,
- )
- .expect("next turn uses completed slow lookup");
+ let pack = pre_turn(config.clone(), identity.clone(), input(2))
+ .expect("next turn uses completed slow lookup");
assert!(pack.markdown.contains("teal"));
assert!(pack.markdown.contains("earlier turn"));
drain(&cache, &key).await;
let mut omitted = identity;
omitted.recall = false;
- assert!(pre_turn(
- &crate::core::runtime::DispatchCtx::ambient(),
- config.clone(),
- omitted.clone(),
- input(4),
- None
- )
- .is_none());
+ assert!(pre_turn(config.clone(), omitted.clone(), input(4)).is_none());
drain(&cache, &Key::new(&config, &omitted, "slow", false)).await;
let turns = crate::memory::test_fixtures::stored(
&engine.inner,
diff --git a/crates/openhuman-core/src/memory/schemas_tests.rs b/crates/openhuman-core/src/memory/schemas_tests.rs
index ca437e93ed..90e1031806 100644
--- a/crates/openhuman-core/src/memory/schemas_tests.rs
+++ b/crates/openhuman-core/src/memory/schemas_tests.rs
@@ -450,37 +450,35 @@ async fn rpc_learn_invalidates_a_cached_prefetch_pack() {
let dispatch = DispatchCtx::new(ctx.clone());
let identity = crate::memory::scope::MemoryIdentity::root().resolve(&config);
let thread = "rpc-learn-invalidates-prefetch";
- let input = || crate::memory::lifecycle::hooks::PreTurnInput {
- thread_id: thread.into(),
- turn_index: 0,
- user_text: "What coffee do I like?".into(),
- in_prompt_from: 0,
- at: chrono::Utc::now(),
- resumed_after_compaction: false,
- observed_actor: None,
- };
+ let input = || (
+ thread.to_string(),
+ 0,
+ "What coffee do I like?".to_string(),
+ 0,
+ chrono::Utc::now(),
+ false,
+ None,
+ );
CoreContext::scope(ctx.clone(), async {
let config = Arc::new(config.clone());
+ let (thread_id, turn_index, user_text, in_prompt_from, at, resumed, observed_actor) =
+ input();
assert!(crate::memory::lifecycle::prefetch::pre_turn(
- &dispatch,
- config.clone(),
- identity.clone(),
- input(),
- None,
+ &dispatch, config.clone(), identity.clone(), thread_id, turn_index, user_text,
+ in_prompt_from, at, resumed, observed_actor, None,
)
.is_none());
crate::memory::lifecycle::prefetch::settle_for_test(
&dispatch, &config, &identity, thread, false,
)
.await;
+ let (thread_id, turn_index, user_text, in_prompt_from, at, resumed, observed_actor) =
+ input();
assert!(
crate::memory::lifecycle::prefetch::pre_turn(
- &dispatch,
- config.clone(),
- identity.clone(),
- input(),
- None,
+ &dispatch, config.clone(), identity.clone(), thread_id, turn_index, user_text,
+ in_prompt_from, at, resumed, observed_actor, None,
)
.is_some(),
"the initial turn should consume its completed pack"
@@ -494,13 +492,12 @@ async fn rpc_learn_invalidates_a_cached_prefetch_pack() {
.await
.unwrap();
+ let (thread_id, turn_index, user_text, in_prompt_from, at, resumed, observed_actor) =
+ input();
assert!(
crate::memory::lifecycle::prefetch::pre_turn(
- &dispatch,
- config,
- identity,
- input(),
- None,
+ &dispatch, config, identity, thread_id, turn_index, user_text, in_prompt_from,
+ at, resumed, observed_actor, None,
)
.is_none(),
"a later turn must not consume a pack cached before RPC learn"