code wiki / _hdl_build / nx_cdmap_interact_gate.nx

nx_cdmap_interact_gate.nx source

↩ module page · 135 lines · 8401 B

1// nx_cdmap_interact_gate.nx -- referee for the position map's INTERACTION DOOR (datavis DV8 cdp_interact, 2026-09-15). 2// The door is ONE inline script the compare base emits after the 2D cut: hover or focus reveals a mark's values, a legend 3// button toggles a player, dragging brushes a region whose players are listed and whose bounds are written into the URL 4// hash as the trace (cdsel=xlo,xhi,ylo,yhi in permil on the cut axes). This gate drives cdp_interact IN-PROCESS onto a 5// /tmp file and holds the emitted door to its contract: the fit domains and the plot frame it was handed are the numbers 6// in the script (so a brush converts pixels with the same domains the page drew with), the trace key is built from a 7// character code (the lexer forbids '#' and '!' in a literal, and the script must carry neither -- the neg-control counts 8// the bytes), the three interactions are wired, and the trace is re-applied on load. When the live search page is on 9// disk, its door is cross-checked structurally (buttons equal marks inside the cdmap svg, one script, one output), announced 10// through gv_kv and never gv_need. SCOPE STATED: a script executed by a browser is the oracle OUTSIDE the path; this gate 11// proves the door's STRUCTURE and its numbers, never that a browser ran it. license_tier: ORIGINAL 12import "nx_swcompare_lib.nx" 13import "nx_syscalls.nx" 14import "nx_gate_verdict.nx" 15 16const G_DIR: *u8 = "/tmp/nx_cdmap_interact_gate/" 17const G_OUT: *u8 = "/tmp/nx_cdmap_interact_gate/door.html" 18const G_LIVE_PAGE: *u8 = "sites/nishifamily/compare/search/index.html" 19const G_LIVE_API: *u8 = "sites/nishifamily/compare/search/api.json" 20const G_MODE_644: i64 = 420 21const G_DIR_MODE: i64 = 493 22const G_XLO: i64 = 700 23const G_XHI: i64 = 1000 24const G_YLO: i64 = 0 25const G_YHI: i64 = 350 26const G_STEP: i64 = 50 27const G_CH_HASH: i64 = 35 28const G_CH_BANG: i64 = 33 29const G_I64_BYTES: i64 = 8 30 31func g_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 32// occurrences of needle in buf[from..to) 33func g_count(buf: *u8, from: i64, to: i64, needle: *u8) -> i64 { 34 let nl: i64 = g_slen(needle) 35 if nl == 0 { return 0 } 36 var c: i64 = 0 37 var i: i64 = from 38 while i + nl <= to { 39 var k: i64 = 0 40 var ok: i64 = 1 41 while k < nl { if buf[i + k] != needle[k] { ok = 0; k = nl } else { k = k + 1 } } 42 if ok == 1 { c = c + 1; i = i + nl } else { i = i + 1 } 43 } 44 return c 45} 46func g_find(buf: *u8, from: i64, to: i64, needle: *u8) -> i64 { 47 let nl: i64 = g_slen(needle) 48 var i: i64 = from 49 while i + nl <= to { 50 var k: i64 = 0 51 var ok: i64 = 1 52 while k < nl { if buf[i + k] != needle[k] { ok = 0; k = nl } else { k = k + 1 } } 53 if ok == 1 { return i } 54 i = i + 1 55 } 56 return 0 - 1 57} 58func g_has(buf: *u8, n: i64, needle: *u8) -> i64 { if g_count(buf, 0, n, needle) > 0 { return 1 } return 0 } 59func g_count_byte(buf: *u8, n: i64, code: i64) -> i64 { var c: i64 = 0; var i: i64 = 0; while i < n { if (buf[i] as i64) == code { c = c + 1 } i = i + 1 } return c } 60 61func main() -> i64 { 62 let ctr: *i64 = gv_ctr() 63 gv_head("=== NX-CDMAP INTERACT GATE -- the position map's JS door: the fit domains and frame it carries, the hash-free trace key, the three interactions, the re-applied trace, and the live page's door structure ===" as *u8) 64 sys_mkdir(G_DIR, G_DIR_MODE) 65 let domx: *i64 = sys_mmap(CL_DOM_W * G_I64_BYTES) as *i64 66 let domy: *i64 = sys_mmap(CL_DOM_W * G_I64_BYTES) as *i64 67 domx[CL_D_LO] = G_XLO; domx[CL_D_HI] = G_XHI; domx[CL_D_STEP] = G_STEP 68 domy[CL_D_LO] = G_YLO; domy[CL_D_HI] = G_YHI; domy[CL_D_STEP] = G_STEP 69 let fd: i64 = sys_openat_wr(G_OUT, G_MODE_644) 70 gv_check("T0-fixture-file-opened" as *u8, (fd >= 0) as i64, ctr) 71 cdp_interact(fd, domx, domy) 72 sys_close(fd) 73 let nb: *i64 = sys_mmap(G_I64_BYTES * 2) as *i64 74 nb[0] = 0 75 let d: *u8 = sys_read_file(G_OUT, nb) 76 let n: i64 = nb[0] 77 gv_check("T1-door-written" as *u8, ((d as i64) != 0) as i64 * (n > 0) as i64, ctr) 78 gv_check_eq("T2-exactly-one-script-element" as *u8, g_count(d, 0, n, "<script>" as *u8) * 10 + g_count(d, 0, n, "</script>" as *u8), 11, ctr) 79 gv_check_eq("T2a-exactly-one-style-block" as *u8, g_count(d, 0, n, "<style>" as *u8), 1, ctr) 80 gv_check("T3-fit-domain-x-in-the-script" as *u8, g_has(d, n, "xlo:700" as *u8) * g_has(d, n, "xhi:1000" as *u8), ctr) 81 gv_check("T3a-fit-domain-y-in-the-script" as *u8, g_has(d, n, "ylo:0" as *u8) * g_has(d, n, "yhi:350" as *u8), ctr) 82 gv_check("T3b-plot-frame-is-the-emitter-padding" as *u8, g_has(d, n, "x0:70" as *u8) * g_has(d, n, "x1:730" as *u8) * g_has(d, n, "y0:30" as *u8) * g_has(d, n, "y1:460" as *u8), ctr) 83 gv_check("T4-trace-key-built-from-a-character-code" as *u8, g_has(d, n, "String.fromCharCode(35)" as *u8) * g_has(d, n, "cdsel=" as *u8), ctr) 84 gv_check_eq("T5-NEG-no-literal-hash-mark-in-the-door" as *u8, g_count_byte(d, n, G_CH_HASH), 0, ctr) 85 gv_check_eq("T5a-NEG-no-bang-in-the-door" as *u8, g_count_byte(d, n, G_CH_BANG), 0, ctr) 86 gv_check("T6-legend-toggle-wired" as *u8, g_has(d, n, "aria-pressed" as *u8) * g_has(d, n, ".cdleg" as *u8) * g_has(d, n, "style.display" as *u8), ctr) 87 gv_check("T7-hover-and-focus-reveal-the-title-values" as *u8, g_has(d, n, "pointerenter" as *u8) * g_has(d, n, "'focus'" as *u8) * g_has(d, n, "querySelector('title')" as *u8), ctr) 88 gv_check("T8-brush-wired-over-the-plot" as *u8, g_has(d, n, "pointerdown" as *u8) * g_has(d, n, "createSVGPoint" as *u8) * g_has(d, n, "replaceState" as *u8), ctr) 89 gv_check("T8a-brush-refuses-a-press-outside-the-frame" as *u8, g_has(d, n, "p.x<F.x0||p.x>F.x1||p.y<F.y0||p.y>F.y1" as *u8), ctr) 90 gv_check("T9-trace-re-applied-from-the-url-on-load" as *u8, g_has(d, n, "location.hash" as *u8) * g_has(d, n, "RegExp" as *u8), ctr) 91 gv_check("T10-door-is-optional-the-legend-reads-without-it" as *u8, g_has(d, n, ".cdleg[aria-pressed='false']" as *u8), ctr) 92 gv_check("T11-selection-names-players-and-bounds-in-permil" as *u8, g_has(d, n, "Selected '+sel.length+' of '" as *u8) * g_has(d, n, "px2x" as *u8) * g_has(d, n, "px2y" as *u8), ctr) 93 // the live page, when it is on disk: announced through gv_kv, never gv_need 94 var live_present: i64 = 0 95 var live_buttons: i64 = 0 - 1 96 var live_marks: i64 = 0 - 1 97 var live_scripts: i64 = 0 - 1 98 var live_outputs: i64 = 0 - 1 99 var live_api_door: i64 = 0 - 1 100 let pl: *i64 = sys_mmap(G_I64_BYTES * 2) as *i64 101 pl[0] = 0 102 let ph: *u8 = sys_read_file(G_LIVE_PAGE, pl) 103 if (ph as i64) != 0 { 104 live_present = 1 105 let pn: i64 = pl[0] 106 let s0: i64 = g_find(ph, 0, pn, "<svg class='cdmap'" as *u8) 107 var s1: i64 = 0 - 1 108 if s0 >= 0 { s1 = g_find(ph, s0, pn, "</svg>" as *u8) } 109 if s1 > s0 { 110 live_marks = g_count(ph, s0, s1, "<circle cx=" as *u8) 111 let f1: i64 = g_find(ph, s1, pn, "</figure>" as *u8) 112 if f1 > s1 { live_buttons = g_count(ph, s1, f1, "class='cdleg'" as *u8); live_outputs = g_count(ph, s1, f1, "<output class='cdsel'" as *u8) } 113 live_scripts = g_count(ph, 0, pn, "<script>" as *u8) 114 } 115 let al: *i64 = sys_mmap(G_I64_BYTES * 2) as *i64 116 al[0] = 0 117 let aj: *u8 = sys_read_file(G_LIVE_API, al) 118 if (aj as i64) != 0 { live_api_door = g_has(aj, al[0], "interact_door" as *u8) } 119 if live_marks > 0 { 120 gv_check_eq("T12-live-one-legend-button-per-mark" as *u8, live_buttons, live_marks, ctr) 121 gv_check_eq("T12a-live-one-output-for-the-selection" as *u8, live_outputs, 1, ctr) 122 gv_check("T12b-live-door-script-present" as *u8, (live_scripts >= 1) as i64, ctr) 123 gv_check_eq("T12c-live-api-announces-the-door" as *u8, live_api_door, 1, ctr) 124 } 125 } 126 gv_values_head() 127 gv_kv("door_bytes" as *u8, n) 128 gv_kv("live_present" as *u8, live_present) 129 gv_kv("live_marks" as *u8, live_marks) 130 gv_kv("live_buttons" as *u8, live_buttons) 131 gv_kv("live_scripts" as *u8, live_scripts) 132 gv_kv("live_outputs" as *u8, live_outputs) 133 gv_kv("live_api_door" as *u8, live_api_door) 134 return gv_verdict("nx_cdmap_interact_gate" as *u8, ctr, "the position map's JS door: its numbers, its hash-free trace key, the three interactions and the re-applied trace, with the live page's door structure when it is on disk" as *u8) 135}