use super::*; fn user(content: serde_json::Value) -> String { let piece: Piece = serde_json::from_value(serde_json::json!({ "kind": "user", "content": content })) .expect("a user piece as the app sends it"); render(&PlainText, &piece) } /// A user message shows what the reader wrote, escaped, and not what rode along for the model. /// /// The break this catches: hook context shown as the reader's words, or their words written into /// the page unescaped. #[test] fn a_user_message_shows_only_the_readers_words() { let html = user(serde_json::json!([ { "type": "text", "content": "why this?" }, { "type": "text", "content": "[hook] Plan check: 10 tool calls" }, ])); assert_eq!(html, "
why <b>this</b>?
"); } /// An image sent first keeps its place, so hook context after it is still hidden. /// /// The break this catches: skipping the blocks that aren't text instead of keeping them as /// placeholders, which moves the hook's note to block 0, where it reads as the reader's own. #[test] fn an_image_keeps_its_place_in_a_user_message() { let html = user(serde_json::json!([ { "type": "image" }, { "type": "text", "content": "[hook] Plan check: 10 tool calls" }, ])); assert_eq!(html, "1 image(s) attached
"); } /// The break this catches: images left without a trace, so a photo sent from the phone vanishes /// from the conversation, or counted wrong, or their glyph written into the page unescaped. #[test] fn images_show_as_the_tuis_attached_line() { let piece: Piece = serde_json::from_value(serde_json::json!({ "kind": "user", "content": [{ "type": "text", "content": "what's this?" }, { "type": "image" }, { "type": "image" }], })) .expect("a user piece as the app sends it"); assert_eq!( render(&Loud, &piece), "what's this?
& 2 image(s) attached
" ); } /// The break this catches: a file or tree piece renamed, sent to another piece's renderer, or the /// tree refusing the `null` changes the app sends before anything changed, so the Files tab's /// request is refused or drawn as something else. #[test] fn the_file_pieces_arrive_by_their_kinds() { let pieces = serde_json::json!([ { "kind": "file", "file": { "path": "a.rs", "text": "x\n", "bytes": 2 } }, { "kind": "file_failed", "error": "wrong_kind" }, { "kind": "tree", "rows": [{ "kind": "note", "depth": 0, "text": "Loading" }], "changes": null }, ]); let pieces: Vechi
"); } /// The break this catches: a brief Luxe wrote shown whole, as a page of instructions in the /// reader's colors. #[test] fn a_brief_shows_as_one_line() { let html = user(serde_json::json!([ { "type": "text", "content": "Draft a reply to @jon on PR 12.\n\nKeep it short." }, ])); assert_eq!(html, "Drafted a reply
"); } /// A question from a review is the reader's, so it shows, under where it was asked. /// /// The break this catches: the brief labeled as one line instead, losing the question the answer /// below it is answering. #[test] fn a_review_question_shows_what_was_asked() { let brief = "Guided review feedback\nSubmission: submission:1\nReview: review:2\n\ Source revision: revision:3\nMode: Question\n\n\ - Question ยท Why two passes?\n\ \x20 Finding ID: finding:2\n\ \x20 Evidence: src/a.rs:3 (new)\n\ \x20 Why two passes?\n\ Do not rewrite unrelated code."; let html = user(serde_json::json!([{ "type": "text", "content": brief }])); assert_eq!( html, "Asked in review \u{b7} src/a.rs:3 (new)\n\ Why two passes?
" ); } /// A renderer that words every status the same, with a mark and words that need escaping. struct Loud; impl Renderer for Loud { fn markdown(&self, _text: &str, _voice: Voice) -> String { String::new() } fn tool_glyph(&self, _tool: &str) -> String { String::new() } fn status(&self, _facts: &StatusFacts) -> Vec