use super::*; #[test] fn a_utility_id_can_never_be_mistaken_for_a_session_id() { let id = utility_id("install-claude", 4242, 1); assert!(is_utility(&id), "{id} does not say it is a utility"); assert!(id.starts_with(UTILITY_PREFIX)); // The two ids a session can ever have: one the host minted, and one a // client brought (a row id, or an agent's uuid). Neither is a utility. for session in [ "host-991-1-20260922T090000Z", "11111111-2222-3333-4444-555555555555", "ses_01H", "", ] { assert!( !is_utility(session), "{session} was read as a utility terminal" ); } } #[test] fn two_utilities_of_one_purpose_never_share_an_id() { assert_ne!(utility_id("clone", 1, 1), utility_id("clone", 1, 2)); // AND NOT ACROSS A RESTART EITHER. The helper outlives the app; an app // holding an id from before a restart must not be handed a different // terminal under the same name. assert_ne!(utility_id("clone", 1, 1), utility_id("clone", 2, 1)); } #[test] fn a_purpose_is_a_folder_name_or_it_is_refused_by_name() { for good in ["install-claude", "sign_in_codex", "clone", "a1"] { assert_eq!(purpose_refusal(good), None, "{good} was refused"); } // Every way a purpose could become a path nobody chose, or a key the // caller does not know it has. for bad in [ "", "../../etc", "install claude", "clone/cottondb", "sign in", "café", ".", ] { let refusal = purpose_refusal(bad).unwrap_or_else(|| panic!("{bad:?} was accepted")); assert!(!refusal.is_empty()); } let long = "x".repeat(PURPOSE_MAX + 1); assert!(purpose_refusal(&long).is_some_and(|said| said.contains("at most"))); assert_eq!(purpose_refusal(&"x".repeat(PURPOSE_MAX)), None); } #[test] fn an_argv_with_nothing_in_it_is_refused_rather_than_started() { assert!(argv_refusal(&[]).is_some()); assert!(argv_refusal(&[" ".to_string()]).is_some()); assert_eq!(argv_refusal(&["/bin/sh".to_string()]), None); } #[test] fn every_refusal_says_what_to_do_about_it() { let busy = busy_refusal("install-claude", "util:install-claude:9-1"); assert!(busy.contains("install-claude")); assert!(busy.contains("util:install-claude:9-1")); let missing = no_program_refusal("npm"); assert!(missing.contains("npm")); assert!(missing.contains("install it first")); }