Skip to content

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

test(session_host): add transcript resume stability tests

Steven Enamakel4c253e90fcc1
diff --git a/crates/openhuman-core/src/agent/session_host/mod.rs b/crates/openhuman-core/src/agent/session_host/mod.rs
index 778c386456..7b68116664 100644
--- a/crates/openhuman-core/src/agent/session_host/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/mod.rs
@@ -82,3 +82,6 @@ mod runtime_adapter_tests;
mod transcript_compat_tests;
#[cfg(test)]
mod typed_transcript_compat_tests;
+#[cfg(test)]
+#[path = "transcript_resume_stable_tests.rs"]
+mod transcript_resume_stable_tests;
diff --git a/crates/openhuman-core/src/agent/session_host/transcript_compat_tests.rs b/crates/openhuman-core/src/agent/session_host/transcript_compat_tests.rs
index 6684a84bf6..4c4c7edc03 100644
--- a/crates/openhuman-core/src/agent/session_host/transcript_compat_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/transcript_compat_tests.rs
@@ -34,7 +34,7 @@ const FIXTURE_DIR: &str = concat!(
/// How a scenario's fixture files are laid out in a fresh workspace.
#[derive(Clone, Copy, PartialEq)]
-enum Layout {
+pub(super) enum Layout {
/// One head transcript at the session's own stem.
Head,
/// A sealed generation 0 plus its generation 1 head.
@@ -47,7 +47,7 @@ enum Layout {
pub(super) struct Scenario {
pub(super) name: &'static str,
pub(super) native: bool,
- layout: Layout,
+ pub(super) layout: Layout,
}
pub(super) static SCENARIOS: &[Scenario] = &[
@@ -208,7 +208,7 @@ pub(super) fn run_async<F: std::future::Future<Output = ()> + Send + 'static>(fu
.expect("test thread panicked");
}
-fn session_raw(root: &Path) -> PathBuf {
+pub(super) fn session_raw(root: &Path) -> PathBuf {
root.join("workspace").join("session_raw")
}
@@ -220,7 +220,7 @@ pub(super) fn stem_path(root: &Path, stem: &str) -> PathBuf {
/// `variant` selects an alternate on-disk generation of a head fixture
/// (`""` the committed legacy capture, `".typed"` the same rows re-written in
/// the typed row form).
-fn place_fixture(root: &Path, scenario: &Scenario, stem: &str, variant: &str) {
+pub(super) fn place_fixture(root: &Path, scenario: &Scenario, stem: &str, variant: &str) {
let name = scenario.name;
match scenario.layout {
Layout::Head => {
diff --git a/crates/openhuman-core/src/agent/session_host/transcript_resume_stable_tests.rs b/crates/openhuman-core/src/agent/session_host/transcript_resume_stable_tests.rs
new file mode 100644
index 0000000000..abe9f1d2e4
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/transcript_resume_stable_tests.rs
@@ -0,0 +1,102 @@
+//! A workspace written by the previous release resumes in place: resuming a
+//! committed fixture neither renames, rewrites nor re-adopts anything, so the
+//! transcript stems and bytes on disk are exactly what the old binary left.
+
+use std::collections::BTreeMap;
+use std::path::Path;
+
+use tinyinference_llm::model::ModelResponse;
+
+use super::transcript_compat_tests::{
+ build_host, model, place_fixture, run_async, session_raw, thread_id, Layout, SCENARIOS,
+};
+
+/// File name -> bytes for everything under the workspace's `session_raw/`.
+fn raw_tree(root: &Path) -> BTreeMap<String, Vec<u8>> {
+ let mut out = BTreeMap::new();
+ let Ok(entries) = std::fs::read_dir(session_raw(root)) else {
+ return out;
+ };
+ for entry in entries.flatten() {
+ let name = entry.file_name().to_string_lossy().into_owned();
+ out.insert(name, std::fs::read(entry.path()).expect("read raw file"));
+ }
+ out
+}
+
+#[test]
+fn resuming_a_committed_workspace_leaves_every_stem_and_byte_untouched() {
+ for scenario in SCENARIOS
+ .iter()
+ .filter(|scenario| scenario.layout != Layout::Legacy)
+ {
+ run_async(async move {
+ let root = tempfile::tempdir().expect("tempdir");
+ let next = model(vec![ModelResponse::assistant("unused")], scenario.native);
+ let mut host = build_host(
+ root.path(),
+ next,
+ scenario.native,
+ &thread_id(scenario.name),
+ );
+ let stem = host.session_id().expect("bound session id");
+ place_fixture(root.path(), scenario, &stem, "");
+ let before = raw_tree(root.path());
+ assert!(!before.is_empty(), "{}: fixture placed", scenario.name);
+
+ assert!(host.resume_bound_session().await.expect("resume"));
+
+ assert_eq!(
+ before,
+ raw_tree(root.path()),
+ "{}: resume must not rename, create or rewrite transcript files",
+ scenario.name
+ );
+ });
+ }
+}
+
+#[test]
+fn a_legacy_workspace_is_adopted_once_and_the_next_process_resumes_in_place() {
+ let scenario = SCENARIOS
+ .iter()
+ .find(|scenario| scenario.layout == Layout::Legacy)
+ .expect("legacy scenario");
+ run_async(async move {
+ let root = tempfile::tempdir().expect("tempdir");
+ let thread = thread_id(scenario.name);
+ let legacy_only;
+ let after_first;
+ {
+ let next = model(vec![ModelResponse::assistant("unused")], scenario.native);
+ let mut host = build_host(root.path(), next, scenario.native, &thread);
+ let stem = host.session_id().expect("bound session id");
+ place_fixture(root.path(), scenario, &stem, "");
+ legacy_only = raw_tree(root.path());
+ assert!(host.resume_bound_session().await.expect("first resume"));
+ after_first = raw_tree(root.path());
+ }
+ // Adoption writes the session's own file and modifies no legacy file.
+ for (name, bytes) in &legacy_only {
+ assert_eq!(
+ after_first.get(name),
+ Some(bytes),
+ "legacy file {name} must stay byte-for-byte"
+ );
+ }
+ assert!(
+ after_first.len() > legacy_only.len(),
+ "adopted file written"
+ );
+
+ // A fresh process over the same workspace resumes without adopting again.
+ let next = model(vec![ModelResponse::assistant("unused")], scenario.native);
+ let mut host = build_host(root.path(), next, scenario.native, &thread);
+ assert!(host.resume_bound_session().await.expect("second resume"));
+ assert_eq!(
+ after_first,
+ raw_tree(root.path()),
+ "second resume must not re-adopt or rewrite anything"
+ );
+ });
+}