code wiki / _hdl_build / nx_archive_capture_gate.nx
nx_archive_capture_gate.nx source
↩ module page · 53 lines · 3527 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_archive_capture_gate.nx -- proves the extract->archive capture: a page whose media URL lives in embedded
4// state is captured -> the archive holds the page AND the media under the SAME URL the extractor found ->
5// simulate the origin vanishing -> the media is retrieved from the archive by that URL, byte-exact. This is the
6// link-rot workflow end to end (minus live network). license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_media_signal.nx"
9import "nx_web_archive.nx"
10import "nx_archive_capture.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 }
15func memeq(a: *u8, ao: i64, b: *u8, blen: i64) -> i64 { var i: i64=0; while i<blen { if (a[ao+i]&0xff)!=(b[i]&0xff) { return 0 } i=i+1 } return 1 }
16func streq(a: *u8, b: *u8) -> i64 { if gsl(a)!=gsl(b) { return 0 } var i: i64=0; while a[i]!=(0 as u8){ if (a[i]&0xff)!=(b[i]&0xff){return 0} i=i+1 } return 1 }
17
18func main() -> i64 {
19 gw("archive-capture SOVEREIGN gate (extract media from page -> archive page+media -> origin dies -> retrieve)\n" as *u8)
20 var pass: i64 = 0
21 var ttl: i64 = 0
22
23 // a page (from a soon-to-vanish site) with its media URL in embedded state
24 let page: *u8 = "<html><body><script>window.__NUXT__={\"video\":{\"url\":\"https://cdn.dead-host.example/v/42/1080.mp4\"}}</script></body></html>" as *u8
25 let page_url: *u8 = "https://dead-host.example/watch/42" as *u8
26 // the media bytes (binary, with embedded CRLF trap)
27 let media: *u8 = sys_mmap(32)
28 media[0]=77 as u8; media[1]=68 as u8; media[2]=65 as u8; media[3]=84 as u8; media[4]=13 as u8; media[5]=10 as u8; media[6]=0 as u8; media[7]=0xFF as u8; media[8]=90 as u8
29 let mlen: i64 = 9
30
31 let warc: *u8 = sys_mmap(1048576)
32 let murl: *u8 = sys_mmap(4096)
33 let off: i64 = ac_capture(page, gsl(page), page_url, "2026-07-11T00:00:00Z" as *u8, media, mlen, "video/mp4" as *u8, warc, 0, murl)
34
35 // C1: extractor found the media URL from the page's embedded state
36 ttl=ttl+1; pass=pass+grow("C1 capture extracted media URL from the page\x00" as *u8, streq(murl, "https://cdn.dead-host.example/v/42/1080.mp4" as *u8))
37 // C2: archive now holds 2 records (page + media)
38 ttl=ttl+1; pass=pass+grow("C2 archive holds page + media (2 records)\x00" as *u8, (wa_count(warc, off) == 2) as i64)
39
40 let op: *i64 = sys_mmap(8) as *i64; let ol: *i64 = sys_mmap(8) as *i64
41 // C3: ORIGIN DIED -- retrieve the media from the archive by the URL the search engine indexed, byte-exact
42 var c3: i64 = 0
43 if wa_lookup(warc, off, murl, gsl(murl), op, ol) == 1 { if ol[0]==mlen { if memeq(warc, op[0], media, mlen)==1 { c3 = 1 } } }
44 ttl=ttl+1; pass=pass+grow("C3 after origin dies: media served from archive by URL, byte-exact\x00" as *u8, c3)
45 // C4: the page itself is preserved too
46 var c4: i64 = 0
47 if wa_lookup(warc, off, page_url, gsl(page_url), op, ol) == 1 { if memeq(warc, op[0], page, gsl(page))==1 { c4 = 1 } }
48 ttl=ttl+1; pass=pass+grow("C4 the page is preserved too\x00" as *u8, c4)
49
50 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
51 if pass == ttl { gw("verdict=GREEN (capture: page's media extracted + archived under its URL -> survives the origin vanishing)\n" as *u8); sys_exit(0); return 0 }
52 gw("verdict=RED\n" as *u8); sys_exit(1); return 1
53}