Cotton code
37 lines · 1.7 KB · RustRaw
//! Tool pictures as photo records, against a real file's schema.mod support;use std::sync::Arc;use cotton_core::definitions::pictures::BUILTIN_TOOL_PICTURES;use cotton_tools::mcp::dispatch::{Ctx, ToolServices};use cotton_tools::tool_pictures::{missing, write_records};use support::harness::Harness;/// RULE: every shipped tool picture becomes a photo record a real file takes —/// the photo row's required columns included — and a second pass finds/// nothing missing. The first version never set `taken_at`, so every server/// start failed the write and Memory, Social (then Stories), Disk and Subscriptions drew/// their names instead of their pictures.#[test]fn the_shipped_pictures_become_photo_records_a_file_takes() {    let h = Harness::new();    let services = ToolServices::none();    let audit = |_: &str, _: &str| {};    let left = h.with(|db| {        let mut ctx = Ctx::for_worker(            db, &h.file, &h.owner_id, cotton_tools::mcp::writer::job("tool-pictures"), "Cotton",            cotton_tools::clock::Clock::now(&h.clock), Arc::clone(&h.random), &services, &audit,        );        // Every shipped built-in picture, then the kit packages' carried ones.        let photos = missing(&ctx, &[]).expect("reads");        assert!(photos.len() >= BUILTIN_TOOL_PICTURES.len(), "{} pictures", photos.len());        write_records(&mut ctx, &photos).expect("writes");        ctx.commit().expect("a photo row the table takes");        (missing(&ctx, &[]).expect("reads").len(), photos.len())    });    let (left, written) = left;    assert_eq!(left, 0, "nothing left to write");    assert_eq!(h.all("SELECT id FROM cotton_photos", &[]).len(), written);}