test: add nested fork regression tests

- branch_options_handles_nested_forks: verifies branch picker returns
  correct branches for both root fork and sub-fork
- render_tree_path_nested_forks_only_emits_at_divergence: confirms fork_info
  doesn't propagate downstream (only at actual divergence point)
This commit is contained in:
Cameron Cordes
2026-08-08 10:58:13 -04:00
parent a1a2d22b5b
commit ef54f0d646
2 changed files with 76 additions and 0 deletions
+31
View File
@@ -2894,6 +2894,37 @@ mod tests {
assert_eq!(f.node_id, u, "divergence node is the forked user turn");
}
#[test]
fn render_tree_path_nested_forks_only_emits_at_divergence() {
// Regression: with .take() instead of .clone(), fork_info should only
// appear at the actual divergence point, not propagate downstream.
// Structure:
// u (user "q1")
// ├── a1 (assistant "answer 1")
// └── a2 (assistant "answer 2")
// ├── q2 (user "q2")
// └── r2 (assistant "reply 2") <- active leaf
//
// Expected fork_info: [None, Some, None, None]
// (only a2 has fork info since it's the divergence from a1)
let mut store = ChatHistoryStore::empty();
let u = store.append_node(None, ChatMessage::user("q1"));
let _a1 = store.append_node(Some(u), assistant_text("answer 1"));
let a2 = store.append_node(Some(u), assistant_text("answer 2"));
let q2 = store.append_node(Some(a2), ChatMessage::user("q2"));
let r2 = store.append_node(Some(q2), assistant_text("reply 2"));
store.active_leaf_id = r2;
let path = store.path_to_leaf(r2).expect("path to active leaf");
let (rendered, _turns, _node_ids, fork_info) = render_tree_path(&store, &path);
assert_eq!(rendered.len(), 4, "user + asst + user + asst");
assert!(fork_info[0].is_none(), "initial user has no fork");
assert!(fork_info[1].is_some(), "a2 is the fork point");
assert!(fork_info[2].is_none(), "q2 should NOT carry fork forward");
assert!(fork_info[3].is_none(), "r2 should NOT carry fork forward");
}
#[test]
fn rewind_strips_assistant_and_tool_scaffolding() {
// Rendered: [user1, asst1, user2, asst2] → cut at rendered index 3