@nac3/runtime 2.5.2 → 2.8.0

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.
package/dist/cli-url.mjs CHANGED
@@ -69,7 +69,7 @@ async function resolveChromium() {
69
69
  registering manifests changes between calls -- and a validator whose
70
70
  findings depend on when it looked is not measuring the page. */
71
71
 
72
- function pageObservation() {
72
+ export function pageObservation() {
73
73
  /* Runs INSIDE the page. Must be self-contained: no closures over
74
74
  anything in this file. */
75
75
  const N = window.NAC;
@@ -108,12 +108,27 @@ function pageObservation() {
108
108
  plugin_slug: m.plugin_slug || null,
109
109
  element_count: Array.isArray(m.elements) ? m.elements.length : null,
110
110
  groups: { tabs: groupLen('tabs'), fields: groupLen('fields'), actions: groupLen('actions') },
111
- /* "Carries HMAC-signed manifests": the only thing a validator
112
- without the tenant secret can see is whether a provenance
111
+ /* "Carries HMAC-signed manifests": a validator holds no tenant
112
+ secret, so what it can see on its own is whether a provenance
113
113
  block is there at all. */
114
114
  provenance_block: !!(m.provenance || m.signature
115
115
  || (m.source && m.source.signature)
116
116
  || (m.provenance_source && m.provenance_source.signature)),
117
+ /* 2.7.0 (audit N-36, closed): and now what the RUNTIME could
118
+ tell. register() verifies a signature against the tenant
119
+ secret the host registered and records the answer, so the page
120
+ can say "I verified this" instead of leaving a tool to guess.
121
+ true = verified, false = present and WRONG, null = nobody
122
+ could tell (no secret on the page), which is not a synonym for
123
+ false and is reported as unverified. */
124
+ provenance_verified: (typeof N.manifest_provenance === 'function'
125
+ && m.plugin_slug)
126
+ ? ((N.manifest_provenance(m.plugin_slug) || {}).verified)
127
+ : undefined,
128
+ provenance_reason: (typeof N.manifest_provenance === 'function'
129
+ && m.plugin_slug)
130
+ ? ((N.manifest_provenance(m.plugin_slug) || {}).reason || null)
131
+ : null,
117
132
  labels: labelMaps(m),
118
133
  };
119
134
  });
@@ -155,6 +170,33 @@ function pageObservation() {
155
170
  });
156
171
 
157
172
  const g = N.validate_global();
173
+ /* 2.7.0: section 8 keys two different requirements on two different
174
+ calls -- level 2 wants {probe: false} and level 3 wants
175
+ {probe: true} -- so the validator makes BOTH instead of making one
176
+ and reporting it twice. A page serving a runtime older than 2.7.0
177
+ ignores the argument; `probed` is the runtime's own echo of it, and
178
+ it is what tells the decider whether the deeper call happened or
179
+ whether it is looking at the same report with a stricter
180
+ threshold. Neither call mutates the page. */
181
+ let gp = g;
182
+ let probeSupported = false;
183
+ try {
184
+ gp = N.validate_global({ probe: true }) || g;
185
+ probeSupported = gp.probed === true;
186
+ } catch (_) { gp = g; probeSupported = false; }
187
+ const flatten = function (report, buckets) {
188
+ return buckets.reduce(function (acc, b) {
189
+ (report[b] || []).forEach(function (f) {
190
+ acc.push({
191
+ bucket: b,
192
+ code: f.code || null,
193
+ severity: f.severity || 'unknown',
194
+ nac_id: f.nac_id || null,
195
+ });
196
+ });
197
+ return acc;
198
+ }, []);
199
+ };
158
200
 
