engine: a kicked services bot rejoins its assigned channel

A PART/KICK of a bot uid updated channel membership but not bot_channels,
so reconcile still believed the bot was present and never rejoined it — an
op could evict a services bot for good. The Part handler now drops the stale
membership and reconciles, so a bot assigned to the channel comes right back.
This commit is contained in:
Jean Chevronnet 2026-07-16 10:03:00 +00:00
parent 7e868babc3
commit a9a3408de0
No known key found for this signature in database
2 changed files with 46 additions and 0 deletions

View file

@ -981,6 +981,14 @@ impl Engine {
NetEvent::Part { uid, channel } => {
self.network.channel_part(&channel, &uid);
self.forget_chatter(&channel, &uid);
// A services bot kicked/parted from a channel it's still assigned
// to rejoins — an op can't evict it. Drop the stale membership so
// reconcile re-adds it.
if let Some(bot_lc) = self.bot_uids.iter().find_map(|(lc, u)| (u == &uid).then(|| lc.clone())) {
if self.bot_channels.remove(&(bot_lc, channel.clone())) {
return self.reconcile_bots();
}
}
Vec::new()
}
NetEvent::ChannelOp { channel, uid, op } => {

View file

@ -1822,6 +1822,44 @@
assert!(out.iter().any(|a| matches!(a, NetAction::ServicePart { channel, .. } if channel == "#c")), "parts on unassign: {out:?}");
}
// A services bot kicked from a channel it's assigned to rejoins at once — an
// op can't evict it.
#[test]
fn kicked_bot_rejoins_its_channel() {
use echo_botserv::BotServ;
use echo_nickserv::NickServ;
let path = std::env::temp_dir().join("echo-kickbot.jsonl");
let _ = std::fs::remove_file(&path);
let mut db = Db::open(&path, "42S");
db.scram_iterations = 4096;
db.register("boss", "password1", None).unwrap();
db.register_channel("#c", "boss").unwrap();
let mut e = Engine::new(
vec![
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
Box::new(BotServ { uid: "42SAAAAAD".into() }),
],
db,
);
e.set_sid("42S".into());
let mut opers = std::collections::HashMap::new();
opers.insert("boss".to_string(), Privs::default().with(echo_api::Priv::Admin));
e.set_opers(opers);
let ns = |e: &mut Engine, t: &str| e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: t.into() });
let bs = |e: &mut Engine, t: &str| e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAD".into(), text: t.into() });
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "boss".into(), host: "h".into() , ip: "0.0.0.0".into() });
ns(&mut e, "IDENTIFY password1");
bs(&mut e, "BOT ADD Bendy bot serv.host Helper");
let bot_uid = bs(&mut e, "ASSIGN #c Bendy").iter().find_map(|a| match a {
NetAction::ServiceJoin { uid, channel } if channel == "#c" => Some(uid.clone()),
_ => None,
}).expect("bot joined on assign");
// The bot is kicked out (the ircd relays this as a PART for its uid).
let out = e.handle(NetEvent::Part { uid: bot_uid.clone(), channel: "#c".into() });
assert!(out.iter().any(|a| matches!(a, NetAction::ServiceJoin { uid, channel } if uid == &bot_uid && channel == "#c")), "kicked bot rejoins: {out:?}");
}
// A channel that expires with an assigned bot parts the bot in the same
// sweep — it must not linger in a channel it no longer serves.
#[test]