Cotton code
49 lines · 2.0 KB · RustRaw
//! The guard that clears the way for dropping `cotton_memory_projects.section_order`.use std::path::{Path, PathBuf};/// Where the column may still be named until the drop lands: the schema that/// declares it.const DECLARES: [&str; 1] = [    "crates/cotton-store/src/schema/",];fn sources(dir: &Path, out: &mut Vec<PathBuf>) {    let Ok(entries) = std::fs::read_dir(dir) else { return };    for entry in entries.flatten() {        let path = entry.path();        let name = entry.file_name();        if path.is_dir() {            if name != "target" && name != "node_modules" && name != ".build" {                sources(&path, out);            }        } else if path.extension().is_some_and(|ext| ext == "rs" || ext == "swift") {            out.push(path);        }    }}/// RULE: no code reads `section_order` (or `sectionOrder`) — a project's sections read in Home's tile order, the one order (architect, 13 Oct 2026), so the column can be dropped in a named move.#[test]fn no_code_reads_the_project_section_order() {    let root = cotton_store::manifest_dir().join("../..").canonicalize().unwrap();    let mut files = Vec::new();    sources(&root.join("crates"), &mut files);    sources(&root.join("apps/cotton/Sources"), &mut files);    sources(&root.join("apps/cotton/Tests"), &mut files);    let me = Path::new(file!()).file_name().unwrap();    let readers: Vec<String> = files        .iter()        .filter(|path| path.file_name() != Some(me))        .filter_map(|path| {            let relative = path.strip_prefix(&root).ok()?.to_string_lossy().replace('\\', "/");            if DECLARES.iter().any(|prefix| relative.starts_with(prefix)) {                return None;            }            let text = std::fs::read_to_string(path).ok()?;            (text.contains("section_order") || text.contains("sectionOrder")).then_some(relative)        })        .collect();    assert!(files.len() > 100, "the sweep found the sources");    assert!(readers.is_empty(), "section_order is still read in: {readers:?}");}