Cotton code
90 lines · 3.1 KB · RustRaw
//! The session model labels, with vectors — every one of these is a STRING the//! owner reads on a page, so a byte of drift is a session that reads two ways//! in two places.use super::*;fn label(id: &str) -> Option<String> {    model_label(Some(id))}#[test]fn reads_the_ids_the_tool_writes() {    assert_eq!(label("claude-fable-5-1").as_deref(), Some("Fable 5.1"));    assert_eq!(        label("claude-opus-4-1-20250805").as_deref(),        Some("Opus 4.1")    );    assert_eq!(        label("claude-sonnet-4-5-20250929").as_deref(),        Some("Sonnet 4.5")    );    assert_eq!(        label("claude-haiku-4-5-fast").as_deref(),        Some("Haiku 4.5 fast")    );    assert_eq!(label("claude-opus-5").as_deref(), Some("Opus 5"));}#[test]fn returns_an_id_it_cannot_read_as_it_came_and_nothing_for_nothing() {    assert_eq!(label("gpt-5").as_deref(), Some("Gpt 5"));    assert_eq!(label("kimi-k2").as_deref(), Some("kimi-k2"));    assert_eq!(label("  "), None);    assert_eq!(model_label(None), None);}/// Node vectors.#[test]fn model_label_matches_the_typescript() {    let vectors: &[(&str, Option<&str>)] = &[        ("claude-fable-5-1", Some("Fable 5.1")),        ("claude-opus-4-1-20250805", Some("Opus 4.1")),        ("claude-sonnet-4-5-20250929", Some("Sonnet 4.5")),        ("claude-haiku-4-5-fast", Some("Haiku 4.5 fast")),        ("claude-opus-5", Some("Opus 5")),        ("gpt-5", Some("Gpt 5")),        ("kimi-k2", Some("kimi-k2")),        ("  ", None),        ("", None),        ("claude-", Some("claude-")),        ("claude", Some("claude")),        ("claude-3-5-sonnet", Some("3 5 sonnet")),        ("claude--opus--4--1", Some("Opus 4.1")),        ("  claude-opus-5  ", Some("Opus 5")),        ("claude-opus-5-20250101-20250202", Some("Opus 5.20250101")),        ("claude-opus-20250805", Some("claude-opus-20250805")),        ("claude-fable-5-1-thinking", Some("Fable 5.1 thinking")),        ("CLAUDE-OPUS-5", Some("CLAUDE-OPUS-5")),        ("opus-5", Some("Opus 5")),        ("5-1", Some("5 1")),    ];    for (id, expected) in vectors {        assert_eq!(label(id).as_deref(), *expected, "for {id:?}");    }}/// The picker's spelling of a family IS `model_label`'s spelling of it.////// The screen offers `fable`; the session that comes back says/// `claude-fable-5-1`. If the two disagreed, one session would read two ways in/// two places — the exact thing this module exists to prevent.#[test]fn every_offered_model_is_spelled_the_way_the_label_spells_it() {    for (id, name) in OFFERED_MODELS {        assert_eq!(            label(&format!("claude-{id}-5-1")).as_deref(),            Some(format!("{name} 5.1").as_str()),            "the picker offers {id} as {name}"        );        assert_eq!(            label(&format!("claude-{id}-4-5-20250929")).as_deref(),            Some(format!("{name} 4.5").as_str()),            "a dated id of {id} reads the same"        );        assert!(            id.chars().all(|c| c.is_ascii_lowercase()),            "an offered id is what `claude --model` takes, not a label"        );    }}