Cotton code
469 lines · 28.9 KB · RustRaw
//! Cotton Meetings on a phone that started its own database and never signed//! in: every `meetings.*` method answers here. Every recording is synthetic.use serde_json::{json, Value};use super::*;use crate::handle::{CottonHandle, OpenConfig, OpenMode};use crate::methods::dispatch;fn manifest() -> Value {    json!({        "genesis": "personal",        "flavour": "meetings",        "name": "Cotton Meetings",        "databases": "single",        "database": "personal",        "business": { "server": { "real": "https://cottondb.com", "dev": "https://dev.example.invalid" } },        "fan": { "home": false, "tools": false, "opens": "meetings" },        "kit": "meetings",        "ground": "blank"    })}fn phone(dir: &tempfile::TempDir) -> CottonHandle {    let handle = CottonHandle::open(OpenConfig {        mode: OpenMode::Phone { container_path: dir.path().to_string_lossy().to_string(), previous_container_path: None },        app_version: None,        time_zone: Some("Asia/Kolkata".to_string()),        device_secret: Some(crate::fixture::paired_secret()),        vault_secret: None,        flavor: cotton_core::flavor::Flavor::Real,        manifest: Some(manifest()),    })    .expect("an open core");    dispatch(&handle, "workspace.startLocal", &json!({ "deviceName": "An invented phone" })).expect("started on the phone");    handle}fn ask(handle: &CottonHandle, method: &str, request: Value) -> Value {    dispatch(handle, method, &request).unwrap_or_else(|error| panic!("{method} {request}: {error:?}"))}fn refused(handle: &CottonHandle, method: &str, request: Value) -> String {    dispatch(handle, method, &request).expect_err("refused").code}fn data(handle: &CottonHandle, table: &str, id: &str) -> Value {    let got = ask(handle, "records.get", json!({ "table": table, "id": id }));    if got["data"].is_object() { got["data"].clone() } else { got["record"]["data"].clone() }}fn listed(handle: &CottonHandle, table: &str, meeting: &str) -> Vec<Value> {    let answer = ask(handle, "records.list", json!({ "table": table, "where": { "meeting": meeting }, "limit": 500 }));    answer["records"].as_array().cloned().unwrap_or_default()}/// A WAV as a recorder leaves it mid-recording: its sizes still say empty.fn torn_wav(path: &std::path::Path, seconds: u32) {    let rate = 16_000u32;    let samples = rate * seconds;    let mut bytes = Vec::new();    bytes.extend_from_slice(b"RIFF");    bytes.extend_from_slice(&0u32.to_le_bytes());    bytes.extend_from_slice(b"WAVEfmt ");    bytes.extend_from_slice(&16u32.to_le_bytes());    bytes.extend_from_slice(&1u16.to_le_bytes());    bytes.extend_from_slice(&1u16.to_le_bytes());    bytes.extend_from_slice(&rate.to_le_bytes());    bytes.extend_from_slice(&(rate * 2).to_le_bytes());    bytes.extend_from_slice(&2u16.to_le_bytes());    bytes.extend_from_slice(&16u16.to_le_bytes());    bytes.extend_from_slice(b"data");    bytes.extend_from_slice(&0u32.to_le_bytes());    for n in 0..samples {        let v = ((n as f32 * 440.0 * std::f32::consts::TAU / rate as f32).sin() * 8000.0) as i16;        bytes.extend_from_slice(&v.to_le_bytes());    }    std::fs::create_dir_all(path.parent().unwrap()).unwrap();    std::fs::write(path, bytes).unwrap();}fn transcript() -> Value {    json!({        "by": "test:synthetic",        "languages": ["en", "hi"],        "speakers": [{ "label": "S1" }, { "label": "S2" }],        "lines": [            { "speaker": "S1", "start_ms": 0, "end_ms": 2_000, "text": "Good morning, shall we start with the budget?", "language": "en" },            { "speaker": "S2", "start_ms": 2_100, "end_ms": 4_000, "text": "हाँ, बजट से शुरू करते हैं।", "language": "hi" },            { "speaker": "S1", "start_ms": 4_200, "end_ms": 6_000, "text": "The budget for the bridge is ready.", "language": "en" }        ]    })}fn recorded(handle: &CottonHandle, kind: &str) -> String {    let started = ask(handle, "meetings.record.start", json!({ "kind": kind }));    let id = started["meeting"].as_str().unwrap().to_string();    torn_wav(std::path::Path::new(started["audio_path"].as_str().unwrap()), 3);    ask(handle, "meetings.record.stop", json!({ "id": id }));    id}/// RULE (voice plan, 17 Nov 2026): A recording is a row from the first second: start writes it at `recording` and names the file the platform appends to; a start sent again with the same take is the same recording.#[test]fn a_recording_is_a_row_from_the_first_second() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let started = ask(&handle, "meetings.record.start", json!({ "kind": "memo", "recorded_on": "An invented phone" }));    let id = started["meeting"].as_str().unwrap();    let row = data(&handle, MEETING, id);    assert_eq!((row["status"].as_str(), row["kind"].as_str(), row["take"].as_str()), (Some("recording"), Some("memo"), Some(id)));    assert!(started["audio_path"].as_str().unwrap().ends_with(&format!("recordings/{id}.wav")));    let again = ask(&handle, "meetings.record.start", json!({ "id": id, "kind": "memo" }));    assert_eq!(again["meeting"], started["meeting"]);    let take = ask(&handle, "meetings.record.start", json!({ "id": "take-from-the-recorder" }));    assert_eq!(take["meeting"], "take-from-the-recorder", "the platform's take id is the meeting's");    ask(&handle, "meetings.record.tick", json!({ "id": id, "duration_ms": 10_000 }));    assert_eq!(data(&handle, MEETING, id)["duration_ms"], 10_000);    assert_eq!(refused(&handle, "meetings.record.start", json!({ "kind": "podcast" })), "bad_request");}/// RULE (voice plan, 17 Nov 2026): Stop keeps the audio in the store, queued for the drain under the meeting's own key (sealed as every person's file is), moves the row to `waiting` with its length and size, and lets the working file go.#[test]fn stop_keeps_the_audio_and_waits_for_a_transcriber() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let started = ask(&handle, "meetings.record.start", json!({}));    let id = started["meeting"].as_str().unwrap().to_string();    let path = std::path::PathBuf::from(started["audio_path"].as_str().unwrap());    torn_wav(&path, 2);    let stopped = ask(&handle, "meetings.record.stop", json!({ "id": id }));    assert_eq!(stopped["status"], "waiting");    let row = data(&handle, MEETING, &id);    assert_eq!(row["status"], "waiting");    assert_eq!(row["duration_ms"], 2_000, "the length read from the fixed header");    assert_eq!(row["audio_bytes"], 44 + 2 * 16_000 * 2);    let key = row["audio"].as_str().unwrap();    assert!(key.ends_with(&format!("/meetings/{id}/full.wav")), "{key}");    assert!(!path.exists(), "the working file is the store's now");    let db = key.split('/').next().unwrap();    assert!(cotton_client::media::sealed::is_person_file(db, key), "a recording is sealed before it leaves the phone");    // The audio is on this phone, and On this phone lists it.    assert_eq!(data(&handle, MEETING, &id)["on_phone"], "kept");    let here = ask(&handle, "records.list", json!({ "table": MEETING, "where": { "on_phone": ["kept"] } }));    assert_eq!(here["records"].as_array().unwrap().len(), 1);    let away = ask(&handle, "records.list", json!({ "table": MEETING, "where": { "on_phone": "absent" } }));    assert!(away["records"].as_array().unwrap().is_empty());    // A second stop is no second recording.    assert_eq!(ask(&handle, "meetings.record.stop", json!({ "id": id }))["status"], "waiting");}/// RULE (voice plan, 17 Nov 2026): After a crash, recovery at launch finishes every recording this phone left with its audio, as stop would; one whose audio did not survive is failed with its reason.#[test]fn a_recording_left_by_a_crash_is_recovered_at_launch() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let kept = ask(&handle, "meetings.record.start", json!({}));    torn_wav(std::path::Path::new(kept["audio_path"].as_str().unwrap()), 1);    let lost = ask(&handle, "meetings.record.start", json!({}));    std::fs::write(lost["audio_path"].as_str().unwrap(), b"").unwrap();    let answer = ask(&handle, "meetings.record.recover", json!({}));    assert_eq!(answer["recovered"].as_array().unwrap().len(), 2);    let kept = data(&handle, MEETING, kept["meeting"].as_str().unwrap());    assert_eq!((kept["status"].as_str(), kept["status_why"].as_str()), (Some("waiting"), Some("recovered")));    let lost = data(&handle, MEETING, lost["meeting"].as_str().unwrap());    assert_eq!((lost["status"].as_str(), lost["status_why"].as_str()), (Some("failed"), Some("no_audio")));    assert!(ask(&handle, "meetings.record.recover", json!({}))["recovered"].as_array().unwrap().is_empty(), "recovery runs once");}/// RULE (voice plan, 17 Nov 2026): `meeting.transcribed` lands speakers and lines in one write and makes the meeting ready with its languages; again, it replaces them, and a name given to a voice stays with its label.#[test]fn a_transcript_lands_speakers_and_lines_in_one_write() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    let landed = ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    assert_eq!((landed["lines"].as_u64(), landed["speakers"].as_u64()), (Some(3), Some(2)));    let row = data(&handle, MEETING, &id);    assert_eq!((row["status"].as_str(), row["languages"].as_str(), row["transcribed_by"].as_str()), (Some("ready"), Some("en,hi"), Some("test:synthetic")));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!(read["lines"].as_array().unwrap().len(), 3);    let first = read["speakers"][0].clone();    assert_eq!((first["label"].as_str(), first["lines"].as_i64(), first["talk_ms"].as_i64()), (Some("S1"), Some(2), Some(3_800)));    ask(&handle, "meetings.speaker.name", json!({ "speaker": first["id"], "name": "Asha" }));    let again = ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    assert_eq!(again["lines"], 3);    assert_eq!(listed(&handle, LINE, &id).len(), 3, "the old lines are replaced, not added to");    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!(read["speakers"][0]["name"], "Asha", "the name stays with S1");    assert_eq!(read["lines"][1]["language"], "hi");    // A person's correction outlives the next transcription of that moment.    let line = read["lines"][0]["id"].clone();    ask(&handle, "meetings.line.correct", json!({ "line": line, "text": "Good morning, shall we begin with the budget?" }));    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!(read["lines"][0]["text"], "Good morning, shall we begin with the budget?");    assert_eq!(read["lines"][0]["edited"], true);    assert_eq!(read["lines"].as_array().unwrap().len(), 3);    // A failure from a transcriber says why.    ask(&handle, "meetings.transcribe", json!({ "id": id }));    ask(&handle, "meetings.transcribed", json!({ "id": id, "failed": "engine_failed" }));    assert_eq!(data(&handle, MEETING, &id)["status_why"], "engine_failed");}/// RULE (voice plan, 17 Nov 2026): Transcribe again puts a ready or failed recording back to waiting; one still recording is refused.#[test]fn transcribe_again_waits_and_a_recording_in_progress_is_refused() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "memo");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    assert_eq!(ask(&handle, "meetings.transcribe", json!({ "id": id, "on": "mac" }))["status"], "waiting");    assert_eq!(data(&handle, MEETING, &id)["transcribe_on"], "mac");    let live = ask(&handle, "meetings.record.start", json!({}));    assert_eq!(refused(&handle, "meetings.transcribe", json!({ "id": live["meeting"] })), "still_recording");}/// RULE (voice plan, 17 Nov 2026): On charge, the phone takes the oldest waiting recording whose audio it holds and that any transcriber or the phone may do; off charge it takes none; the Mac's own are left to it.#[test]fn the_phone_takes_the_next_recording_only_on_charge() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let mac = recorded(&handle, "meeting");    ask(&handle, "meetings.transcribed", json!({ "id": mac, "transcript": transcript() }));    ask(&handle, "meetings.transcribe", json!({ "id": mac, "on": "mac" }));    let mine = recorded(&handle, "memo");    assert!(ask(&handle, "meetings.next", json!({ "on": "phone", "charging": false }))["meeting"].is_null());    let next = ask(&handle, "meetings.next", json!({ "on": "phone", "charging": true }));    assert_eq!(next["meeting"], mine.as_str());    assert!(std::path::Path::new(next["audio_path"].as_str().unwrap()).exists());    assert_eq!(next["windows"][0]["end_ms"], 3_000);    assert_eq!(data(&handle, MEETING, &mine)["status"], "transcribing");    assert!(ask(&handle, "meetings.next", json!({ "on": "phone", "charging": true }))["meeting"].is_null());    // The phone hands its windows; the core merges them.    let landed = ask(&handle, "meetings.transcribed", json!({ "id": mine, "by": "phone:sherpa:test", "windows": [        { "index": 0, "start_ms": 0, "end_ms": 3_000, "language": "te", "lines": [{ "speaker": "a", "start_ms": 100, "end_ms": 900, "text": "నమస్కారం" }] }    ]}));    assert_eq!(landed["lines"], 1);    assert_eq!(data(&handle, MEETING, &mine)["languages"], "te");}/// RULE (voice plan, 17 Nov 2026): Signed in, the phone claims through the object before it takes a recording: `next { peek }` names the candidate and claims nothing, `except` passes over one the object refused (the Mac holds it), and `next { id }` takes that one only.#[test]fn the_phone_peeks_claims_and_takes_the_one_it_was_given() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let first = recorded(&handle, "meeting");    let second = recorded(&handle, "memo");    let peeked = ask(&handle, "meetings.next", json!({ "on": "phone", "charging": true, "peek": true }));    assert_eq!(peeked["meeting"], first.as_str());    assert_eq!(data(&handle, MEETING, &first)["status"], "waiting", "a peek claims nothing");    // The object refused the first (the Mac holds it): the phone passes over it.    let other = ask(&handle, "meetings.next", json!({ "on": "phone", "charging": true, "peek": true, "except": [first] }));    assert_eq!(other["meeting"], second.as_str());    let taken = ask(&handle, "meetings.next", json!({ "on": "phone", "charging": true, "id": second }));    assert_eq!(taken["meeting"], second.as_str());    assert_eq!(data(&handle, MEETING, &second)["status"], "transcribing");    assert_eq!(data(&handle, MEETING, &first)["status"], "waiting");}/// RULE (voice plan, 17 Nov 2026): Search finds words in what was said across recordings, in any script, case aside, each hit with its time and speaker.#[test]fn search_finds_what_was_said() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    let hits = ask(&handle, "meetings.search", json!({ "q": "BUDGET" }));    assert_eq!(hits["total"], 2);    assert_eq!(hits["hits"][0]["start_ms"], 0);    assert_eq!(hits["hits"][1]["text"], "The budget for the bridge is ready.");    assert_eq!(ask(&handle, "meetings.search", json!({ "q": "बजट" }))["total"], 1);    assert_eq!(ask(&handle, "meetings.search", json!({ "q": "budget bridge", "id": id }))["total"], 1);    assert_eq!(ask(&handle, "meetings.search", json!({ "q": "nothing like this" }))["total"], 0);}/// RULE (voice plan, 17 Nov 2026): A meeting exports as an open bundle: its audio, the transcript as text, SRT and JSON, the names given to voices used.#[test]fn a_meeting_exports_as_an_open_bundle() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    let first = ask(&handle, "meetings.read", json!({ "id": id }))["speakers"][0]["id"].clone();    ask(&handle, "meetings.speaker.name", json!({ "speaker": first, "name": "Asha" }));    let out = tempfile::tempdir().unwrap();    let bundle = ask(&handle, "meetings.export", json!({ "id": id, "dir": out.path().to_string_lossy() }));    let names: Vec<&str> = bundle["files"].as_array().unwrap().iter().map(|f| f["name"].as_str().unwrap()).collect();    assert_eq!(names, ["transcript.txt", "transcript.srt", "transcript.json", "recording.wav"]);    let text = std::fs::read_to_string(out.path().join("transcript.txt")).unwrap();    assert!(text.starts_with("Asha [0:00]\nGood morning"), "{text}");    let srt = std::fs::read_to_string(out.path().join("transcript.srt")).unwrap();    assert!(srt.starts_with("1\n00:00:00,000 --> 00:00:02,000\nAsha: Good morning"), "{srt}");    let json: Value = serde_json::from_str(&std::fs::read_to_string(out.path().join("transcript.json")).unwrap()).unwrap();    assert_eq!(json["languages"], json!(["en", "hi"]));    assert_eq!(std::fs::metadata(out.path().join("recording.wav")).unwrap().len(), 44 + 3 * 32_000);    let only = ask(&handle, "meetings.export", json!({ "id": id, "format": "srt", "dir": out.path().join("srt").to_string_lossy() }));    assert_eq!(only["files"].as_array().unwrap().len(), 1);}/// RULE (meetings-summaries, 17 Nov 2026): Summarise asks the person's Mac (its local model) for the summary again, and puts a meeting whose summaries were off back on; nothing leaves the person's devices.#[test]fn summarise_asks_the_mac() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    ask(&handle, "records.update", json!({ "table": MEETING, "id": id, "patch": { "summarise_on": "off" } }));    let asked = ask(&handle, "meetings.summarise", json!({ "id": id }));    assert_eq!(asked["status"], "asked");    assert!(asked["said"].as_str().unwrap().contains("Mac"), "{asked}");    let row = data(&handle, MEETING, &id);    assert_eq!(row["summarise_on"], "mac");    assert!(row["summary_asked_at"].as_str().is_some_and(|at| !at.is_empty()));}/// RULE (meetings-summaries, 17 Nov 2026): A ready meeting with no summary says why in the person's words: no Mac has written it yet, the Mac has not fetched the model, it failed, or summaries are off for it; one with a summary, or not ready, says nothing.#[test]fn a_meeting_without_a_summary_says_why() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    assert_eq!(ask(&handle, "meetings.read", json!({ "id": id }))["summary_note"], Value::Null, "not ready yet");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    let note = |handle: &CottonHandle| ask(handle, "meetings.read", json!({ "id": id }))["summary_note"].as_str().map(str::to_string);    assert!(note(&handle).unwrap().contains("No Mac"), "{:?}", note(&handle));    ask(&handle, "records.update", json!({ "table": "meetings_meeting", "id": id, "patch": { "summarise_on": "off" } }));    assert!(note(&handle).unwrap().contains("off"));    ask(&handle, "meetings.summarise", json!({ "id": id }));    ask(&handle, "records.update", json!({ "table": "meetings_meeting", "id": id, "patch": { "summary": "- The budget was agreed.", "summarised_by": "an invented assistant" } }));    assert_eq!(note(&handle), None);}/// RULE (meetings-summaries, 17 Nov 2026): An opened meeting offers each action with one act, Add to todos, which makes a todo from it (its words, its day, the meeting it came from) linked from the action; an action already added says so and makes no second todo.#[test]fn an_action_is_added_to_todos_once() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": transcript() }));    ask(&handle, "records.update", json!({ "table": MEETING, "id": id, "patch": { "title": "Budget check-in" } }));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    let s1 = read["speakers"][0]["id"].as_str().unwrap().to_string();    ask(&handle, "meetings.speaker.name", json!({ "speaker": s1, "name": "Asha" }));    let made = |data: Value| ask(&handle, "records.create", json!({ "table": ACTION, "data": data }))["id"].as_str().map(str::to_string).unwrap_or_default();    made(json!({ "meeting": id, "position": 2, "words": "Look at the slow search" }));    made(json!({ "meeting": id, "position": 1, "words": "Send the revised budget", "who": "S1", "speaker": s1, "due": "2026-11-19", "due_said": "by Thursday" }));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    let actions = read["actions"].as_array().unwrap();    assert_eq!(actions.len(), 2);    assert_eq!((actions[0]["words"].as_str(), actions[0]["who"].as_str(), actions[0]["due"].as_str()), (Some("Send the revised budget"), Some("Asha"), Some("2026-11-19")));    assert_eq!(actions[1]["who"], Value::Null, "nobody took it on: no owner is made up");    assert_eq!((actions[0]["added"].as_bool(), actions[0]["act"]["label"].as_str()), (Some(false), Some("Add to todos")));    let action = actions[0]["id"].as_str().unwrap().to_string();    let added = ask(&handle, "meetings.action.todo", json!({ "id": action }));    assert_eq!((added["added"].as_bool(), added["already"].as_bool()), (Some(true), Some(false)));    let todo = data(&handle, "todo", added["todo"].as_str().unwrap());    assert_eq!(todo["title"], "Send the revised budget");    assert_eq!(todo["@day_parts"]["due_at"]["day"], "2026-11-19", "the action's day, in the phone's zone: {todo}");    assert!(todo["notes"].as_str().unwrap().contains("Budget check-in"), "{todo}");    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!((read["actions"][0]["added"].as_bool(), read["actions"][0]["act"].clone(), read["actions"][0]["said"].as_str()), (Some(true), Value::Null, Some("Added to todos")));    assert_eq!(read["actions"][1]["added"], false);    let again = ask(&handle, "meetings.action.todo", json!({ "id": action }));    assert_eq!((again["already"].as_bool(), again["todo"].clone()), (Some(true), added["todo"].clone()));    let todos = ask(&handle, "records.list", json!({ "table": "todo", "limit": 50 }));    assert_eq!(todos["records"].as_array().unwrap().len(), 1, "added once");    assert_eq!(refused(&handle, "meetings.action.todo", json!({ "id": "no-such-action" })), "not_found");}/// RULE (meetings-core, 17 Nov 2026): The phone's windows and merge are the core's rules: windows for a length, and many heard windows as one transcript.#[test]fn windows_and_merge_are_the_cores() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let cut = ask(&handle, "meetings.windows", json!({ "duration_ms": 60_000 }));    assert_eq!(cut["windows"].as_array().unwrap().len(), 3);    let merged = ask(&handle, "meetings.merge", json!({ "by": "x", "windows": [        { "index": 0, "start_ms": 0, "end_ms": 30_000, "lines": [{ "speaker": "a", "start_ms": 0, "end_ms": 1_000, "text": "one" }] },        { "index": 1, "start_ms": 27_000, "end_ms": 57_000, "lines": [{ "speaker": "a", "start_ms": 40_000, "end_ms": 41_000, "text": "two" }] }    ]}));    assert_eq!(merged["transcript"]["lines"].as_array().unwrap().len(), 2);}/// RULE (android parity, 17 Nov 2026): `meetings.read` gives both phones what the transcript page plays from: the marks as a list of ms and the audio's key with its path on this phone, so neither phone works out where the recording is.#[test]fn read_names_the_audio_and_the_marks() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let started = ask(&handle, "meetings.record.start", json!({ "kind": "meeting" }));    let id = started["meeting"].as_str().unwrap().to_string();    torn_wav(std::path::Path::new(started["audio_path"].as_str().unwrap()), 3);    ask(&handle, "meetings.record.stop", json!({ "id": id, "marks": [2_000, 500] }));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!(read["marks"], json!([500, 2_000]));    let path = read["audio"]["path"].as_str().expect("this phone holds the recording");    assert!(std::path::Path::new(path).is_file());    assert!(read["audio"]["key"].as_str().is_some_and(|k| !k.is_empty()));}/// RULE (voice-meetings-finish, 19 Nov 2026): what Android's recorder says at Stop is kept by the core: an ADTS take (`format: "aac"`), its marks, the stretches a call silenced and a take finished after a kill (`recovered`); `meetings.read` answers them with `audio_path` while this phone holds the audio.#[test]fn an_android_take_keeps_its_marks_silences_and_recovery() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let started = ask(&handle, "meetings.record.start", json!({ "kind": "meeting", "id": "take-1" }));    let take = dir.path().join("take-1.aac");    std::fs::write(&take, [0xFFu8, 0xF1, 0x50, 0x80, 0x01, 0x7F, 0xFC, 0, 0, 0]).unwrap();    let stopped = ask(&handle, "meetings.record.stop", json!({        "id": started["meeting"], "path": take.to_string_lossy(), "format": "aac", "duration_ms": 61_000,        "marks": [20_000], "silenced": [[30_000, 40_000]], "recovered": true,    }));    assert_eq!(stopped["status"], "waiting");    let read = ask(&handle, "meetings.read", json!({ "id": started["meeting"] }));    assert_eq!(read["marks"], json!([20_000]));    assert_eq!(read["silenced"], json!([[30_000, 40_000]]));    assert_eq!(read["meeting"]["status_why"], "recovered");    assert!(read["meeting"]["audio"].as_str().is_some_and(|key| key.ends_with(".aac")), "{read}");    let path = read["audio_path"].as_str().expect("this phone holds the recording");    assert_eq!(read["audio"]["path"].as_str(), Some(path));    assert!(std::path::Path::new(path).is_file());}/// RULE (android parity, 17 Nov 2026): Discard is the core's: a recording still being made goes, row and working file, on the person's word; a stopped one is never discarded this way, and one already gone answers as discarded.#[test]fn discard_takes_only_a_recording_in_progress() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let started = ask(&handle, "meetings.record.start", json!({ "kind": "meeting" }));    let id = started["meeting"].as_str().unwrap().to_string();    let path = std::path::PathBuf::from(started["audio_path"].as_str().unwrap());    torn_wav(&path, 1);    let gone = ask(&handle, "meetings.record.discard", json!({ "id": id }));    assert_eq!(gone["discarded"], true);    assert_eq!(refused(&handle, "meetings.read", json!({ "id": id })), "not_found", "the row is gone");    assert!(!path.exists(), "the working file is gone");    assert_eq!(ask(&handle, "meetings.record.discard", json!({ "id": id }))["discarded"], true, "again is not refused");    let kept = recorded(&handle, "meeting");    assert_eq!(refused(&handle, "meetings.record.discard", json!({ "id": kept })), "refused");    assert_eq!(data(&handle, MEETING, &kept)["status"], "waiting");}/// RULE (android parity, 17 Nov 2026): `meetings.read` says the meeting's state in words, the same on both phones: waiting says whether this phone on charge may do it, a failure says why from `why.*`.#[test]fn read_says_the_state_in_words() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    assert_eq!(ask(&handle, "meetings.read", json!({ "id": id }))["status_words"], "Waiting for your Mac, or for this phone to be charging");    assert_eq!(ask(&handle, "meetings.read", json!({ "id": id, "charging": true }))["status_words"], "Waiting for your Mac to turn it into text");    ask(&handle, "meetings.transcribed", json!({ "id": id, "failed": "engine_failed" }));    assert_eq!(ask(&handle, "meetings.read", json!({ "id": id }))["status_words"], "Failed: It could not be turned into text. Try again.");    assert_eq!(ask(&handle, "meetings.read", json!({ "id": id }))["transcribed_by"], Value::Null);}/// RULE (owner, 17 Nov 2026): Telugu speech lands in Latin letters (cotton_rules script/written.json, the one value); Hindi and English land as heard.#[test]fn telugu_lands_in_latin_letters() {    let dir = tempfile::tempdir().unwrap();    let handle = phone(&dir);    let id = recorded(&handle, "meeting");    let mut t = transcript();    t["lines"][0]["text"] = json!("సరే, బడ్జెట్ రేపు చూద్దాం");    t["lines"][0]["language"] = json!("te");    ask(&handle, "meetings.transcribed", json!({ "id": id, "transcript": t }));    let read = ask(&handle, "meetings.read", json!({ "id": id }));    assert_eq!(read["lines"][0]["text"], "sare, badjet repu chooddaam");    assert_eq!(read["lines"][1]["text"], "हाँ, बजट से शुरू करते हैं।");}