const TRACKED_TURN_SRC: &str = include_str!("../channels/discord/tracked_turn.rs");
const HANDLER_SRC: &str = include_str!("../channels/discord/handler.rs");
const RESUME_SRC: &str = include_str!("../channels/discord/resume.rs");
const MANAGER_SRC: &str = include_str!("../channels/manager.rs");
const UI_SRC: &str = include_str!("../cli/ui.rs");
#[test]
fn runner_claims_the_slot_before_any_token_can_cancel() {
let claim = TRACKED_TURN_SRC
.find("dstate.try_begin_turn(session_id)")
.expect("runner claims the turn slot");
let store = TRACKED_TURN_SRC
.find(".store_cancel_token(session_id")
.expect("runner stores a cancel token");
assert!(
claim < store,
"the slot claim must precede store_cancel_token (#1990 landmine)"
);
}
#[test]
fn runner_flush_releases_the_slot_before_draining() {
let drop_guard = TRACKED_TURN_SRC
.find("drop(_turn_guard);")
.expect("runner releases the slot explicitly before the flush");
let drain = TRACKED_TURN_SRC
.find("dstate.drain_followups(session_id)")
.expect("runner drains leftover follow-ups at turn end");
assert!(
drop_guard < drain,
"the guard must drop before the end-of-turn flush drains (#1990)"
);
assert!(
TRACKED_TURN_SRC.contains("ResumeDispatch::Display"),
"the flush spawns a tracked Display turn"
);
}
#[test]
fn ingress_handler_claims_queues_and_acks_instead_of_forking() {
assert!(
HANDLER_SRC.contains("discord_state.try_begin_turn(session_id)"),
"ingress claims the session slot (#1990)"
);
assert!(
HANDLER_SRC.contains("mid-turn follow-up queued for session"),
"the queued path is logged for the issue's repro"
);
assert!(
HANDLER_SRC.contains("ReactionType::Unicode(\"👀\".to_string())"),
"a queued follow-up gets the 👀 ack like Telegram's"
);
assert!(
HANDLER_SRC.contains("drop(_turn_guard);")
&& HANDLER_SRC.contains("discord_state.drain_followups(session_id)"),
"the ingress turn flushes its queue at end (#1990)"
);
}
#[test]
fn background_completion_rides_the_runner_and_queues_on_loss() {
assert!(
RESUME_SRC.contains("run_tracked_resume_turn"),
"background completions run visibly through the runner (#1990)"
);
let dispatch = RESUME_SRC
.find("ResumeDispatch::Push")
.expect("the completion push is the runner's dispatch");
assert!(
RESUME_SRC[..dispatch].contains("await"),
"the runner call awaits the turn"
);
assert!(
RESUME_SRC.contains("state.enqueue_followup(session_id, msg)"),
"a Queued outcome re-queues the full message"
);
}
#[test]
fn tool_loop_injection_callback_is_wired_for_discord() {
let wiring = MANAGER_SRC
.find("followup_queue_callback")
.expect("manager wires the follow-up queue callback");
assert!(
MANAGER_SRC[wiring..].contains("create_agent_service_full(Some(followup_cb)"),
"the callback is passed as the queue slot, not the enqueue slot"
);
}
#[test]
fn boot_recovery_has_a_discord_branch_promising_the_hold() {
assert!(
UI_SRC.contains("crate::channels::discord::tracked_turn::ResumeDispatch::Recovery"),
"boot recovery dispatches a tracked Recovery turn for discord"
);
assert!(
UI_SRC.contains("it is held for"),
"the recovery prompt promises the mid-turn hold (#1990)"
);
assert!(
UI_SRC.contains("ResumeTurnOutcome::Queued") && UI_SRC.contains("record_parked()"),
"a boot replay that lost the claim parks in the ledger (#1242)"
);
}