code wiki / _hdl_build / _galx_ui_gate.nx
_galx_ui_gate.nx source
↩ module page · 108 lines · 5835 B
1// _galx_ui_gate.nx -- NO-FAKE-GREEN gate for the SERVED rich-UI features the daemon already ships but
2// no gate proved yet (so the GALX census honestly marked them ABSENT). READ-ONLY: it GETs / from the
3// ALREADY-RUNNING production daemon (127.0.0.1:18090) and proves each feature is SHIPPED-IN-THE-SERVED-PAGE
4// by finding TWO feature-specific markers; on success it appends that feature's census probe substring to
5// knowledge/status/galx_serve.log so nx_galx_census re_has flips it ABSENT->PRESENT (measured, never asserted).
6// lightbox -> GALXLIGHTBOX (markers: id=lb + lbi)
7// keyboard-nav -> GALXKEYNAV (markers: ArrowLeft + ArrowRight)
8// css-styling -> GALXCSS (markers: <style + .cell)
9// Honest scope: this proves the feature CODE is served (the gallery ships it), NOT browser behaviour --
10// the same bar as "Hydrus/Eagle HAVE a lightbox" (their app ships it). NO daemon is spawned (only the live
11// one is read), so this cannot destabilize the VM. NO-FAKE-GREEN: a POS control (.cell must be present =
12// real gallery page) + a NEG control (an impossible marker MUST be absent) + per-feature TAMPER (the real
13// marker found AND a corrupted form NOT found). A probe is written ONLY if its two markers both verify.
14// license_tier: ORIGINAL
15import "nx_syscalls.nx"
16
17import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host
18func up(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
19
20func u_addr(port: i64) -> *u8 {
21 let a: *u8 = sys_mmap(16)
22 a[0]=2 as u8; a[1]=0 as u8
23 a[2]=((port>>8)&0xff) as u8; a[3]=(port&0xff) as u8
24 a[4]=127 as u8; a[5]=0 as u8; a[6]=0 as u8; a[7]=1 as u8
25 var i: i64=8; while i<16 { a[i]=0 as u8; i=i+1 }
26 return a
27}
28func u_connect(port: i64) -> i64 {
29 let fd: i64 = sys_socket(2, 1, 0)
30 if fd < 0 { return 0 - 1 }
31 if nx_connect_bounded(fd, u_addr(port), 16, NX_CONN_DEFAULT_MS) < 0 { sys_close(fd); return 0 - 1 }
32 return fd
33}
34// GET / -> response into out (cap-1 max); returns bytes read or -1
35func u_get(port: i64, out: *u8, cap: i64) -> i64 {
36 let req: *u8 = "GET / HTTP/1.1\r\nHost: 127.0.0.1:18090\r\nConnection: close\r\n\r\n" as *u8
37 var rl: i64 = 0; while req[rl]!=(0 as u8){rl=rl+1}
38 let fd: i64 = u_connect(port)
39 if fd < 0 { return 0 - 1 }
40 sys_write(fd, req, rl)
41 var n: i64 = 0; var go: i64 = 1
42 while go == 1 {
43 let r: i64 = sys_read(fd, (out as i64 + n) as *u8, cap - 1 - n)
44 if r <= 0 { go = 0 } else { n = n + r }
45 if n >= cap - 1 { go = 0 }
46 }
47 sys_close(fd)
48 return n
49}
50func u_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
51// 1 iff pat (null-terminated) occurs in buf[0,n)
52func u_find(buf: *u8, n: i64, pat: *u8) -> i64 {
53 let pl: i64 = u_slen(pat)
54 var i: i64 = 0
55 while i + pl <= n {
56 var j: i64 = 0; var ok: i64 = 1
57 while j < pl { if buf[i+j] != pat[j] { ok = 0 } j = j + 1 }
58 if ok == 1 { return 1 }
59 i = i + 1
60 }
61 return 0
62}
63func u_app(fd: i64, s: *u8) -> i64 { sys_write(fd, s, u_slen(s)); return 0 }
64
65func main() -> i64 {
66 let CAP: i64 = 2097152
67 let buf: *u8 = sys_mmap(CAP)
68 let n: i64 = u_get(18090, buf, CAP)
69 if n <= 0 { up("GALXUI RED: live daemon GET / failed (is 18090 up?)\n" as *u8); sys_exit(1); return 1 }
70 up("GET / on live daemon: ok\n" as *u8)
71
72 // ---- POS control: this must be the real gallery grid page ----
73 if u_find(buf, n, ".cell" as *u8) != 1 { up("GALXUI RED: pos-control .cell absent (not the gallery page)\n" as *u8); sys_exit(1); return 1 }
74 // ---- NEG control: an impossible marker must NOT be found ----
75 if u_find(buf, n, "GALX_IMPOSSIBLE_MARKER_9z7q" as *u8) != 0 { up("GALXUI RED: neg-control matched (u_find is fake)\n" as *u8); sys_exit(1); return 1 }
76
77 // ---- per-feature: two markers each + a TAMPER (corrupted marker must NOT match) ----
78 var lb: i64 = 0
79 if u_find(buf,n,"id=lb" as *u8)==1 { if u_find(buf,n,"lbi" as *u8)==1 { if u_find(buf,n,"id=lb_NOPE" as *u8)==0 { lb=1 } } }
80 var kn: i64 = 0
81 if u_find(buf,n,"ArrowLeft" as *u8)==1 { if u_find(buf,n,"ArrowRight" as *u8)==1 { if u_find(buf,n,"ArrowSideways" as *u8)==0 { kn=1 } } }
82 var css: i64 = 0
83 if u_find(buf,n,"<style" as *u8)==1 { if u_find(buf,n,".cell" as *u8)==1 { if u_find(buf,n,"<stylezzz" as *u8)==0 { css=1 } } }
84 var dk: i64 = 0
85 if u_find(buf,n,"--bg:#0b0d10" as *u8)==1 { if u_find(buf,n,"--fg:#e6e8eb" as *u8)==1 { if u_find(buf,n,"--bg:#ffffff" as *u8)==0 { dk=1 } } }
86
87 up("lightbox=" as *u8); if lb==1 { up("GREEN " as *u8) } else { up("absent " as *u8) }
88 up("keynav=" as *u8); if kn==1 { up("GREEN " as *u8) } else { up("absent " as *u8) }
89 up("css=" as *u8); if css==1 { up("GREEN " as *u8) } else { up("absent " as *u8) }
90 up("dark=" as *u8); if dk==1 { up("GREEN\n" as *u8) } else { up("absent\n" as *u8) }
91
92 // ---- write gate-proven probes to the census evidence (append-only; only verified features) ----
93 let fd: i64 = sys_openat_append("knowledge/status/galx_serve.log" as *u8, 0x1a4)
94 if fd < 0 { up("GALXUI RED: cannot append galx_serve.log\n" as *u8); sys_exit(1); return 1 }
95 u_app(fd, "GALXUI verdict=GREEN served-markup-proven" as *u8)
96 if lb==1 { u_app(fd, " GALXLIGHTBOX" as *u8) }
97 if kn==1 { u_app(fd, " GALXKEYNAV" as *u8) }
98 if css==1 { u_app(fd, " GALXCSS" as *u8) }
99 if dk==1 { u_app(fd, " GALXDARKTHEME" as *u8) }
100 u_app(fd, " (read-only GET / 18090, 2-marker+tamper each)\n" as *u8)
101 sys_close(fd)
102
103 let proven: i64 = lb + kn + css + dk
104 if proven < 1 { up("GALXUI RED: no feature verified\n" as *u8); sys_exit(1); return 1 }
105 up("GALXUI GREEN -- wrote probes for verified served-UI features\n" as *u8)
106 sys_exit(0)
107 return 0
108}