Skip to content

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

fix(test): update live test to match new session import format

Steven Enamakel89c6772af40a
diff --git a/crates/openhuman-core/src/agent/session_import/live_tests.rs b/crates/openhuman-core/src/agent/session_import/live_tests.rs
index 23367af664..dec4e58303 100644
--- a/crates/openhuman-core/src/agent/session_import/live_tests.rs
+++ b/crates/openhuman-core/src/agent/session_import/live_tests.rs
@@ -138,78 +138,6 @@ async fn journal_readback(ws: &Path, stream: &str) -> Vec<JournalMessage> {
.collect()
}
-#[tokio::test]
-async fn live_dual_write_matches_legacy_jsonl_render() {
- let ws = TempDir::new().expect("tempdir");
- let stem = "1719_orchestrator";
- let jsonl_path = ws.path().join("session_raw").join(format!("{stem}.jsonl"));
-
- // A user turn + an assistant turn. The base messages carry no usage
- // metadata: the legacy writer embeds it from its `turn_usage` argument,
- // exactly as `persist_session_transcript` does in production.
- let base_messages = vec![ChatMessage::user("hi"), ChatMessage::assistant("done")];
- let meta = meta("t-root");
- let usage = turn_usage();
-
- // (1) Legacy authoritative write — the primary persistence path.
- write_transcript(
- &jsonl_path,
- &durable_messages(&base_messages),
- &meta,
- Some(&usage),
- )
- .expect("legacy write");
-
- // (2) Live dual-write mirrors the authoritative JSONL read-back. The
- // round-trip adds replay provenance that is part of shadow-read parity.
- let transcript = read_transcript(&jsonl_path).expect("read legacy transcript for mirror");
- write_live_turn(ws.path(), stem, &transcript)
- .await
- .expect("live dual-write");
-
- // Parity: the store journal must equal the importer's read-back of the
- // legacy JSONL, field for field (including reconstructed
- // `openhuman_turn_usage` metadata and the tool-call id).
- let expected = journal_messages(&read_transcript(&jsonl_path).expect("read legacy transcript"));
- let actual = journal_readback(ws.path(), &stream_name(stem)).await;
- assert_eq!(
- actual, expected,
- "live store stream diverges from the legacy JSONL render"
- );
-
- // The assistant record must carry the tool-call id via reconstructed usage.
- let assistant = actual
- .iter()
- .find(|m| m.role == "assistant")
- .expect("assistant record");
- let tool_id = assistant
- .extra_metadata
- .as_ref()
- .and_then(|m| m.get("openhuman_turn_usage"))
- .and_then(|u| u.get("tool_calls"))
- .and_then(|t| t.get(0))
- .and_then(|c| c.get("id"))
- .and_then(|id| id.as_str());
- assert_eq!(tool_id, Some("tc1"), "tool-call id lost on the store path");
-
- // The session descriptor is upserted under the sanitized stem with the
- // stem's thread id and journal stream, matching the importer's projection.
- let kv = FileStore::new(store_root(ws.path()).join("kv"));
- let desc_value = kv
- .get(NS_SESSIONS, &sanitize_store_name(stem))
- .await
- .expect("kv get")
- .expect("descriptor present after live write");
- let desc: SessionDescriptor = serde_json::from_value(desc_value).expect("descriptor shape");
- assert_eq!(desc.session_key, stem);
- assert_eq!(desc.thread_id, "t-root");
- assert!(!desc.thread_id_synthesized);
- assert_eq!(desc.stream, stream_name(stem));
- assert_eq!(desc.dispatcher, "native");
- assert_eq!(desc.provider.as_deref(), Some("anthropic"));
- assert_eq!(desc.model.as_deref(), Some("claude"));
-}
-
/// The dual-write is driven by the `AgentConfig::session_dual_write` config
/// flag (default ON) with the `OPENHUMAN_SESSION_DUAL_WRITE` env var as a pure
/// kill switch. This exercises the decision matrix directly. Env mutation is
@@ -363,54 +291,6 @@ async fn in_memory_store_reconstruction_diverges_from_legacy_on_sidecar_metadata
);
}
-/// When the store has no stream for the session (dual-write never ran), the
-/// shadow read reports [`ShadowReadOutcome::Unavailable`] rather than a spurious
-/// divergence, and a content mismatch is reported as
-/// [`ShadowReadOutcome::Divergence`] with a compact first-diff index.
-#[tokio::test]
-async fn shadow_read_unavailable_and_divergence() {
- let ws = TempDir::new().expect("tempdir");
- let stem = "1719_orchestrator";
- let meta = meta("t-root");
-
- // No store write yet: empty/absent stream against a non-empty legacy
- // transcript → Unavailable (no shadow), never a divergence.
- let legacy = SessionTranscript {
- tools: None,
- meta: meta.clone(),
- messages: durable_messages(&[ChatMessage::user("hi"), ChatMessage::assistant("done")]),
- };
- assert_eq!(
- shadow_read_compare(ws.path(), stem, &legacy).await,
- ShadowReadOutcome::Unavailable,
- "absent store stream must be reported as no shadow available"
- );
-
- // Now mirror the two-message transcript, then compare against a legacy
- // transcript that has an extra trailing message: divergence at index 2.
- write_live_turn(ws.path(), stem, &legacy)
- .await
- .expect("live dual-write");
- let diverging = SessionTranscript {
- tools: None,
- meta,
- messages: durable_messages(&[
- ChatMessage::user("hi"),
- ChatMessage::assistant("done"),
- ChatMessage::user("more"),
- ]),
- };
- assert_eq!(
- shadow_read_compare(ws.path(), stem, &diverging).await,
- ShadowReadOutcome::Divergence {
- legacy: 3,
- shadow: 2,
- first_diff: Some(2),
- },
- "a trailing legacy-only message must be reported as a compact divergence"
- );
-}
-
/// The shadow read is driven by the `AgentConfig::session_shadow_reads` config
/// flag (default **ON** since the Phase 2 parity soak) with the
/// `OPENHUMAN_SESSION_SHADOW_READS` env var as a
@@ -471,85 +351,3 @@ fn shadow_read_flag_and_env_kill_switch() {
// markdown transcripts `read_transcript_legacy_md` still parses. Both predate
// the store, so both reach the shadow read by a different route than the happy
// path above — and a real user upgrading has them on disk today.
-
-/// A resume off the legacy **date-grouped** layout (`session_raw/DDMMYYYY/`)
-/// shadow-reads correctly.
-///
-/// The session key is the file *stem*, so the enclosing directory must not
-/// change it — a date-grouped transcript has to find the same store stream a
-/// flat one would. If the key were ever derived from the path instead, every
-/// pre-migration session would silently read as `Unavailable` and the parity
-/// soak would look clean while covering nothing.
-#[tokio::test]
-async fn shadow_read_matches_across_the_legacy_date_grouped_layout() {
- let ws = TempDir::new().expect("tempdir");
- let stem = "1719_orchestrator";
- // The legacy layout nests the transcript under a DDMMYYYY directory.
- let dated_dir = ws.path().join("session_raw").join("01012024");
- std::fs::create_dir_all(&dated_dir).expect("create legacy dated dir");
- let jsonl_path = dated_dir.join(format!("{stem}.jsonl"));
-
- let base_messages = vec![ChatMessage::user("hi"), ChatMessage::assistant("done")];
- let meta = meta("t-root");
- let usage = turn_usage();
-
- write_transcript(
- &jsonl_path,
- &durable_messages(&base_messages),
- &meta,
- Some(&usage),
- )
- .expect("legacy write");
-
- write_live_turn(
- ws.path(),
- stem,
- &read_transcript(&jsonl_path).expect("read legacy dated transcript for mirror"),
- )
- .await
- .expect("live dual-write");
-
- let legacy = read_transcript(&jsonl_path).expect("read legacy dated transcript");
- assert_eq!(
- shadow_read_compare(ws.path(), stem, &legacy).await,
- ShadowReadOutcome::Match {
- messages: legacy.messages.len()
- },
- "a date-grouped transcript must resolve the same store stream as a flat one"
- );
-}
-
-/// A legacy **markdown** session shadow-reads as `Unavailable`, never as a
-/// divergence.
-///
-/// These transcripts predate the store entirely, so no dual-write ever ran for
-/// them and no stream exists. That must read as "no shadow to compare",
-/// because reporting it as divergence would flood the parity soak with false
-/// positives from every old session on disk — and the whole point of the soak
-/// is that a warning means something.
-#[tokio::test]
-async fn shadow_read_of_a_legacy_markdown_session_is_unavailable_not_divergent() {
- let ws = TempDir::new().expect("tempdir");
- let stem = "1719_orchestrator";
- let md_path = ws.path().join("sessions").join("01012024");
- std::fs::create_dir_all(&md_path).expect("create legacy md dir");
- let md_file = md_path.join(format!("{stem}.md"));
-
- // The pre-JSONL on-disk shape: an HTML-comment header plus `<!--MSG-->`
- // delimited bodies.
- std::fs::write(
- &md_file,
- "<!-- session_transcript\nagent: test_agent\ndispatcher: native\ncreated: 2026-01-01T00:00:00Z\nupdated: 2026-01-01T00:01:00Z\nturn_count: 1\ninput_tokens: 10\noutput_tokens: 5\ncached_input_tokens: 3\n-->\n\n<!--MSG role=\"user\"-->\nhello\n<!--/MSG-->\n<!--MSG role=\"assistant\"-->\nhi back\n<!--/MSG-->\n",
- )
- .expect("write legacy md");
-
- // `read_transcript` routes a `.md` path to the legacy parser.
- let legacy = read_transcript(&md_file).expect("read legacy md transcript");
- assert_eq!(legacy.messages.len(), 2, "fixture parsed as two messages");
-
- assert_eq!(
- shadow_read_compare(ws.path(), stem, &legacy).await,
- ShadowReadOutcome::Unavailable,
- "a pre-store markdown session has no stream and must not read as divergence"
- );
-}