openbutler-protocol 0.0.2

The wire contract between the OpenButler daemon and its clients: frame encoding, action envelopes, and the shared state types.
Documentation
//! Transcript patch contract: the text continuation carries the stream it
//! belongs to, and an older host's frame still reads as plain text.

#![allow(clippy::unwrap_used)]

use openbutler_protocol::session::{SessionEntriesPatch, TextDelta, TextDeltaKind};
use serde_json::json;

#[test]
fn a_reasoning_continuation_keeps_its_kind() {
    let patch = SessionEntriesPatch::Delta {
        append: vec![],
        replace: vec![],
        append_text: vec![TextDelta {
            index: 7,
            delta: "thinking".to_owned(),
            kind: TextDeltaKind::Reasoning,
        }],
    };
    let encoded = serde_json::to_value(&patch).unwrap();
    assert_eq!(encoded["kind"], "delta");
    assert_eq!(encoded["appendText"][0]["kind"], "reasoning");
    let decoded: SessionEntriesPatch = serde_json::from_value(encoded).unwrap();
    assert_eq!(decoded, patch);
}

#[test]
fn a_continuation_without_a_kind_reads_as_text() {
    // The frame an older host sends: no `kind` field at all.
    let patch = json!({
        "kind": "delta",
        "append": [],
        "replace": [],
        "appendText": [{ "index": 3, "delta": "answer" }]
    });
    let decoded: SessionEntriesPatch = serde_json::from_value(patch).unwrap();
    let SessionEntriesPatch::Delta { append_text, .. } = decoded else {
        panic!("a delta patch");
    };
    assert_eq!(append_text[0].kind, TextDeltaKind::Text);
}