159
201
  return {
160
202
  nac: true,
@@ -175,24 +217,27 @@ function pageObservation() {
175
217
  disagree about. `tolerated` is reported and NOT counted: the
176
218
  host registered it as tracked debt, which is a different claim
177
219
  than "clean". */
178
- findings: ['duplicates', 'orphans', 'unmounted', 'convention_violations',
179
- 'plugin_instance_violations'].reduce(function (acc, b) {
180
- (g[b] || []).forEach(function (f) {
181
- /* severity 'unknown' rather than a guess: a runtime older than
182
- 2.5.0 attaches neither code nor severity to any bucket item
183
- (audit N-14), and defaulting those to 'error' would make the
184
- validator invent a severity the page never stated. Unknown
185
- counts as failing -- fail closed -- and the report says why
186
- instead of printing a number it made up. */
187
- acc.push({
188
- bucket: b,
189
- code: f.code || null,
190
- severity: f.severity || 'unknown',
191
- nac_id: f.nac_id || null,
192
- });
193
- });
194
- return acc;
195
- }, []),
220
+ /* severity 'unknown' rather than a guess: a runtime older than
221
+ 2.5.0 attaches neither code nor severity to any bucket item
222
+ (audit N-14), and defaulting those to 'error' would make the
223
+ validator invent a severity the page never stated. Unknown
224
+ counts as failing -- fail closed -- and the report says why
225
+ instead of printing a number it made up. */
226
+ findings: flatten(g, ['duplicates', 'orphans', 'unmounted',
227
+ 'convention_violations', 'plugin_instance_violations']),
228
+ /* The probed report, with the two buckets only a probe fills. */
229
+ findings_probed: flatten(gp, ['duplicates', 'orphans', 'unmounted',
230
+ 'convention_violations', 'plugin_instance_violations',
231
+ 'ambiguous', 'unreachable']),
232
+ /* 2.7.0: `gated` is deliberately NOT in the list above. An element
233
+ that declares what opens it (undrivable_until) is keeping the
234
+ contract, so counting it as a finding would make the honest
235
+ declaration cost a conformance level -- which is the opposite of
236
+ the incentive this field exists to create. It is counted
237
+ separately so the report can SAY how many there are instead of
238
+ staying silent about a surface an agent has to open first. */
239
+ gated_count: ((gp && gp.gated) || []).length,
240
+ probe_supported: probeSupported,
196
241
  tolerated_count: (g.tolerated || []).length,
197
242
  };
198
243
  }
@@ -305,7 +350,18 @@ function pass(detail) { return { verdict: 'pass', detail }; }
305
350
  function failV(detail) { return { verdict: 'fail', detail }; }
306
351
  function unverified(detail) { return { verdict: 'unverified', detail }; }
307
352
 
