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:
1 parent
a1a2d22b5b
commit
ef54f0d646
2 files changed
+76
No files matched your search
@@ -743,4 +743,49 @@ mod tests {
|
||||
assert_eq!(store.nodes[1].parent_id, Some(parent));
|
||||
assert_eq!(store.nodes[1].id, child);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_options_handles_nested_forks() {
|
||||
// Regression: verify sub-fork display when there are multiple forks.
|
||||
// Structure:
|
||||
// root (user "q1")
|
||||
// ├── a1 (assistant "answer 1")
|
||||
// └── a2 (assistant "answer 2")
|
||||
// ├── q2 (user "q2")
|
||||
// │ ├── r1 (assistant "reply 1")
|
||||
// │ └── r2 (assistant "reply 2") <- active leaf
|
||||
//
|
||||
// branch_options_at(root) should return [a1, a2] (2 branches)
|
||||
// branch_options_at(q2) should return [r1, r2] (2 sub-branches)
|
||||
let mut store = ChatHistoryStore::empty();
|
||||
let root = store.append_node(None, mk_msg("user", "q1"));
|
||||
let a1 = store.append_node(Some(root), mk_msg("assistant", "answer 1"));
|
||||
let a2 = store.append_node(Some(root), mk_msg("assistant", "answer 2"));
|
||||
let q2 = store.append_node(Some(a2), mk_msg("user", "q2"));
|
||||
let r1 = store.append_node(Some(q2), mk_msg("assistant", "reply 1"));
|
||||
let r2 = store.append_node(Some(q2), mk_msg("assistant", "reply 2"));
|
||||
store.active_leaf_id = r2;
|
||||
|
||||
// Root fork: should show [a1, a2's subtree]
|
||||
let opts = store.branch_options_at(root, r2);
|
||||
assert_eq!(opts.len(), 2);
|
||||
assert_eq!(opts[0].id, a1);
|
||||
assert_eq!(opts[0].position, Some(1));
|
||||
assert_eq!(opts[0].snippet, "answer 1");
|
||||
// a2's subtree includes r2, so the rep should be r2 (preferred leaf)
|
||||
assert_eq!(opts[1].id, r2);
|
||||
assert_eq!(opts[1].position, Some(2));
|
||||
assert_eq!(opts[1].snippet, "answer 2");
|
||||
|
||||
// Sub-fork at q2: should show [r1, r2]
|
||||
let opts = store.branch_options_at(q2, r2);
|
||||
assert_eq!(opts.len(), 2);
|
||||
assert_eq!(opts[0].id, r1);
|
||||
assert_eq!(opts[0].position, Some(1));
|
||||
assert_eq!(opts[0].snippet, "reply 1");
|
||||
assert_eq!(opts[1].id, r2);
|
||||
assert_eq!(opts[1].position, Some(2));
|
||||
assert_eq!(opts[1].snippet, "reply 2");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user