← Commit history
v2.1.7: Mouser's on-order quantity no longer counts as stock (adom/adom-parts-search#13, Noah). STM32G0B1CBT6 read "12415 in stock" and was recommended, but Mouser had none on the shelf: 415 due 2027-02-22 and 12,000 with no date. A board was ordered on that number and came back back-ordered.
7 files changed
+90−51
Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-parts-search"-version = "2.1.6"+version = "2.1.7" dependencies = [ "base64", "clap",
Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-parts-search"-version = "2.1.6"+version = "2.1.7" edition = "2021" description = "Parts Search Electronics component search — CLI, backend HTTP service, and Hydrogen webview app" license = "MIT"
VERSION+1−1@@ -1 +1 @@-2.1.6+2.1.7
install.shpackage.json+1−40@@ -34,44 +34,5 @@ "SKILL.md", "BUILD-SKILL.md", "CHANGELOG.md"- ],- "changelog": "Mouser's on-order quantity no longer counts as stock (adom/adom-parts-search#13, Noah). STM32G0B1CBT6 read \"12415 in stock\" and was recommended, but Mouser had none on the shelf: 415 due 2027-02-22 and 12,000 with no date. A board was ordered on that number and came back back-ordered.",- "discovery_triggers": [- "parts search",- "find part",- "source component",- "source part",- "compare distributors",- "compare vendors",- "Mouser or DigiKey",- "BOM sourcing",- "price this part",- "where can I get",- "check stock",- "parts availability",- "fastest delivery",- "cheapest part",- "component search",- "part lookup",- "price breaks"- ],- "discovery_pitch": "Search Mouser, DigiKey and JLCPCB in parallel with product photos; Mouser-preferred best-source pick. Say 'with parts search' to your AI.",- "sample_prompts": [- {- "label": "source an STM32F103RBT6",- "prompt": "source an STM32F103RBT6"- },- {- "label": "where can I get an ESP32-S3-WROOM cheape",- "prompt": "where can I get an ESP32-S3-WROOM cheapest and fastest"- },- {- "label": "compare Mouser, DigiKey and JLCPCB for a",- "prompt": "compare Mouser, DigiKey and JLCPCB for an LM555"- },- {- "label": "price this BOM across distributors",- "prompt": "price this BOM across distributors"- } ]-}+}
src/vendors.rs+86−8@@ -63,6 +63,9 @@ pub struct VendorHit { /// What this hit's numbers do not tell you: a reel listing's 0 stock, or a price the vendor did not send. #[serde(default, skip_serializing_if = "Option::is_none")] pub note: Option<String>,+ /// Mouser's quantity on order from the factory. Not stock: nothing ships from it today (adom/adom-parts-search#13).+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub on_order: Option<u64>, /// URL to a STEP/IGES/GLB/ZIP CAD model, when the source vendor /// exposes one. Click-through usually redirects through SamacSys / /// SnapEDA / Ultra Librarian auth.@@ -198,7 +201,7 @@ mod relevance_tests { fn hit(mpn: &str) -> VendorHit { VendorHit { vendor: Vendor::JLCPCB, vendor_pn: "C1".into(), mpn: mpn.into(), manufacturer: String::new(), description: String::new(), stock: 1, unit_price: None, price_100: None, lead_time: String::new(), image_url: None, datasheet_url: None, product_url: None,- flags: vec![], price_breaks: vec![], min_order: None, packaging: None, note: None, cad_3d_url: None, cad_3d_format: None, cad_3d_source: None }+ flags: vec![], price_breaks: vec![], min_order: None, packaging: None, note: None, on_order: None, cad_3d_url: None, cad_3d_format: None, cad_3d_source: None } } /// adom/adom-jlcpcb#3: the catalogue and the query disagree on punctuation; the right part stays. #[test]@@ -384,15 +387,33 @@ fn digikey_note(h: &VendorHit) -> Option<String> { h.min_order.filter(|m| *m > 1).map(|m| format!(" (minimum {})", m)).unwrap_or_default())) } +/// Mouser's on-order quantity must never read as stock. adom-mouser now keeps them apart (stock + on_order ++/// on_order_dates, adom/adom-mouser#1); an answer cached before that still has "12415 On Order" counted as stock 12415,+/// so the availability sentence decides too: on order and not in stock means 0 in stock.+fn mouser_availability(c: &Value) -> (u64, Option<u64>, Option<String>) {+ let reported = c.get("stock").and_then(|v| v.as_u64()).unwrap_or(0);+ let text = c.get("stock_text").and_then(|v| v.as_str()).unwrap_or("").to_lowercase();+ let on_order_only = text.contains("on order") && !text.contains("in stock");+ let stock = if on_order_only { 0 } else { reported };+ let on_order = c.get("on_order").and_then(|v| v.as_u64()).filter(|n| *n > 0)+ .or(if on_order_only && reported > 0 { Some(reported) } else { None });+ let first = c.get("on_order_dates").and_then(|v| v.as_array())+ .and_then(|a| a.iter().find_map(|l| Some(format!(" (first {} expected {})", l.get("quantity")?.as_u64()?, l.get("date")?.as_str()?))))+ .unwrap_or_default();+ let note = on_order.filter(|_| stock == 0).map(|n| format!("0 in stock at Mouser; {} on order{}. Nothing ships from on-order quantity today.", n, first));+ (stock, on_order, note)+}+ fn normalize_mouser(c: &Value) -> VendorHit { let breaks = price_breaks(c);+ let (stock, on_order, note) = mouser_availability(c); VendorHit { vendor: Vendor::Mouser, vendor_pn: c.get("mouser_pn").and_then(|v| v.as_str()).unwrap_or("").to_string(), mpn: c.get("mpn").and_then(|v| v.as_str()).unwrap_or("").to_string(), manufacturer: c.get("manufacturer").and_then(|v| v.as_str()).unwrap_or("").to_string(), description: c.get("description").and_then(|v| v.as_str()).unwrap_or("").to_string(),- stock: c.get("stock").and_then(|v| v.as_u64()).unwrap_or(0),+ stock, unit_price: c.get("unit_price").and_then(|v| v.as_str()).map(String::from), price_100: price_at_qty(&breaks, 100), lead_time: c.get("lead_time").and_then(|v| v.as_str()).unwrap_or("").to_string(),@@ -407,7 +428,7 @@ fn normalize_mouser(c: &Value) -> VendorHit { }, min_order: c.get("min_order").and_then(|v| v.as_u64()), packaging: c.get("packaging").and_then(|v| v.as_str()).filter(|p| !p.is_empty()).map(String::from),- note: None,+ note, on_order, price_breaks: breaks, cad_3d_url: None, // Mouser API doesn't expose CAD links cad_3d_format: None,@@ -442,7 +463,7 @@ fn normalize_digikey(c: &Value) -> VendorHit { f }, min_order: c.get("min_order").and_then(|v| v.as_u64()),- note: None,+ note: None, on_order: None, price_breaks: breaks, cad_3d_url: cad_url, cad_3d_format: cad_fmt,@@ -472,6 +493,7 @@ fn normalize_jlcpcb(c: &Value) -> VendorHit { min_order: c.get("min_order").and_then(|v| v.as_u64()).or_else(|| breaks.first().map(|b| b.qty)), packaging: None, // JLCPCB's search snapshot can answer with stock and no price (adom/adom-parts-search#10): say so, never a blank+ on_order: None, note: if unit_price.is_none() { Some("JLCPCB's parts snapshot sent no price for this part. See the price on its JLCPCB page.".into()) } else { None }, price_100: price_at_qty(&breaks, 100), unit_price,@@ -602,6 +624,8 @@ pub fn search_all( } }; let mut block = block;+ // "In stock only" holds here too: a Mouser hit cached with on-order quantity as stock still says 0 now+ if in_stock_only { block.hits.retain(|h| h.stock > 0); } block.hits.truncate(limit.max(1) as usize); match vendor { Vendor::Mouser => agg.mouser = block, Vendor::DigiKey => agg.digikey = block, Vendor::JLCPCB => agg.jlcpcb = block } }@@ -685,11 +709,17 @@ fn build_empty_state(agg: &AggregatedResults) -> EmptyState { // said "returned zero hits ... are currently erroring" with nothing erroring. if m_ok && d_ok && j_ok && (m_hits + d_hits + j_hits) > 0 { let jlc_stock: u64 = agg.jlcpcb.hits.iter().map(|h| h.stock).max().unwrap_or(0);+ // nothing in stock, but Mouser has some on order: say how much and when, so nobody orders it as if it ships+ let mouser_on_order = agg.mouser.hits.iter().filter(|h| h.stock == 0).find_map(|h| h.on_order.map(|n| (n, h.note.clone())))+ .map(|(n, note)| format!(" Mouser has {} on order and none in stock{}.", n,+ note.and_then(|t| t.find(" (first").map(|k| t[k..].split(')').next().unwrap_or("").to_string() + ")")).unwrap_or_default()))+ .unwrap_or_default(); if agg.digikey.hits.iter().any(reel_stock_unknown) { return EmptyState { title: format!("No in-stock listing found for \"{q}\", but DigiKey's cut tape was not checked."), explanation: format!(- "Mouser has no stock or a long lead time. DigiKey answered with its full-reel listing only, which reads 0; its cut tape and Digi-Reel stock is not in this answer.{}",+ "Mouser has no stock or a long lead time. DigiKey answered with its full-reel listing only, which reads 0; its cut tape and Digi-Reel stock is not in this answer.{}{}",+ mouser_on_order, if jlc_stock > 0 { format!(" JLCPCB has {} for boards it assembles.", jlc_stock) } else { String::new() }), hint: "Open the part's DigiKey page from its card to see cut-tape stock before calling it unavailable.".into(), };@@ -697,7 +727,8 @@ fn build_empty_state(agg: &AggregatedResults) -> EmptyState { return EmptyState { title: format!("No distributor has \"{q}\" in stock right now."), explanation: format!(- "Mouser and DigiKey list it, but with no stock or a long lead time.{}",+ "Mouser and DigiKey list it, but with no stock or a long lead time.{}{}",+ mouser_on_order, if jlc_stock > 0 { format!(" JLCPCB has {} for boards it assembles.", jlc_stock) } else { String::new() }), hint: "Check the lead times on the cards, ask for an alternate part, or have JLCPCB assemble the board.".into(), };@@ -908,7 +939,7 @@ mod recommendation_tests { manufacturer: "TI".into(), description: "test".into(), stock, unit_price: Some(price.into()), price_100: None, lead_time: "0".into(), image_url: None, datasheet_url: None, product_url: None, flags: vec![],- price_breaks: vec![], min_order: None, packaging: None, note: None,+ price_breaks: vec![], min_order: None, packaging: None, note: None, on_order: None, cad_3d_url: None, cad_3d_format: None, cad_3d_source: None, } }@@ -1074,7 +1105,7 @@ mod empty_state_tests { fn hit(v: Vendor, stock: u64) -> VendorHit { VendorHit { vendor: v, vendor_pn: "x".into(), mpn: "TPS62840DLCR".into(), manufacturer: String::new(), description: String::new(), stock, unit_price: None, price_100: None, lead_time: String::new(), image_url: None, datasheet_url: None, product_url: None, flags: vec![],- price_breaks: vec![], min_order: None, packaging: None, note: None,+ price_breaks: vec![], min_order: None, packaging: None, note: None, on_order: None, cad_3d_url: None, cad_3d_format: None, cad_3d_source: None } } #[test]@@ -1221,3 +1252,50 @@ mod listing_tests { assert!(r.reason.ends_with("Minimum order 4000 (Tape & Reel)."), "{}", r.reason); } }++#[cfg(test)]+mod on_order_tests {+ //! adom/adom-parts-search#13: Mouser's on-order quantity is not stock.+ use super::*;++ /// An answer cached before adom-mouser's fix: the on-order quantity sits in `stock`.+ #[test]+ fn a_cached_on_order_answer_reads_zero_in_stock() {+ let h = normalize_mouser(&json!({"mouser_pn": "511-STM32G0B1CBT6", "mpn": "STM32G0B1CBT6", "stock": 12415, "stock_text": "12415 On Order"}));+ assert_eq!(h.stock, 0);+ assert_eq!(h.on_order, Some(12415));+ assert!(h.note.unwrap().contains("12415 on order"));+ }++ /// The fixed service's answer: stock 0, on_order and dates in their own fields.+ #[test]+ fn the_fixed_answer_names_the_first_lot() {+ let h = normalize_mouser(&json!({"mpn": "STM32G0B1CBT6", "stock": 0, "stock_text": "12415 On Order", "on_order": 12415,+ "on_order_dates": [{"quantity": 415, "date": "2027-02-22"}, {"quantity": 12000, "date": null}]}));+ assert_eq!((h.stock, h.on_order), (0, Some(12415)));+ assert!(h.note.unwrap().contains("(first 415 expected 2027-02-22)"));+ }++ #[test]+ fn real_stock_is_untouched() {+ let h = normalize_mouser(&json!({"mpn": "LM358DR", "stock": 55000, "stock_text": "55,000 In Stock"}));+ assert_eq!((h.stock, h.on_order, h.note), (55000, None, None));+ let h = normalize_mouser(&json!({"mpn": "X", "stock": 1234, "stock_text": "1,234 In Stock, 500 On Order", "on_order": 500}));+ assert_eq!((h.stock, h.on_order), (1234, Some(500)));+ assert!(h.note.is_none(), "in stock: no on-order warning");+ }++ /// The reported case end to end: no recommendation, and the empty state says what is on order.+ #[test]+ fn nothing_is_recommended_and_the_empty_state_names_the_order() {+ let ok = |h: Vec<VendorHit>| VendorBlock { ok: true, total: h.len() as u64, hits: h, ..Default::default() };+ let m = normalize_mouser(&json!({"mpn": "STM32G0B1CBT6", "stock": 12415, "stock_text": "12415 On Order"}));+ let d = normalize_digikey(&json!({"digikey_pn": "497-STM32G0B1CBT6-ND", "mpn": "STM32G0B1CBT6", "stock": 0, "packaging": "Tray"}));+ let a = AggregatedResults { query: "STM32G0B1CBT6".into(), mouser: ok(vec![m]), digikey: ok(vec![d]), jlcpcb: ok(vec![]), ..Default::default() };+ assert!(pick_winner(&a, &a.query).is_none());+ assert!(pick_cheapest(&a, &a.query).is_none());+ let e = build_empty_state(&a);+ assert!(e.title.contains("No distributor has"), "{}", e.title);+ assert!(e.explanation.contains("Mouser has 12415 on order and none in stock"), "{}", e.explanation);+ }+}
uninstall.sh