nx_compare_results_gate.nx source
↩ module page · 90 lines · 8013 B
1// nx_compare_results_gate.nx -- gate for a board's ONE results page and the click-to-open primitive under it (ecosystem
2// EC64, 2026-09-17). In-process over nx_compare_results_lib and nx_reveal_lib: the policy decision in both directions
3// (a file may tighten, never loosen), a planted results file with a superseded slug, a malformed row, an adult row, an
4// explicit row and an undeclared class, and the audit held to a planted bare image. No files are written.
5// license_tier: ORIGINAL No hw writes (Rule 26).
6import "nx_syscalls.nx"
7import "nx_gate_verdict.nx"
8import "nx_compare_results_lib.nx"
9
10const CG_FIXTURE: *u8 = "The board's results, prose line.\nresult|canon-close|canon|2026-09-17|face-synthetic|Canon face|-|/img/canon.png|headline one\nresult|fit|twin-fit|2026-09-16|face-synthetic|OLD ROW|-|/img/old.png|old\nresult|fit|twin-fit|2026-09-17|face-synthetic|Fitted face|/report/fit|/img/fit.png|headline two\nresult|seed-7|synth-seed|2026-09-17|face-synthetic|Seed 7|-|/img/seed7.png|headline three\nresult|planted-adult|synth-seed|2026-09-17|nudity-synthetic|Planted <script>alert(1)</script>|-|/img/adult.png|planted \"quote\" & amp\nresult|planted-explicit|synth-seed|2026-09-17|explicit|Planted explicit|-|/img/SECRET-EXPLICIT.png|never carries its href\nresult|planted-unknown|synth-seed|2026-09-17|some-new-class|Planted unknown|-|/img/SECRET-UNKNOWN.png|an undeclared class is withheld\nresult|too|few|fields\n"
11const CG_GENERAL: *u8 = "result|one|canon|2026-09-17|face-synthetic|One face|-|/img/one.png|a page with no adult item\n"
12const CG_PROSE_ONLY: *u8 = "no result rows here\njust prose\n"
13const CG_FILE_LOOSEN: *u8 = "class|explicit|open|general|algorithmicMedia|an operator file trying to open explicit media\nclass|chart|click|general|algorithmicMedia|charts tightened to click\nclass|newclass|open|adult|algorithmicMedia|a new adult class declared open\n"
14const CG_BARE_PAGE: *u8 = "<html><body><p><img src=\"/x.png\"></p></body></html>"
15const CG_COVERED_PAGE: *u8 = "<html><body><details class=\"nx-reveal\" data-class=\"face-synthetic\"><summary>s</summary><figure><img src=\"/x.png\"></figure></details></body></html>"
16const CG_DOM: *u8 = "fixtureboard"
17const CG_PAGE_CAP: i64 = 131072
18const CG_TINY_CAP: i64 = 64
19const CG_ROWS: i64 = 7
20const CG_LIVE: i64 = 6
21const CG_BAD_LINE: i64 = 9
22const CG_KINDS: i64 = 3
23const CG_CLICK: i64 = 4
24const CG_GATED: i64 = 2
25
26func cg_has(buf: *u8, n: i64, lit: *u8) -> i64 {
27 let m: i64 = rvl_slen(lit)
28 var i: i64 = 0
29 while i + m <= n {
30 if rvl_at(buf, n, i, lit) == 1 { return 1 }
31 i = i + 1
32 }
33 return 0
34}
35func main(argc: i64, argv: *i64) -> i64 {
36 gv_head("nx_compare_results_gate: one results page per board, every image behind the click-to-open primitive" as *u8)
37 let ctr: *i64 = gv_ctr()
38 let nofile: *u8 = 0 as *u8
39 // the policy decision, built-in rows only
40 gv_check_eq("policy-a-synthetic-face-is-click-to-open" as *u8, rvl_mode(nofile, 0, "face-synthetic" as *u8), RVL_MODE_CLICK, ctr)
41 gv_check_eq("policy-a-chart-may-render-inline" as *u8, rvl_mode(nofile, 0, "chart" as *u8), RVL_MODE_OPEN, ctr)
42 gv_check_eq("neg-control-policy-explicit-media-is-withheld" as *u8, rvl_mode(nofile, 0, "explicit" as *u8), RVL_MODE_GATED, ctr)
43 gv_check_eq("neg-control-policy-nude-reference-media-is-withheld" as *u8, rvl_mode(nofile, 0, "nudity-reference" as *u8), RVL_MODE_GATED, ctr)
44 gv_check_eq("neg-control-policy-an-undeclared-class-is-withheld" as *u8, rvl_mode(nofile, 0, "nobody-declared-this" as *u8), RVL_MODE_GATED, ctr)
45 // an operator file may tighten and may never loosen
46 let fl: i64 = rvl_slen(CG_FILE_LOOSEN)
47 gv_check_eq("neg-control-a-policy-file-cannot-open-explicit-media" as *u8, rvl_mode(CG_FILE_LOOSEN, fl, "explicit" as *u8), RVL_MODE_GATED, ctr)
48 gv_check_eq("a-policy-file-can-tighten-charts-to-click" as *u8, rvl_mode(CG_FILE_LOOSEN, fl, "chart" as *u8), RVL_MODE_CLICK, ctr)
49 gv_check_eq("neg-control-a-file-class-rated-adult-is-never-inline" as *u8, rvl_mode(CG_FILE_LOOSEN, fl, "newclass" as *u8), RVL_MODE_CLICK, ctr)
50 // the planted results file
51 let out: *u8 = sys_mmap(CG_PAGE_CAP)
52 let rep: *i64 = sys_mmap(CRES_R_N * CRES_I64) as *i64
53 let hn: i64 = cres_render(CG_DOM, CG_FIXTURE, rvl_slen(CG_FIXTURE), nofile, 0, out, CG_PAGE_CAP, rep)
54 gv_check("planted-results-render-to-a-page" as *u8, (hn > 0) as i64, ctr)
55 gv_check_eq("well-formed-rows-counted" as *u8, rep[CRES_R_ROWS], CG_ROWS, ctr)
56 gv_check_eq("a-later-slug-supersedes-the-earlier-row" as *u8, rep[CRES_R_SUPERSEDED], 1, ctr)
57 gv_check_eq("live-rows-are-rows-less-superseded" as *u8, rep[CRES_R_LIVE], CG_LIVE, ctr)
58 gv_check_eq("neg-control-a-short-row-is-malformed-not-a-card" as *u8, rep[CRES_R_MALFORMED], 1, ctr)
59 gv_check_eq("the-malformed-row-is-named-by-line" as *u8, rep[CRES_R_FIRST_BAD_LINE], CG_BAD_LINE, ctr)
60 gv_check_eq("kinds-listed-once-each" as *u8, rep[CRES_R_KINDS], CG_KINDS, ctr)
61 gv_check_eq("click-to-open-images-counted" as *u8, rep[CRES_R_CLICK], CG_CLICK, ctr)
62 gv_check_eq("withheld-images-counted" as *u8, rep[CRES_R_GATED], CG_GATED, ctr)
63 gv_check_eq("the-undeclared-class-is-counted-as-unknown" as *u8, rep[CRES_R_UNKNOWN], 1, ctr)
64 gv_check_eq("the-image-partition-sums-to-the-live-rows" as *u8, rep[CRES_R_OPEN] + rep[CRES_R_CLICK] + rep[CRES_R_GATED], CG_LIVE, ctr)
65 gv_check_eq("no-media-tag-sits-outside-a-reveal-block" as *u8, rep[CRES_R_BARE], 0, ctr)
66 gv_check_eq("neg-control-a-withheld-href-never-reaches-the-page" as *u8, cg_has(out, hn, "SECRET" as *u8), 0, ctr)
67 gv_check_eq("neg-control-the-superseded-row-is-not-on-the-page" as *u8, cg_has(out, hn, "OLD ROW" as *u8), 0, ctr)
68 gv_check_eq("an-adult-item-puts-the-rating-meta-in-the-head" as *u8, cg_has(out, hn, "<meta name=\"rating\" content=\"adult\">" as *u8), 1, ctr)
69 gv_check_eq("neg-control-script-text-in-a-title-is-escaped" as *u8, cg_has(out, hn, "<script>" as *u8), 0, ctr)
70 gv_check_eq("the-report-link-is-carried" as *u8, cg_has(out, hn, "href=\"/report/fit\"" as *u8), 1, ctr)
71 gv_check_eq("images-are-lazy-inside-the-closed-block" as *u8, cg_has(out, hn, "loading=\"lazy\"" as *u8), 1, ctr)
72 gv_check_eq("a-synthetic-render-says-so-in-a-machine-readable-place" as *u8, cg_has(out, hn, "data-digital-source-type=\"algorithmicMedia\"" as *u8), 1, ctr)
73 let page_bytes: i64 = hn
74 let click_n: i64 = rep[CRES_R_CLICK]
75 // a page with no adult item carries no rating meta
76 let hg: i64 = cres_render(CG_DOM, CG_GENERAL, rvl_slen(CG_GENERAL), nofile, 0, out, CG_PAGE_CAP, rep)
77 gv_check("a-general-page-renders" as *u8, (hg > 0) as i64, ctr)
78 gv_check_eq("neg-control-a-general-page-carries-no-rating-meta" as *u8, cg_has(out, hg, "name=\"rating\"" as *u8), 0, ctr)
79 // refusals
80 gv_check_eq("neg-control-a-tiny-buffer-refuses-instead-of-truncating" as *u8, cres_render(CG_DOM, CG_FIXTURE, rvl_slen(CG_FIXTURE), nofile, 0, out, CG_TINY_CAP, rep), CRES_E_OVERFLOW, ctr)
81 gv_check_eq("neg-control-prose-without-rows-refuses" as *u8, cres_render(CG_DOM, CG_PROSE_ONLY, rvl_slen(CG_PROSE_ONLY), nofile, 0, out, CG_PAGE_CAP, rep), CRES_E_NOROWS, ctr)
82 // the verifier fires on a planted bare image and acquits a covered one
83 let arep: *i64 = sys_mmap(RVL_A_N * CRES_I64) as *i64
84 gv_check_eq("the-audit-fires-on-a-planted-bare-image" as *u8, rvl_audit(CG_BARE_PAGE, rvl_slen(CG_BARE_PAGE), arep), 1, ctr)
85 gv_check_eq("the-audit-acquits-an-image-inside-a-reveal-block" as *u8, rvl_audit(CG_COVERED_PAGE, rvl_slen(CG_COVERED_PAGE), arep), 0, ctr)
86 gv_check_eq("and-counts-it-as-covered" as *u8, arep[RVL_A_COVERED], 1, ctr)
87 gv_values_head()
88 gv_kv("fixture_page_bytes" as *u8, page_bytes); gv_kv("fixture_click_images" as *u8, click_n); gv_kv("general_page_bytes" as *u8, hg)
89 return gv_verdict("nx_compare_results_gate" as *u8, ctr, "one results page per board over planted rows, with the click-to-open policy held in both directions" as *u8)
90}