kryptheon 0.1.44 → 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -203,6 +203,26 @@
203
203
  head.appendChild(el('b', null, job.title));
204
204
  head.appendChild(el('span', 'tag ' + (job.running ? 'sun' : ok ? 'leaf' : 'ember'),
205
205
  job.running ? 'running' : ok ? 'finished' : 'did not finish'));
206
+ if (job.running && job.stoppable) {
207
+ // A run that adds data to the app can be ended part way. What it
208
+ // finished is kept and said; the rest is said as not tested.
209
+ var stop = el('button', 'job-close', job.stopping ? 'Stopping...' : 'Stop');
210
+ stop.type = 'button';
211
+ stop.disabled = !!job.stopping;
212
+ // On the press itself, not the click: the panel is redrawn while the
213
+ // run goes, and a click whose press and release land on two drawings
214
+ // of the button is lost - measured, on this panel.
215
+ var stopNow = function (e) {
216
+ if (e) e.preventDefault();
217
+ if (stop.disabled) return;
218
+ stop.disabled = true;
219
+ stop.textContent = 'Stopping...';
220
+ post('/api/stop', {}).catch(function (err) { toast('Could not stop: ' + err.message); });
221
+ };
222
+ stop.addEventListener('mousedown', stopNow);
223
+ stop.addEventListener('click', stopNow);
224
+ head.appendChild(stop);
225
+ }
206
226
  if (!job.running) {
207
227
  var close = el('button', 'job-close', 'Close');
208
228
  close.type = 'button';
@@ -272,7 +292,9 @@
272
292
  return new Promise(function (resolve) {
273
293
  (function tick() {
274
294
  getJob().then(function (now) {
275
- if (now) { job = now; renderJob(); }
295
+ // Drawn again only when something in it changed, so a button in it
296
+ // stays the same button between presses.
297
+ if (now && JSON.stringify(now) !== JSON.stringify(job)) { job = now; renderJob(); }
276
298
  if (now && now.running) setTimeout(tick, 700);
277
299
  else resolve(now);
278
300
  }, function () { setTimeout(tick, 1500); });
@@ -280,8 +302,8 @@
280
302
  });
281
303
  }
282
304
 
283
- var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database' };
284
- var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk' };
305
+ var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases' };
306
+ var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember' };
285
307
 
286
308
  function counts() {
287
309
  var confirmed = state.findings.filter(function (f) { return f.status === 'confirmed'; }).length;
@@ -351,7 +373,7 @@
351
373
  var built = state.checks.filter(function (x) { return x.available; }).length;
352
374
  byId('builtText').textContent = built + ' / ' + state.checks.length;
353
375
  byId('builtBar').style.width = Math.round((built / state.checks.length) * 100) + '%';
354
- byId('builtNote').textContent = (state.checks.length - built) + ' more are listed as not available - never as passed.';
376
+ byId('builtNote').textContent = (state.checks.length - built) + ' more are coming soon - never shown as passed.';
355
377
  var name = state.project.name || 'Project';
356
378
  var last = (state.looks || [])[0];
357
379
  byId('subline').textContent = name + ' - ' + (last ? 'watching, last look ' + ago(last.at) : 'watching for changes');
@@ -845,7 +867,13 @@
845
867
  head.appendChild(icon(openRow === f.id ? 'change' : 'arrow', 18));
846
868
  head.addEventListener('click', function () { openRow = openRow === f.id ? null : f.id; renderFindings(); });
847
869
  card.appendChild(head);
848
- if (pending && pending.step === 'finding' && pending.finding && pending.finding.id === f.id) {
870
+ if (probeAsking && probeAsking.finding && probeAsking.finding.id === f.id) {
871
+ var askingProbe = el('div', 'controls f-quick');
872
+ askingProbe.appendChild(probeConsentBox(probeAsking.check, 'Yes, try it again', function (body) {
873
+ runJob('/api/recheck', Object.assign({ id: f.id }, body)).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
874
+ }, 'Re-check: replays this flow as recorded, then once more with the value that found this. Two runs.'));
875
+ card.appendChild(askingProbe);
876
+ } else if (pending && pending.step === 'finding' && pending.finding && pending.finding.id === f.id) {
849
877
  var asking = el('div', 'controls f-quick');
850
878
  asking.appendChild(consentBox('Yes, check it again', pending.words.consent));
851
879
  card.appendChild(asking);
@@ -920,14 +948,54 @@
920
948
  });
921
949
  }
922
950
 
923
- var STATE_TONE = { 'problems found': 'ember', 'things to check': 'amber', 'last run held': 'leaf', 'nothing found': 'leaf' };
951
+ var STATE_TONE = { 'problems found': 'ember', 'things to check': 'amber', 'last run held': 'leaf', 'nothing found': 'leaf', 'stopped part way': 'amber', 'nothing was tested': 'amber' };
952
+ var PROBE_LABEL = { edge: 'Try inputs - adds test data' };
953
+
954
+ // Which probe check is asking for a yes right now, and for which finding
955
+ // when it is a re-check. Nothing that adds data to the app runs without it.
956
+ var probeAsking = null;
957
+ function probeConsentBox(id, yesLabel, onYes, what) {
958
+ var check = state.checks.filter(function (c) { return c.id === id; })[0];
959
+ var asks = check && check.asks;
960
+ var box = el('div', 'consent');
961
+ box.appendChild(el('div', 'd-step', 'THIS ADDS TEST DATA TO YOUR APP'));
962
+ // The first line says what this press does; the rest - where, and what
963
+ // it leaves behind - is the same for the check and for a re-check.
964
+ var lines = ((asks && asks.lines) || []).slice();
965
+ if (what && lines.length) lines[0] = what;
966
+ box.appendChild(linesBox(asks && asks.live.length ? 'warn' : 'help', lines));
967
+ var tick = null;
968
+ if (asks && asks.live.length) {
969
+ var label = el('label', 'tick');
970
+ tick = el('input');
971
+ tick.type = 'checkbox';
972
+ label.appendChild(tick);
973
+ label.appendChild(document.createTextNode(' ' + asks.live.join(', ') + ' is my own test copy, not the live app real people use'));
974
+ box.appendChild(label);
975
+ }
976
+ var row = el('div', 'd-actions');
977
+ var yes = button('sun sm', 'check', yesLabel, function () {
978
+ if (tick && !tick.checked) { toast('Tick that it is your own test copy first - or run it against your app on this computer.'); return; }
979
+ var body = { consent: true, liveConfirmed: tick ? tick.checked : false };
980
+ probeAsking = null;
981
+ renderChecks();
982
+ renderFindings();
983
+ onYes(body);
984
+ });
985
+ yes.setAttribute('data-action', 'probe');
986
+ yes.disabled = busy;
987
+ row.appendChild(yes);
988
+ row.appendChild(button('sm', null, 'Cancel', function () { probeAsking = null; renderChecks(); renderFindings(); }));
989
+ box.appendChild(row);
990
+ return box;
991
+ }
924
992
  function checkSwitch(c) {
925
993
  var sw = el('label', 'switch');
926
994
  var input = el('input');
927
995
  input.type = 'checkbox';
928
996
  input.checked = !!c.enabled;
929
997
  input.disabled = !c.available;
930
- input.setAttribute('aria-label', c.label + (c.available ? '' : ' - not available'));
998
+ input.setAttribute('aria-label', c.label + (c.available ? '' : ' - coming soon'));
931
999
  input.addEventListener('change', function () { setCheck(c.id, input.checked, input); });
932
1000
  sw.appendChild(input);
933
1001
  sw.appendChild(el('span', 'track'));
@@ -945,7 +1013,7 @@
945
1013
  var row = el('div', 'na');
946
1014
  row.appendChild(checkSwitch(c));
947
1015
  var nm = el('div', null, c.label);
948
- nm.appendChild(el('span', 'na-lock', 'NOT AVAILABLE'));
1016
+ nm.appendChild(el('span', 'na-lock', 'COMING SOON'));
949
1017
  row.appendChild(nm);
950
1018
  na.appendChild(row);
951
1019
  return;
@@ -962,7 +1030,27 @@
962
1030
  // What the nightly run inside the database last said - its own answer,
963
1031
  // not this terminal's, so it gets its own line.
964
1032
  if (c.nightly) card.appendChild(el('div', 'c-what', c.nightly));
965
- if (c.runnable && c.enabled) {
1033
+ if (c.lastRun) {
1034
+ var lr = c.lastRun;
1035
+ card.appendChild(el('div', 'c-what', 'Last pressed ' + ago(lr.at) + ': ' + lr.runsDone + ' of ' + lr.runsPlanned + ' runs' +
1036
+ (lr.stopped ? ' (stopped)' : '') + ', ' + lr.held + ' held, ' + lr.notTested + ' not tested, ' +
1037
+ plural(lr.testData, 'test write') + ' left in your app.'));
1038
+ }
1039
+ if (c.asks && c.enabled) {
1040
+ if (probeAsking && probeAsking.check === c.id && !probeAsking.finding) {
1041
+ card.appendChild(probeConsentBox(c.id, 'Yes, add test data and run', function (body) {
1042
+ runJob('/api/probe', Object.assign({ id: c.id }, body)).then(function (done) {
1043
+ var r = (done && done.result) || {};
1044
+ toast(r.ok ? 'Finished: ' + (r.summary || 'done') : 'It could not finish' + (r.why ? ' - ' + r.why : ''));
1045
+ }, function () {});
1046
+ }));
1047
+ } else {
1048
+ var tryIt = button('sm', 'play', PROBE_LABEL[c.id] || 'Run it', function () { probeAsking = { check: c.id }; renderChecks(); });
1049
+ tryIt.setAttribute('data-action', 'probe');
1050
+ tryIt.disabled = busy;
1051
+ card.appendChild(withCommand(tryIt, 'npx kryptheon ' + c.id));
1052
+ }
1053
+ } else if (c.runnable && c.enabled) {
966
1054
  var run = button('sm', 'play', 'Run now', function () { runChecks([c.id], run); });
967
1055
  run.setAttribute('data-action', 'run');
968
1056
  run.disabled = busy;
@@ -1030,6 +1118,9 @@
1030
1118
  // A database finding is re-checked in the database: the same check, the
1031
1119
  // same yes first, then this one finding judged.
1032
1120
  if (f.check === 'data') { prepare('recheck', 'finding', f); return; }
1121
+ // An input finding is re-checked by typing its value again, which adds
1122
+ // test data to the app: the same yes as the check's own button, first.
1123
+ if (f.check === 'edge') { probeAsking = { check: 'edge', finding: f }; openRow = null; renderFindings(); return; }
1033
1124
  runJob('/api/recheck', { id: f.id }).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
1034
1125
  }
1035
1126
  function heard(f, r) {
@@ -1212,6 +1303,6 @@
1212
1303
  // while a yes is being asked for, and not while someone is typing.
1213
1304
  setInterval(function () {
1214
1305
  var typing = document.activeElement === dbInput || document.activeElement === recordInput;
1215
- if (!busy && !openRow && !pending && !typing) load();
1306
+ if (!busy && !openRow && !pending && !probeAsking && !typing) load();
1216
1307
  }, 5000);
1217
1308
  })();
@@ -302,6 +302,12 @@
302
302
  .controls pre.help { color: var(--on-light); background: rgba(18, 22, 29, 0.05); border-left: 2px solid var(--on-light); }
303
303
  .controls pre.warn { color: var(--orange-deep); background: rgba(255, 77, 0, 0.06); border-left: 2px solid var(--orange); }
304
304
  .consent { display: grid; gap: 10px; }
305
+ .check .consent { margin-top: 12px; }
306
+ .consent pre { margin: 0; padding: 14px 16px; font: 12px/1.65 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
307
+ .consent pre.help { color: var(--on-light); background: rgba(18, 22, 29, 0.05); border-left: 2px solid var(--on-light); }
308
+ .consent pre.warn { color: var(--orange-deep); background: rgba(255, 77, 0, 0.06); border-left: 2px solid var(--orange); }
309
+ .consent .tick { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
310
+ .consent .tick input { margin-top: 3px; }
305
311
  .act { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; }
306
312
  .act .btn, .step .act .btn { margin-top: 0; }
307
313
  .step .act { margin-top: 14px; }
@@ -419,7 +425,7 @@
419
425
  <section class="view" id="view-checks" hidden>
420
426
  <div class="check-grid" id="checkList"></div>
421
427
  <div class="card gap">
422
- <div class="card-head"><div><h3>Not built yet</h3><div class="c-sub">Listed so you know they exist - never shown as passed</div></div><span class="badge" id="naBadge">0</span></div>
428
+ <div class="card-head"><div><h3>Coming soon</h3><div class="c-sub">Being built, in this order - never shown as passed</div></div><span class="badge" id="naBadge">0</span></div>
423
429
  <div class="na-grid" id="naList"></div>
424
430
  </div>
425
431
  </section>