← Commit history

demo: wait for the restarted KiCad before retrying, so a recoverable cache rebuild stops reading as a missing artifact

John Lauer ·446575a7ea ·2mo ago ·parent 193741a
1 file changed +25−1
web-control-demo.html+25−1
@@ -1573,6 +1573,24 @@ for (const w of mine) {   // 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 waitForKicad(c, tries) {+    var n = 0;+    function probe() {+      n++;+      return postVerb("kicad_status", {}).then(function (r) {+        var alive = r.s === 200 && r.j && r.j.success !== false && !r.j.errorCode;+        if (alive) { clog(c, "  KiCad is back after ~" + (n * 5) + "s"); return true; }+        if (n >= tries) { clog(c, "  KiCad did not come back within ~" + (n * 5) + "s"); return false; }+        return new Promise(function (rs) { setTimeout(rs, 5000); }).then(probe);+      }, function () {+        if (n >= tries) return false;+        return new Promise(function (rs) { setTimeout(rs, 5000); }).then(probe);+      });+    }+    clog(c, "  waiting for the restarted KiCad to answer ...");+    return probe();+  }+   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;@@ -1652,7 +1670,13 @@ for (const w of mine) {             if (restarted && !st._retried) {               st._retried = true;               clog(c, "  " + st.label + ": the bridge restarted KiCad to rebuild its cache and timed out waiting for it. That work is DONE, so retrying once ...");-              return new Promise(function (res2) { setTimeout(res2, 6000); }).then(function () {+              // Wait for the RESTART, not for a guess. A fixed 6s pause fired+              // while KiCad was still coming up, so the retry failed too and a+              // recoverable condition was reported as a missing artifact.+              // Poll kicad_status until the fresh instance answers (cap ~2 min),+              // because a library is only proven when all three artifacts open -+              // giving up early turns a slow success into a false failure.+              return waitForKicad(c, 24).then(function () {                 return postVerb(st.cmd, st.args()).then(function (r2) {                   var j2 = r2.j || {};                   var ok2 = r2.s === 200 && j2.success !== false && !j2.errorCode &&