diff --git a/crates/axe-telegram/src/telegram.rs b/crates/axe-telegram/src/telegram.rs index 38aa2e9..29265da 100644 --- a/crates/axe-telegram/src/telegram.rs +++ b/crates/axe-telegram/src/telegram.rs @@ -71,7 +71,7 @@ const UPDATE_ATTEMPTS: u32 = 3; /// is 1-32 lowercase letters, digits and underscores; the description 1-256 /// characters. `/web` is listed only with `[telegram] web_login` /// ([`WEB_COMMAND`]). -pub const OWNER_COMMANDS: [(&str, &str); 13] = [ +pub const OWNER_COMMANDS: [(&str, &str); 12] = [ ( "status", "This bot: state, live run, wakes, services, schedules", @@ -90,7 +90,6 @@ pub const OWNER_COMMANDS: [(&str, &str); 13] = [ ("stop", "Stop the live run; queued wakes are kept"), ("pause", "Pause: no new wakes, stop the live run"), ("resume", "Resume a paused bot"), - ("reset", "Clear the session; the next run starts fresh"), ("runtimes", "Runtimes, their logins, and routing"), ( "board", @@ -2541,7 +2540,7 @@ impl Gateway { } /// `/status`, `/node`, `/cost`, `/goals`, `/services`, `/routines`, - /// `/stop`, `/pause`, `/resume`, `/reset`, `/runtimes`, `/board`, `/web`: + /// `/stop`, `/pause`, `/resume`, `/runtimes`, `/board`, `/web`: /// handled here, never waking the bot, so they /// work with no agent runtime logged in. The reply is recorded. #[allow(clippy::too_many_arguments)] @@ -2587,9 +2586,6 @@ impl Gateway { "resume" => store .bot_change(actor, &b.name(), "resume") .map(|_| "resumed".to_string()), - "reset" => store - .bot_change(actor, &b.name(), "reset") - .map(|_| "session cleared; the next run starts fresh".to_string()), "board" => { self.board_command(b, store, actor, chat, m["message_thread_id"].as_i64(), arg) } diff --git a/crates/axe/tests/telegram.rs b/crates/axe/tests/telegram.rs index b2f8878..bf94306 100644 --- a/crates/axe/tests/telegram.rs +++ b/crates/axe/tests/telegram.rs @@ -1818,13 +1818,13 @@ fn owner_commands_are_handled_without_waking_the_bot() { let t = axe::remote::epoch(); axe::schedule::add(&mut conn, &axe::db::Actor::new("t"), "cos", &sched, "w", t).unwrap(); } - let cmds = ["/status", "/stop", "/pause", "/resume", "/reset@cos_bot"]; + let cmds = ["/status", "/stop", "/pause", "/resume@cos_bot"]; for (i, c) in cmds.iter().enumerate() { rig.stub .push(text_msg(100 + i as i64, 200 + i as i64, OWNER, OWNER, c)); } - rig.stub.wait_confirmed(104); - wait_for("5 replies", 20, || rig.sent_to(OWNER).len() >= 5); + rig.stub.wait_confirmed(103); + wait_for("4 replies", 20, || rig.sent_to(OWNER).len() >= 4); let replies: Vec = rig .sent_to(OWNER) .iter() @@ -1845,17 +1845,12 @@ fn owner_commands_are_handled_without_waking_the_bot() { assert!(replies[1].contains("stopping the live run")); assert!(replies[2].starts_with("paused")); assert_eq!(replies[3], "resumed"); - assert!( - replies[4].contains("has a live run; stop it first"), - "{}", - replies[4] - ); let replied_to: Vec = rig .sent_to(OWNER) .iter() .map(|p| p["reply_parameters"]["message_id"].as_i64().unwrap()) .collect(); - assert_eq!(replied_to, [200, 201, 202, 203, 204]); + assert_eq!(replied_to, [200, 201, 202, 203]); assert!( rig.inbound().is_empty(), @@ -1897,7 +1892,6 @@ fn owner_commands_are_handled_without_waking_the_bot() { r#"{"command":"stop"}"#, r#"{"command":"pause"}"#, r#"{"command":"resume"}"#, - r#"{"command":"reset"}"#, ] ); assert!( @@ -1905,7 +1899,7 @@ fn owner_commands_are_handled_without_waking_the_bot() { "commands are answered, not acked" ); // Replies are part of the conversation history. - assert_eq!(rig.messages().len(), 5); + assert_eq!(rig.messages().len(), 4); } #[test] @@ -6148,14 +6142,14 @@ fn command_menu_lists_the_routed_commands_for_the_owner_only() { .iter() .map(|(c, _)| *c) .collect(); - assert_eq!(names.len(), 13, "{names:?}"); + assert_eq!(names.len(), 12, "{names:?}"); for c in [ "runtimes", "node", "cost", "goals", "services", "routines", "board", ] { assert!(names.contains(&c), "{c} in {names:?}"); } - // Retired (owner msg #5897). - for c in ["tasks", "task", "wake"] { + // Retired (owner msgs #5897, #6598). + for c in ["tasks", "task", "wake", "reset"] { assert!(!names.contains(&c), "{c} in {names:?}"); } @@ -6176,6 +6170,28 @@ fn command_menu_lists_the_routed_commands_for_the_owner_only() { }); assert!(rig.inbound().is_empty(), "{:?}", rig.inbound()); assert!(rig.message_wakes().is_empty()); + + // A retired command, like any unknown one, is a plain message to the + // bot: stored and waking it, with no command reply and no bot change. + let replies = rig.sent_to(OWNER).len(); + rig.stub.push(text_msg(400, 500, OWNER, OWNER, "/reset")); + rig.stub.wait_confirmed(400); + wait_for("/reset stored", 20, || !rig.inbound().is_empty()); + let texts: Vec = rig.inbound().into_iter().map(|m| m.2).collect(); + assert_eq!(texts, ["/reset"]); + wait_for("/reset wakes the bot", 20, || { + !rig.message_wakes().is_empty() + }); + assert_eq!(rig.sent_to(OWNER).len(), replies, "no command reply"); + let resets: i64 = rig + .db() + .query_row( + "SELECT COUNT(*) FROM bot_events WHERE kind='reset'", + [], + |r| r.get(0), + ) + .unwrap(); + assert_eq!(resets, 0); } /// `/web` (task 2133): off by default, it is not in the `/` menu and says @@ -6649,12 +6665,12 @@ fn owner_commands_and_their_api_twins_record_the_same_actions() { let tg = Rig::new(); live_run(&tg); let tg_from = last_event(&tg); - for (i, c) in ["/stop", "/pause", "/resume", "/reset"].iter().enumerate() { + for (i, c) in ["/stop", "/pause", "/resume"].iter().enumerate() { tg.stub .push(text_msg(100 + i as i64, 200 + i as i64, OWNER, OWNER, c)); } - tg.stub.wait_confirmed(103); - wait_for("4 replies", 20, || tg.sent_to(OWNER).len() >= 4); + tg.stub.wait_confirmed(102); + wait_for("3 replies", 20, || tg.sent_to(OWNER).len() >= 3); // The API. let api = Rig::new(); live_run(&api); @@ -6663,10 +6679,7 @@ fn owner_commands_and_their_api_twins_record_the_same_actions() { &["bot", "stop", "cos"][..], &["bot", "pause", "cos"], &["bot", "resume", "cos"], - &["bot", "reset", "cos"], ] { - // Like Telegram, a refused action (reset with a live run) is an - // answer, not a change. let _ = api.srv().run(a); } let want = owner_trace(&api, api_from); diff --git a/docs/user/primitives/bot.md b/docs/user/primitives/bot.md index 0fa89f9..edd8e57 100644 --- a/docs/user/primitives/bot.md +++ b/docs/user/primitives/bot.md @@ -28,7 +28,8 @@ lines it writes for you, with what needs your decision first. Heavy work it hand | `axe bot show NAME` / `axe bot log NAME` / `axe bot show NAME --notes` | State, history, notebook | | `axe bot board show` | What the owner should see (`--bot NAME`) | | `axe bot set NAME …` | Change identity, conduct, repos or runtime (with `--why`) | -| `axe bot pause` / `resume` / `stop` / `reset` | Control its runs and session | +| `axe bot pause` / `resume` / `stop` | Control its runs (also Telegram `/pause`, `/resume`, `/stop`) | +| `axe bot reset NAME` | Operator only: clear its agent session so the next run starts fresh | Telegram owner commands (`/status`, `/node`, `/cost`, `/runtimes`, `/board`, ...) are answered by the server without waking the bot. Each one is