code wiki / _hdl_build / nx_torrent_shell_gate.nx
nx_torrent_shell_gate.nx source
↩ module page · 54 lines · 3919 B
1// nx_torrent_shell_gate.nx -- referee for the R4a Nishi-emitted /torrent frontend. PROVES the emitted markup
2// carries the required elements: title, the DESTINATION selector (media=SFW / gallery=NSFW), the area-aware
3// add (POST /torrent/api/add with area=), the status poll, and the watch/stream player. GREEN iff all present.
4// Prints verdict=GREEN to STDOUT *and* returns the exit code. Durable -> knowledge/status/torrent_shell_gate.log.
5// license_tier: ORIGINAL
6import "nx_torrent_shell.nx"
7import "nx_syscalls.nx"
8
9func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); 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}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
11func g_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
12func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); 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}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
13func has(buf: *u8, n: i64, pat: *u8) -> i64 {
14 var pl: i64=0; while pat[pl]!=(0 as u8){pl=pl+1}
15 if pl<=0 { return 0 }
16 var i: i64=0
17 while i + pl <= n { var j: i64=0; var m: i64=1; while j<pl { if buf[i+j]!=pat[j] {m=0;j=pl} else {j=j+1} } if m==1 { return 1 } i=i+1 }
18 return 0
19}
20func chk(got: i64, want: i64, label: *u8) -> i64 {
21 g_puts(" "); g_puts(label); g_puts(" got="); g_num(got); g_puts(" want="); g_num(want)
22 if got == want { g_puts(" PASS\n"); return 1 }
23 g_puts(" FAIL\n"); return 0
24}
25
26func main() -> i64 {
27 g_puts("=== TORRENT SHELL GATE (R4a: Nishi-emitted /torrent frontend) ===\n" as *u8)
28 var pass: i64=0
29 var rows: i64=0
30 let buf: *u8 = sys_mmap(65536); let n: i64 = ts_emit(buf)
31
32 rows=rows+1; if n > 1200 { pass=pass+1; g_puts(" emitted length>1200 got="); g_num(n); g_puts(" PASS\n" as *u8) } else { g_puts(" emitted length>1200 got="); g_num(n); g_puts(" FAIL\n" as *u8) }
33 rows=rows+1; pass=pass+chk(has(buf, n, "<title>Nishi Torrent" as *u8), 1, "title 'Nishi Torrent'" as *u8)
34 rows=rows+1; pass=pass+chk(has(buf, n, "id=area" as *u8), 1, "destination selector present" as *u8)
35 rows=rows+1; pass=pass+chk(has(buf, n, "value=media" as *u8), 1, " -> media (SFW) option" as *u8)
36 rows=rows+1; pass=pass+chk(has(buf, n, "value=gallery" as *u8), 1, " -> gallery (NSFW) option" as *u8)
37 rows=rows+1; pass=pass+chk(has(buf, n, "/torrent/api/add" as *u8), 1, "add endpoint" as *u8)
38 rows=rows+1; pass=pass+chk(has(buf, n, "&area=" as *u8), 1, " -> add posts the area flag" as *u8)
39 rows=rows+1; pass=pass+chk(has(buf, n, "/torrent/api/status" as *u8), 1, "status poll" as *u8)
40 rows=rows+1; pass=pass+chk(has(buf, n, "/torrent/stream/" as *u8), 1, "watch/stream endpoint" as *u8)
41 rows=rows+1; pass=pass+chk(has(buf, n, "<video" as *u8), 1, "video player element" as *u8)
42 rows=rows+1; pass=pass+chk(has(buf, n, "403" as *u8), 1, "handles area-denied (403) honestly" as *u8)
43
44 g_puts("----\nTORRENT-SHELL-GATE rows=" as *u8); g_num(rows); g_puts(" pass=" as *u8); g_num(pass)
45 if pass==rows { g_puts(" verdict=GREEN\n" as *u8) } else { g_puts(" verdict=RED\n" as *u8) }
46 let lg: i64=sys_openat_append("knowledge/status/torrent_shell_gate.log" as *u8, 0x1a4)
47 if lg>=0 {
48 g_w(lg, "TORRENT-SHELL-GATE rows=" as *u8); g_wn(lg, rows); g_w(lg, " pass=" as *u8); g_wn(lg, pass)
49 if pass==rows { g_w(lg, " verdict=GREEN\n" as *u8) } else { g_w(lg, " verdict=RED\n" as *u8) }
50 sys_close(lg)
51 }
52 if pass==rows { sys_exit(0); return 0 }
53 sys_exit(1); return 1
54}