test(tui): pin mounted resume against raw subagent handoff envelopes

#6954 item 4 asks for a regression test in `mod mounted_history_tests`:
a session saved with a raw runtime handoff envelope must resume, because
`prepare_mounted_session` acknowledges the projector output rather than
the bytes on disk.

The fixture persists a real completion envelope built by
`subagent_completion_runtime_message`, asserts the on-disk projection keeps
it verbatim, asserts `project_owned_messages_for_restore` changes it (so the
fixture cannot silently stop covering the bug), then resumes and requires the
original session id.

Verified: `CODEWHALE_CACHE_ROOT=/Volumes/VIXinSSD/cw-build-cache
./scripts/dev-cargo.sh test -p codewhale-tui --lib -- mounted_history`
-> 15 passed; 0 failed; 15372 filtered out. Reverting the projection-aware
comparison in `synchronize_history_operation` to `observed.messages ==
session.messages` makes the new test fail with "canonical history mailbox
acknowledgement changed", confirming it guards the fix; source restored to
HEAD afterwards. `rustfmt --edition 2024 --check crates/tui/src/lib.rs` clean.
This commit is contained in:
CodeWhale Bot committed 2026-10-23 04:29:01 -07:00
1 parent 842d2cecf4
commit 47af509cb0
1 file changed
+57
+57
View File
@@ -17461,6 +17461,63 @@ mod mounted_history_tests {
Ok(())
}
#[tokio::test]
async fn mounted_resume_accepts_saved_raw_subagent_handoff_envelopes() -> Result<()> {
let _env = lock_test_env();
let _runtime_override = EnvVarGuard::remove("CODEWHALE_RUNTIME_DIR");
let _legacy_runtime_override = EnvVarGuard::remove("DEEPSEEK_RUNTIME_DIR");
let temp = tempfile::tempdir()?;
let root = temp.path().canonicalize()?;
let _home = EnvVarGuard::set("CODEWHALE_HOME", root.join("home"));
let workspace = root.join("workspace");
std::fs::create_dir(&workspace)?;
let manager = SessionManager::default_location()?;
let messages = vec![
Message {
role: Role::User,
content: vec![ContentBlock::Text {
text: "spawn a scout".into(),
cache_control: None,
}],
},
crate::runtime_handoff::subagent_completion_runtime_message(
r#"{"agent_id":"owned-handoff","status":"completed","summary":"saved child summary"}"#,
),
];
let mut saved = create_saved_session(&messages, "mounted-handoff", &workspace, 7, None);
saved
.metadata
.set_model_provider_route("custom", Some("CaseRoute"));
manager.save_session(&saved)?;
let saved = manager.load_session_snapshot_bounded(
&saved.metadata.id,
codewhale_protocol::MAX_CANONICAL_HISTORY_BYTES,
)?;
assert_eq!(
saved.messages, messages,
"the saved projection keeps the raw handoff envelope verbatim"
);
assert_ne!(
crate::runtime_handoff::project_owned_messages_for_restore(saved.messages.clone()),
saved.messages,
"the fixture must carry history the restore projection rewrites"
);
let cli = cli(&workspace);
let (_, id) = prepare_mounted_session(
&cli,
prepare_interactive_config(&cli, &config(), true)?,
saved.metadata.id.clone(),
MountedHistoryIntent::Resume,
plugins(&workspace),
)
.await?;
assert_eq!(
id, saved.metadata.id,
"resume must acknowledge projected history instead of refusing it"
);
Ok(())
}
#[tokio::test]
async fn mounted_forks_keep_every_branch_and_source_bytes_with_distinct_durable_ids()
-> Result<()> {