@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/CHANGELOG.md +928 -0
- package/NOTICE +15 -0
- package/README.md +110 -3
- package/SPEC.md +1590 -25
- package/contract-head.json +4 -4
- package/dist/cli-harness.mjs +468 -0
- package/dist/cli-levels.json +56 -15
- package/dist/cli-lint.mjs +718 -24
- package/dist/cli-url.mjs +234 -80
- package/dist/cli.js +317 -12
- package/dist/dom-harness.mjs +578 -0
- package/dist/nac-chat-client.browser.js +47 -6
- package/dist/nac-chat-client.cjs +47 -6
- package/dist/nac-chat-client.mjs +47 -6
- package/dist/nac-v2-extensions.browser.js +359 -18
- package/dist/nac-v2-extensions.cjs +359 -18
- package/dist/nac-v2-extensions.d.ts +1 -1
- package/dist/nac-v2-extensions.mjs +359 -18
- package/dist/nac.browser.js +2482 -88
- package/dist/nac.cjs +2482 -88
- package/dist/nac.d.ts +131 -2
- package/dist/nac.mjs +2482 -88
- package/package.json +30 -3
package/contract-head.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"api_schema": 1,
|
|
3
|
-
"chain_head": "sha384-
|
|
4
|
-
"entry_count":
|
|
3
|
+
"chain_head": "sha384-SXMXI/DYUS5hH9TiPBTSmHxsUcGz+KUtzVGbXTTZR+aatm+ZKdj1vDD2+/8HNab8",
|
|
4
|
+
"entry_count": 8,
|
|
5
5
|
"generated_by": "scripts/build-contract-api.mjs",
|
|
6
6
|
"note": "The third of three independent witnesses of the contract chain head (audit N-24). This copy is immutable once published: npm does not allow a version to be republished, so a host that rewrites the chain cannot reach back and change it. If this head disagrees with the one the host serves for this version, do not trust the host. Present from 2.5.0 onward; earlier releases were published before this API existed.",
|
|
7
7
|
"protocol": "NAC3",
|
|
8
|
-
"published_at": "2026-
|
|
9
|
-
"runtime_version": "2.
|
|
8
|
+
"published_at": "2026-11-25",
|
|
9
|
+
"runtime_version": "2.8.0",
|
|
10
10
|
"surface": "contract-head-witness",
|
|
11
11
|
"witnesses": {
|
|
12
12
|
"host": "api/index.json served by the web host (chain_head)",
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/* =====================================================================
|
|
2
|
+
cli-harness.mjs -- the THIRD mode of `nac validate`: decide what is
|
|
3
|
+
decidable by MOUNTING the page in Node, and declare the rest with
|
|
4
|
+
its reason.
|
|
5
|
+
|
|
6
|
+
WHY IT EXISTS. The CLI had two modes and the gap between them was
|
|
7
|
+
the size of this file. Pointed at a URL it loads a browser and
|
|
8
|
+
reports a conformance level; pointed at a directory it reads files
|
|
9
|
+
and answers `NOT DECIDABLE IN THIS MODE`. That second answer
|
|
10
|
+
reasons correctly and concludes too much:
|
|
11
|
+
|
|
12
|
+
"a static lint reads files; every requirement of section 8 is
|
|
13
|
+
about what the runtime registered and what the page does"
|
|
14
|
+
|
|
15
|
+
True, and between "read the files" and "drive Chromium" there is a
|
|
16
|
+
rung this project already built twenty times: the runtime loaded in
|
|
17
|
+
Node over a synthesised document, which is how 18 of its suites
|
|
18
|
+
work. A requirement like "NAC.click(id) works for every advertised
|
|
19
|
+
id" does not need Chrome to be PARTLY decided -- it needs the
|
|
20
|
+
runtime, a registered manifest and a document that answers.
|
|
21
|
+
|
|
22
|
+
WHAT THIS MODE DOES, and the honest shape of it:
|
|
23
|
+
1. parses the page's markup into the synthesised document;
|
|
24
|
+
2. loads the runtime (the real one, ours, not the adopter's);
|
|
25
|
+
3. RUNS THE PAGE'S OWN SCRIPTS in that sandbox, because the
|
|
26
|
+
manifest is something the page declares and most pages build it
|
|
27
|
+
with their own helpers -- reading the literal would work for
|
|
28
|
+
the simple ones and silently miss the rest;
|
|
29
|
+
4. asks the runtime the same questions the browser mode asks, with
|
|
30
|
+
the SAME observer and the SAME decider table (exported from
|
|
31
|
+
cli-url.mjs), so the two modes cannot form two opinions about
|
|
32
|
+
what the contract says;
|
|
33
|
+
5. reports, per requirement, DECIDED (pass / fail) or
|
|
34
|
+
NOT-DECIDABLE with the reason it is not.
|
|
35
|
+
|
|
36
|
+
AND WHAT IT REFUSES TO CLAIM, which is the part worth reading. Of
|
|
37
|
+
the eleven requirements of section 8, this mode decides FIVE --
|
|
38
|
+
measured, not estimated: the first draft of this comment said six.
|
|
39
|
+
The other six are declared, one by one, and the published contract is
|
|
40
|
+
what classifies them rather than a list typed here: `check: "human"`
|
|
41
|
+
is a judgement no tool makes, `check: "behavioural"` needs the page
|
|
42
|
+
DRIVEN, and one requirement that the contract calls static is
|
|
43
|
+
declared undecidable HERE for a reason that belongs to this mode --
|
|
44
|
+
`validate_global({probe: true})` asks the document whether an
|
|
45
|
+
element is reachable, and a synthesised document answers whatever
|
|
46
|
+
its stub decides, not what a browser would.
|
|
47
|
+
|
|
48
|
+
A mode that decided eleven of eleven would be lying about at least
|
|
49
|
+
one, and the one it would lie about is `isTrusted`: in a synthesised
|
|
50
|
+
document the fixture writes that flag, so a harness can only ever
|
|
51
|
+
check that the code LOOKS at it.
|
|
52
|
+
|
|
53
|
+
IT EXECUTES THE PAGE. Said plainly because an adopter has to know:
|
|
54
|
+
this mode runs the page's inline scripts, and its local
|
|
55
|
+
`<script src="...">` files, inside a Node sandbox with no network
|
|
56
|
+
and no storage beyond a stub. The static mode (`nac validate <dir>`
|
|
57
|
+
with no flag) still touches nothing and still reads only bytes --
|
|
58
|
+
that mode's promise is not weakened by this one existing.
|
|
59
|
+
|
|
60
|
+
ASCII only.
|
|
61
|
+
===================================================================== */
|
|
62
|
+
|
|
63
|
+
import fs from 'node:fs';
|
|
64
|
+
import path from 'node:path';
|
|
65
|
+
import vm from 'node:vm';
|
|
66
|
+
import { loadLevels, DECIDERS, pageObservation, reportLevel } from './cli-url.mjs';
|
|
67
|
+
|
|
68
|
+
const HERE = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'));
|
|
69
|
+
|
|
70
|
+
/* ------------------------------------------------------------------ */
|
|
71
|
+
/* where the pieces live, in a checkout and in an installed package */
|
|
72
|
+
/* ------------------------------------------------------------------ */
|
|
73
|
+
|
|
74
|
+
/* The DOM is the one the battery uses, published as dist/dom-harness.mjs
|
|
75
|
+
by runtime/build.mjs. ONE implementation with two consumers -- the
|
|
76
|
+
suites read it from test/lib/, this reads the published copy -- and
|
|
77
|
+
never a second stub written for this file, which is the shape of
|
|
78
|
+
duplication this release spent its length removing. */
|
|
79
|
+
function resolveHarnessModule() {
|
|
80
|
+
const candidates = [
|
|
81
|
+
path.join(HERE, '..', 'dist', 'dom-harness.mjs'), /* installed package */
|
|
82
|
+
path.join(HERE, 'dom-harness.mjs'), /* a checkout, running from src/ */
|
|
83
|
+
];
|
|
84
|
+
for (const c of candidates) if (fs.existsSync(c)) return c;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* The runtime SOURCE to mount: js/nac.js in a checkout (authoritative),
|
|
89
|
+
dist/nac.cjs in an installed package (what the adopter actually got). */
|
|
90
|
+
function resolveRuntimeSource() {
|
|
91
|
+
const candidates = [
|
|
92
|
+
path.join(HERE, '..', '..', 'js', 'nac.js'),
|
|
93
|
+
path.join(HERE, '..', 'dist', 'nac.cjs'),
|
|
94
|
+
path.join(HERE, '..', 'dist', 'nac.browser.js'),
|
|
95
|
+
];
|
|
96
|
+
for (const c of candidates) if (fs.existsSync(c)) return c;
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* ------------------------------------------------------------------ */
|
|
101
|
+
/* the page: which one, and what it is made of */
|
|
102
|
+
/* ------------------------------------------------------------------ */
|
|
103
|
+
|
|
104
|
+
/* A conformance level is a property of a PAGE, not of a directory, so
|
|
105
|
+
this mode decides one page per run and SAYS which. Pointed at a
|
|
106
|
+
directory it takes index.html; with no index and more than one
|
|
107
|
+
candidate it refuses and lists them, rather than picking one and
|
|
108
|
+
reporting a level the reader did not ask for. */
|
|
109
|
+
export function choosePage(target) {
|
|
110
|
+
const st = fs.existsSync(target) ? fs.statSync(target) : null;
|
|
111
|
+
if (!st) return { error: 'not found: ' + target };
|
|
112
|
+
if (st.isFile()) return { page: target };
|
|
113
|
+
const here = fs.readdirSync(target)
|
|
114
|
+
.filter((f) => /\.(html?|php)$/i.test(f))
|
|
115
|
+
.sort();
|
|
116
|
+
if (!here.length) {
|
|
117
|
+
return { error: 'no page to mount under ' + target
|
|
118
|
+
+ ': this mode needs an .html / .htm / .php file, and found none. '
|
|
119
|
+
+ 'The static mode (no --harness) reads every markup extension instead.' };
|
|
120
|
+
}
|
|
121
|
+
const index = here.filter((f) => /^index\./i.test(f))[0];
|
|
122
|
+
if (index) return { page: path.join(target, index) };
|
|
123
|
+
if (here.length === 1) return { page: path.join(target, here[0]) };
|
|
124
|
+
return { error: 'more than one page under ' + target + ' and no index: '
|
|
125
|
+
+ here.slice(0, 8).join(', ') + (here.length > 8 ? ', ...' : '')
|
|
126
|
+
+ '. A conformance level belongs to ONE page, so name the file: '
|
|
127
|
+
+ 'nac validate ' + path.join(target, here[0]) + ' --harness' };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ---- a small HTML reader ------------------------------------------
|
|
131
|
+
Enough to build the tree the runtime resolves against: elements,
|
|
132
|
+
attributes, text and the script blocks. NOT a browser parser, and it
|
|
133
|
+
says so where it matters -- it does not fix malformed nesting, it
|
|
134
|
+
ignores namespaces, and it treats every unknown tag as an element.
|
|
135
|
+
The alternative was a dependency, and this package declares zero. */
|
|
136
|
+
const VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
137
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
138
|
+
const RAW_TAGS = new Set(['script', 'style', 'textarea', 'title']);
|
|
139
|
+
|
|
140
|
+
export function parseHtml(html) {
|
|
141
|
+
const root = { tag: '#root', attrs: {}, kids: [], text: '' };
|
|
142
|
+
const stack = [root];
|
|
143
|
+
const scripts = [];
|
|
144
|
+
let i = 0;
|
|
145
|
+
|
|
146
|
+
const top = () => stack[stack.length - 1];
|
|
147
|
+
|
|
148
|
+
while (i < html.length) {
|
|
149
|
+
const lt = html.indexOf('<', i);
|
|
150
|
+
if (lt < 0) {
|
|
151
|
+
const txt = html.slice(i);
|
|
152
|
+
if (txt.trim()) top().kids.push({ tag: '#text', text: txt, attrs: {}, kids: [] });
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (lt > i) {
|
|
156
|
+
const txt = html.slice(i, lt);
|
|
157
|
+
if (txt.trim()) top().kids.push({ tag: '#text', text: txt, attrs: {}, kids: [] });
|
|
158
|
+
}
|
|
159
|
+
/* comment / doctype / CDATA */
|
|
160
|
+
if (html.startsWith('<!--', lt)) {
|
|
161
|
+
const end = html.indexOf('-->', lt + 4);
|
|
162
|
+
i = end < 0 ? html.length : end + 3;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (html.startsWith('<!', lt)) {
|
|
166
|
+
const end = html.indexOf('>', lt);
|
|
167
|
+
i = end < 0 ? html.length : end + 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const gt = html.indexOf('>', lt);
|
|
171
|
+
if (gt < 0) break;
|
|
172
|
+
const inner = html.slice(lt + 1, gt);
|
|
173
|
+
if (inner.startsWith('/')) {
|
|
174
|
+
const name = inner.slice(1).trim().toLowerCase();
|
|
175
|
+
for (let k = stack.length - 1; k > 0; k--) {
|
|
176
|
+
if (stack[k].tag === name) { stack.length = k; break; }
|
|
177
|
+
}
|
|
178
|
+
i = gt + 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const m = /^([a-zA-Z][\w:-]*)([\s\S]*)$/.exec(inner);
|
|
182
|
+
if (!m) { i = gt + 1; continue; }
|
|
183
|
+
const tag = m[1].toLowerCase();
|
|
184
|
+
const attrs = {};
|
|
185
|
+
const attrRx = /([:@\w-]+)(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
186
|
+
let a;
|
|
187
|
+
const attrText = m[2].replace(/\/$/, '');
|
|
188
|
+
while ((a = attrRx.exec(attrText)) !== null) {
|
|
189
|
+
const key = a[1];
|
|
190
|
+
const val = a[3] !== undefined ? a[3] : (a[4] !== undefined ? a[4] : (a[5] !== undefined ? a[5] : ''));
|
|
191
|
+
attrs[key] = val;
|
|
192
|
+
}
|
|
193
|
+
const selfClosing = /\/\s*$/.test(m[2]) || VOID_TAGS.has(tag);
|
|
194
|
+
|
|
195
|
+
if (RAW_TAGS.has(tag)) {
|
|
196
|
+
const closeRx = new RegExp('</\\s*' + tag + '\\s*>', 'i');
|
|
197
|
+
const rest = html.slice(gt + 1);
|
|
198
|
+
const cm = closeRx.exec(rest);
|
|
199
|
+
const body = cm ? rest.slice(0, cm.index) : rest;
|
|
200
|
+
if (tag === 'script') {
|
|
201
|
+
scripts.push({ src: attrs.src || null, code: attrs.src ? '' : body, type: attrs.type || null });
|
|
202
|
+
} else {
|
|
203
|
+
const node = { tag, attrs, kids: [], text: body };
|
|
204
|
+
top().kids.push(node);
|
|
205
|
+
}
|
|
206
|
+
i = gt + 1 + (cm ? cm.index + cm[0].length : rest.length);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const node = { tag, attrs, kids: [], text: '' };
|
|
211
|
+
top().kids.push(node);
|
|
212
|
+
if (!selfClosing) stack.push(node);
|
|
213
|
+
i = gt + 1;
|
|
214
|
+
}
|
|
215
|
+
return { root, scripts };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* ------------------------------------------------------------------ */
|
|
219
|
+
/* the run */
|
|
220
|
+
/* ------------------------------------------------------------------ */
|
|
221
|
+
|
|
222
|
+
/* WHY THESE FIVE ARE NOT DECIDED HERE, each in its own words. Keyed by
|
|
223
|
+
the DECIDER name the published contract gives the requirement, not
|
|
224
|
+
by requirement id: an id is a hash of a sentence and changes when
|
|
225
|
+
the sentence is reworded, and this reason is about the MECHANISM. */
|
|
226
|
+
const NOT_DECIDABLE_HERE = {
|
|
227
|
+
action_completion_events:
|
|
228
|
+
'the completion event comes from the PAGE handler, and this mode does not click: '
|
|
229
|
+
+ 'it mounts the page and asks the runtime what it registered. Point the URL mode '
|
|
230
|
+
+ 'at it with --drive to decide this one.',
|
|
231
|
+
click_resolves_and_lands:
|
|
232
|
+
'resolution IS measured -- see the surface line of this report, and '
|
|
233
|
+
+ 'unresolved_advertised in --json -- but whether the click LANDS is the page own '
|
|
234
|
+
+ 'handler answering, and that needs the page driven (URL mode, --drive). An '
|
|
235
|
+
+ 'advertised id that resolves to nothing makes this requirement decidably FALSE, '
|
|
236
|
+
+ 'and this mode reports that case as a failure rather than as undecidable.',
|
|
237
|
+
validate_global_no_findings:
|
|
238
|
+
'the probe pass asks the DOCUMENT whether an element is reachable -- layout, visibility, '
|
|
239
|
+
+ 'geometry -- and a synthesised document answers whatever its stub decides, not what a '
|
|
240
|
+
+ 'browser would. Deciding this here would be measuring the stub. The published contract '
|
|
241
|
+
+ 'calls this requirement static because in a BROWSER no driving is needed; in Node it is '
|
|
242
|
+
+ 'not, and this mode says so rather than inheriting the word.',
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export function runHarness(target, opts) {
|
|
246
|
+
const o = opts || {};
|
|
247
|
+
const levels = loadLevels();
|
|
248
|
+
const chosen = o.page ? { page: o.page } : choosePage(target);
|
|
249
|
+
if (chosen.error) return { ok: false, error: chosen.error };
|
|
250
|
+
|
|
251
|
+
const harnessPath = resolveHarnessModule();
|
|
252
|
+
const runtimeSource = resolveRuntimeSource();
|
|
253
|
+
if (!harnessPath) {
|
|
254
|
+
return { ok: false, error: 'this build ships no dom-harness.mjs, so there is no document to '
|
|
255
|
+
+ 'mount the page in. Run `npm --prefix runtime run build`.' };
|
|
256
|
+
}
|
|
257
|
+
if (!runtimeSource) {
|
|
258
|
+
return { ok: false, error: 'cannot find a runtime to mount: looked for ../js/nac.js and '
|
|
259
|
+
+ 'dist/nac.cjs next to this file.' };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return { ok: true, pending: { page: chosen.page, harnessPath, runtimeSource, levels } };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* The mount + observe + decide, async because the harness module is
|
|
266
|
+
loaded dynamically (it is a sibling artefact, not a dependency). */
|
|
267
|
+
export async function harnessDecide(target, opts) {
|
|
268
|
+
const prep = runHarness(target, opts);
|
|
269
|
+
if (!prep.ok) return prep;
|
|
270
|
+
const { page, harnessPath, runtimeSource, levels } = prep.pending;
|
|
271
|
+
|
|
272
|
+
const html = fs.readFileSync(page, 'utf8');
|
|
273
|
+
const parsed = parseHtml(html);
|
|
274
|
+
|
|
275
|
+
const harness = await import('file://' + harnessPath.split(path.sep).join('/'));
|
|
276
|
+
const { loadRuntime, el } = harness;
|
|
277
|
+
|
|
278
|
+
/* The tree. Built from the parse, attribute by attribute: every
|
|
279
|
+
data-nac-* the page paints is what the runtime resolves against. */
|
|
280
|
+
function toFactory(node) {
|
|
281
|
+
if (node.tag === '#text') return null;
|
|
282
|
+
const kids = node.kids.map(toFactory).filter(Boolean);
|
|
283
|
+
const attrs = Object.assign({}, node.attrs);
|
|
284
|
+
if (node.text && node.text.trim()) attrs.text = node.text.trim().slice(0, 200);
|
|
285
|
+
return el(node.tag, attrs, kids);
|
|
286
|
+
}
|
|
287
|
+
const tree = parsed.root.kids.map(toFactory).filter(Boolean);
|
|
288
|
+
|
|
289
|
+
let h;
|
|
290
|
+
try {
|
|
291
|
+
h = loadRuntime({ tree, runtimeSource, href: 'file://' + page });
|
|
292
|
+
} catch (e) {
|
|
293
|
+
return { ok: false, error: 'the runtime did not load in the harness: ' + (e && e.message) };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* THE PAGE'S OWN SCRIPTS. A manifest is something the page declares,
|
|
297
|
+
and most pages build it with their own helpers -- reading the
|
|
298
|
+
literal would work for the simple ones and silently miss the rest,
|
|
299
|
+
which is the false green this project keeps finding. Each block is
|
|
300
|
+
run on its own and a failure is REPORTED, never swallowed: a
|
|
301
|
+
manifest that needs something only a browser has is exactly what
|
|
302
|
+
an adopter wants to hear from this mode. */
|
|
303
|
+
const scriptLog = [];
|
|
304
|
+
/* vm.createContext() contextifies the sandbox OBJECT and hands the
|
|
305
|
+
same object back, and loadRuntime builds its sandbox out of the
|
|
306
|
+
window it returns -- so the window IS the context handle. */
|
|
307
|
+
const sandbox = h.window;
|
|
308
|
+
const dir = path.dirname(page);
|
|
309
|
+
for (const s of parsed.scripts) {
|
|
310
|
+
if (s.type && !/javascript|module|^$/i.test(s.type)) {
|
|
311
|
+
scriptLog.push({ src: s.src, skipped: 'type="' + s.type + '" is not javascript' });
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
let code = s.code;
|
|
315
|
+
let label = 'inline';
|
|
316
|
+
if (s.src) {
|
|
317
|
+
/* Only what the tree itself serves: a remote script is not
|
|
318
|
+
fetched (this mode has no network, by design) and that is
|
|
319
|
+
reported rather than passed over. */
|
|
320
|
+
if (/^https?:|^\/\//i.test(s.src)) {
|
|
321
|
+
scriptLog.push({ src: s.src, skipped: 'remote script: this mode has no network' });
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const abs = path.resolve(dir, s.src.replace(/^\//, ''));
|
|
325
|
+
if (!fs.existsSync(abs)) {
|
|
326
|
+
scriptLog.push({ src: s.src, skipped: 'not found on disk at ' + abs });
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
/* The page loads the runtime, and so did this mode a moment ago.
|
|
330
|
+
Running it twice would install a SECOND NAC over the first and
|
|
331
|
+
throw away everything the first had registered -- which is not
|
|
332
|
+
a crash, it is a quieter thing: the report would be about the
|
|
333
|
+
second instance and nobody would know.
|
|
334
|
+
|
|
335
|
+
TWO belts, and both are load-bearing. The resolved path
|
|
336
|
+
catches the page loading the very file this mode mounted. The
|
|
337
|
+
NAME catches a different file called nac.js -- a vendored copy,
|
|
338
|
+
a bundle, a stub -- which is the only belt that can. That
|
|
339
|
+
second one matched the POSIX separator alone until 2026-11-27,
|
|
340
|
+
so on Windows it never fired and the impostor ran: measured,
|
|
341
|
+
it answered "N.manifest is not a function" because the second
|
|
342
|
+
script had replaced the NAC the page had just registered
|
|
343
|
+
against. Both separators now. Receipt: the three assertions
|
|
344
|
+
over fixtures/harness/vendored-runtime-name/ in
|
|
345
|
+
test/cli-harness.mjs. */
|
|
346
|
+
if (path.resolve(abs) === path.resolve(runtimeSource)
|
|
347
|
+
|| /(^|[\\\/])nac(\.browser)?\.js$/.test(abs)) {
|
|
348
|
+
scriptLog.push({ src: s.src, skipped: 'this IS the runtime, already mounted by this mode' });
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
code = fs.readFileSync(abs, 'utf8');
|
|
352
|
+
label = s.src;
|
|
353
|
+
}
|
|
354
|
+
if (!code || !code.trim()) continue;
|
|
355
|
+
try {
|
|
356
|
+
vm.runInContext(code, sandbox, { filename: label });
|
|
357
|
+
scriptLog.push({ src: label, ran: true });
|
|
358
|
+
} catch (e) {
|
|
359
|
+
scriptLog.push({ src: label, ran: false, error: String((e && e.message) || e).slice(0, 200) });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/* The observation: the SAME function the browser mode evaluates
|
|
364
|
+
inside the page, run inside this sandbox. Not a copy of it. */
|
|
365
|
+
let obs;
|
|
366
|
+
try {
|
|
367
|
+
obs = vm.runInContext('(' + pageObservation.toString() + ')()',
|
|
368
|
+
sandbox, { filename: 'pageObservation' });
|
|
369
|
+
} catch (e) {
|
|
370
|
+
return { ok: false, error: 'the observation failed inside the harness: ' + (e && e.message) };
|
|
371
|
+
}
|
|
372
|
+
if (!obs || obs.nac === false) {
|
|
373
|
+
return { ok: false, error: 'the runtime mounted and the page never registered anything this '
|
|
374
|
+
+ 'mode could observe', scripts: scriptLog };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* Resolution, measured before the verdicts because one of them
|
|
378
|
+
depends on it: an advertised id that resolves to NOTHING makes
|
|
379
|
+
"NAC.click(id) works for every advertised id" decidably false,
|
|
380
|
+
and refusing to decide a requirement that is already broken would
|
|
381
|
+
be hiding behind the honest half of this mode. The asymmetry is
|
|
382
|
+
the point -- a negative can be decided here, a positive cannot. */
|
|
383
|
+
const painted = obs.dom_id_list || [];
|
|
384
|
+
const unresolved = (obs.advertised || [])
|
|
385
|
+
.filter((a) => painted.indexOf(a.nac_id) < 0)
|
|
386
|
+
.map((a) => a.nac_id);
|
|
387
|
+
|
|
388
|
+
/* The decision: the published contract classifies, this mode decides
|
|
389
|
+
what it can and declares the rest. */
|
|
390
|
+
const verdicts = [];
|
|
391
|
+
for (const lv of levels.levels) {
|
|
392
|
+
for (const r of lv.requirements) {
|
|
393
|
+
let verdict = 'unverified';
|
|
394
|
+
let detail = null;
|
|
395
|
+
let decided_by = null;
|
|
396
|
+
if (!r.machine_checkable) {
|
|
397
|
+
detail = 'not decidable by a tool: ' + (r.note || 'this is a judgement, not a measurement');
|
|
398
|
+
} else if (r.decider === 'click_resolves_and_lands' && unresolved.length) {
|
|
399
|
+
verdict = 'fail';
|
|
400
|
+
decided_by = 'resolution (the negative half of ' + r.decider + ')';
|
|
401
|
+
detail = unresolved.length + ' advertised id(s) resolve to no element in this page: '
|
|
402
|
+
+ unresolved.slice(0, 5).join(', ') + (unresolved.length > 5 ? ', ...' : '')
|
|
403
|
+
+ '. A click cannot work on an id nothing paints, so this requirement is false '
|
|
404
|
+
+ 'without needing the page driven -- the POSITIVE still is not decidable here.';
|
|
405
|
+
} else if (NOT_DECIDABLE_HERE[r.decider]) {
|
|
406
|
+
detail = NOT_DECIDABLE_HERE[r.decider];
|
|
407
|
+
} else if (!DECIDERS[r.decider]) {
|
|
408
|
+
detail = 'this build implements no decider named "' + r.decider + '"';
|
|
409
|
+
} else {
|
|
410
|
+
const v = DECIDERS[r.decider]({ obs, levels });
|
|
411
|
+
verdict = v.verdict;
|
|
412
|
+
detail = v.detail;
|
|
413
|
+
decided_by = r.decider;
|
|
414
|
+
}
|
|
415
|
+
verdicts.push({
|
|
416
|
+
level: lv.level,
|
|
417
|
+
level_id: lv.id,
|
|
418
|
+
requirement_id: r.id,
|
|
419
|
+
text: r.text,
|
|
420
|
+
machine_checkable: r.machine_checkable,
|
|
421
|
+
check: r.check,
|
|
422
|
+
decider: r.decider,
|
|
423
|
+
verdict,
|
|
424
|
+
detail,
|
|
425
|
+
decided_by,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* PER LEVEL, which is the number a reader of this mode actually
|
|
431
|
+
needs. reportLevel() answers the published question -- "which
|
|
432
|
+
level may be reported" -- and its blocked_by lists every failing
|
|
433
|
+
requirement regardless of level, which is right for the browser
|
|
434
|
+
mode and confusing here: a reader asking why level 1 is not
|
|
435
|
+
asserted does not need to hear about a level 3 requirement. So
|
|
436
|
+
this breaks it down, and the shared function is left alone. */
|
|
437
|
+
const by_level = levels.levels.map((lv) => {
|
|
438
|
+
const mine = verdicts.filter((v) => v.level === lv.level);
|
|
439
|
+
return {
|
|
440
|
+
level: lv.level,
|
|
441
|
+
level_id: lv.id,
|
|
442
|
+
total: mine.length,
|
|
443
|
+
passed: mine.filter((v) => v.verdict === 'pass').map((v) => v.requirement_id),
|
|
444
|
+
failed: mine.filter((v) => v.verdict === 'fail').map((v) => v.requirement_id),
|
|
445
|
+
not_decidable: mine.filter((v) => v.verdict === 'unverified').map((v) => v.requirement_id),
|
|
446
|
+
};
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const level = reportLevel(levels, verdicts);
|
|
450
|
+
return {
|
|
451
|
+
ok: true,
|
|
452
|
+
mode: 'harness',
|
|
453
|
+
page: page,
|
|
454
|
+
runtime_source: runtimeSource,
|
|
455
|
+
runtime_version: obs.version || null,
|
|
456
|
+
spec_version: obs.spec_version || null,
|
|
457
|
+
validator_version: levels.version,
|
|
458
|
+
scripts: scriptLog,
|
|
459
|
+
advertised: (obs.advertised || []).length,
|
|
460
|
+
painted: painted.length,
|
|
461
|
+
unresolved_advertised: unresolved,
|
|
462
|
+
requirements: verdicts,
|
|
463
|
+
by_level,
|
|
464
|
+
level,
|
|
465
|
+
decided: verdicts.filter((v) => v.verdict !== 'unverified').length,
|
|
466
|
+
total: verdicts.length,
|
|
467
|
+
};
|
|
468
|
+
}
|
package/dist/cli-levels.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generated_by": "runtime/build.mjs from SPEC.md section 8 via scripts/spec-levels.mjs",
|
|
3
3
|
"note": "Build input for the CLI validator. The published, signed copy of the same facts is api/v/<version>/levels.json.",
|
|
4
|
-
"version": "2.
|
|
5
|
-
"spec_version": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
|
+
"spec_version": "2.8",
|
|
6
6
|
"locales_required": [
|
|
7
7
|
"es",
|
|
8
8
|
"en",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"nac:field:changed"
|
|
25
25
|
],
|
|
26
26
|
"tab": [
|
|
27
|
-
"nac:tab:activated"
|
|
27
|
+
"nac:tab:activated",
|
|
28
|
+
"nac:tab:activation_failed"
|
|
28
29
|
],
|
|
29
30
|
"breadcrumb-item": [
|
|
30
31
|
"nac:breadcrumb:navigated"
|
|
@@ -51,6 +52,46 @@
|
|
|
51
52
|
],
|
|
52
53
|
"filter-control": [
|
|
53
54
|
"nac:table:filter_changed"
|
|
55
|
+
],
|
|
56
|
+
"button": [
|
|
57
|
+
"nac:action:succeeded",
|
|
58
|
+
"nac:action:failed"
|
|
59
|
+
],
|
|
60
|
+
"map-marker": [
|
|
61
|
+
"nac:map:marker_selected"
|
|
62
|
+
],
|
|
63
|
+
"map-layer": [
|
|
64
|
+
"nac:map:layer_toggled"
|
|
65
|
+
],
|
|
66
|
+
"chart-series": [
|
|
67
|
+
"nac:chart:series_toggled"
|
|
68
|
+
],
|
|
69
|
+
"calendar-event": [
|
|
70
|
+
"nac:calendar:event_selected"
|
|
71
|
+
],
|
|
72
|
+
"tree-node": [
|
|
73
|
+
"nac:tree:selected"
|
|
74
|
+
],
|
|
75
|
+
"carousel-slide": [
|
|
76
|
+
"nac:carousel:slide_changed"
|
|
77
|
+
],
|
|
78
|
+
"toast": [
|
|
79
|
+
"nac:toast:dismissed"
|
|
80
|
+
],
|
|
81
|
+
"banner": [
|
|
82
|
+
"nac:banner:dismissed"
|
|
83
|
+
],
|
|
84
|
+
"combobox": [
|
|
85
|
+
"nac:field:changed"
|
|
86
|
+
],
|
|
87
|
+
"listbox": [
|
|
88
|
+
"nac:field:changed"
|
|
89
|
+
],
|
|
90
|
+
"slider": [
|
|
91
|
+
"nac:slider:value_changed"
|
|
92
|
+
],
|
|
93
|
+
"richtext": [
|
|
94
|
+
"nac:richtext:format_applied"
|
|
54
95
|
]
|
|
55
96
|
},
|
|
56
97
|
"reporting": {
|
|
@@ -76,15 +117,15 @@
|
|
|
76
117
|
"note": "A tool cannot decide which widgets an agent SHOULD be able to operate. It can report unannotated interactive elements as candidates; whether each one belongs in the contract is the author's call. Any validator that reports this requirement as passed is overreaching."
|
|
77
118
|
},
|
|
78
119
|
{
|
|
79
|
-
"id": "L1-
|
|
80
|
-
"text": "Every `data-nac-role=\"action\"` element fires `nac:action:succeeded` after its side effect.",
|
|
81
|
-
"text_sha384": "sha384-
|
|
120
|
+
"id": "L1-7bd8a7a0",
|
|
121
|
+
"text": "Every `data-nac-role=\"action\"` element fires `nac:action:succeeded` after its side effect -- **except when that side effect is a navigation that unloads the document**, where there is no \"after\": nothing is left to emit the event and nothing is left to hear it. Such an element MAY emit BEFORE navigating, which is what lets an agent await a confirmation, and a validator MUST report the ones that do not as navigating rather than as failing. (Through 2.6 this bullet carried no exception, so a page whose actions are plain `<a href>` links could not reach level 1 at all -- 31 of the 39 actions of this project's own landing page are such links. The reference validator already separated them and answered `unverified`; what was missing was the sentence. Audit N-38, closed in 2.7.0.)",
|
|
122
|
+
"text_sha384": "sha384-0skLTEePAARZdx3hH9a7/QBDauYFJhTnoxa+Xp69FsB65Sh7dxvp7GcKRc+Jcy0y",
|
|
82
123
|
"machine_checkable": true,
|
|
83
124
|
"check": "behavioural",
|
|
84
125
|
"decider": "action_completion_events",
|
|
85
126
|
"requires_drive": true,
|
|
86
127
|
"falsified_by": [],
|
|
87
|
-
"note": "Decidable only by clicking every advertised action and waiting for its completion event
|
|
128
|
+
"note": "Decidable only by clicking every advertised action and waiting for its completion event; no finding code covers it, so a validator must drive the page and report the ids that never completed. REVIEWED AGAIN in 2.7.0 because the sentence changed: it now EXEMPTS an action whose side effect is a navigation that unloads the document, which is the case the old wording had no outcome for -- nothing survives an unload to emit the event, and the validator was answering unverified for every page with links (31 of the 39 actions of this project own landing). The decider now fails only a NON-navigating action that stayed silent, counts a navigating one as exempt, and still refuses to call it a pass when NOT ONE action emitted: an exemption that measured nothing is reported as unverified, not as satisfied. Audit N-38, closed."
|
|
88
129
|
},
|
|
89
130
|
{
|
|
90
131
|
"id": "L1-bb23d963",
|
|
@@ -111,7 +152,7 @@
|
|
|
111
152
|
"missing_in_dom",
|
|
112
153
|
"plugin_not_mounted"
|
|
113
154
|
],
|
|
114
|
-
"note": "Resolution can be checked statically; that the click actually lands needs the page driven."
|
|
155
|
+
"note": "Resolution can be checked statically; that the click actually lands needs the page driven. REVIEWED AGAIN in 2.7.0 together with the completion requirement, because the same hole was in both: a click on a plain link LANDS -- the element would have navigated, and the validator cancels the navigation in the bubble phase on purpose so the page survives to be measured -- and then times out waiting for a completion event that nothing can emit after an unload. Section 8 exempts that event for a navigation now, so the timeout is an exemption and not a hole, and the decider passes instead of answering unverified. Fixing only the other requirement would have left level 1 blocked for any page with links, which is exactly the damage PND-047 recorded. The honesty line is the same in both: if NOT ONE click produced an observable landing, the verdict stays unverified -- an exemption is not a measurement."
|
|
115
156
|
}
|
|
116
157
|
]
|
|
117
158
|
},
|
|
@@ -123,15 +164,15 @@
|
|
|
123
164
|
"cumulative": true,
|
|
124
165
|
"requirements": [
|
|
125
166
|
{
|
|
126
|
-
"id": "L2-
|
|
127
|
-
"text": "
|
|
128
|
-
"text_sha384": "sha384-
|
|
167
|
+
"id": "L2-a33b0c5d",
|
|
168
|
+
"text": "Declares its surface EXPLICITLY in the manifest instead of leaving it to be inferred from the DOM, in either published shape: `elements[]` with a `role` on every entry, which is the canonical shape of section 4, or the legacy `tabs[]` / `fields[]` / `actions[]` arrays. (Through 2.6 this bullet named only the three legacy arrays, so a page written the way section 4 documents failed level 2 as worded -- including this project's own landing page, whose two manifests use `elements[]`. Audit N-37, closed in 2.7.0.)",
|
|
169
|
+
"text_sha384": "sha384-Y5rpEn7GQ8P3R3azwHfLL3orUSbZYn0iTffIgJiB92VGXDzRSMX48TEJEdiVpo5B",
|
|
129
170
|
"machine_checkable": true,
|
|
130
171
|
"check": "static",
|
|
131
|
-
"decider": "
|
|
172
|
+
"decider": "manifest_declares_surface",
|
|
132
173
|
"requires_drive": false,
|
|
133
174
|
"falsified_by": [],
|
|
134
|
-
"note": "Decidable by reading the registered manifest: the
|
|
175
|
+
"note": "Decidable by reading the registered manifest: the surface is declared there rather than inferred from the DOM. REVIEWED AGAIN in 2.7.0 because the sentence changed: it used to name only tabs[] / fields[] / actions[], which is the LEGACY manifest shape, so a page written the way section 4 documents (elements[] with a role per entry) failed this requirement as worded -- including this project own landing page. The sentence now accepts EITHER published shape and the decider reads both, which is why it was renamed from manifest_declares_groups to manifest_declares_surface: it no longer checks three groups, it checks that the surface is declared. What it still fails is a manifest that declares neither, which is the condition the requirement is actually about. Audit N-37, closed. The gap left over, named so it is not mistaken for covered: no finding code reports an undeclared surface, so this verdict comes from the decider and not from a published code."
|
|
135
176
|
},
|
|
136
177
|
{
|
|
137
178
|
"id": "L2-610ad4be",
|
|
@@ -184,7 +225,7 @@
|
|
|
184
225
|
"decider": "manifest_hmac_block_present",
|
|
185
226
|
"requires_drive": false,
|
|
186
227
|
"falsified_by": [],
|
|
187
|
-
"note": "Decidable
|
|
228
|
+
"note": "Decidable in the POSITIVE since 2.7.0, which is new. A manifest that carries no provenance block definitively does not satisfy this, so the validator FAILS it -- that half always worked. The other half did not exist: the runtime exposed no manifest verification at all, so a block that WAS present could only be reported unverified and no tool could ever assert level 3 (audit N-36). 2.7.0 implements section 7.2: register() verifies the signature against the tenant secret the host registered and records the answer, and NAC.manifest_provenance(slug) publishes it on the page. The decider now separates three answers -- verified (pass), present and REFUSED by the runtime (fail), present with no secret registered so nobody on the page can tell (unverified). The validator still holds no tenant secret and never will: what changed is that it can ask the page what the page could verify. Audit N-36 is closed."
|
|
188
229
|
},
|
|
189
230
|
{
|
|
190
231
|
"id": "L3-788469c4",
|
|
@@ -206,7 +247,7 @@
|
|
|
206
247
|
"decider": "validate_global_no_findings",
|
|
207
248
|
"requires_drive": false,
|
|
208
249
|
"falsified_by": [],
|
|
209
|
-
"note": "Same call as the level 2 requirement above with a stricter threshold: zero findings of ANY severity.
|
|
250
|
+
"note": "Same call as the level 2 requirement above with a stricter threshold: zero findings of ANY severity. Through 2.6 that was ALL it was, because validate_global() took no arguments and never read `probe` although SPEC.md published the signature as validate_global(opts?: {probe?: boolean}) -- so passing {probe: true} was accepted and ignored and this check was the level 2 check with a higher bar rather than the deeper inspection the sentence implies (audit N-35). 2.7.0 defines and implements probing: two further buckets, `ambiguous` (one declared id on 2+ DOM nodes, so find() resolves it by document order) and `unreachable` (mounted but behind aria-hidden / inert / not displayed, which is what click() refuses). Both are empty unless asked for, so the level 2 requirement is unaffected. Audit N-35 is closed."
|
|
210
251
|
}
|
|
211
252
|
]
|
|
212
253
|
}
|