← All Pull Requests

AI Flow: JLCPCB 0.1.7 (#4) #5

Merged Released in 0.1.7 on 20 Nov 2026 opened by Colby Knox
Merges jlcpcb-0.1.7 → main

AI Flow: JLCPCB 0.1.7: two fixes from Sven Claar (#4).

  • kicad.rs: Footprint.no_bom (exclude_from_bom, board_only, DNP); sourcing needs no BOM row or LCSC number for them.
  • rotation.rs: on an EasyEDA refusal of pup, the check looks once for a live nb profile with the Adom extension and uses it for the rest; otherwise it names the fix.

Tests: 15 pass (two added).

🤖 Generated with Claude Code

Diff Skip to comments

Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-aiflow-jlcpcb"-version = "0.1.6"+version = "0.1.7" dependencies = [  "clap",  "regex",
Cargo.toml+1−1
@@ -2,7 +2,7 @@ # Copied from adom/adom-aiflow template/flow-app. This copy is yours: change anything, never depend on aiflow. [package] name = "adom-aiflow-jlcpcb"-version = "0.1.6"+version = "0.1.7" edition = "2021" license = "MIT" 
bin/adom-aiflow-jlcpcb
⋯ 1 unchanged line ⋯
docs/release-0.1.7.mdadded+12
@@ -0,0 +1,12 @@+# AI Flow: JLCPCB 0.1.7++Two fixes from Sven Claar (#4).++- **Sourcing leaves out footprints excluded from the BOM.** Bare test pads (`exclude_from_bom`, `board_only`) and+  not-fitted parts (DNP) were listed as "board references with no BOM row" when the BOM left them out, and as "no LCSC+  number" when it kept a "no part" row, so sourcing could not close either way. They now need neither, as the JLCPCB+  CPL already left them out.+- **The rotation check falls back to the user's own browser when EasyEDA refuses the automated one.** EasyEDA answers+  pup with 403, so every part ended `retrieval-unverified`. On a refusal, the check now looks once for a browser profile+  on the same desktop with the Adom extension running (nb) and reads the remaining footprints there; with none, it says+  that adding the extension (with the user's OK) is the fix. `--browser-target`/`--browser-profile` still choose one.
package.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow-jlcpcb",   "type": "app",-  "version": "0.1.6",+  "version": "0.1.7",   "title": "AI Flow: JLCPCB",   "description": "The JLCPCB ordering stage of AI Flow: from a finished board to assembled boards from JLCPCB. Part substitutes proven from both datasheets, the gerber zip, BOM and CPL from the desktop's own KiCad, every part's rotation checked against JLCPCB's own footprint and corrected, placement-preview evidence, the quote, the human's recorded OK before payment, and rotation corrections shared on component pages. Open source (MIT): build it with ./build.sh.",   "category": "Developer Tools",
page.json+2−3
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow-jlcpcb",   "type": "app",-  "version": "0.1.6",+  "version": "0.1.7",   "title": "AI Flow: JLCPCB",   "description": "The JLCPCB ordering stage of AI Flow: from a finished board to assembled boards from JLCPCB. Part substitutes proven from both datasheets, the gerber zip, BOM and CPL from the desktop's own KiCad, every part's rotation checked against JLCPCB's own footprint and corrected, placement-preview evidence, the quote, the human's recorded OK before payment, and rotation corrections shared on component pages. Open source (MIT): build it with ./build.sh.",   "category": "Developer Tools",@@ -59,8 +59,7 @@   "visibility": "public",   "org": "adom",   "author": {-    "name": "John Lauer",-    "email": "[email protected]"+    "name": "John Lauer"   },   "updated_at": "2026-10-06T17:03:49.203Z" }\ No newline at end of file
src/kicad.rs+18−2
@@ -10,7 +10,10 @@ pub struct Pad { pub x: f64, pub y: f64, pub w: f64, pub h: f64, pub rot: f64 } #[allow(dead_code)] // placement fields kept for stages that need them pub struct Footprint { pub reference: String, pub name: String, pub x: f64, pub y: f64, pub rot: f64, pub bottom: bool, pub pads: BTreeMap<String, Pad>,     /// every pad, a repeated number (a split thermal pad, a mounting tab) included (issue #3)-    pub all_pads: Vec<(String, Pad)> }+    pub all_pads: Vec<(String, Pad)>,+    /// issue #4 (Sven Claar): excluded from the BOM (`exclude_from_bom`, `board_only`) or not fitted (DNP): a bare+    /// test pad, a fiducial; it needs no BOM row and no LCSC number+    pub no_bom: bool }  /// Each top-level `(footprint ...)` block, matching parentheses outside quoted strings. fn blocks(t: &str) -> Vec<&str> {@@ -38,6 +41,7 @@ pub fn footprints(text: &str) -> BTreeMap<String, Footprint> {     let re_name = Regex::new(r#"\(footprint "([^"]+)""#).unwrap();     let re_at = Regex::new(r"\(at ([-\d.]+) ([-\d.]+)(?: ([-\d.]+))?\)").unwrap();     let re_pad = Regex::new(r#"(?s)\(pad "([^"]*)" (?:smd|thru_hole) \w+.*?\(at ([-\d.]+) ([-\d.]+)(?: ([-\d.]+))?\).*?\(size ([-\d.]+) ([-\d.]+)\)"#).unwrap();+    let re_nobom = Regex::new(r#"\(attr [^)]*\b(exclude_from_bom|board_only|dnp)\b|\(dnp(?: yes)?\)"#).unwrap();     let f = |s: &str| s.parse::<f64>().unwrap_or(0.0);     let mut out = BTreeMap::new();     for b in blocks(text) {@@ -53,7 +57,8 @@ pub fn footprints(text: &str) -> BTreeMap<String, Footprint> {             all_pads.push((c[1].to_string(), pad.clone()));             pads.entry(c[1].to_string()).or_insert(pad);         }-        out.insert(reference.clone(), Footprint { reference, name, x, y, rot, bottom: head.contains("(layer \"B.Cu\")"), pads, all_pads });+        let no_bom = re_nobom.is_match(b);+        out.insert(reference.clone(), Footprint { reference, name, x, y, rot, bottom: head.contains("(layer \"B.Cu\")"), pads, all_pads, no_bom });     }     out }@@ -82,4 +87,15 @@ mod tests {         assert_eq!(super::g(90.0), "90");         assert_eq!(super::ref_key("R10") > super::ref_key("R2"), true);     }++    /// Issue #4: a footprint excluded from the BOM (a bare test pad) or not fitted is marked no_bom.+    #[test]+    fn excluded_and_dnp_footprints_need_no_bom_row() {+        let t = r#"(kicad_pcb (footprint "TP:Pad_0.5mm" (layer "F.Cu") (at 1 1) (property "Reference" "TP1") (attr smd exclude_from_bom exclude_from_pos_files) (pad "1" smd circle (at 0 0) (size 0.5 0.5)))+ (footprint "R:R0402" (layer "F.Cu") (at 2 2) (property "Reference" "R1") (attr smd) (pad "1" smd rect (at 0 0) (size 0.5 0.5)))+ (footprint "R:R0402" (layer "F.Cu") (at 3 3) (property "Reference" "R2") (attr smd dnp) (pad "1" smd rect (at 0 0) (size 0.5 0.5))))"#;+        let f = super::footprints(t);+        assert!(f["TP1"].no_bom && f["R2"].no_bom && !f["R1"].no_bom, "{:?}", f.values().map(|x| (&x.reference, x.no_bom)).collect::<Vec<_>>());+    }+ }
src/main.rs+5−2
@@ -246,10 +246,13 @@ fn main() {                 let l = bom.lcsc(row); let l = l.as_str();                 for rf in split.split(bom.get(row, "ref")).filter(|s| !s.is_empty()) {                     covered.insert(rf.to_string());-                    if !rotation::SKIP_FIT.contains(&fit.as_str()) && !re_c.is_match(l) { let m = bom.get(row, "mpn").trim(); missing.push(if m.is_empty() { rf.to_string() } else { format!("{rf} ({m})") }); }+                    // issue #4: a footprint excluded from the BOM (a bare test pad) or not fitted needs no LCSC number+                    let no_bom = fps.get(rf).map(|f| f.no_bom).unwrap_or(false);+                    if !no_bom && !rotation::SKIP_FIT.contains(&fit.as_str()) && !re_c.is_match(l) { let m = bom.get(row, "mpn").trim(); missing.push(if m.is_empty() { rf.to_string() } else { format!("{rf} ({m})") }); }                 }             }-            let mut absent: Vec<String> = fps.keys().filter(|r| !covered.contains(*r) && !r.starts_with('#')).cloned().collect();+            // issue #4 (Sven Claar): nor a BOM row (the JLCPCB CPL leaves them out already)+            let mut absent: Vec<String> = fps.iter().filter(|(r, f)| !covered.contains(*r) && !r.starts_with('#') && !f.no_bom).map(|(r, _)| r.clone()).collect();             absent.sort_by_key(|r| kicad::ref_key(r));             if !missing.is_empty() || !absent.is_empty() {                 p.log(&th, "sourcing-open", json!({"noLcsc": missing, "noBomRow": absent}));
src/rotation.rs+51−1
@@ -29,6 +29,28 @@ type Pads = BTreeMap<String, (f64, f64)>; pub struct JlcFootprint { pub title: String, pub pads: Pads, pub all: Vec<(String, (f64, f64))> }  /// JLCPCB's footprint for one LCSC number, or None when EasyEDA has none.+/// A retrieval error that is a refusal (403, access denied), not a missing part.+fn refused(e: &str) -> bool {+    let l = e.to_ascii_lowercase();+    l.contains("403") || l.contains("access denied") || l.contains("forbidden") || l.contains("could not be satisfied")+}++/// The user's own browser profile on the desktop with the Adom extension live (nb), for a vendor page that refuses+/// pup; Err says why there is none and what fixes it.+fn live_native_profile(br: &Bridge) -> Result<String, String> {+    let r = br.call("nbrowser_profiles", &json!({"reason": "the JLCPCB rotation check: EasyEDA refused the automated browser, so read the footprint in the user's own browser"}));+    pick_native_profile(&r)+}++/// The profile to use from an `nbrowser_profiles` reply: live with the extension, the active one first.+pub fn pick_native_profile(reply: &Value) -> Result<String, String> {+    let profiles = Bridge::field(reply, "profiles").and_then(|v| v.as_array()).cloned().unwrap_or_default();+    let ok: Vec<&Value> = profiles.iter().filter(|p| p["extensionInstalled"] == true && p["live"] == true && p["blocked"] != true).collect();+    ok.iter().find(|p| p["active"] == true).or(ok.first()).and_then(|p| p["profile"].as_str()).map(str::to_string)+        .ok_or_else(|| if profiles.is_empty() { "EasyEDA refused the automated browser, and the user's own browser could not be asked (no native browser bridge answered): install it, or check those parts' pin 1 by eye".to_string() }+            else { "EasyEDA refused the automated browser, and no browser profile on that desktop has the Adom extension running: with the user's OK, add the extension to their browser (nbrowser_readiness says how), then export again".to_string() })+}+ pub fn jlc_footprint(br: &Bridge, lcsc: &str, native: Option<(&str,&str)>, evidence: &Path) -> Result<Option<JlcFootprint>, String> {     let url = format!("https://easyeda.com/api/products/{lcsc}/components?version=6.4.19.5");     // Reuse today's exact vendor response; never cache an access error as absence.@@ -290,10 +312,27 @@ pub fn check(br: &Bridge, board: &Path, bom: &Table, overrides: &Map<String, Val     let mut order: Vec<String> = lcsc.keys().filter(|r| parts.contains_key(*r)).cloned().collect();     order.sort_by_key(|r| ref_key(r));     let mut cache: BTreeMap<String, Option<JlcFootprint>> = BTreeMap::new();+    // issue #4 (Sven Claar): EasyEDA refuses pup's automated browser (403). Before giving up, the check looks once+    // for the user's own browser with the Adom extension (nb) on the same desktop and uses it for the rest+    let mut auto_native: Option<(String, String)> = None;+    let mut auto_note: Option<String> = None;     for rf in &order {         let c = &lcsc[rf];         if !cache.contains_key(c) {-            match jlc_footprint(br,c,native,evidence) {+            let pick = native.or(auto_native.as_ref().map(|(a, b)| (a.as_str(), b.as_str())));+            let mut got = jlc_footprint(br,c,pick,evidence);+            if native.is_none() && auto_native.is_none() && auto_note.is_none() && got.as_ref().err().is_some_and(|e| refused(e)) {+                match live_native_profile(br) {+                    Ok(p) => {+                        auto_native = Some((br.target.clone(), p));+                        let (a, b) = auto_native.as_ref().unwrap();+                        got = jlc_footprint(br,c,Some((a.as_str(), b.as_str())),evidence);+                    }+                    Err(why) => auto_note = Some(why),+                }+            }+            let got = got.map_err(|why| match &auto_note { Some(n) => format!("{why}; {n}"), None => why });+            match got {                 Ok(fp) => { cache.insert(c.clone(),fp); }                 Err(why) => {                     let failed = vec![(rf.clone(),why.clone())];@@ -551,4 +590,15 @@ mod tests {         assert_eq!((f.delta, signed(f.delta)), (270, -90));         assert!(f.residual < 1e-9 && (f.offset.0 - 0.1).abs() < 1e-9);     }++    /// Issue #4: the user's own browser profile is used only when its Adom extension is live.+    #[test]+    fn a_live_extension_profile_is_picked_or_the_fix_is_named() {+        let r = json!({"ok": true, "profiles": [{"profile": "chrome:Default", "live": false, "extensionInstalled": false}, {"profile": "chrome:Work", "live": true, "extensionInstalled": true, "active": false}, {"profile": "edge:Me", "live": true, "extensionInstalled": true, "active": true}]});+        assert_eq!(pick_native_profile(&r).unwrap(), "edge:Me");+        let none = json!({"profiles": [{"profile": "chrome:Default", "live": false, "extensionInstalled": false}]});+        assert!(pick_native_profile(&none).unwrap_err().contains("Adom extension"));+        assert!(refused("C123: footprint retrieval failed: 403 Forbidden") && !refused("C123: no valid footprint response"));+    }+ }

Comments

No comments yet.

Log in to comment.