← Commit history

demo: verify the LIBRARY in the captured evidence, not just the editor type - a green tick over a stock-library window is worse than a failure

John Lauer ·193741a90e ·2mo ago ·parent 1e7a559
1 file changed +41−9
web-control-demo.html+41−9
@@ -1566,16 +1566,34 @@ for (const w of mine) {   // shot was byte-identical for 8 of the 10 parts.   //   // John, 2026-08-20: "a library is all 3 of those items".-  function appendPicked(c, d, pickTitle, label) {+  // `expect` is the "LIB:NAME" the caller asked for. A KiCad editor titles itself+  // "<library>:<part> - <Editor>", so the library is IN the evidence and must be+  // checked. Measured 2026-08-20: kicad_show_symbol returned success with the+  // editor on stock "LED:WS2812B-2020" when the caller named "Adom", and this+  // card scored it 3/3 because it only matched on "symbol editor". A card that+  // renders a picture of the WRONG library under a green tick is worse than one+  // that fails: the picture is what a human trusts.+  function appendPicked(c, d, pickTitle, label, expect) {     var shots = findShots(d).filter(function (s) { return s && (s.image || s.base64 || s.png); });     if (!shots.length) return false;+    var titleOf = function (s) { return ((s.title || s.label || s.window || "") + ""); };     var want = (pickTitle || "").toLowerCase();-    var picked = want ? shots.filter(function (s) {-      return ((s.title || s.label || "") + "").toLowerCase().indexOf(want) >= 0;-    }) : shots;+    var picked = want ? shots.filter(function (s) { return titleOf(s).toLowerCase().indexOf(want) >= 0; }) : shots;     if (!picked.length) picked = [shots[shots.length - 1]];+    if (expect) {+      var e = expect.toLowerCase();+      var exact = picked.filter(function (s) { return titleOf(s).toLowerCase().indexOf(e) >= 0; });+      if (!exact.length) {+        var got = titleOf(picked[0]);+        clog(c, "  WRONG LIBRARY: asked for '" + expect + "' but the window is '" + got + "'");+        addShot(c.card, picked[0].image || picked[0].base64 || picked[0].png,+          "REJECTED " + label + " - wrong library: " + got);+        return false;+      }+      picked = exact;+    }     var s0 = picked[0];-    addShot(c.card, s0.image || s0.base64 || s0.png, label + " - " + (s0.title || s0.label || "window"));+    addShot(c.card, s0.image || s0.base64 || s0.png, label + " - " + titleOf(s0));     return true;   } @@ -1601,8 +1619,10 @@ for (const w of mine) {     }).then(function () {       var steps = [         { cmd: "kicad_show_symbol", label: "symbol", pick: "symbol editor",+          expect: function () { return PART.kicadLib + ":" + (PART.kicadSymbolName || PART.name); },           args: function () { return { symbolName: PART.kicadSymbolName || PART.name, library: PART.kicadLib }; } },         { cmd: "kicad_show_footprint", label: "footprint", pick: "footprint editor",+          expect: function () { return PART.kicadLib + ":" + (PART.kicadFootprintName || PART.name); },           args: function () { return { footprintName: PART.kicadFootprintName || PART.name, library: PART.kicadLib }; } },         { cmd: "kicad_show_3d_chip", label: "3D model", pick: "3d viewer",           args: function () { return { footprintName: PART.kicadFootprintName || PART.name, library: PART.kicadLib }; } }@@ -1641,8 +1661,13 @@ for (const w of mine) {                   if (!ok2) { clog(c, "  " + st.label + " FAILED after the retry: " + (j2.error || j2.errorCode || ("HTTP " + r2.s))); return; }                   clog(c, "  " + st.label + " opened on the retry (the restart had already fixed it)");                   return settleThenCapture(c, "kicad_state").then(function (sr) {-                    if (!(sr.s === 200 && sr.j && appendPicked(c, sr.j, st.pick, st.label)))-                      clog(c, "  (" + st.label + " opened but no capture came back)");+                    var proven2 = sr.s === 200 && sr.j && appendPicked(c, sr.j, st.pick, st.label, st.expect && st.expect());+                    if (!proven2) {+                      clog(c, "  " + st.label + ": retry reported success but the capture did not prove it");+                      for (var i = results.length - 1; i >= 0; i--) {+                        if (results[i].label === st.label) { results[i].ok = false; break; }+                      }+                    }                   });                 });               });@@ -1653,8 +1678,15 @@ for (const w of mine) {               return;             }             return settleThenCapture(c, "kicad_state").then(function (sr) {-              if (!(sr.s === 200 && sr.j && appendPicked(c, sr.j, st.pick, st.label)))-                clog(c, "  (" + st.label + " opened but no capture came back)");+              var proven = sr.s === 200 && sr.j && appendPicked(c, sr.j, st.pick, st.label, st.expect && st.expect());+              if (!proven) {+                // The verb said success; the evidence does not back it. Believe+                // the evidence - that is the whole point of capturing it.+                clog(c, "  " + st.label + ": the verb reported success but the capture did not prove it");+                for (var i = results.length - 1; i >= 0; i--) {+                  if (results[i].label === st.label) { results[i].ok = false; break; }+                }+              }             });           });         });