agentmux_srv_core/backend/container/
routes.rs1use crate::backend::route_audience::{self, Served, UNCLASSIFIED};
11
12pub fn refusal(path: &str, served: Served) -> Option<&'static str> {
14 route_audience::refusal(path, served)
15}
16
17pub fn refusal_message(path: &str, served: Served) -> Option<String> {
20 let why = refusal(path, served)?;
21 if why == UNCLASSIFIED {
22 tracing::warn!(path, "a container agent called a route with no audience; declare it in srv's route table or name it in backend/route_audience.rs");
23 }
24 Some(format!("this route is not available to container agents: {why}"))
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 fn nothing(_: &str) -> bool {
34 false
35 }
36
37 #[test]
38 fn what_a_container_agent_cannot_do_says_why_and_what_to_do() {
39 let cases = [
40 ("/api/v1/shell/create", "can't run commands on the host"),
41 ("/api/v1/ptyshell/input", "can't run commands on the host"),
42 ("/api/v1/conn/list", "can't run commands on the host"),
43 ("/api/v1/agent/desktop/authorize", "launch programs"),
44 ("/api/v1/host/vault", "for the AgentMux app itself"),
45 ("/agentmux/reactive/poller/config", "for the AgentMux app itself"),
46 ("/api/messaging/discord/send", "for the AgentMux app itself"),
47 ("/agentmux/service", "generic gateway"),
48 ("/ws", "generic gateway"),
49 ("/agentmux/stream-local-file", "reads files on the host"),
50 ("/api/v1/agent/self/upgrade", "replaces the app"),
51 ("/api/v1/agent/globalmemory/write", "read it but not change it"),
52 ];
53 for (path, says) in cases {
54 let message = refusal_message(path, nothing).unwrap_or_else(|| panic!("{path} should be refused"));
55 assert!(message.starts_with("this route is not available to container agents: "), "{message}");
56 assert!(message.contains(says), "{path}: {message}");
57 }
58 }
59
60 #[test]
61 fn near_misses_are_not_taken_for_a_refused_prefix() {
62 for path in ["/api/v1/shells", "/api/v1/hostile", "/api/v1/agent/desktops"] {
64 assert_eq!(refusal(path, nothing), Some(UNCLASSIFIED), "{path}");
65 }
66 }
67}