//! An input reaches the model as framed text, not as anonymous words. What the frame
//! states is derived from the durable event every time, so the same input renders the same
//! way on replay, and the stored content keeps the sender's own words.
use klbr_daemon::daemon::{input_frame, input_origin};
use klbr_runtime::store::Event;
use serde_json::json;
fn input_event(payload: serde_json::Value) -> Event {
Event {
id: 123,
kind: "input".into(),
payload,
created_ms: 1_789_325_940_000,
}
}
#[test]
fn an_input_carries_when_it_arrived_and_who_sent_it() {
let event = input_event(json!({"content": "do the thing", "source": "operator"}));
assert_eq!(
input_frame(&event, "do the thing"),
"[2026-09-13T18:59:00Z · operator]\ndo the thing"
);
}
#[test]
fn a_peer_request_names_the_identity_it_must_be_answered_with() {
let payload = json!({
"content": "send me the receipt",
"peer_request_id": "req-7",
"sender_session_id": "peer-a",
});
assert_eq!(input_origin(&payload), "peer request req-7 from peer-a");
assert_eq!(
input_frame(&input_event(payload), "send me the receipt"),
"[2026-09-13T18:59:00Z · peer request req-7 from peer-a]\nsend me the receipt"
);
}
#[test]
fn the_senders_words_are_not_the_place_the_frame_is_written() {
// The frame is assembled on read, so the durable content stays exactly as it arrived.
let payload = json!({"content": "raw words", "source": "operator"});
let event = input_event(payload.clone());
let rendered = input_frame(&event, payload["content"].as_str().unwrap());
assert!(!payload["content"].as_str().unwrap().contains('['));
assert!(rendered.starts_with("[2026-09-13T18:59:00Z · operator]\n"));
assert!(rendered.ends_with("raw words"));
}
#[test]
fn an_input_without_a_source_is_still_placed_in_time() {
let event = input_event(json!({"content": "who am i"}));
assert_eq!(input_origin(&event.payload), "input");
assert_eq!(
input_frame(&event, "who am i"),
"[2026-09-13T18:59:00Z · input]\nwho am i"
);
}
#[test]
fn an_unanswerable_clock_does_not_invent_one() {
let mut event = input_event(json!({"content": "x", "source": "operator"}));
event.created_ms = 0;
assert_eq!(input_frame(&event, "x"), "[time unknown · operator]\nx");
}