56 lines · 1.7 KB · RustRaw
//! What the hook command puts on the wire. The blocking half is driven//! against a fake socket in `tests/hook_subcommand.rs`.use super::*;#[test]fn a_hook_forwards_the_event_the_session_and_the_payload_verbatim() { let stdin = r#"{"session_id":"s-1","transcript_path":"/tmp/t.jsonl","hook_event_name":"Stop","cwd":"/work"}"#; let Request::Hook { event, session_id, payload, } = request("Stop", stdin) else { panic!("a hook builds a hook request"); }; assert_eq!(event, "Stop"); assert_eq!(session_id.as_deref(), Some("s-1")); assert_eq!(payload["transcript_path"], "/tmp/t.jsonl"); assert_eq!(payload["cwd"], "/work");}#[test]fn a_payload_with_no_session_id_still_travels_rather_than_being_dropped() { let Request::Hook { session_id, payload, .. } = request("Notification", r#"{"notification_type":"idle_prompt"}"#) else { panic!("a hook builds a hook request"); }; assert_eq!(session_id, None); assert_eq!(payload["notification_type"], "idle_prompt");}#[test]fn something_that_is_not_json_is_forwarded_as_text_so_the_host_log_shows_it() { let Request::Hook { payload, .. } = request("Stop", "not json at all") else { panic!("a hook builds a hook request"); }; assert_eq!(payload, serde_json::Value::String("not json at all".into()));}#[tokio::test]async fn no_daemon_means_no_opinion_never_a_crashed_turn() { let dir = tempfile::tempdir().expect("a scratch directory"); let outcome = run( BLOCKING_EVENT, &dir.path().join("nothing-here.sock"), "{}", Duration::from_millis(50), ) .await; assert_eq!(outcome, HookOutcome::silent());}