Skip to content

Commit b5d201a

Browse files
author
Larry
committed
test(acp): drive a routed edit through the native steer decision
The new test pushes an admitted edit into a running scope and calls the listener's steer decision. It checks that the sent steer request carries the original's route and that the running turn gets no cancel signal. Restoring the old edit gate, or dropping the route at the send, fails it. Signed-off-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent b28022b commit b5d201a

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

‎crates/buzz-acp/src/lib.rs‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9531,6 +9531,89 @@ mod edit_native_steer_tests {
95319531
assert_eq!(queued.steer_event.edit, Some(resolved));
95329532
assert_eq!(queued.reaction_target_id, original.id.to_hex());
95339533
}
9534+
9535+
/// End to end through the listener's steer decision: a routed edit that
9536+
/// arrives during a running turn goes out as a native steer carrying the
9537+
/// original's route, and the running turn is not cancelled.
9538+
#[tokio::test]
9539+
async fn routed_edit_steers_running_turn_with_original_route() {
9540+
let root = "ab".repeat(32);
9541+
let original = message(Some(&root));
9542+
let channel_id = Uuid::new_v4();
9543+
let ingress =
9544+
|event: nostr::Event, edit: Option<queue::ResolvedEdit>| NormalListenerIngress {
9545+
buzz_event: relay::BuzzEvent {
9546+
connection_generation: 0,
9547+
channel_id,
9548+
event,
9549+
},
9550+
effective_author: "author".into(),
9551+
prompt_tag: "@mention".into(),
9552+
edit,
9553+
};
9554+
9555+
// A turn is already running in the scope.
9556+
let mut queue = EventQueue::new(config::DedupMode::Queue);
9557+
let running = ingress(message(None), None);
9558+
let scope = running.session_scope(scope::SessionPolicy::Channel, false);
9559+
running.push(&mut queue, scope.clone());
9560+
queue.flush_next().expect("running turn");
9561+
assert!(queue.is_scope_in_flight(&scope));
9562+
9563+
let mut pool = AgentPool::from_slots(vec![]);
9564+
let (control_tx, mut control_rx) = tokio::sync::oneshot::channel();
9565+
let (steer_tx, mut steer_rx) = tokio::sync::mpsc::channel(1);
9566+
let task = pool.join_set.spawn(async {});
9567+
pool.task_map_mut().insert(
9568+
task.id(),
9569+
pool::TaskMeta {
9570+
agent_index: 0,
9571+
channel_id: Some(channel_id),
9572+
scope: Some(scope.clone()),
9573+
turn_id: "t".into(),
9574+
recoverable_batch: None,
9575+
control_tx: Some(control_tx),
9576+
steer_tx: Some(steer_tx),
9577+
successful_steer_deliveries: HashSet::new(),
9578+
},
9579+
);
9580+
9581+
let edit = edit_event(&original.id.to_hex(), &[]);
9582+
let resolved = queue::ResolvedEdit {
9583+
target_event_id: original.id.to_hex(),
9584+
target_thread_tags: queue::parse_thread_tags(&original),
9585+
};
9586+
let edit_ingress = ingress(edit, Some(resolved));
9587+
assert_eq!(
9588+
edit_ingress.session_scope(scope::SessionPolicy::Channel, false),
9589+
scope
9590+
);
9591+
let (ack_tx, _ack_rx) = mpsc::unbounded_channel();
9592+
edit_ingress
9593+
.push(&mut queue, scope.clone())
9594+
.steer_or_interrupt(
9595+
MultipleEventHandling::Steer,
9596+
None,
9597+
&mut pool,
9598+
&mut queue,
9599+
&ack_tx,
9600+
);
9601+
9602+
let request = steer_rx.try_recv().expect("edit is sent as a native steer");
9603+
let body = request.prompt_blocks.join("\n");
9604+
assert!(
9605+
body.contains(&format!("Edit of: {}", original.id.to_hex())),
9606+
"{body}"
9607+
);
9608+
assert!(body.contains(&format!("root={root}")), "{body}");
9609+
assert!(
9610+
matches!(
9611+
control_rx.try_recv(),
9612+
Err(tokio::sync::oneshot::error::TryRecvError::Empty)
9613+
),
9614+
"native steer must not cancel the running turn"
9615+
);
9616+
}
95349617
}
95359618

95369619
#[cfg(test)]

0 commit comments

Comments
 (0)