308
- const DECIDERS = {
353
+ /* EXPORTED, 2026-11-27 (PLAN_LUNES / PND-141): the harness mode of
354
+ runtime/src/cli-harness.mjs decides the same eleven requirements
355
+ over a page mounted in Node instead of one loaded in a browser, and
356
+ it does it with THESE deciders and THIS observer -- not with copies.
357
+
358
+ That is the whole point of the third mode: between "read the files"
359
+ and "drive a browser" there was a missing rung, and a rung that
360
+ carried its own decider table would be a second opinion about what
361
+ the contract says. One table, two observers. The observer below is
362
+ already written to be self-contained (it runs inside the page), so
363
+ the harness can run the same function text inside its sandbox. */
364
+ export const DECIDERS = {
309
365
  manifest_registered(ctx) {
310
366
  const n = ctx.obs.plugin_count;
311
367
  return n >= 1
@@ -313,25 +369,44 @@ const DECIDERS = {
313
369
  : failV('no manifest is registered (finding code no_manifest)');
314
370
  },
315
371
 
316
- manifest_declares_groups(ctx) {
317
- /* Read LITERALLY: the sentence names tabs[], fields[] and
318
- actions[]. That is the LEGACY manifest shape; section 4
319
- documents elements[] as the canonical one, so a page written the
320
- documented way fails this as worded. The validator does not
321
- rewrite the requirement to what it probably meant -- that is
322
- what the hash-keyed review in the sidecar is for, and the gap is
323
- audit N-37. */
372
+ manifest_declares_surface(ctx) {
373
+ /* 2.7.0. This decider was `manifest_declares_groups` and read the
374
+ sentence LITERALLY, which is what a validator owes a published
375
+ requirement: the sentence named tabs[] / fields[] / actions[],
376
+ the LEGACY manifest shape, so a page written the way section 4
377
+ documents -- elements[] with a role per entry -- failed it as
378
+ worded. It was not the validator's place to decide what the
379
+ sentence probably meant; it was the owner's to fix the sentence,
380
+ which is what the hash-keyed review in the sidecar exists to
381
+ force. The sentence now accepts EITHER shape (audit N-37,
382
+ closed), so this reads both, and what it still fails is the
383
+ condition the requirement is really about: a manifest that
384
+ declares neither, leaving the surface to be inferred. */
385
+ if (!ctx.obs.manifests.length) return failV('no manifest to read');
324
386
  const missing = [];
387
+ const byShape = { canonical: 0, legacy: 0, both: 0 };
325
388
  for (const m of ctx.obs.manifests) {
326
- const gaps = ['tabs', 'fields', 'actions'].filter((g) => !(m.groups[g] > 0));
327
- if (gaps.length) missing.push((m.plugin_slug || '(unnamed)') + ' lacks ' + gaps.join('/'));
389
+ const canonical = m.element_count > 0;
390
+ const legacy = ['tabs', 'fields', 'actions'].some((g) => m.groups[g] > 0);
391
+ if (canonical && legacy) byShape.both += 1;
392
+ else if (canonical) byShape.canonical += 1;
393
+ else if (legacy) byShape.legacy += 1;
394
+ else {
395
+ missing.push((m.plugin_slug || '(unnamed)')
396
+ + ' declares neither elements[] nor tabs[]/fields[]/actions[]');
397
+ }
328
398
  }
329
- if (!ctx.obs.manifests.length) return failV('no manifest to read');
330
- return missing.length === 0
331
- ? pass('every manifest declares tabs[], fields[] and actions[]')
332
- : failV(missing.length + ' of ' + ctx.obs.manifests.length + ' manifest(s) do not declare the three arrays: '
333
- + missing.slice(0, 4).join('; ') + (missing.length > 4 ? '; ...' : '')
334
- + ' -- note: these manifests use the canonical elements[] shape instead (audit N-37)');
399
+ if (missing.length) {
400
+ return failV(missing.length + ' of ' + ctx.obs.manifests.length
401
+ + ' manifest(s) declare no surface at all, so what an agent can address is left to be '
402
+ + 'inferred from the DOM: ' + missing.slice(0, 4).join('; ')
403
+ + (missing.length > 4 ? '; ...' : ''));
404
+ }
405
+ const shapes = [];
406
+ if (byShape.canonical) shapes.push(byShape.canonical + ' with elements[]');
407
+ if (byShape.legacy) shapes.push(byShape.legacy + ' with the legacy arrays');
408
+ if (byShape.both) shapes.push(byShape.both + ' with both');
409
+ return pass('every manifest declares its surface explicitly (' + shapes.join(', ') + ')');
335
410
  },
336
411
 
337
412
  label_i18n_covers_locales(ctx) {
@@ -371,16 +446,40 @@ const DECIDERS = {
371
446
  },
372
447
 
373
448
  validate_global_no_findings(ctx) {
374
- const n = ctx.obs.findings.length;
375
- /* The sentence asks for {probe: true}. validate_global() takes no
376
- arguments and never reads `probe`, although SPEC.md 10.1
377
- publishes the option -- audit N-35. So this is the level-2 check
378
- with a stricter threshold, not the deeper probing the sentence
379
- implies, and the report says so rather than quietly passing. */
380
- const caveat = ' -- note: the runtime ignores the {probe: true} this requirement asks for (audit N-35), so this is the same call with a stricter threshold';
449
+ /* 2.7.0 (audit N-35, closed). The sentence asks for {probe: true}.
450
+ Until 2.7.0 validate_global() took no arguments and never read
451
+ `probe` although SPEC.md 10.1 published the option, so this was
452
+ the level-2 check with a stricter threshold and the report had
453
+ to SAY so rather than quietly pass. Runtimes from 2.7.0 on honour
454
+ it, and the validator reads the probed report -- two buckets
455
+ deeper -- when the page's own runtime says it probed. The caveat
456
+ survives for exactly the case it was written for: a page serving
457
+ an older runtime, where the deeper call is still being ignored. */
458
+ const probed = !!ctx.obs.probe_supported;
459
+ const findings = probed
460
+ ? (ctx.obs.findings_probed || ctx.obs.findings)
461
+ : ctx.obs.findings;
462
+ const n = findings.length;
463
+ const caveat = probed
464
+ ? ''
465
+ : ' -- note: the runtime on this page ignores the {probe: true} this requirement asks for'
466
+ + ' (audit N-35, fixed in 2.7.0), so this is the level-2 call with a stricter threshold'
467
+ + ' rather than the deeper inspection the sentence implies';
468
+ const gated = ctx.obs.gated_count || 0;
469
+ const gatedNote = gated
470
+ ? '; ' + gated + ' declared-and-gated element(s) were reported outside the '
471
+ + 'findings, each naming the id that opens it'
472
+ : '';
473
+ const deeper = probed
474
+ ? ' (probed: the ambiguous and unreachable buckets were asked for too'
475
+ + gatedNote + ')'
476
+ : '';
381
477
  return n === 0
382
- ? pass('validate_global reports 0 findings of any severity' + caveat)
383
- : failV(n + ' finding(s) of some severity' + caveat);
478
+ ? pass('validate_global reports 0 findings of any severity' + deeper + caveat)
479
+ : failV(n + ' finding(s) of some severity' + deeper + ': '
480
+ + findings.slice(0, 4).map((f) => (f.code || f.bucket)
481
+ + (f.nac_id ? '(' + f.nac_id + ')' : '')).join(', ')
482
+ + (n > 4 ? ', ...' : '') + caveat);
384
483
  },
385
484
 
386
485
  manifest_hmac_block_present(ctx) {
@@ -389,13 +488,34 @@ const DECIDERS = {
389
488
  if (withBlock.length === 0) {
390
489
  return failV('no registered manifest carries a provenance block, so none can be HMAC-signed');
391
490
  }
392
- /* Present, and that is as far as any tool gets. The validator has
393
- no tenant secret, and the runtime exposes no manifest
394
- verification to ask -- sign_provenance / verify_provenance cover
395
- an event's detail.source, never a manifest (audit N-36). */
491
+ /* 2.7.0: until this release the answer stopped here -- block
492
+ present, authenticity unknowable, so this requirement could
493
+ never pass and no tool could assert level 3 (audit N-36). The
494
+ runtime verifies manifests now and records what it could tell,
495
+ so the three answers are separable. */
496
+ const refused = withBlock.filter((m) => m.provenance_verified === false);
497
+ if (refused.length) {
498
+ return failV(refused.length + ' manifest(s) carry a provenance signature the runtime '
499
+ + 'REFUSED: it does not match the HMAC of the manifest body under any registered '
500
+ + 'tenant secret (SPEC.md sec 7.2)');
501
+ }
502
+ const verified = withBlock.filter((m) => m.provenance_verified === true);
503
+ if (verified.length === withBlock.length) {
504
+ return pass(verified.length + ' of ' + ctx.obs.manifests.length
505
+ + ' manifest(s) carry a provenance signature the runtime verified against the '
506
+ + "host's registered tenant secret");
507
+ }
508
+ if (verified.length) {
509
+ return unverified(verified.length + ' of ' + withBlock.length
510
+ + ' signed manifest(s) were verified by the runtime; the rest carry a block the page '
511
+ + 'cannot check because no tenant secret is registered for them');
512
+ }
513
+ /* The pre-2.7.0 answer, and still the right one for a page that
514
+ registers no secret: the block is there and nobody on the page
515
+ can say whether it is authentic. */
396
516
  return unverified(withBlock.length + ' of ' + ctx.obs.manifests.length
397
- + ' manifest(s) carry a provenance block, and no tool can confirm it is authentic: '
398
- + 'the validator holds no tenant secret and the runtime exposes no manifest verification (audit N-36)');
517
+ + ' manifest(s) carry a provenance block and no tenant secret is registered on the '
518
+ + 'page, so neither the runtime nor this validator can confirm it is authentic');
399
519
  },
400
520
 
401
521
  action_completion_events(ctx) {
@@ -406,34 +526,40 @@ const DECIDERS = {
406
526
  const driven = ctx.driveResults.filter((r) => ctx.actionIds.indexOf(r.id) >= 0);
407
527
  if (!driven.length) return failV('no data-nac-role="action" element is advertised, so the page fires nothing');
408
528
  const navigated = driven.filter((r) => r.navigated);
409
- /* A navigating anchor that emits nothing is NOT a measured failure.
410
- Its side effect is leaving the page, and nothing can emit a
411
- completion event after its own unload -- so the requirement as
412
- written has no outcome a tool can record for it either way. The
413
- validator says that, instead of counting it as a defect of the
414
- page or quietly as a pass. Audit N-38. */
529
+ /* 2.7.0 (audit N-38, closed). A navigating anchor that emits
530
+ nothing is not a defect of the page and never was: nothing can
531
+ emit a completion event after its own unload. Until 2.7.0 the
532
+ requirement had no exception, so the only honest verdict for a
533
+ page with links was `unverified` -- and 31 of the 39 actions of
534
+ this project's own landing are links, which is how a sentence
535
+ with a hole blocked level 1 for most of the web. The sentence
536
+ exempts navigation now, so a navigating action is EXEMPT rather
537
+ than unmeasurable.
538
+
539
+ What did not get relaxed, and is the line worth holding: an
540
+ exemption that measured nothing is not a pass. If not one action
541
+ emitted, the verdict stays unverified -- otherwise a page whose
542
+ every action is a link would collect this requirement for free,
543
+ which is the overreach the sidecar's honesty rule forbids. */
544
+ const emitted = driven.filter((r) => r.succeeded);
415
545
  const navSilent = driven.filter((r) => !r.succeeded && !r.navigated && r.nav_link);
416
546
  const silent = driven.filter((r) => !r.succeeded && !r.navigated && !r.nav_link);
547
+ const exempt = navSilent.length + navigated.length;
417
548
  if (silent.length) {
418
549
  return failV(silent.length + ' of ' + driven.length + ' scripted action(s) did not fire nac:action:succeeded: '
419
550
  + silent.slice(0, 4).map((r) => r.id).join(', ') + (silent.length > 4 ? ', ...' : ''));
420
551
  }
421
- if (navSilent.length) {
422
- return unverified((driven.length - navSilent.length - navigated.length) + ' of ' + driven.length
423
- + ' action(s) fired nac:action:succeeded. The other ' + navSilent.length
424
- + ' are plain links whose side effect is a navigation, and no element can emit a completion'
425
- + ' event after its own unload, so this requirement has no outcome a tool can record for them'
426
- + ' (audit N-38): ' + navSilent.slice(0, 4).map((r) => r.id).join(', ')
427
- + (navSilent.length > 4 ? ', ...' : ''));
552
+ if (exempt && !emitted.length) {
553
+ return unverified('all ' + driven.length + ' advertised action(s) are navigations, which '
554
+ + 'section 8 exempts from this requirement, so NOTHING was measured: an exemption is not '
555
+ + 'a measurement, and this page has no non-navigating action to decide it on');
428
556
  }
429
- if (navigated.length) {
430
- /* Not a pass. The event may well have fired; the page went away
431
- before anything could watch it, and "probably fired" is not a
432
- measurement. */
433
- return unverified((driven.length - navigated.length) + ' of ' + driven.length
434
- + ' action(s) fired nac:action:succeeded, and ' + navigated.length
435
- + ' navigated the page away before the event could be observed: '
436
- + navigated.slice(0, 4).map((r) => r.id).join(', ') + (navigated.length > 4 ? ', ...' : ''));
557
+ if (exempt) {
558
+ return pass(emitted.length + ' of ' + driven.length
559
+ + ' advertised action(s) fired nac:action:succeeded; the other ' + exempt
560
+ + ' navigate, which section 8 exempts because nothing survives an unload to emit it: '
561
+ + navSilent.concat(navigated).slice(0, 4).map((r) => r.id).join(', ')
562
+ + (exempt > 4 ? ', ...' : ''));
437
563
  }
438
564
  return pass('all ' + driven.length + ' advertised action(s) fired nac:action:succeeded');
439
565
  },
@@ -472,11 +598,33 @@ const DECIDERS = {
472
598
  + bad.slice(0, 4).map((r) => r.id + ' -> ' + r.click_error).join(', ')
473
599
  + (bad.length > 4 ? ', ...' : '') + '; ' + scope);
474
600
  }
475
- if (navTimeout.length) {
601
+ /* 2.7.0 (audit N-38, closed). This used to stop at `unverified`
602
+ for a plain link, and the comment above already said why that
603
+ was uncomfortable: the click LANDED -- the element would have
604
+ navigated, and the validator cancelled the navigation on purpose
605
+ so the page would survive to be measured -- and it timed out
606
+ only waiting for a completion event. Section 8 exempts that
607
+ event for a navigation now, so the timeout stops being a hole
608
+ and becomes an exemption, and a page with links can reach level
609
+ 1 at all. Without this the sentence would be fixed in one
610
+ requirement and still blocking in the next one, which is how
611
+ PND-047 described the damage: "the level 1 of ANY page with
612
+ links cannot be asserted".
613
+
614
+ Same line as the completion decider, and for the same reason: if
615
+ NOT ONE click produced an observable landing, nothing was
616
+ measured and the verdict stays unverified. */
617
+ const observed = ctx.driveResults.filter((r) => !r.click_error);
618
+ if (navTimeout.length && !observed.length) {
476
619
  return unverified('every advertised id resolves, and ' + scope
477
- + '. ' + navTimeout.length + ' of the clicks timed out waiting for a completion event because'
478
- + ' the element is a plain link: the click landed, and nothing can report it after unload'
479
- + ' (audit N-38)');
620
+ + '. Every click measured was a plain link whose completion section 8 exempts, so NOTHING'
621
+ + ' was observed landing: an exemption is not a measurement');
622
+ }
623
+ if (navTimeout.length) {
624
+ return pass('every advertised id resolves, and ' + scope
625
+ + '. ' + navTimeout.length + ' of the clicks are plain links: the click landed and the'
626
+ + ' completion event is the one section 8 exempts, because nothing survives an unload to'
627
+ + ' report it (audit N-38)');
480
628
  }
481
629
  return pass('every advertised id resolves, and ' + scope);
482
630
  },
@@ -486,7 +634,7 @@ export const IMPLEMENTED_DECIDERS = Object.keys(DECIDERS).sort();
486
634
 
487
635
  /* ---- the report ------------------------------------------------------ */
488
636
 
489
- function decideAll(levels, ctx) {
637
+ export function decideAll(levels, ctx) {
490
638
  const out = [];
491
639
  for (const lv of levels.levels) {
492
640
  for (const r of lv.requirements) {
@@ -525,7 +673,7 @@ function decideAll(levels, ctx) {
525
673
  lets a report say "level 1" without saying that three of its four
526
674
  requirements were never measured. A level is a measurement, not a
527
675
  certificate. */
528
- function reportLevel(levels, verdicts) {
676
+ export function reportLevel(levels, verdicts) {
529
677
  let reached = null;
530
678
  for (const lv of levels.levels) {
531
679
  const upto = verdicts.filter((v) => v.level <= lv.level && v.machine_checkable);
@@ -740,6 +888,12 @@ export async function validateUrl(url, opts = {}) {
740
888
  declared_ids: obs.total_ids,
741
889
  dom_ids: obs.dom_ids,
742
890
  findings: obs.findings,
891
+ /* 2.7.0: the probed report travels too, so a consumer of --json can
892
+ see what the deeper call found without having to drive the page
893
+ again. Equal to `findings` on a page whose runtime predates the
894
+ probe, and `probe_supported` says which of the two it is. */
895
+ findings_probed: obs.findings_probed || obs.findings,
896
+ probe_supported: !!obs.probe_supported,
743
897
  tolerated_count: obs.tolerated_count,
744
898
  console_errors: consoleErrors,
745
899
  drive,