app
AI Flow: PCBWay
Public Made by Adomby adom
Prepare PCBWay RFQs, preserve manufacturing gates, track complete vendor quotes and compare assembly costs. MIT Rust CLI with Pup workflow skill.
← All Pull Requests
adom-aiflow-pcbway 0.1.3: checks report findings, nothing is a hard gate #2
Merges
aiflow-pcbway-0.1.3 → mainadom-aiflow-pcbway 0.1.3 follows AI Flow's dynamic-skill rule (adom-aiflow PR #77): it's a guide, never a gate.
- What a check finds is now printed as FINDINGS after OK (exit 0) and recorded in the ledger:
- scope fields
- a stale package or quote
- missing MPN or manufacturer
- BOM/centroid differences
- quote quantity, inclusions and breakdown sum
- account identity
- an unconfirmed receipt (
nextstays at submit) - compare's like-for-like problems
ERROR (could not run)is only for an input it can't use. The old hint "never relax a gate" is gone.- It reads AI Flow's own export files as they are: BOM columns in any case or alias, several references in one cell (
C1 C2), a DNP column, and kicad-cli'sRef,PosX,PosY,Rot,Sidecentroid with top/bottom normalised to Top/Bottom. - Unit tests updated (7 pass). tests/workflow.py is updated to the new contract and adds a case with AI Flow's export files; it passes.
🤖 Generated with Claude Code
Diff Skip to comments
Cargo.lock+1−1@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow-pcbway"-version = "0.1.2"+version = "0.1.3" dependencies = [ "clap", "serde_json",
Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-aiflow-pcbway"-version = "0.1.2"+version = "0.1.3" edition = "2021" license = "MIT" [dependencies]
bin/adom-aiflow-pcbway⋯ 1 unchanged line ⋯
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow-pcbway", "type": "app",- "version": "0.1.2",+ "version": "0.1.3", "title": "AI Flow: PCBWay", "description": "Prepare PCBWay RFQs, preserve manufacturing gates, track complete vendor quotes and compare assembly costs. MIT Rust CLI with Pup workflow skill.", "category": "Developer Tools",
page.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow-pcbway", "type": "app",- "version": "0.1.2",+ "version": "0.1.3", "title": "AI Flow: PCBWay", "description": "Prepare PCBWay RFQs, preserve manufacturing gates, track complete vendor quotes and compare assembly costs. MIT Rust CLI with Pup workflow skill.", "category": "Developer Tools",
skills/adom-aiflow-pcbway/SKILL.md+7−2@@ -6,11 +6,16 @@ description: "Get an evidence-backed PCBWay PCB and assembly quote, compare it w Run `adom-aiflow-pcbway --project <quote-project> next` on resume and after each action. Pass `--ai-thread <thread>` on mutations. This Rust CLI records a ledger and validates file hashes. It has no payment or purchase command. +This is a **dynamic skill** (see adom-aiflow's "What a dynamic skill is"): the binary guides and checks, you do+the work and decide. No step is a hard gate. Commands answer `OK:` and then `FINDINGS` when a check found something+(suggestions; the command still did its job). `ERROR (could not run)` is only for an input it cannot read. `next`+suggests the step with open items.+ ## Scope and preparation Read the board release, prior quote and acceptance gates. Create a separate quote variant; do not rewrite the production BOM. Use `examples/scope.json` as the input contract and run `init --scope scope.json`, then `export`. All file paths in the scope must identify real nonempty files. Quantity, assembly scope, finish, dimensions, thickness and copper weight must match the comparison. Explicitly list hand-fitted Q1, cooling, wiring and other excluded items. -Input BOM columns: `ref,mpn,manufacturer,value,fit`. One row per reference; fit=post/dnp/exclude omits the part. Exact MPN and manufacturer are mandatory. LCSC numbers are optional supplier cross-references, never a replacement for MPNs. Input centroid columns: `Designator,Mid X,Mid Y,Layer,Rotation`; units mm; Top/Bottom. Native CAD zero rotation is not vendor placement approval. Never transfer JLC-specific rotation corrections to PCBWay. Preserve coordinate provenance, units, origin and bottom-side convention in centroidConvention. Use desktop/service KiCad through the standard shim for fresh CAD exports; never install KiCad in the container.+Input BOM columns: `ref,mpn,manufacturer,value,fit`, matched whatever their case and with the usual aliases, so AI Flow's `export` BOM (Reference, MPN, Manufacturer, Value, DNP; several references in one cell) reads as it is. fit=post/dnp/exclude or DNP omits the part. Give every part its exact MPN and manufacturer: a missing one is a finding, and PCBWay will pick or ask. LCSC numbers are optional supplier cross-references, never a replacement for MPNs. Input centroid columns: `Designator,Mid X,Mid Y,Layer,Rotation` (kicad-cli's `Ref,PosX,PosY,Rot,Side`, AI Flow's `export` CPL, also reads as it is); units mm; top/bottom is written as Top/Bottom. Native CAD zero rotation is not vendor placement approval. Never transfer JLC-specific rotation corrections to PCBWay. Preserve coordinate provenance, units, origin and bottom-side convention in centroidConvention. Use desktop/service KiCad through the standard shim for fresh CAD exports; never install KiCad in the container. `export` makes a clearly marked PRICING ONLY package. It checks reference-set parity, duplicates, finite coordinates, layer names and current file hashes. This does NOT certify DRC, pin mapping, rotation, geometry, soldering or thermal performance. Preserve failed AIFlow manufacturing checks in openChecks and disclose them in assembly notes. Before production, run PCBWay rules from adom/pcb-design-rules and review vendor placement drawings, polarity and pin1. A PCBWay RFQ must never clear an unrelated JLC failure. @@ -50,7 +55,7 @@ If waiting on the vendor or sign-in, persist `blocked --reason <concrete-depende ## Comparison and finish line -`compare --baseline <vendor-pricing.json>` refuses incomplete PCBWay pricing, stale package evidence and different quantity/currency. It returns exclusions for manual scope comparison. Verify part variants, finish, hand soldering and attrition independently; numerical comparison is not proof of identical scope. `report` writes current status. Continue until a complete quote is returned or an external dependency prevents progress. Do not stop at an upload or progress report.+`compare --baseline <vendor-pricing.json>` reports incomplete PCBWay pricing, stale package evidence and different quantity/currency as findings (the comparison is not like for like until they are fixed). It returns exclusions for manual scope comparison. Verify part variants, finish, hand soldering and attrition independently; numerical comparison is not proof of identical scope. `report` writes current status. Continue until a complete quote is returned or an external dependency prevents progress. Do not stop at an upload or progress report. This initial release supports quotation and evidence tracking. Purchase, delivery and placement approval remain outside its implemented command set. Do not describe them as automated.
src/csvio.rs+26−1@@ -71,8 +71,33 @@ impl Table { .collect(), }) }+ /// A column by name: exact first, then case and punctuation ignored, then the usual aliases, so AI Flow's+ /// `export` files (Reference/MPN/Manufacturer/Value; kicad-cli's Ref/PosX/PosY/Rot/Side) and JLCPCB-style+ /// files both read as they are. pub fn col(&self, name: &str) -> Option<usize> {- self.head.iter().position(|h| h == name)+ if let Some(i) = self.head.iter().position(|h| h == name) {+ return Some(i);+ }+ let norm = |s: &str| {+ s.chars()+ .filter(|c| c.is_ascii_alphanumeric())+ .collect::<String>()+ .to_ascii_lowercase()+ };+ let aliases: &[&str] = match name {+ "ref" | "Designator" => &["ref", "refs", "reference", "references", "designator", "designators", "refdes"],+ "mpn" => &["mpn", "manufacturerpartnumber", "manufacturerpn", "mfrpn", "partnumber"],+ "manufacturer" => &["manufacturer", "mfr", "mfg", "maker"],+ "value" => &["value", "comment", "val", "description"],+ "Mid X" => &["midx", "posx", "x", "centerx", "locationx"],+ "Mid Y" => &["midy", "posy", "y", "centery", "locationy"],+ "Rotation" => &["rotation", "rot", "angle"],+ "Layer" => &["layer", "side"],+ _ => &[],+ };+ std::iter::once(norm(name))+ .chain(aliases.iter().map(|a| a.to_string()))+ .find_map(|w| self.head.iter().position(|h| norm(h) == w)) } pub fn get<'a>(&self, row: &'a [String], name: &str) -> &'a str { self.col(name)
src/main.rs+188−81@@ -10,6 +10,21 @@ use std::{ path::{Path, PathBuf}, }; type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;++// A dynamic skill (see adom-aiflow): checks report and suggest, never block. ERROR means only "I could not run"+// (a missing or unreadable input); everything a check finds is a finding printed after OK, with the command done.+static FINDINGS: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());+fn finding(msg: impl Into<String>) {+ let m = msg.into();+ if let Ok(mut f) = FINDINGS.lock() {+ if !f.contains(&m) {+ f.push(m);+ }+ }+}+fn findings() -> Vec<String> {+ FINDINGS.lock().map(|f| f.clone()).unwrap_or_default()+} #[derive(Parser)] #[command( version,@@ -83,6 +98,12 @@ fn write(p: &Path, v: &Value) -> Result<()> { fn hash(p: &Path) -> Result<String> { Ok(format!("{:x}", Sha256::digest(fs::read(p)?))) }+/// A field that should be filled: a finding when it is not.+fn want(v: &Value, k: &str, what: &str) {+ if v[k].as_str().unwrap_or("").trim().is_empty() {+ finding(format!("{what} has no {k}"));+ }+} fn nonempty(v: &Value, k: &str) -> Result<String> { let s = v[k].as_str().unwrap_or(""); if s.trim().is_empty() {@@ -118,18 +139,18 @@ fn valid_scope(v: &Value) -> Result<()> { "centroidConvention", "openChecks", ] {- nonempty(v, k)?;+ want(v, k, "the scope"); } for k in ["widthMm", "heightMm", "thicknessMm", "copperOz"] { if v[k].as_f64().unwrap_or(0.) <= 0. {- return Err(format!("invalid {k}").into());+ finding(format!("the scope has no {k}: PCBWay's quote form asks for it")); } } if v["layers"].as_u64().unwrap_or(0) < 1 {- return Err("layers required".into());+ finding("the scope has no layers count: PCBWay's quote form asks for it"); } if !v["exclusions"].is_array() {- return Err("explicit exclusions array required".into());+ finding("the scope lists no exclusions: say what the quote leaves out (shipping, tax, parts you supply) so it compares like for like"); } Ok(()) }@@ -137,25 +158,28 @@ fn load(d: &Path) -> Result<Value> { let s = read(&d.join("state.json"))?; for v in s["inputs"].as_object().ok_or("inputs missing")?.values() { if !current(v) {- return Err("input changed: init a new run; old quote must not be reused".into());+ finding("an input (board, BOM, centroid or Gerbers) changed since init: a quote recorded before describes the old files; init a new run in a fresh --project for the new ones"); } } Ok(s) }+/// Is the exported package current (same scope, files unchanged)?+fn package_current(d: &Path, s: &Value) -> bool {+ read(&d.join("package.json")).is_ok_and(|p| {+ p["scopeDigest"] == digest(s)+ && p["files"].as_array().is_some_and(|a| a.iter().all(current))+ })+}+/// The exported package; a stale one is a finding (the commands still run). fn package(d: &Path, s: &Value) -> Result<Value> {- let p = read(&d.join("package.json"))?;- if p["scopeDigest"] != digest(s) {- return Err("package has stale scope".into());- }- for v in p["files"].as_array().ok_or("package files missing")? {- if !current(v) {- return Err("exported file changed; re-export and repeat vendor review".into());- }+ let p = read(&d.join("package.json")).map_err(|_| "no package yet: run `export` first")?;+ if !package_current(d, s) {+ finding("the package is stale (the scope or an exported file changed since export): run `export` again and repeat the vendor review"); } Ok(p) } fn step(d: &Path, s: &Value) -> String {- if package(d, s).is_err() {+ if !package_current(d, s) { return "export: make the pricing-only BOM/centroid/Gerber package".into(); } if let Ok(a) = read(&d.join("account.json")) {@@ -166,7 +190,7 @@ fn step(d: &Path, s: &Value) -> String { let p = read(&d.join("package.json")).unwrap(); let stamp = digest(&p); let r = read(&d.join("submitted.json")).unwrap_or(Value::Null);- if r["packageDigest"] != stamp || !current(&r["evidence"]) {+ if r["packageDigest"] != stamp || !current(&r["evidence"]) || r["receiptConfirmed"] != true { return "submit: use the visible Hydrogen webview (Pup optional), verify intended account, upload package for RFQ; record actual vendor receipt with submitted".into(); } let q = read(&d.join("quote.json")).unwrap_or(Value::Null);@@ -181,61 +205,112 @@ fn step(d: &Path, s: &Value) -> String { fn export(d: &Path, s: &Value) -> Result<Value> { let bom = csvio::Table::read(Path::new(s["inputs"]["bom"]["path"].as_str().unwrap()))?; let cpl = csvio::Table::read(Path::new(s["inputs"]["centroid"]["path"].as_str().unwrap()))?;- for h in ["ref", "mpn", "manufacturer", "value"] {+ if bom.col("ref").is_none() {+ return Err("the BOM has no reference column (ref, Reference or Designator)".into());+ }+ for h in ["mpn", "manufacturer", "value"] { if bom.col(h).is_none() {- return Err(format!("BOM missing {h}").into());+ finding(format!("the BOM has no {h} column")); } } for h in ["Designator", "Mid X", "Mid Y", "Layer", "Rotation"] { if cpl.col(h).is_none() {- return Err(format!("centroid missing {h}").into());+ return Err(format!("the centroid has no {h} column (kicad-cli's Ref/PosX/PosY/Rot/Side also work)").into()); } } let mut included = BTreeMap::new(); let mut seen = BTreeSet::new(); let mut excluded = Vec::new();+ let dnp = |r: &Vec<String>| {+ let fit = bom.get(r, "fit").to_lowercase();+ let d = bom.get(r, "dnp").to_lowercase();+ ["post", "dnp", "exclude"].contains(&fit.as_str()) || ["yes", "true", "1", "dnp"].contains(&d.as_str())+ };+ let (mut no_mpn, mut dupes) = (Vec::new(), Vec::new()); for r in &bom.rows {- let reference = bom.get(r, "ref");- if reference.is_empty() || !seen.insert(reference.to_string()) {- return Err("empty/duplicate BOM reference".into());- }- if ["post", "dnp", "exclude"].contains(&bom.get(r, "fit").to_lowercase().as_str()) {- excluded.push(reference.to_string());+ // a row may name several references (AI Flow's BOM: "C2 C3 C4")+ let refs: Vec<String> = bom+ .get(r, "ref")+ .split([' ', ',', ';'])+ .filter(|x| !x.is_empty())+ .map(String::from)+ .collect();+ if refs.is_empty() {+ finding("a BOM row has no reference: left out"); continue; }- if bom.get(r, "mpn").is_empty() || bom.get(r, "manufacturer").is_empty() {- return Err(format!("{reference} requires exact MPN and manufacturer").into());+ for reference in refs {+ if !seen.insert(reference.clone()) {+ dupes.push(reference);+ continue;+ }+ if dnp(r) {+ excluded.push(reference);+ continue;+ }+ if bom.get(r, "mpn").is_empty() || bom.get(r, "manufacturer").is_empty() {+ no_mpn.push(reference.clone());+ }+ included.insert(reference, r); }- included.insert(reference.to_string(), r);+ }+ if !dupes.is_empty() {+ finding(format!("references on more than one BOM row (the first row is used): {}", dupes.join(", ")));+ }+ if !no_mpn.is_empty() {+ finding(format!("no exact MPN and manufacturer for {}: PCBWay will pick a part or ask; add them to the BOM for a like-for-like quote", no_mpn.join(", "))); } let mut placements = BTreeSet::new(); let mut xyz = vec![vec!["Designator", "Mid X", "Mid Y", "Layer", "Rotation"] .into_iter() .map(String::from) .collect()];+ let (mut not_in_bom, mut bad_place) = (Vec::new(), Vec::new()); for r in &cpl.rows { let reference = cpl.get(r, "Designator");- if !included.contains_key(reference) || !placements.insert(reference.to_string()) {- return Err(format!("unexpected/duplicate centroid {reference}").into());+ if excluded.iter().any(|e| e == reference) {+ continue; }- for h in ["Mid X", "Mid Y", "Rotation"] {- let n = cpl.get(r, h).trim_end_matches("mm").trim().parse::<f64>()?;- if !n.is_finite() {- return Err("nonfinite placement".into());- }+ if !included.contains_key(reference) {+ not_in_bom.push(reference.to_string());+ continue; }- if !["Top", "Bottom"].contains(&cpl.get(r, "Layer")) {- return Err("centroid layer must be Top/Bottom".into());+ if !placements.insert(reference.to_string()) {+ finding(format!("{reference} is in the centroid twice: the first row is used"));+ continue; }- xyz.push(- ["Designator", "Mid X", "Mid Y", "Layer", "Rotation"]- .iter()- .map(|h| cpl.get(r, h).into())- .collect(),- );+ let ok = ["Mid X", "Mid Y", "Rotation"].iter().all(|h| {+ cpl.get(r, h).trim_end_matches("mm").trim().parse::<f64>().is_ok_and(|n| n.is_finite())+ });+ if !ok {+ bad_place.push(reference.to_string());+ }+ // PCBWay's centroid says Top/Bottom; kicad-cli says top/bottom+ let layer = match cpl.get(r, "Layer").to_ascii_lowercase().as_str() {+ "top" | "t" | "f" | "front" | "f.cu" => "Top".to_string(),+ "bottom" | "b" | "back" | "b.cu" => "Bottom".to_string(),+ other => {+ finding(format!("{reference}: centroid layer {other:?} is not top or bottom"));+ other.to_string()+ }+ };+ xyz.push(vec![+ reference.to_string(),+ cpl.get(r, "Mid X").into(),+ cpl.get(r, "Mid Y").into(),+ layer,+ cpl.get(r, "Rotation").into(),+ ]);+ }+ if !not_in_bom.is_empty() {+ finding(format!("in the centroid but not in the BOM (left out): {}", not_in_bom.join(", ")));+ }+ if !bad_place.is_empty() {+ finding(format!("no numeric position or rotation for {}", bad_place.join(", "))); }- if included.keys().cloned().collect::<BTreeSet<_>>() != placements {- return Err("BOM and centroid reference sets differ".into());+ let unplaced: Vec<&String> = included.keys().filter(|r| !placements.contains(*r)).collect();+ if !unplaced.is_empty() {+ finding(format!("in the BOM but not in the centroid (PCBWay cannot place them): {}", unplaced.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(", "))); } let mut rows = vec![vec![ "Item",@@ -287,47 +362,51 @@ fn export(d: &Path, s: &Value) -> Result<Value> { write(&d.join("package.json"), &p)?; Ok(p) }+/// A quote's facts. ERROR only when it cannot be read as a quote (kind, total, a cost that is not a number);+/// what is missing or does not add up is a finding: the quote is recorded and the human sees what is open. fn quote_valid(v: &Value, qty: u64) -> Result<()> { if !["calculator-only", "vendor-partial", "vendor-full"] .contains(&v["kind"].as_str().unwrap_or("")) {- return Err("invalid quote kind".into());+ return Err("kind must be calculator-only, vendor-partial or vendor-full".into()); } for k in ["vendorReference", "currency", "checkedAt", "scopeNote"] {- nonempty(v, k)?;+ want(v, k, "the quote"); } if v["quantity"].as_u64() != Some(qty) {- return Err("quote quantity differs from scope".into());+ finding(format!("the quote is for {} boards but the scope says {qty}", v["quantity"])); } let total = v["totalBeforeShippingTax"] .as_f64()- .ok_or("missing numeric total")?;+ .ok_or("totalBeforeShippingTax must be a number")?; if !total.is_finite() || total <= 0. {- return Err("invalid total".into());+ return Err("totalBeforeShippingTax must be a positive number".into()); } if !v["exclusions"].is_array() {- return Err("exclusions required".into());+ finding("the quote lists no exclusions (shipping, tax, parts not included)"); } if v["kind"] == "vendor-full" { for k in ["pcb", "components", "assembly"] { if v["includes"][k] != true {- return Err(format!("full quote must include {k}").into());+ finding(format!("a vendor-full quote that does not say it includes {k}: it may not compare like for like")); } } }- let items = v["breakdown"]- .as_object()- .ok_or("itemized breakdown required")?;- let mut sum = 0.;- for x in items.values() {- let n = x.as_f64().ok_or("cost must be numeric")?;- if !n.is_finite() || n < 0. {- return Err("invalid cost".into());+ match v["breakdown"].as_object() {+ None => finding("no itemized breakdown: ask PCBWay for PCB, parts, setup, assembly and shipping separately"),+ Some(items) => {+ let mut sum = 0.;+ for x in items.values() {+ let n = x.as_f64().ok_or("every breakdown cost must be a number")?;+ if !n.is_finite() || n < 0. {+ finding(format!("a breakdown cost is {n}"));+ }+ sum += n;+ }+ if (sum - total).abs() > 0.011 {+ finding(format!("the breakdown sums to {sum:.2} but the total is {total:.2}"));+ } }- sum += n;- }- if (sum - total).abs() > 0.011 {- return Err("breakdown does not sum to total".into()); } Ok(()) }@@ -397,7 +476,7 @@ fn run(c: &Cli) -> Result<Value> { evidence, } => { if s["scope"]["account"] != email.as_str() {- return Err("account differs from intended scope identity".into());+ finding(format!("the account {email} is not the one the scope names ({}): check it is the account the human meant", s["scope"]["account"])); } let v = json!({"email":email,"status":status,"evidence":file(&json!(evidence))?}); write(&d.join("account.json"), &v)?;@@ -411,7 +490,7 @@ fn run(c: &Cli) -> Result<Value> { nonempty(&v, "vendorReference")?; nonempty(&v, "submittedAt")?; if v["receiptConfirmed"] != true {- return Err("actual vendor receipt required; a click is not a receipt".into());+ finding("receiptConfirmed is not true: a click is not a receipt; `next` stays at submit until PCBWay confirms it received the RFQ"); } v["evidence"] = file(&v["evidence"])?; v["packageDigest"] = json!(digest(&p));@@ -440,16 +519,14 @@ fn run(c: &Cli) -> Result<Value> { let p = package(&d, &s)?; let q = read(&d.join("quote.json"))?; if q["packageDigest"] != digest(&p) || !current(&q["evidence"]) {- return Err("stale quote evidence".into());+ finding("the quote is stale (the package or its evidence changed since it was recorded)"); } let b = read(baseline)?; if q["kind"] != "vendor-full" {- return Err(- "no full PCBWay quote: do not compare calculator with full JLC assembly".into(),- );+ finding(format!("the PCBWay quote is {}, not a full quote: it does not compare like for like with a full JLCPCB assembly price", q["kind"])); } if q["quantity"] != b["quantity"] || q["currency"] != b["currency"] {- return Err("quantity/currency mismatch".into());+ finding(format!("quantity or currency differ: PCBWay {} {}, baseline {} {}", q["quantity"], q["currency"], b["quantity"], b["currency"])); } json!({"pcbway":q["totalBeforeShippingTax"],"baseline":b["totalBeforeShippingTax"],"difference":q["totalBeforeShippingTax"].as_f64().unwrap()-b["totalBeforeShippingTax"].as_f64().ok_or("baseline total missing")?,"scopeReviewRequired":true,"pcbwayExclusions":q["exclusions"],"baselineExclusions":b["excludes"]}) }@@ -467,7 +544,7 @@ fn run(c: &Cli) -> Result<Value> { writeln!( f, "{}",- json!({"unixSeconds":std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs(),"aiThread":c.ai_thread,"command":std::env::args().collect::<Vec<_>>(),"result":result})+ json!({"unixSeconds":std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs(),"aiThread":c.ai_thread,"command":std::env::args().collect::<Vec<_>>(),"result":result,"findings":findings()}) )?; } Ok(result)@@ -475,9 +552,19 @@ fn run(c: &Cli) -> Result<Value> { fn main() { let c = Cli::parse(); match run(&c) {- Ok(v) => println!("OK: {}", serde_json::to_string_pretty(&v).unwrap()),+ Ok(v) => {+ println!("OK: {}", serde_json::to_string_pretty(&v).unwrap());+ let f = findings();+ if !f.is_empty() {+ println!("FINDINGS (suggestions, nothing is blocked):");+ for x in f {+ println!(" - {x}");+ }+ println!("Suggestion: fix what is real, or tell the human what is open; `next` suggests the step.");+ }+ } Err(e) => {- eprintln!("ERROR: {e}\nHint: repair the evidence or input; never relax a gate. Run next after correction.");+ eprintln!("ERROR (could not run): {e}\nHint: fix the input and run again; `next` suggests what to do."); std::process::exit(1) } }@@ -488,24 +575,44 @@ mod tests { fn q() -> Value { json!({"kind":"vendor-full","quantity":5,"currency":"USD","checkedAt":"2026-10-20","vendorReference":"test","scopeNote":"five boards","totalBeforeShippingTax":20.,"includes":{"pcb":true,"components":true,"assembly":true},"breakdown":{"pcb":5.,"parts":10.,"assembly":5.},"exclusions":["shipping","tax"]}) }+ static SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(());+ fn found(v: &Value, qty: u64) -> Vec<String> {+ let _one_at_a_time = SERIAL.lock().unwrap_or_else(|e| e.into_inner()); // FINDINGS is process-wide+ FINDINGS.lock().unwrap().clear();+ quote_valid(v, qty).unwrap();+ findings()+ } #[test]- fn full_requires_components() {+ fn full_without_components_is_a_finding_not_a_stop() { let mut v = q(); v["includes"]["components"] = json!(false);- assert!(quote_valid(&v, 5).is_err())+ assert!(found(&v, 5).iter().any(|f| f.contains("components"))); } #[test]- fn rejects_quantity_drift() {- assert!(quote_valid(&q(), 10).is_err())+ fn quantity_drift_is_a_finding() {+ assert!(found(&q(), 10).iter().any(|f| f.contains("10"))); } #[test]- fn rejects_bad_sum() {+ fn a_bad_sum_is_a_finding() { let mut v = q(); v["totalBeforeShippingTax"] = json!(19);- assert!(quote_valid(&v, 5).is_err())+ assert!(found(&v, 5).iter().any(|f| f.contains("sums to")));+ }+ #[test]+ fn full_price_has_no_findings() {+ assert!(found(&q(), 5).is_empty());+ }+ #[test]+ fn an_unreadable_quote_is_still_an_error() {+ let mut v = q();+ v["kind"] = json!("guess");+ assert!(quote_valid(&v, 5).is_err()); } #[test]- fn full_price_valid() {- assert!(quote_valid(&q(), 5).is_ok())+ fn ai_flow_export_columns_read_as_they_are() {+ let t = csvio::Table { head: ["Reference", "Qty", "Value", "Footprint", "Manufacturer", "MPN", "DNP"].map(String::from).to_vec(), rows: vec![] };+ assert_eq!((t.col("ref"), t.col("value"), t.col("manufacturer"), t.col("mpn")), (Some(0), Some(2), Some(4), Some(5)));+ let c = csvio::Table { head: ["Ref", "Val", "Package", "PosX", "PosY", "Rot", "Side"].map(String::from).to_vec(), rows: vec![] };+ assert_eq!((c.col("Designator"), c.col("Mid X"), c.col("Mid Y"), c.col("Rotation"), c.col("Layer")), (Some(0), Some(3), Some(4), Some(5), Some(6))); } }
tests/workflow.py+23−10@@ -1,13 +1,15 @@-"""Exercise real CLI evidence gates in an isolated synthetic project (not vendor evidence)."""+"""Exercise the CLI evidence checks in an isolated synthetic project (not vendor evidence). A dynamic skill: checks+are findings printed after OK (exit 0); only an input it cannot use is an error.""" import json, pathlib, subprocess, sys, tempfile binary=str(pathlib.Path(sys.argv[1]).resolve()) with tempfile.TemporaryDirectory() as tmp: p=pathlib.Path(tmp) def put(n,v): f=p/n;f.write_text(json.dumps(v) if isinstance(v,dict) else v);return str(f)- def run(*args,ok=True):+ def run(*args,ok=True,finds=None): r=subprocess.run([binary,'--project',tmp,'--ai-thread','test',*args],capture_output=True,text=True) assert (r.returncode==0)==ok,(args,r.stdout,r.stderr)+ if finds: assert 'FINDINGS' in r.stdout and finds in r.stdout,(args,finds,r.stdout) return r.stdout scope={'quantity':5,'assembly':'top','widthMm':72,'heightMm':72,'thicknessMm':1.6,'copperOz':1,'layers':2,'finish':'HASL','target':'test','account':'test','centroidConvention':'native','openChecks':'unapproved','exclusions':['shipping','tax']} for k,s in [('board','synthetic board'),('gerbers','synthetic archive'),('bom','ref,mpn,manufacturer,value,fit\nR1,ABC,M,1k,\n'),('centroid','Designator,Mid X,Mid Y,Layer,Rotation\nR1,1mm,2mm,Top,0\n')]:scope[k]=put(k,s)@@ -15,19 +17,30 @@ with tempfile.TemporaryDirectory() as tmp: run('init','--scope',str(p/'scope.json'),ok=False) evidence=put('evidence.txt','synthetic vendor evidence, not a real quote') receipt={'vendorReference':'TEST','submittedAt':'2026-10-20','receiptConfirmed':False,'evidence':evidence}- run('submitted','--receipt',put('receipt.json',receipt),ok=False)+ run('submitted','--receipt',put('receipt.json',receipt),finds='a click is not a receipt');assert 'submit:' in run('next') receipt['receiptConfirmed']=True;run('submitted','--receipt',put('receipt.json',receipt)) q={'kind':'calculator-only','vendorReference':'TEST','quantity':5,'currency':'USD','checkedAt':'2026-10-20','scopeNote':'test','totalBeforeShippingTax':25,'breakdown':{'assembly':25},'exclusions':['PCB','components'],'includes':{'pcb':False,'assembly':True,'components':False},'evidence':evidence} run('quote','--facts',put('quote.json',q));assert 'await-quote' in run('next') baseline=put('baseline.json',{'quantity':5,'currency':'USD','totalBeforeShippingTax':30})- run('compare','--baseline',baseline,ok=False)- q['kind']='vendor-full';run('quote','--facts',put('quote.json',q),ok=False)+ run('compare','--baseline',baseline,finds='not a full quote')+ q['kind']='vendor-full';run('quote','--facts',put('quote.json',q),finds='does not say it includes components') q['includes']={'pcb':True,'components':True,'assembly':True};q['breakdown']={'pcb':5,'components':15,'assembly':5};q['exclusions']=['shipping','tax'] run('quote','--facts',put('quote.json',q));assert 'quote-complete' in run('next');run('compare','--baseline',baseline)- pathlib.Path(evidence).write_text('changed');assert 'submit:' in run('next');run('compare','--baseline',baseline,ok=False)+ pathlib.Path(evidence).write_text('changed');assert 'submit:' in run('next');run('compare','--baseline',baseline,finds='the quote is stale') (p/'pcbway-flow/upload/BOM-PRICING-ONLY.csv').write_text('changed');assert 'export:' in run('next')- pathlib.Path(scope['board']).write_text('changed');run('next',ok=False)- print('PASS: partial totals, missing inclusion, stale evidence, stale exports, changed inputs, duplicate init and vendor receipt gates')+ pathlib.Path(scope['board']).write_text('changed');run('next',finds='changed since init')+ # AI Flow's own export files (grouped references, kicad-cli centroid) work as they are+ with tempfile.TemporaryDirectory() as t2:+ q2=pathlib.Path(t2)+ s2=dict(scope)+ s2['bom']=str(q2/'b.csv');(q2/'b.csv').write_text('Reference,Qty,Value,Footprint,Manufacturer,MPN,DNP\nC1 C2,2,1u,C_0603,Murata,GRM188,\nMP1,1,pin,Pin,,,DNP\n')+ s2['centroid']=str(q2/'c.csv');(q2/'c.csv').write_text('Ref,Val,Package,PosX,PosY,Rot,Side\nC1,1u,C_0603,1,2,90,top\nC2,1u,C_0603,3,4,0,bottom\n')+ for k in ['board','gerbers']: s2[k]=scope[k]+ (q2/'s.json').write_text(json.dumps(s2))+ r=subprocess.run([binary,'--project',t2,'--ai-thread','test','init','--scope',str(q2/'s.json')],capture_output=True,text=True);assert r.returncode==0,r.stdout+r.stderr+ r=subprocess.run([binary,'--project',t2,'--ai-thread','test','export'],capture_output=True,text=True);assert r.returncode==0 and 'FINDINGS' not in r.stdout,r.stdout+r.stderr+ cen=(q2/'pcbway-flow/upload/CENTROID-UNAPPROVED.csv').read_text();assert 'C2,3,4,Bottom,0' in cen,cen+ print('PASS: partial totals, missing inclusion, stale evidence, stale exports, changed inputs and vendor receipt reported as findings; duplicate init is an error') # Display selection is exercised through stub tools, without opening user windows. with tempfile.TemporaryDirectory() as tmp:@@ -43,6 +56,6 @@ with tempfile.TemporaryDirectory() as tmp: r=subprocess.run(base+['show','--surface','pup'],env=env,capture_output=True,text=True);assert r.returncode!=0 r=subprocess.run(base+['show','--surface','pup','--target','test-desktop'],env=env,capture_output=True,text=True);assert r.returncode==0 and 'test-desktop' in r.stdout e=root/'evidence.txt';e.write_text('Synthetic account status')- r=subprocess.run(base+['account','--email','[email protected]','--status','signed-in','--evidence',str(e)],capture_output=True);assert r.returncode!=0+ r=subprocess.run(base+['account','--email','[email protected]','--status','signed-in','--evidence',str(e)],capture_output=True,text=True);assert r.returncode==0 and 'is not the one the scope names' in r.stdout r=subprocess.run(base+['account','--email','[email protected]','--status','captcha-required','--evidence',str(e)],capture_output=True);assert r.returncode==0- print('PASS: default webview, explicit Pup target, intended account identity and pending account tracking')+ print('PASS: default webview, explicit Pup target, account identity finding and pending account tracking')
Comments
Log in to comment.
No comments yet.