Cotton code
44 lines · 1.6 KB · RustRaw
//! Storage through the generic records verbs, using invented device rows.mod support;use rusqlite::types::Value as SqlValue;use serde_json::json;use support::harness::Harness;use support::mcp::{call_tool_raw, mint_token};const NOW: &str = "2026-09-08T10:00:00.000Z";fn text(value: &str) -> SqlValue {    SqlValue::Text(value.to_string())}fn admit(h: &Harness, device: &str, name: &str) {    h.run(        "INSERT INTO cotton_devices (id, workspace_id, device_id, name, platform, approved_at, approved_by_device, created_at, updated_at) VALUES (?, ?, ?, ?, 'ios', ?, 'self', ?, ?)",        &[            text(&format!("device-row-{device}")),            text(&h.workspace_id),            text(device),            text(name),            text(NOW),            text(NOW),            text(NOW),        ],    );}/// RULE: Storage rows are computed device readings. Generic records never/// create or delete one, because an invented or removed row would disagree/// with the synced storage-rule engine.#[test]fn generic_storage_refuses_create_and_delete() {    let mut h = Harness::new();    let token = mint_token(&mut h, &["read", "write"], "Synthetic assistant");    admit(&h, "storage-remote", "Synthetic phone");    let create = call_tool_raw(&h, &token, "create_record", json!({"table":"storage", "data":{"name":"Photos"}}));    assert!(create.is_error, "{}", create.text);    let id = "storage:14:storage-remote:machine";    let delete = call_tool_raw(&h, &token, "delete_record", json!({"table":"storage", "id":id}));    assert!(delete.is_error, "{}", delete.text);}