Skip to content

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

test(agent): add session harness tests for part 03

Steven Enamakel326ff0b7d862
diff --git a/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs b/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
index 60e549d70a..d0c0e1e190 100644
--- a/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
+++ b/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
@@ -704,3 +704,57 @@ async fn a_resumed_transcript_prefix_is_absorbed_into_history() {
],
);
}
+
+/// A resumed prefix with no leading system message must not erase this
+/// turn's freshly rendered one.
+///
+/// `bound_cached_transcript_messages` keeps a leading system message only
+/// "when present" — a transcript that was never seeded with one (or was
+/// truncated ahead of it) hands `absorb_resumed_transcript_prefix` a `cached`
+/// prefix with no system entry at all. Unconditionally dropping the current
+/// system message(s) in that case would leave `history` with none, which is
+/// strictly worse than the stale-but-present one this turn already built.
+#[tokio::test]
+async fn a_resumed_prefix_without_a_system_message_keeps_the_current_one() {
+ use crate::openhuman::agent::messages::{ChatMessage, ConversationMessage};
+
+ let workspace = tempfile::TempDir::new().expect("temp workspace");
+ let canned = crate::openhuman::agent::harness::session::transcript::SessionTranscript {
+ meta: fake_transcript_meta("thr_resume_no_system"),
+ messages: vec![
+ ChatMessage::user("first question"),
+ ChatMessage::assistant("first answer"),
+ ],
+ };
+ let (mut agent, _handle) = agent_with_fake_locator(workspace.path(), Some(canned));
+ agent.try_load_session_transcript();
+
+ agent.history = vec![
+ ConversationMessage::Chat(ChatMessage::system("freshly rendered prompt")),
+ ConversationMessage::Chat(ChatMessage::user("second question")),
+ ];
+
+ agent.absorb_resumed_transcript_prefix();
+
+ let rendered: Vec<(&str, &str)> = agent
+ .history
+ .iter()
+ .map(|entry| match entry {
+ ConversationMessage::Chat(chat) => (chat.role.as_str(), chat.content.as_str()),
+ other => panic!("expected only Chat entries, got {other:?}"),
+ })
+ .collect();
+ assert_eq!(
+ rendered,
+ vec![
+ ("user", "first question"),
+ ("assistant", "first answer"),
+ // The cached prefix supplied no system message, so this turn's
+ // freshly rendered one must survive rather than being dropped
+ // unconditionally.
+ ("system", "freshly rendered prompt"),
+ ("user", "second question"),
+ ],
+ "the current system prompt must be kept when the cached prefix has none"
+ );
+}