Skip to content

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

test(session_host): assert legacy transcripts stay byte-for-byte untouched

Steven Enamakel3aacef8490af
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 bd61543b39..996adab35f 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
@@ -241,12 +241,12 @@ pub(super) fn classic_path(root: &Path, stem: &str) -> PathBuf {
/// Imports the classic files placed under the workspace's `session_raw/` into
/// the root's store, as the first start after an upgrade does.
-pub(super) fn import_placed(root: &Path) {
+pub(super) fn import_placed(root: &Path) -> (usize, usize, usize) {
crate::storage::import::sessions::import_transcript_groups(
store_provider(root).as_ref(),
&root.join("workspace"),
)
- .expect("import the placed fixtures");
+ .expect("import the placed fixtures")
}
/// Everything the root's store holds for `session`'s thread, by stem: the
@@ -286,7 +286,12 @@ pub(super) fn store_tree(
/// `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).
-pub(super) fn place_fixture(root: &Path, scenario: &Scenario, stem: &str, variant: &str) {
+pub(super) fn place_fixture(
+ root: &Path,
+ scenario: &Scenario,
+ stem: &str,
+ variant: &str,
+) -> (usize, usize, usize) {
let name = scenario.name;
match scenario.layout {
Layout::Head => {
@@ -314,7 +319,7 @@ pub(super) fn place_fixture(root: &Path, scenario: &Scenario, stem: &str, varian
}
}
}
- import_placed(root);
+ import_placed(root)
}
fn place(from: PathBuf, to: PathBuf) {
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
index a667901682..6152fbb9a9 100644
--- 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
@@ -59,41 +59,34 @@ fn a_legacy_workspace_is_adopted_once_and_the_next_process_resumes_in_place() {
let root = tempfile::tempdir().expect("tempdir");
let thread = thread_id(scenario.name);
let legacy_stems = ["1700000001_orchestrator", "1700000002_orchestrator"];
- let legacy_rows = |root: &Path| -> Vec<Value> {
- let locator = store_locator(root);
- legacy_stems
- .iter()
- .map(|stem| {
- let history = locator
- .open_stem(
- stem,
- crate::storage::sessions::splice_fixture_tests::blank_meta(),
- )
- .expect("bind a legacy stem");
- serde_json::to_value(history.messages().expect("read a legacy root"))
- .expect("rows")
- })
- .collect()
- };
- let imported;
+ let legacy_files: Vec<_> = legacy_stems
+ .iter()
+ .map(|stem| super::transcript_compat_tests::classic_path(root.path(), stem))
+ .collect();
+ let legacy_bytes;
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, "");
- imported = legacy_rows(root.path());
- assert!(imported
+ let import = place_fixture(root.path(), scenario, &stem, "");
+ assert_eq!(import, (2, 2, 0), "legacy fixture import counts");
+ legacy_bytes = legacy_files
.iter()
- .all(|rows| !rows.as_array().unwrap().is_empty()));
+ .map(|path| std::fs::read(path).expect("read placed legacy transcript"))
+ .collect::<Vec<_>>();
assert!(host.resume_bound_session().await.expect("first resume"));
after_first = tree(root.path(), &thread, &host);
}
- // Adoption writes the session's own transcript and modifies no legacy root.
+ // Adoption writes the canonical session stem without changing the old
+ // source files that the one-time importer read.
assert_eq!(
- legacy_rows(root.path()),
- imported,
- "legacy roots must stay as imported"
+ legacy_files
+ .iter()
+ .map(|path| std::fs::read(path).expect("read legacy transcript after resume"))
+ .collect::<Vec<_>>(),
+ legacy_bytes,
+ "legacy source files must stay byte-for-byte untouched"
);
assert!(
after_first
@@ -106,6 +99,14 @@ fn a_legacy_workspace_is_adopted_once_and_the_next_process_resumes_in_place() {
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!(
+ legacy_files
+ .iter()
+ .map(|path| std::fs::read(path).expect("read legacy transcript after restart"))
+ .collect::<Vec<_>>(),
+ legacy_bytes,
+ "a second process must not modify the legacy source files"
+ );
assert_eq!(
after_first,
tree(root.path(), &thread, &host),