Persona R10 fix-ups: tests account for every draft they leave unsent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 19:54:22 +01:00
commit 55da50cd19

View file

@ -57,6 +57,15 @@ pub(crate) fn answered(packet: &Packet, prose: &str, answer: Value) -> Value {
decide(&model, "test", packet, "The room is warm.", prose, &Tuning::default())
}
/// `answer` with every draft of `prose` it does not send or gap held, citing `quote` of her thought (Soul's R10: every
/// draft is accounted for).
pub(crate) fn holding_the_rest(mut answer: Value, prose: &str, quote: &str) -> Value {
let used: Vec<i64> = ["say", "amend", "suggest", "gaps"].iter().flat_map(|key| answer[key].as_array().cloned().unwrap_or_default()).filter_map(|item| item["draft"].as_i64()).collect();
let held: Vec<Value> = drafts(prose).drafts.iter().map(|draft| draft.n as i64).filter(|n| !used.contains(n)).map(|n| json!({ "draft": n, "how": "held", "quote": quote })).collect();
answer["unsent"] = json!(held);
answer
}
fn decided_in(packet: &Packet, prose: &str, say: Value) -> Value {
answered(packet, prose, json!({ "say": say, "gaps": [] }))
}
@ -133,7 +142,8 @@ fn prose_without_a_draft_says_nothing_whatever_the_model_cites() {
#[test]
fn a_number_that_names_no_draft_is_refused_and_one_draft_goes_one_place() {
let prose = "<typed>One.</typed> <typed>Two.</typed>";
let prose = "I hold these back for now. <typed>One.</typed> <typed>Two.</typed>";
let decided = |prose: &str, say: Value| answered(&packet(), prose, holding_the_rest(json!({ "say": say, "gaps": [] }), prose, "hold these back for now"));
let three = decided(prose, json!([{ "draft": 3 }, { "draft": 0 }, { "mentions": [] }]));
assert!(texts(&three).is_empty(), "{three}");
assert_eq!(three["refused"].as_array().unwrap().len(), 3, "each is reported: {three}");
@ -339,12 +349,13 @@ fn a_draft_gap_names_its_draft_and_carries_its_words() {
#[test]
fn a_gap_quote_shown_back_is_four_words_of_thought_outside_every_draft() {
let prose = "I could tell Nibu. <typed>I could tell Nibu the truth.</typed> Not yet.";
let gaps = gaps_of(&packet(), prose, json!([
let answer = json!({ "say": [], "gaps": [
{ "kind": "unwritten", "draft": null, "quote": "tell", "detail": "" },
{ "kind": "unwritten", "draft": null, "quote": "I could tell Nibu the truth.", "detail": "" },
{ "kind": "conditional", "draft": null, "quote": "I could tell Nibu.", "detail": "" },
{ "kind": "conditional", "draft": null, "quote": "I will tell Nibu tomorrow.", "detail": "" },
]));
], "unsent": [{ "draft": 1, "how": "held", "quote": "Not yet" }] });
let gaps = answered(&packet(), prose, answer)["gaps"].as_array().unwrap().clone();
assert_eq!(gaps.iter().map(|gap| gap["from"].as_str().unwrap()).collect::<Vec<_>>(), ["unlocated", "unlocated", "thought", "unlocated"], "one word; inside a draft only; four words of thought; words not in his prose: {gaps:?}");
assert_eq!(gaps[2]["start_byte"], 0, "located in his thought, not in the draft that repeats it");
assert_eq!(gaps[0]["quote"], "tell", "an unlocated quote is kept for the trace");
@ -460,8 +471,8 @@ fn an_amendment_adds_a_whole_draft_after_a_listed_line_of_his_and_rewrites_nothi
#[test]
fn an_amendment_off_the_list_a_second_one_or_one_reusing_a_draft_is_refused_and_reported() {
let prose = "<typed>Correction one.</typed> <typed>Correction two.</typed>";
let amend = |packet: &Packet, say: Value, amend: Value| answered(packet, prose, json!({ "say": say, "gaps": [], "amend": amend }));
let prose = "I hold the rest. <typed>Correction one.</typed> <typed>Correction two.</typed>";
let amend = |packet: &Packet, say: Value, amend: Value| answered(packet, prose, holding_the_rest(json!({ "say": say, "gaps": [], "amend": amend }), prose, "hold the rest"));
let reasons = |decision: &Value| decision["refused"].as_array().unwrap().iter().map(|refused| (refused["act"].as_str().unwrap().to_owned(), refused["reason"].as_str().unwrap().to_owned())).collect::<Vec<_>>();
let off = amend(&amendable_packet(), json!([]), json!([{ "target": "$ev-1", "draft": 1 }]));
assert_eq!((off["amended"].as_array().unwrap().len(), reasons(&off)), (0, vec![("amend".to_owned(), "not_amendable".to_owned())]), "an event id the model invents is no id on the list: {off}");
@ -485,7 +496,8 @@ fn the_interpreter_sees_his_lines_by_id_never_by_event_and_is_told_he_never_take
const NOTE: &str = "Deru says the kettle's top note is too shrill to live with. I think the start-up sound wants a softer attack.";
fn noted(packet: &Packet, say: Value, suggest: Value) -> Value {
answered(packet, &format!("I'll leave Self a note. <typed>{NOTE}</typed> And then: <typed>Another thought.</typed>"), json!({ "say": say, "gaps": [], "suggest": suggest }))
let prose = format!("I'll leave Self a note. <typed>{NOTE}</typed> And then: <typed>Another thought.</typed>");
answered(packet, &prose, holding_the_rest(json!({ "say": say, "gaps": [], "suggest": suggest }), &prose, "And then"))
}
fn refusals(decision: &Value) -> Vec<(String, String)> {
@ -689,8 +701,8 @@ fn k18_a_note_whose_answer_does_not_say_private_is_refused_as_private() {
/// only in case or in a curly apostrophe were reported not found; an addition could not carry a promise.
#[test]
fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_one_too() {
let prose = "<typed>Missed you too. I'll send the render tonight.</typed> <typed>Also the kettle sounds fine.</typed>";
let say = |draft: u64, promises: &str| answered(&packet(), prose, json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "doable": false, "needs": "words_only" }] }], "gaps": [] }));
let prose = "I hold one back. <typed>Missed you too. I'll send the render tonight.</typed> <typed>Also the kettle sounds fine.</typed>";
let say = |draft: u64, promises: &str| answered(&packet(), prose, holding_the_rest(json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "doable": false, "needs": "words_only" }] }], "gaps": [] }), prose, "hold one back"));
let short = say(2, "the");
assert_eq!((short["gaps"].as_array().unwrap().len(), short["promises_unused"].clone()), (0, json!([{ "draft": 2, "promises": "the", "why": "fewer than four words" }])), "{short}");
assert_eq!(say(1, "the render tonight")["promises_unused"][0]["why"], "fewer than four words");
@ -792,7 +804,7 @@ fn k24_a_read_is_what_her_thought_reaches_for_and_nothing_a_model_made_up() {
assert_eq!(cannot["read_refused"][0]["why"], "no_read_here", "{cannot}");
let prompt = speech_prompt(&reading, "x", prose, &Tuning::default());
assert!(prompt.contains("`read` names one thing he reaches for") && !speech_prompt(&packet(), "x", prose, &Tuning::default()).contains("`read` names"), "the read contract only on a turn that can read");
assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","read"]"#));
assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","read","unsent"]"#));
}
/// Soul's R6: a later call decides over the whole wake. Drafts are numbered across it and an earlier one may still be
@ -829,7 +841,7 @@ fn r6_a_draft_the_later_prose_supersedes_is_not_sent() {
let earlier = answered(&packet, first, json!({ "say": [{ "draft": 1 }], "gaps": [] }));
assert_eq!(texts(&earlier), ["Meta, my read came back empty."]);
let prose = format!("{first}\n\nNo, the read worked; that draft is wrong. <typed>Meta, the read worked: the knee bends first.</typed>");
let reply = json!({ "say": [{ "draft": 2 }], "gaps": [] }).to_string();
let reply = json!({ "say": [{ "draft": 2 }], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "that draft is wrong" }] }).to_string();
let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone());
let reads = ["The knee bends first.".to_owned()];
let decision = decide_in(&model, "test", &packet, "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &reads, before: first });