← Commit history

Fix source picker labels: name altium/fusion format variants properly (Component Search Engine - Altium/Fusion 360 Library), not raw 'altium'/'fusion'

John Lauer ·cb425f71c7 ·3mo ago ·parent 6f223fd
1 file changed +26−20
src/server.rs+26−20
@@ -43,12 +43,19 @@ pub struct AppState { /// Map a source slug to a friendly label. Delegates to the SHARED provenance /// rule (see the chip-provenance-labeling skill): label by where it was actually /// downloaded, name the maker site, never call an aggregator "Manufacturer".-fn source_label(slug: &str, manufacturer: &str) -> String {+/// Label a source for the picker. `discovery_label` is the human name of where+/// the whole library bundle was downloaded (e.g. "Component Search Engine") —+/// the format variants (altium/fusion) came from that SAME bundle, so they're+/// named "<discovery> - <Format> Library", matching chip-fetcher's carat.+fn source_label(slug: &str, manufacturer: &str, discovery_label: &str) -> String {     match slug {         "auto" => "Auto · grouped".to_string(),         "ds2sf" => format!("PDF Datasheet from {}", crate::provenance::source_label("manufacturer", manufacturer)),-        // Every other symbol source is a KiCad-library symbol render → name the-        // download source + the format, e.g. "Component Search Engine - KiCad Library".+        // The format variants of the SAME downloaded bundle — name the format, not "KiCad".+        "manufacturer" => format!("{discovery_label} - KiCad Library"),+        "altium" => format!("{discovery_label} - Altium Library"),+        "fusion" | "fusion360" => format!("{discovery_label} - Fusion 360 Library"),+        // A KiCad-format variant discovered from a different vendor → name that source.         other => format!("{} - KiCad Library", crate::provenance::source_label(other, manufacturer)),     } }@@ -302,25 +309,24 @@ fn regenerate() {         .and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok())         .and_then(|v| v.get("manufacturer").and_then(|x| x.as_str()).map(String::from))         .unwrap_or_default();+    // Where the whole library bundle was downloaded (discovery_source) — NOT who+    // authored it (content_origin). A TI model pulled from CSE reads "Component+    // Search Engine", not "Manufacturer". The altium/fusion format variants came+    // from this SAME bundle, so they share this discovery source.+    let discovery = read_file(&m.dir, &format!("{}-file-provenance.json", m.mpn))+        .and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok())+        .and_then(|v| v.get(format!("{}.kicad_sym", m.mpn)).and_then(|e| e.get("discovery_source").or_else(|| e.get("content_origin"))).and_then(|s| s.as_str()).map(String::from))+        .or_else(|| {+            read_file(&m.dir, "info.json")+                .and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok())+                .and_then(|v| v.get("source_of_record").and_then(|s| s.get("kicad_sym")).and_then(|s| s.as_str()).map(String::from))+        })+        .unwrap_or_else(|| "cse".to_string());+    let discovery_label = crate::provenance::source_label(&discovery, &manufacturer);+     let mut source_labels: std::collections::HashMap<String, String> = std::collections::HashMap::new();     for s in &sources {-        source_labels.insert(s.clone(), source_label(s, &manufacturer));-    }-    if m.has_mfr {-        // The canonical "manufacturer" entry is labeled by WHERE it was downloaded-        // (discovery_source) — NOT who authored it (content_origin). A TI model-        // pulled from CSE reads "Component Search Engine", not "Manufacturer".-        let origin = read_file(&m.dir, &format!("{}-file-provenance.json", m.mpn))-            .and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok())-            .and_then(|v| v.get(format!("{}.kicad_sym", m.mpn)).and_then(|e| e.get("discovery_source").or_else(|| e.get("content_origin"))).and_then(|s| s.as_str()).map(String::from))-            .or_else(|| {-                read_file(&m.dir, "info.json")-                    .and_then(|s| serde_json::from_str::<serde_json::Value>(&s).ok())-                    .and_then(|v| v.get("source_of_record").and_then(|s| s.get("kicad_sym")).and_then(|s| s.as_str()).map(String::from))-            });-        if let Some(o) = origin {-            source_labels.insert("manufacturer".to_string(), source_label(&o, &manufacturer));-        }+        source_labels.insert(s.clone(), source_label(s, &manufacturer, &discovery_label));     }      // A vendor variant source = a discovered <mpn>.<method>.kicad_sym.