code wiki / (root) / nx_tg_mftotal_gate.nx

nx_tg_mftotal_gate.nx source

↩ module page · 26 lines · 1869 B

1// nx_tg_mftotal_gate.nx -- proves tg_multifile_total sums the info-dict "files" list correctly (the fix for 2// multi-file torrents stalling at 99%: the last partial piece was mis-sized as full plen because total fell 3// back to npc*plen). Builds a 2-file info-dict (100 + 50 = 150) and checks the sum. license_tier: ORIGINAL 4import "nx_torrent_get.nx" 5import "nx_gate_verdict.nx" 6 7func mt_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 8func mt_n(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0 {t[0]=48 as u8;k=1} while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1} let o: *u8=sys_mmap(28); var i: i64=0; while i<k {o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 9 10func main() -> i64 { 11 // info-dict with a "files" list: file1 length=100, file2 length=50 -> real total 150 12 let meta: *u8 = "d5:filesld6:lengthi100e4:pathl5:file1eed6:lengthi50e4:pathl5:file2eee4:name4:teste" as *u8 13 var msize: i64=0; while meta[msize]!=(0 as u8) { msize=msize+1 } 14 // npc=10, plen=64 -> npc*plen=640 would be the WRONG fallback; the real total is 150 15 let t: i64 = tg_multifile_total(meta, msize, 10, 64) 16 mt_p("TG-MFTOTAL-GATE authored=organ files_sum=" as *u8); mt_n(t); mt_p(" (expect 150; old-bug fallback would be 640)\n" as *u8) 17 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 18 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 19 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 20 let ctr__dry: *i64 = gv_ctr() 21 ctr__dry[0] = t 22 ctr__dry[1] = 150 23 let rc__dry: i64 = gv_verdict("TG-MFTOTAL-GATE" as *u8, ctr__dry, "multi-file total summed correctly -> last piece sizes right -> completes)" as *u8) 24 sys_exit(rc__dry) 25 return rc__dry 26}