//! The daemon's own decisions that are pure. The socket, the spawn and the //! blocked permission hook are driven end to end in `tests/host_socket.rs`. use super::*; #[test] fn a_notification_names_a_kind_and_never_guesses_at_one() { let kind = |json: serde_json::Value| notification_kind(&json); assert_eq!( kind(serde_json::json!({"notification_type": "permission_prompt"})), WaitingKind::Permission ); assert_eq!( kind(serde_json::json!({"notification_type": "agent_needs_input"})), WaitingKind::Question ); assert_eq!( kind(serde_json::json!({"notification_type": "elicitation_dialog"})), WaitingKind::Question ); assert_eq!( kind(serde_json::json!({"notification_type": "idle_prompt"})), WaitingKind::Input ); assert_eq!( kind(serde_json::json!({"matcher": "permission_prompt"})), WaitingKind::Permission ); assert_eq!(kind(serde_json::json!({})), WaitingKind::Input); } #[test] fn a_permission_request_takes_the_agent_s_own_id_when_it_has_one() { assert_eq!( permission_request_id(&serde_json::json!({"request_id": "req-1"})), "req-1" ); assert_eq!( permission_request_id(&serde_json::json!({"tool_use_id": "toolu_9"})), "toolu_9" ); } #[test] fn two_requests_the_agent_did_not_name_never_share_an_id() { let first = permission_request_id(&serde_json::json!({})); let second = permission_request_id(&serde_json::json!({})); assert_ne!( first, second, "two concurrent requests answered by one id would answer the wrong one" ); } #[test] fn an_unknown_session_is_refused_with_the_id_and_the_reason_in_the_sentence() { let said = unknown("abc"); assert!(said.contains("abc")); assert!( said.contains("restarted"), "the refusal names the reason a session can be missing — got {said}" ); } /// **A SOCKET PATH TOO LONG IS A SENTENCE, NOT `SUN_LEN`.** /// /// Measured 2026-09-19: a data directory under a session scratchpad made the /// helper die with `the session host could not start: path must be shorter /// than SUN_LEN` — no path, no number, and nothing saying which variable to /// move. The real data folder never reaches it; a `COTTON_MAC_DATA_DIR` somebody set /// does, which is exactly when a person needs to be told. #[test] fn a_socket_path_too_long_for_sun_path_is_refused_by_name() { let short = std::path::Path::new("/Users/me/CottonDB/session-host.sock"); assert!(socket_path_refusal(short).is_none()); // One byte under the limit is bound, one byte over is refused: the // boundary is the whole of this rule. let fits = std::path::PathBuf::from(format!("/{}", "a".repeat(SOCKET_PATH_MAX - 2))); assert_eq!(fits.as_os_str().as_encoded_bytes().len(), SOCKET_PATH_MAX - 1); assert!(socket_path_refusal(&fits).is_none()); let over = std::path::PathBuf::from(format!("/{}", "a".repeat(SOCKET_PATH_MAX - 1))); let refusal = socket_path_refusal(&over).expect("a path that cannot be bound is refused"); let said = refusal.to_string(); assert!(said.contains(&over.display().to_string()), "{said}"); assert!(said.contains(&SOCKET_PATH_MAX.to_string()), "{said}"); assert!(said.contains("COTTON_MAC_DATA_DIR"), "{said}"); }