nx_wpt_runner.nx source
↩ module page · 462 lines · 30715 B
1// nx_wpt_runner.nx -- BR1 v3: THE SOVEREIGN WPT HARNESS with TIME-SPINE TELEMETRY (2026-08-19).
2//
3// v1 ran real web-platform-tests through the browser's own JS+DOM lane. v2 fixed this harness's own
4// overclaim (assert_throws any-throw) and made async_test synchronous with arithmetic incompleteness.
5// v3 integrates the August-2026 test-intelligence field, measured against it honestly:
6// - CONTENT-ADDRESSED RUNS (the Bazel/TIA class, but EXACT): a run is keyed by
7// (engine_sha = sha256 of this very binary, corpus_sha = sha256 over the SORTED name+bytes of
8// every .html in the directory). Same key => the result CANNOT differ (the engine is
9// bit-deterministic), so re-running is refused with the prior row as the answer (--force
10// overrides). Develocity-class predictive selection is PROBABILISTIC ("99% of failures");
11// ours is an invariant, not a bet -- and it is only available because determinism was proven
12// first (same bytes twice => bit-identical render).
13// - THE TIME SPINE: every counted run appends ONE TSV row to the history file -- results
14// documented against time, so two rows say "and it is improving/regressing" where one row
15// can only say a level. Schema mapped onto the OpenTelemetry CI/CD semantic conventions
16// (v1.27+ cicd.* / test.* attribute families) so an OTLP exporter is a future formatter,
17// not a redesign: epoch_s(cicd.pipeline.run start) dir(test.suite name)
18// engine_sha16(service.version) corpus_sha16(vcs.ref analog) counters(test.case results)
19// dur_ms(pipeline duration) verdict.
20// - REGRESSION DETECTION: against the newest prior row with the SAME corpus (engine free to
21// differ -- that comparison is the point), pass-down or fail-up flags REGRESSION and exits 4
22// so a beat can alarm. Improvement is reported and exits 0.
23// - FLAKINESS REFUTED, NOT MANAGED (--twice): the field marks a test FLAKY when it both fails
24// and passes across runs and then works around it; our engine is deterministic, so the
25// whole directory runs twice and ANY divergence in any per-file counter is a REAL BUG
26// (exit 5 DETERMINISM-VIOLATION), never noise to be tolerated.
27// - CONTROLS FIRST, ALWAYS (unchanged law): runtime-synthesized neg+pos control; a harness
28// that cannot see a failure counts nothing. All buffers derived from inputs, no fixed caps.
29//
30// usage: nx_wpt_runner <dir-of-.html-tests> [historyfile] [--force] [--twice]
31// ENTRY: wpt_run(dir, histpath, force, twice) IS the harness (the /compare/browser BR1 contract symbol);
32// main only parses argv and delegates, so the contract names the code that does the work,
33// never a stub wearing its name (re-keyed 2026-08-23: the board had watched `wpt_run` while
34// the harness lived in main + wpt_run_page, so a LANDED rung ranked #1 OPEN for five days).
35// exit: 0 counted (incl improvement) | 2 harness unproven | 3 usage | 4 REGRESSION | 5 NONDETERMINISM
36// license_tier: ORIGINAL expect_exit: 0
37
38import "nx_syscalls.nx"
39import "nx_js_eval.nx"
40import "nx_sha256.nx"
41import "nx_wpt_spine.nx" // the shared telemetry spine (extracted 2026-08-19 when nx_wpt_reftest became consumer #2)
42
43// ---- DECLARED BOUNDS (rule 11: named for PURPOSE, never inline). These are the harness's own
44// envelope, not tuning knobs: the name-pool and file-index caps bound ONE directory enumeration
45// (wsp_collect_names receives both and is the place that must announce if a directory exceeds
46// them), the path cap is the kernel PATH_MAX class, the row cap bounds one 14-field TSV spine row,
47// and the serializer headroom is the slack added to 2x the page size for the DOM serializer's
48// own markup. Hoisted 2026-08-23 because the magic ratchet refused the v3 source at first build
49// (9 sites vs the v2 baseline of 4); values unchanged, so the rebuild is behaviour-identical.
50const WPT_NAMEBUF_CAP: i64 = 1048576
51const WPT_MAX_FILES: i64 = 8192
52const WPT_PATH_CAP: i64 = 4096
53const WPT_ROW_CAP: i64 = 2048
54const WPT_SERIALIZE_HEADROOM: i64 = 65536
55
56// ---- tiny io helpers ----
57func wr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
58func wrn(v: i64) -> i64 {
59 var m: i64 = v; if m < 0 { wr("-" as *u8); m = 0 - m }
60 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 }
61 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
62 let o: *u8 = sys_mmap(24); var i: i64 = 0; while i < k { o[i] = t[k-1-i]; i = i + 1 }
63 sys_write(1, o, k); return 0
64}
65func scat(dst: *u8, off: i64, src: *u8) -> i64 { var i: i64 = 0; while src[i] != (0 as u8) { dst[off+i] = src[i]; i = i + 1 } return off + i }
66func scatn(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[off+i] = src[i]; i = i + 1 } return off + n }
67func catnum(dst: *u8, off: i64, v: i64) -> i64 {
68 var m: i64 = v; var o: i64 = off
69 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m }
70 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 }
71 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
72 var i: i64 = 0; while i < k { dst[o] = t[k-1-i]; o = o + 1; i = i + 1 }
73 return o
74}
75func ends_with(s: *u8, n: i64, suf: *u8, sn: i64) -> i64 {
76 if n < sn { return 0 }
77 var i: i64 = 0
78 while i < sn { if s[n-sn+i] != suf[i] { return 0 } i = i + 1 }
79 return 1
80}
81func count_marks(hay: *u8, n: i64, needle: *u8) -> i64 {
82 var nl: i64 = 0; while needle[nl] != (0 as u8) { nl = nl + 1 }
83 var c: i64 = 0
84 var i: i64 = 0
85 while i + nl <= n {
86 var k: i64 = 0
87 var hit: i64 = 1
88 while k < nl { if hay[i+k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } }
89 if hit == 1 { c = c + 1; i = i + nl } else { i = i + 1 }
90 }
91 return c
92}
93func streqz(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
94
95// ---- THE SHIM (v2): pure-JS synchronous testharness; markers built at RUNTIME by concatenation
96// because the DOM serializer re-emits script SOURCE (a literal marker matched itself and saturated
97// every count on v1's first run -- the detector-finds-its-own-fixture law). assert_* that need
98// witness power our string-throw interpreter lacks throw a sentinel routed to UNSUPPORTED --
99// never fake-pass (v1's assert_throws any-throw overclaim), never poison fail.
100func wpt_shim() -> *u8 {
101 return "<div id=\"wptlog9x\"></div><script>var __w = document.getElementById('wptlog9x'); var __UN = '@@WPT_' + 'UNSUPPORTED_ASSERT@@ '; function __log(s){ var d = document.createElement('div'); d.textContent = s; __w.appendChild(d); } function __fmt(x){ if (x === null) { return 'null'; } if (x === undefined) { return 'undefined'; } return '' + x; } function __isun(e){ var m = '' + e; return m.indexOf('@@WPT_' + 'UNSUPPORTED_ASSERT@@') === 0; } function __calln(g, a){ var n = a.length; if (n === 0) { return g(); } if (n === 1) { return g(a[0]); } if (n === 2) { return g(a[0], a[1]); } if (n === 3) { return g(a[0], a[1], a[2]); } if (n === 4) { return g(a[0], a[1], a[2], a[3]); } throw __UN + 'shim forwards at most 4 arguments: this interpreter has no Function.prototype.apply (MEASURED, knowledge/wptcap) so the forward is an explicit arity dispatch, and this call passed ' + n; } function assert_true(v, m){ if (v !== true) { throw 'assert_true got ' + __fmt(v) + ' ' + __fmt(m); } } function assert_false(v, m){ if (v !== false) { throw 'assert_false got ' + __fmt(v) + ' ' + __fmt(m); } } function assert_equals(a, b, m){ if (a !== b) { throw 'assert_equals got ' + __fmt(a) + ' expected ' + __fmt(b) + ' ' + __fmt(m); } } function assert_not_equals(a, b, m){ if (a === b) { throw 'assert_not_equals ' + __fmt(a) + ' ' + __fmt(m); } } function assert_array_equals(a, b, m){ if (a.length !== b.length) { throw 'assert_array_equals length ' + a.length + ' vs ' + b.length + ' ' + __fmt(m); } var i; for (i = 0; i < a.length; i = i + 1) { if (a[i] !== b[i]) { throw 'assert_array_equals at ' + i + ' ' + __fmt(m); } } } function assert_in_array(v, arr, m){ var i; var hit = 0; for (i = 0; i < arr.length; i = i + 1) { if (arr[i] === v) { hit = 1; } } if (hit === 0) { throw 'assert_in_array ' + __fmt(v) + ' ' + __fmt(m); } } function assert_throws_js(c, f, m){ throw __UN + 'assert_throws_js needs exception-TYPE identity our string-throw interpreter cannot witness ' + __fmt(m); } function assert_throws_dom(t, f, m){ throw __UN + 'assert_throws_dom needs DOMException identity ' + __fmt(m); } function assert_throws_exactly(t, f, m){ throw __UN + 'assert_throws_exactly ' + __fmt(m); } function assert_unreached(m){ throw 'assert_unreached ' + __fmt(m); } function assert_own_property(o, p, m){ throw __UN + 'assert_own_property needs hasOwnProperty semantics ' + __fmt(m); } function assert_class_string(o, c, m){ throw __UN + 'assert_class_string needs Class internals ' + __fmt(m); } function format_value(v){ return __fmt(v); } function test(f, name){ try { f(); __log('@@WPT_' + 'PASS@@ ' + __fmt(name)); } catch (e) { if (__isun(e)) { __log('@@WPT_' + 'UNSUP@@ ' + __fmt(name) + ' :: ' + __fmt(e)); } else { __log('@@WPT_' + 'FAIL@@ ' + __fmt(name) + ' :: ' + __fmt(e)); } } } function async_test(a, b){ var name = b; var fn = null; if (typeof a === 'string') { name = a; } else { fn = a; } __log('@@WPT_' + 'ASTART@@ ' + __fmt(name)); var t = { failed: 0, unsup: 0, msg: '', ended: 0 }; t.__guard = function(e){ if (__isun(e)) { t.unsup = 1; } else { t.failed = 1; } t.msg = '' + e; }; t.__run0 = function(g){ if (t.ended === 1) { return; } try { g(); } catch (e) { t.__guard(e); } }; t.__run1 = function(g, v){ if (t.ended === 1) { return; } try { g(v); } catch (e) { t.__guard(e); } }; t.__runA = function(g, a){ if (t.ended === 1) { return; } try { __calln(g, a); } catch (e) { t.__guard(e); } }; t.step = function(g){ t.__run0(g); }; t.step_func = function(g){ return function(){ t.__runA(g, arguments); }; }; t.step_func_done = function(g){ return function(){ t.__runA(g, arguments); t.done(); }; }; t.step_timeout = function(g, ms){ t.step(g); }; t.unreached_func = function(m){ return function(){ t.step(function(){ assert_unreached(m); }); }; }; t.add_cleanup = function(g){}; t.done = function(){ if (t.ended === 1) { return; } t.ended = 1; if (t.unsup === 1) { __log('@@WPT_' + 'AUNSUP@@ ' + __fmt(name) + ' :: ' + t.msg); } else { if (t.failed === 1) { __log('@@WPT_' + 'AFAIL@@ ' + __fmt(name) + ' :: ' + t.msg); } else { __log('@@WPT_' + 'APASS@@ ' + __fmt(name)); } } }; if (fn !== null) { t.__run1(fn, t); } return t; } function promise_test(f, name){ __log('@@WPT_' + 'UNSUP@@ promise ' + __fmt(name)); } var __loadfns = []; if (typeof window === 'undefined') { window = {}; } window.addEventListener = function(type, fn){ if (type === 'load' || type === 'DOMContentLoaded') { __loadfns.push(fn); } }; function __fire_load(){ var i; for (i = 0; i < __loadfns.length; i = i + 1) { try { __loadfns[i](); } catch (e) { } } } function setup(o){} function done(){} function add_completion_callback(f){}</script>\x00" as *u8
102}
103
104func wpt_shim_tail() -> *u8 {
105 // THE PAGE HAS NO EVENT LOOP, SO `load` MUST BE DISPATCHED EXPLICITLY, AFTER the test's own
106 // scripts have registered their handlers -- which is why this is a SEPARATE trailing script
107 // and not part of wpt_shim(): the shim is prepended, so anything it ran would fire BEFORE the
108 // handlers exist and register nothing. MEASURED 2026-08-26, dom/nodes slice: every async_test
109 // that calls t.done() from inside a load handler STARTED AND NEVER FINISHED -- 147 of 244
110 // assertions (602 permil) counted as async_incomplete, all from Document-createElement.html,
111 // which returned ZERO sync verdicts. An unjudged assertion is an abstention nobody counts, so
112 // this converts invisible into scored; it does NOT promise those tests pass, and the honest
113 // expectation is that most become async_fail because the iframe lane they need is absent.
114 // The typeof guard means a shim that failed to define the dispatcher degrades to the OLD
115 // behaviour (incomplete) rather than throwing and taking the whole page's counts with it.
116 return "<script>if (typeof __fire_load === 'function') { __fire_load(); }</script>\x00" as *u8
117}
118
119// run ONE page (shim + test html + load-dispatch tail) through the browser's own shared-genv lane.
120// out[0..6] = pass fail unsup astart apass afail aunsup return 0 ok / 1 render failed
121func wpt_run_page(html: *u8, hlen: i64, out: *i64) -> i64 {
122 let shim: *u8 = wpt_shim()
123 var sl: i64 = 0
124 while shim[sl] != (0 as u8) { sl = sl + 1 }
125 let tail: *u8 = wpt_shim_tail()
126 var tl: i64 = 0
127 while tail[tl] != (0 as u8) { tl = tl + 1 }
128 let pcap: i64 = sl + hlen + tl + 16
129 let page: *u8 = sys_mmap(pcap)
130 var po: i64 = scatn(page, 0, shim, sl)
131 po = scatn(page, po, html, hlen)
132 po = scatn(page, po, tail, tl)
133 let ocap: i64 = po * 2 + WPT_SERIALIZE_HEADROOM
134 let outh: *u8 = sys_mmap(ocap)
135 // shared-genv lane: the plain page lane runs each <script> in a FRESH env, so a harness
136 // defined in script 1 is invisible to the test in script 2 (the first honest control run
137 // caught exactly that -- pass=0 fail=0, counts refused).
138 let obox: *i64 = sys_mmap(32) as *i64
139 let prc: i64 = js_render_page_pending_begin(page, po, 0 as *u8, 0, obox)
140 if prc != 0 { return 1 }
141 let on: i64 = js_render_page_serialize(obox[2], outh, ocap)
142 if on <= 0 { return 1 }
143 out[0] = count_marks(outh, on, "@@WPT_PASS@@\x00" as *u8)
144 out[1] = count_marks(outh, on, "@@WPT_FAIL@@\x00" as *u8)
145 out[2] = count_marks(outh, on, "@@WPT_UNSUP@@\x00" as *u8)
146 out[3] = count_marks(outh, on, "@@WPT_ASTART@@\x00" as *u8)
147 out[4] = count_marks(outh, on, "@@WPT_APASS@@\x00" as *u8)
148 out[5] = count_marks(outh, on, "@@WPT_AFAIL@@\x00" as *u8)
149 out[6] = count_marks(outh, on, "@@WPT_AUNSUP@@\x00" as *u8)
150 return 0
151}
152
153
154
155// THE CANONICAL TIME SPINE. Named here rather than spelled at the call site so there is exactly one
156// owner: two rival history files (bench/wpt/ and knowledge/status/) had already grown because each
157// caller chose its own path, which is the duplicate-ruler defect wearing a filename.
158func wpt_hist_default() -> *u8 {
159 return "bench/wpt/wpt_history.tsv" as *u8
160}
161
162func main(argc: i64, argv: *i64) -> i64 {
163 if argc < 2 {
164 wr("usage: nx_wpt_runner <dir-of-.html-tests> [historyfile] [--force] [--twice]\n" as *u8)
165 wr(" content-addressed: same (engine sha, corpus sha) refuses to re-run (--force overrides);\n" as *u8)
166 wr(" every counted run appends a TSV row to historyfile (the time spine);\n" as *u8)
167 wr(" regression vs the newest same-corpus row exits 4; --twice proves determinism or exits 5.\n" as *u8)
168 sys_exit(3); return 3
169 }
170 let dir: *u8 = argv[1] as *u8
171 var histpath: *u8 = 0 as *u8
172 var force: i64 = 0
173 var twice: i64 = 0
174 var ai: i64 = 2
175 while ai < argc {
176 let a: *u8 = argv[ai] as *u8
177 if streqz(a, "--force" as *u8) == 1 { force = 1 } else {
178 if streqz(a, "--twice" as *u8) == 1 { twice = 1 } else { histpath = a } }
179 ai = ai + 1
180 }
181 // A SPINE THAT ONLY RECORDS WHEN THE CALLER REMEMBERS THE PATH IS AN ADOPTION GAP WITH EXTRA STEPS.
182 // MEASURED 2026-08-26: wsp_append is guarded by histpath != 0, so every run invoked as
183 // `nx_wpt_runner <dir>` printed WPT-ROW ... COUNTED and persisted NOTHING -- four such runs that day,
184 // including the one that took async_incomplete 147 -> 0, were absent from every history file while the
185 // usage text promised "every counted run appends a TSV row to historyfile". Defaulting closes it BY
186 // CONSTRUCTION; the path is ANNOUNCED so a reader never has to guess which file a row went to, and
187 // src= distinguishes an explicit caller path from the default.
188 var histsrc: *u8 = "argv" as *u8
189 if (histpath as i64) == 0 { histpath = wpt_hist_default(); histsrc = "DEFAULT" as *u8 }
190 wr("WPT-HISTORY path=" as *u8); wr(histpath); wr(" src=" as *u8); wr(histsrc); wr("
191" as *u8)
192 let rc: i64 = wpt_run(dir, histpath, force, twice)
193 // CANONICAL VERDICT LINE -- LAST, and POSITIONAL (the estate's judge anchors on the final line, not
194 // on matched text, which is why this is appended rather than woven into the domain lines above).
195 // This harness's own vocabulary is COUNTED / CACHED / REGRESSION / DETERMINISM-VIOLATION: rich, exact,
196 // and completely unreadable to the evidence layer, which keys on GREEN|RED. Widening THAT reader is how
197 // an estate acquires two spellings of success, so the EMITTER says the canonical word and keeps every
198 // domain line intact above it. Emitted HERE, in main, because there are five exit paths through
199 // wpt_run and a verdict line added to four of them is the half-fix that ships.
200 // WHAT IS JUDGED: whether the MEASUREMENT is sound -- controls proven, corpus keyed and counted, no
201 // regression against the spine, no nondeterminism. It is NOT the browser's score. A benchmark that
202 // honestly reports 8 passes of 97 is a WORKING benchmark; conflating the instrument's health with its
203 // subject's score would make every honest measurement of a young engine read as a broken instrument,
204 // and would punish exactly the act of measuring.
205 if rc == 0 { wr("verdict=GREEN\n" as *u8) } else { wr("verdict=RED\n" as *u8) }
206 sys_exit(rc)
207 return rc
208}
209
210// THE HARNESS. Runs the control pair, keys the run (engine sha, corpus sha), enumerates the
211// directory, executes (twice under --twice), detects regression against the spine, appends the
212// row, and RETURNS the verdict code (0 counted | 2 harness unproven | 3 cannot key/open |
213// 4 REGRESSION | 5 NONDETERMINISM). Output is byte-for-byte what main printed before the split;
214// main owns the process exit.
215func wpt_run(dir: *u8, histpath: *u8, force: i64, twice: i64) -> i64 {
216 let t_start: i64 = sys_now_ms()
217
218 // ---- CONTROL FIRST (a harness that cannot fail counts nothing) ----
219 let ctl: *u8 = "<script>test(function(){ assert_equals(1, 2, 'neg'); }, 'must-fail'); test(function(){ assert_true(true, 'pos'); }, 'must-pass');</script>\x00" as *u8
220 var cl: i64 = 0
221 while ctl[cl] != (0 as u8) { cl = cl + 1 }
222 let cres: *i64 = sys_mmap(64) as *i64
223 cres[0]=0; cres[1]=0; cres[2]=0; cres[3]=0; cres[4]=0; cres[5]=0; cres[6]=0
224 let crc: i64 = wpt_run_page(ctl, cl, cres)
225 wr("WPT-CONTROL pass=" as *u8); wrn(cres[0]); wr(" fail=" as *u8); wrn(cres[1]); wr(" render_rc=" as *u8); wrn(crc); wr("\n" as *u8)
226 if crc != 0 { wr("WPT verdict=HARNESS-UNPROVEN (control page did not render) -- counts REFUSED\n" as *u8); return 2 }
227 if cres[0] != 1 { wr("WPT verdict=HARNESS-UNPROVEN (positive control did not pass) -- counts REFUSED\n" as *u8); return 2 }
228 if cres[1] != 1 { wr("WPT verdict=HARNESS-UNPROVEN (negative control did not fail) -- counts REFUSED\n" as *u8); return 2 }
229
230 // ---- ENGINE IDENTITY: sha256 of this very binary (the runner IS the engine) ----
231 let esha: *u8 = sys_mmap(24)
232 if wsp_engine_sha(esha) != 0 {
233 wr("WPT: cannot hash /proc/self/exe -- refusing an unkeyed run\n" as *u8)
234 return 3
235 }
236
237 // ---- PASS A: deterministic enumeration + CORPUS HASH (hash precedes execution, so the
238 // cache decision is made before any work -- run tests intelligently, mechanically) ----
239 let namebuf: *u8 = sys_mmap(WPT_NAMEBUF_CAP)
240 let offs: *i64 = sys_mmap(8 * WPT_MAX_FILES) as *i64
241 let nfiles: i64 = wsp_collect_names(dir, ".html" as *u8, namebuf, WPT_NAMEBUF_CAP, offs, WPT_MAX_FILES)
242 if nfiles < 0 { wr("WPT: cannot open dir\n" as *u8); return 3 }
243 let csha: *u8 = sys_mmap(24)
244 wsp_corpus_sha(dir, namebuf, offs, nfiles, csha)
245 let path: *u8 = sys_mmap(WPT_PATH_CAP)
246 let dbase: *u8 = sys_mmap(256)
247 wsp_base_of(dir, dbase)
248
249 // ---- INTELLIGENT SKIP: newest history row with same (dir, engine, corpus) ----
250 var hbuf: *u8 = 0 as *u8
251 var hn: i64 = 0
252 if (histpath as i64) != 0 {
253 let hp: *i64 = sys_mmap(16) as *i64
254 hbuf = sys_read_file(histpath, hp)
255 if (hbuf as i64) != 0 { hn = hp[0] }
256 }
257 let rlen: *i64 = sys_mmap(16) as *i64
258 if force == 0 { if hn > 0 {
259 let hit: i64 = wsp_hist_find(hbuf, hn, dbase, esha, csha, rlen)
260 if hit >= 0 {
261 wr("WPT-CACHED dir=" as *u8); wr(dbase)
262 wr(" -- identical (engine_sha, corpus_sha); the engine is bit-deterministic so the result CANNOT differ. Prior row:\n" as *u8)
263 sys_write(1, ((hbuf as i64) + hit) as *u8, rlen[0])
264 wr("\nverdict=CACHED (pass --force to re-run anyway)\n" as *u8)
265 return 0
266 }
267 } }
268
269 // ---- PASS B: execute (twice when --twice; any counter divergence is a real bug) ----
270 let percnt: *i64 = sys_mmap(8 * 8 * WPT_MAX_FILES) as *i64 // 8 slots per file: 7 counters + render rc
271 let percnt2: *i64 = sys_mmap(8 * 8 * WPT_MAX_FILES) as *i64
272 var rounds: i64 = 1
273 if twice == 1 { rounds = 2 }
274 var round: i64 = 0
275 var nondet: i64 = 0
276 var files: i64 = 0
277 var ran: i64 = 0
278 var pass: i64 = 0
279 var fail: i64 = 0
280 var unsup: i64 = 0
281 var apass: i64 = 0
282 var afail: i64 = 0
283 var aunsup: i64 = 0
284 var ainc: i64 = 0
285 var nores: i64 = 0
286 var rfail: i64 = 0
287 let res: *i64 = sys_mmap(64) as *i64
288 while round < rounds {
289 var slot: *i64 = percnt
290 if round == 1 { slot = percnt2 }
291 files = 0; ran = 0; pass = 0; fail = 0; unsup = 0; apass = 0; afail = 0; aunsup = 0; ainc = 0; nores = 0; rfail = 0
292 var fi: i64 = 0
293 while fi < nfiles {
294 let nm: *u8 = ((namebuf as i64) + offs[fi]) as *u8
295 var pp: i64 = scat(path, 0, dir)
296 pp = scat(path, pp, "/" as *u8)
297 pp = scat(path, pp, nm)
298 path[pp] = 0 as u8
299 files = files + 1
300 let lnp: *i64 = sys_mmap(16) as *i64
301 let body: *u8 = sys_read_file(path, lnp)
302 if (body as i64) == 0 {
303 rfail = rfail + 1
304 slot[fi*8 + 7] = 0 - 1
305 } else {
306 res[0]=0; res[1]=0; res[2]=0; res[3]=0; res[4]=0; res[5]=0; res[6]=0
307 let rrc: i64 = wpt_run_page(body, lnp[0], res)
308 slot[fi*8 + 7] = rrc
309 if rrc != 0 { rfail = rfail + 1 } else {
310 ran = ran + 1
311 var ci: i64 = 0
312 while ci < 7 { slot[fi*8 + ci] = res[ci]; ci = ci + 1 }
313 pass = pass + res[0]
314 fail = fail + res[1]
315 unsup = unsup + res[2]
316 apass = apass + res[4]
317 afail = afail + res[5]
318 aunsup = aunsup + res[6]
319 ainc = ainc + (res[3] - res[4] - res[5] - res[6])
320 if res[0] == 0 { if res[1] == 0 { if res[2] == 0 { if res[3] == 0 { nores = nores + 1 } } } }
321 if round == 0 {
322 wr("WPT-FILE " as *u8); wr(nm)
323 wr(" pass=" as *u8); wrn(res[0]); wr(" fail=" as *u8); wrn(res[1])
324 wr(" unsup=" as *u8); wrn(res[2])
325 wr(" apass=" as *u8); wrn(res[4]); wr(" afail=" as *u8); wrn(res[5])
326 wr(" ainc=" as *u8); wrn(res[3] - res[4] - res[5] - res[6]); wr("\n" as *u8)
327 }
328 }
329 sys_free_file(body, lnp[0])
330 }
331 fi = fi + 1
332 }
333 round = round + 1
334 }
335 if twice == 1 {
336 var di: i64 = 0
337 while di < nfiles {
338 var ci2: i64 = 0
339 while ci2 < 8 {
340 if percnt[di*8 + ci2] != percnt2[di*8 + ci2] {
341 nondet = nondet + 1
342 wr("WPT-NONDETERMINISM file=" as *u8); wr(((namebuf as i64) + offs[di]) as *u8)
343 wr(" counter=" as *u8); wrn(ci2)
344 wr(" run1=" as *u8); wrn(percnt[di*8 + ci2])
345 wr(" run2=" as *u8); wrn(percnt2[di*8 + ci2]); wr("\n" as *u8)
346 ci2 = 8
347 } else { ci2 = ci2 + 1 }
348 }
349 di = di + 1
350 }
351 }
352 let dur: i64 = sys_now_ms() - t_start
353
354 // ---- REGRESSION vs the newest same-corpus row (engine free to differ: that IS the comparison) ----
355 var regr: i64 = 0
356 var regep: i64 = 0 - 1
357 var prevpass: i64 = 0 - 1
358 var prevfail: i64 = 0 - 1
359 var prevainc: i64 = 0 - 1
360 var reclass: i64 = 0
361 if hn > 0 {
362 let base: i64 = wsp_hist_find(hbuf, hn, dbase, 0 as *u8, csha, rlen)
363 if base >= 0 {
364 regep = wsp_hist_col_int(hbuf, base, rlen[0], 0)
365 prevpass = wsp_hist_col_int(hbuf, base, rlen[0], 7)
366 prevfail = wsp_hist_col_int(hbuf, base, rlen[0], 8)
367 prevainc = wsp_hist_col_int(hbuf, base, rlen[0], 10)
368 // A PASS DROP IS ALWAYS A REGRESSION AND NOTHING EXCUSES IT: an assertion that was never
369 // judged cannot previously have been PASSING, so judging more can raise fail and can NEVER
370 // lower pass. That asymmetry is what makes the next test sound rather than a loophole.
371 if (pass + apass) < prevpass { regr = 1 }
372 if (fail + afail) > prevfail {
373 // A FAIL RISE HAS TWO POSSIBLE CAUSES AND THE OLD RULE COULD NOT TELL THEM APART, SO IT
374 // ASSERTED THE ALARMING ONE: it printed "the engine changed for the worse" whenever fail
375 // rose. MEASURED on dom_nodes: pass 32 -> 32 UNCHANGED, fail 1222 -> 1361 (+139), while
376 // incomplete fell 202 -> 56 (-146). Nothing regressed; the harness stopped abstaining.
377 // The rule below is deliberately CONSERVATIVE -- the rise is excused ONLY when it is
378 // FULLY covered by the fall in previously-unjudged assertions AND pass did not drop, so
379 // any unexplained fail beyond that still flags and a real regression cannot hide here.
380 let frise: i64 = (fail + afail) - prevfail
381 let ifall: i64 = prevainc - ainc
382 var explained: i64 = 0
383 if prevainc >= 0 {
384 if ifall > 0 {
385 if frise <= ifall {
386 if (pass + apass) >= prevpass { explained = 1 }
387 }
388 }
389 }
390 if explained == 1 { reclass = 1 } else { regr = 1 }
391 }
392 }
393 }
394
395 // ---- THE ROW (PIPE-delimited since 2026-08-27; the OTel cicd/test mapping is in this file's
396 // header and is unchanged -- the MAPPING was always the point and the delimiter never was).
397 // The separator is WSP_FS, owned by nx_wpt_spine, which is the single reader this writer and
398 // nx_wpt_reftest share. Its reader accepts the legacy tab too, so every history row written
399 // before today stays readable and the regression baseline survives the change.
400 let row: *u8 = sys_mmap(WPT_ROW_CAP)
401 var ro: i64 = 0
402 ro = catnum(row, ro, sys_now_realtime_sec()); row[ro] = WSP_FS as u8; ro = ro + 1
403 ro = scat(row, ro, dbase); row[ro] = WSP_FS as u8; ro = ro + 1
404 ro = scat(row, ro, esha); row[ro] = WSP_FS as u8; ro = ro + 1
405 ro = scat(row, ro, csha); row[ro] = WSP_FS as u8; ro = ro + 1
406 ro = catnum(row, ro, nfiles); row[ro] = WSP_FS as u8; ro = ro + 1
407 ro = catnum(row, ro, ran); row[ro] = WSP_FS as u8; ro = ro + 1
408 ro = catnum(row, ro, rfail); row[ro] = WSP_FS as u8; ro = ro + 1
409 ro = catnum(row, ro, pass + apass); row[ro] = WSP_FS as u8; ro = ro + 1
410 ro = catnum(row, ro, fail + afail); row[ro] = WSP_FS as u8; ro = ro + 1
411 ro = catnum(row, ro, unsup + aunsup); row[ro] = WSP_FS as u8; ro = ro + 1
412 ro = catnum(row, ro, ainc); row[ro] = WSP_FS as u8; ro = ro + 1
413 ro = catnum(row, ro, nores); row[ro] = WSP_FS as u8; ro = ro + 1
414 ro = catnum(row, ro, dur); row[ro] = WSP_FS as u8; ro = ro + 1
415 if nondet > 0 { ro = scat(row, ro, "NONDETERMINISM" as *u8) } else {
416 if regr == 1 { ro = scat(row, ro, "REGRESSION-vs-" as *u8); ro = catnum(row, ro, regep) } else {
417 if reclass == 1 { ro = scat(row, ro, "RECLASSIFIED-vs-" as *u8); ro = catnum(row, ro, regep) } else {
418 ro = scat(row, ro, "COUNTED" as *u8) } } }
419 row[ro] = 10 as u8; ro = ro + 1
420 wr("WPT-ROW " as *u8); sys_write(1, row, ro)
421 if (histpath as i64) != 0 {
422 if wsp_append(histpath, row, ro) != 0 { wr("WPT: history append FAILED (row printed above is the only copy)\n" as *u8) }
423 }
424 wr("WPT dir=" as *u8); wr(dbase)
425 wr(" files=" as *u8); wrn(nfiles)
426 wr(" ran=" as *u8); wrn(ran)
427 wr(" render_or_read_fail=" as *u8); wrn(rfail)
428 wr(" tests_pass=" as *u8); wrn(pass)
429 wr(" tests_fail=" as *u8); wrn(fail)
430 wr(" tests_unsupported=" as *u8); wrn(unsup)
431 wr(" async_pass=" as *u8); wrn(apass)
432 wr(" async_fail=" as *u8); wrn(afail)
433 wr(" async_unsup_assert=" as *u8); wrn(aunsup)
434 wr(" async_incomplete=" as *u8); wrn(ainc)
435 wr(" files_no_result=" as *u8); wrn(nores)
436 wr(" dur_ms=" as *u8); wrn(dur)
437 wr(" engine=" as *u8); wr(esha)
438 wr(" corpus=" as *u8); wr(csha)
439 wr("\n" as *u8)
440 if nondet > 0 {
441 wr("verdict=DETERMINISM-VIOLATION -- the engine diverged between two identical runs; this is a REAL BUG, never flake to tolerate\n" as *u8)
442 return 5
443 }
444 if regr == 1 {
445 wr("verdict=REGRESSION vs epoch " as *u8); wrn(regep)
446 wr(" (pass " as *u8); wrn(prevpass); wr(" -> " as *u8); wrn(pass + apass)
447 wr(", fail " as *u8); wrn(prevfail); wr(" -> " as *u8); wrn(fail + afail)
448 wr(") -- same corpus, so the engine changed for the worse\n" as *u8)
449 return 4
450 }
451 if reclass == 1 {
452 wr("verdict=RECLASSIFIED vs epoch " as *u8); wrn(regep)
453 wr(" (pass " as *u8); wrn(prevpass); wr(" -> " as *u8); wrn(pass + apass)
454 wr(", fail " as *u8); wrn(prevfail); wr(" -> " as *u8); wrn(fail + afail)
455 wr(", incomplete " as *u8); wrn(prevainc); wr(" -> " as *u8); wrn(ainc)
456 wr(") -- the fail rise is FULLY accounted for by assertions that were previously UNJUDGED and are now scored. An unjudged assertion can never have been passing, so judging more raises fail and can NEVER lower pass: the harness got honest, the engine did not get worse. A pass DROP, or a fail rise beyond the incomplete fall, would still be REGRESSION.\n" as *u8)
457 return 0
458 }
459 wr("verdict=COUNTED (controls proven; the row above is the time-spine record)\n" as *u8)
460 return 0
461}
462