code wiki / _hdl_build / nx_media_adapt_gate.nx
nx_media_adapt_gate.nx source
↩ module page · 73 lines · 4437 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_media_adapt_gate.nx -- proves the LIVE EXTRACTOR self-heals end-to-end. A page whose ONLY media URL sits
4// on a novel host with no extension + unseeded path (exactly what a site update looks like) is a MISS for the
5// default seeded orchestrator. After the adaptive table LEARNS that host (critic/adversary confirmed it's
6// media), the SAME orchestrator entry point extracts it -- and after persist->fresh-load it STILL extracts.
7// This is the wiring proof: healing isn't a side gadget, it's in the extraction path. license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9import "nx_media_signal.nx"
10import "nx_media_state.nx"
11import "nx_media_extract.nx"
12import "nx_extract_heal.nx"
13import "nx_gate_verdict.nx"
14
15func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
16" as *u8); return ok }
17func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
18
19func main() -> i64 {
20 gw("media-adapt SOVEREIGN gate (LIVE extractor: miss -> learn -> extracts -> persist -> fresh still extracts)\n" as *u8)
21 var pass: i64 = 0
22 var ttl: i64 = 0
23 let best: *u8 = sys_mmap(4096)
24 let kb: *i64 = sys_mmap(8) as *i64
25 // a page whose only media URL is a novel-host, extension-less stream (a site-update shape)
26 let page: *u8 = "<html><body><script>var s=\"https://cdn-x7.streamhost.net/deliver/vod/abc123\";player.load(s)</script></body></html>" as *u8
27 let plen: i64 = gsl(page)
28 let advurl: *u8 = "streamhost.net/deliver/vod/abc123" as *u8
29
30 // A1: DEFAULT orchestrator (fresh seed) MISSES it -- this is the failure a site change causes
31 let c1: i64 = mx_extract(page, plen, best, 4096, kb)
32 ttl=ttl+1; pass=pass+grow("A1 default orchestrator MISSES novel-host stream (conf 0)\x00" as *u8, (c1 == 0) as i64)
33
34 // A2: LEARN the host into a table, then the SAME entry point (mx_extract_t) EXTRACTS it
35 let t: *i64 = xh_new()
36 xh_seed(t)
37 xh_learn(t, "https://cdn-x7.streamhost.net/deliver/vod/abc123" as *u8, gsl("https://cdn-x7.streamhost.net/deliver/vod/abc123" as *u8), XT_DIRECT)
38 let c2: i64 = mx_extract_t(page, plen, best, 4096, kb, t)
39 var a2: i64 = 0
40 if c2 > 0 { if kb[0] == XT_DIRECT { if xt_has(best, gsl(best), advurl) == 1 { a2 = 1 } } }
41 ttl=ttl+1; pass=pass+grow("A2 after learn, live extractor RETURNS the stream (DIRECT)\x00" as *u8, a2)
42
43 // A3: persist -> FRESH load -> the SAME page still extracts (durable heal in the extraction path)
44 let path: *u8 = "/tmp/xh_live.tbl" as *u8
45 xh_save(t, path)
46 let t2: *i64 = xh_new()
47 let loaded: i64 = xh_load(t2, path)
48 let c3: i64 = mx_extract_t(page, plen, best, 4096, kb, t2)
49 var a3: i64 = 0
50 if loaded > 0 { if c3 > 0 { if kb[0] == XT_DIRECT { if xt_has(best, gsl(best), advurl) == 1 { a3 = 1 } } } }
51 ttl=ttl+1; pass=pass+grow("A3 persist->fresh-load: SAME page still extracts (durable)\x00" as *u8, a3)
52
53 // A4: an unrelated-host page is still a miss with the healed table (no over-generalization in the extractor)
54 let other: *u8 = "<script>var s=\"https://cdn.unrelated.net/thing/xyz\"</script>" as *u8
55 let c4: i64 = mx_extract_t(other, gsl(other), best, 4096, kb, t2)
56 ttl=ttl+1; pass=pass+grow("A4 unrelated-host page still MISS after heal (no over-generalize)\x00" as *u8, (c4 == 0) as i64)
57
58 // A5: seeded knowledge still works through the healed table (a plain .m3u8 page)
59 let hpage: *u8 = "<script>var u=\"https://c/master.m3u8\"</script>" as *u8
60 let c5: i64 = mx_extract_t(hpage, gsl(hpage), best, 4096, kb, t2)
61 ttl=ttl+1; pass=pass+grow("A5 seeded .m3u8 still extracts (HLS) via healed table\x00" as *u8, ((c5 > 0)) as i64 * ((kb[0] == XT_HLS) as i64))
62
63 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
64 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
65 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
66 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
67 let ctr__dry: *i64 = gv_ctr()
68 ctr__dry[0] = pass
69 ctr__dry[1] = ttl
70 let rc__dry: i64 = gv_verdict("MEDIA-ADAPT-GATE" as *u8, ctr__dry, "the extraction path itself adapts: a learned pattern turns a miss into a real extraction, durably)" as *u8)
71 sys_exit(rc__dry)
72 return rc__dry
73}