code wiki / _hdl_build / nx_sniff_faillog_gate.nx

nx_sniff_faillog_gate.nx source

↩ module page · 56 lines · 3914 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_sniff_faillog_gate.nx -- verifies the daemon's FAILURE-LOGGING mechanism natively (no JS engine, so it's 4// unblocked by the sibling's in-flight nx_js_eval edit). Mirrors exactly what nx_media_sniff_daemon does on each 5// request: detect a MISS (`"found":false` in the JSON), append url+reason via xh_log, flush to a file, and (the 6// point) the file then holds the real-world failures that fuel auto-heal. A HIT (`"found":true`) is NOT logged. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_media_signal.nx" 10import "nx_extract_heal.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15// the daemon's exact miss-detector 16func dcontains(hay: *u8, hl: i64, needle: *u8) -> i64 { var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} if nl==0 { return 1 } var i: i64=0; let last: i64=hl-nl; while i<=last { var j: i64=0; var m: i64=1; while j<nl { if (hay[i+j]&0xff)!=(needle[j]&0xff) { m=0; j=nl } else { j=j+1 } } if m==1 { return 1 } i=i+1 } return 0 } 17 18func main() -> i64 { 19 gw("sniff-faillog SOVEREIGN gate (daemon failure-logging: miss -> log url+reason -> flush -> readback)\n" as *u8) 20 var pass: i64 = 0 21 var ttl: i64 = 0 22 let path: *u8 = "nx_faillog_test.log" as *u8 23 let miss_json: *u8 = "{\"found\":false,\"route\":\"none\",\"url\":null}" as *u8 24 let hit_json: *u8 = "{\"found\":true,\"route\":\"hls\",\"url\":\"https://cdn/master.m3u8\"}" as *u8 25 26 // F1: miss-detector fires on found:false, not on found:true (the daemon's guard) 27 ttl=ttl+1; pass=pass+grow("F1 dcontains detects found:false (miss)\x00" as *u8, dcontains(miss_json, gsl(miss_json), "\"found\":false" as *u8)) 28 ttl=ttl+1; pass=pass+grow("F2 dcontains does NOT fire on found:true (hit)\x00" as *u8, (dcontains(hit_json, gsl(hit_json), "\"found\":false" as *u8) == 0) as i64) 29 30 // F3: two real misses -> log url+reason each -> flush -> read the file back 31 let flog: *u8 = sys_mmap(1048576) 32 var off: i64 = 0 33 off = xh_log(flog, off, 1048576, "https://vk.com/video-220401040_456239479" as *u8, gsl("https://vk.com/video-220401040_456239479" as *u8), "none" as *u8) 34 off = xh_log(flog, off, 1048576, "https://site.example/watch/999" as *u8, gsl("https://site.example/watch/999" as *u8), "fetch-failed" as *u8) 35 xh_flush(path, flog, off) 36 // read it back 37 let fd: i64 = sys_openat_rd(path) 38 ttl=ttl+1; pass=pass+grow("F3 log file created + readable\x00" as *u8, (fd >= 0) as i64) 39 let rb: *u8 = sys_mmap(1048576) 40 var n: i64 = 0 41 if fd >= 0 { n = sys_read(fd, rb, 1048576); sys_close(fd) } 42 // F4: both failing URLs + their reasons persisted (this is the self-heal fuel) 43 var f4: i64 = 1 44 if dcontains(rb, n, "vk.com/video-220401040" as *u8) == 0 { f4 = 0 } 45 if dcontains(rb, n, "none" as *u8) == 0 { f4 = 0 } 46 if dcontains(rb, n, "site.example/watch/999" as *u8) == 0 { f4 = 0 } 47 if dcontains(rb, n, "fetch-failed" as *u8) == 0 { f4 = 0 } 48 ttl=ttl+1; pass=pass+grow("F4 both misses (url+reason) persisted to the file\x00" as *u8, f4) 49 // F5: the record is tab-separated url<TAB>reason<NL> (xh_log format = machine-parseable for the heal step) 50 ttl=ttl+1; pass=pass+grow("F5 records are TAB-delimited (parseable for xh_learn)\x00" as *u8, dcontains(rb, n, "\t" as *u8)) 51 52 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 53 gw("(failure log = the adversary corpus: an operator/critic reviews it, xh_learn feeds the table, extractor adapts)\n" as *u8) 54 if pass == ttl { gw("verdict=GREEN (daemon failure-logging captures real-world misses url+reason, durably, as self-heal fuel)\n" as *u8); sys_exit(0); return 0 } 55 gw("verdict=RED\n" as *u8); sys_exit(1); return 1 56}