code wiki / _hdl_build / nx_video_sniff_api_gate.nx

nx_video_sniff_api_gate.nx source

↩ module page · 66 lines · 3666 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_video_sniff_api_gate.nx -- proves the API layer: the sniff result formats as a JSON API response and a 4// `?url=` request query parses (URL-decoded). This is the contract a daemon route / MCP tool returns + reads. license_tier: ORIGINAL expect_exit: 0 5import "nx_syscalls.nx" 6import "nx_js_eval.nx" 7import "nx_media_jsexec.nx" 8import "nx_video_sniff.nx" 9import "nx_gate_verdict.nx" 10 11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 12" as *u8); return ok } 13func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 14func streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while 1==1 { let x: i64=a[i]&0xff; let y: i64=b[i]&0xff; if x!=y { return 0 } if x==0 { return 1 } i=i+1 } return 0 } 15 16func chk_json(kind: i64, plan: *u8, want: *u8) -> i64 { 17 let out: *u8 = sys_mmap(2560) 18 vs_result_json(kind, plan, out, 2560) 19 if streq(out, want) == 1 { return 1 } 20 gw(" got=[" as *u8); gw(out); gw("]\n" as *u8); return 0 21} 22func chk_query(q: *u8, want: *u8) -> i64 { 23 let out: *u8 = sys_mmap(2048) 24 vs_query_url(q, gsl(q), out, 2048) 25 if streq(out, want) == 1 { return 1 } 26 gw(" got=[" as *u8); gw(out); gw("]\n" as *u8); return 0 27} 28 29func main() -> i64 { 30 gw("video-sniff API gate (result -> JSON + request ?url= -> decoded)\n" as *u8) 31 var pass: i64 = 0 32 var ttl: i64 = 0 33 34 // --- result -> JSON --- 35 ttl=ttl+1; pass=pass+grow("J1 hls -> found+route+url\x00" as *u8, 36 chk_json(VSK_HLS, "ROUTE=hls URL=https://cdn/x.m3u8" as *u8, "{\"found\":true,\"route\":\"hls\",\"url\":\"https://cdn/x.m3u8\"}" as *u8)) 37 ttl=ttl+1; pass=pass+grow("J2 none -> found:false url:null\x00" as *u8, 38 chk_json(VSK_NONE, "ROUTE=none URL=-" as *u8, "{\"found\":false,\"route\":\"none\",\"url\":null}" as *u8)) 39 ttl=ttl+1; pass=pass+grow("J3 guard-killed -> found:false\x00" as *u8, 40 chk_json(VSK_KILLED, "ROUTE=guard-killed URL=- (runaway)" as *u8, "{\"found\":false,\"route\":\"guard-killed\",\"url\":null}" as *u8)) 41 ttl=ttl+1; pass=pass+grow("J4 direct -> found+mp4\x00" as *u8, 42 chk_json(VSK_DIRECT, "ROUTE=direct URL=https://c/v.mp4" as *u8, "{\"found\":true,\"route\":\"direct\",\"url\":\"https://c/v.mp4\"}" as *u8)) 43 // --- request ?url= parse (URL-decoded) --- 44 ttl=ttl+1; pass=pass+grow("Q1 percent-decode https%3A%2F%2F...\x00" as *u8, 45 chk_query("url=https%3A%2F%2Fx.com%2Fp%2Fm.m3u8" as *u8, "https://x.com/p/m.m3u8" as *u8)) 46 ttl=ttl+1; pass=pass+grow("Q2 url= amid other params\x00" as *u8, 47 chk_query("foo=1&url=https://a.b/c&bar=2" as *u8, "https://a.b/c" as *u8)) 48 ttl=ttl+1; pass=pass+grow("Q3 '+' -> space\x00" as *u8, 49 chk_query("url=a+b+c" as *u8, "a b c" as *u8)) 50 ttl=ttl+1 51 let q4o: *u8 = sys_mmap(2048) 52 let q4q: *u8 = "noturl=1&x=2" as *u8 53 let q4n: i64 = vs_query_url(q4q, gsl(q4q), q4o, 2048) 54 pass=pass+grow("Q4 no url param -> empty (len 0)\x00" as *u8, (q4n == 0) as i64) 55 56 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 57 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 58 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 59 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 60 let ctr__dry: *i64 = gv_ctr() 61 ctr__dry[0] = pass 62 ctr__dry[1] = ttl 63 let rc__dry: i64 = gv_verdict("VIDEO-SNIFF-API-GATE" as *u8, ctr__dry, "sniff result -> JSON API response + request ?url= parsing)" as *u8) 64 sys_exit(rc__dry) 65 return rc__dry 66}