code wiki / _hdl_build / nx_site_ingest_test.nx
nx_site_ingest_test.nx source
↩ module page · 92 lines · 5494 B
1// nx_site_ingest_test.nx -- ACCEPTANCE GATE for flag-ingestible-sites + full-site auto-ingest.
2// Exact KATs on robots permission, license detection, the ingest verdict, sitemap enumeration, the
3// starve-proof property, and a REAL write of a mirrored page into the local library.
4import "nx_site_ingest.nx"
5import "nx_syscalls.nx"
6
7func it_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func it_putn(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 }
9func it_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
10
11func main() -> i64 {
12 var pass: i64 = 0
13 var total: i64 = 0
14
15 // T1: robots "Disallow: /" forbids everything
16 total = total + 1
17 let r1: *u8 = "User-agent: *\nDisallow: /\n" as *u8
18 let p_any: *u8 = "/papers/1" as *u8
19 if si_robots_allows(r1, it_len(r1), p_any, it_len(p_any)) == 0 { pass = pass + 1 } else { it_puts("T1 FAIL disallow-all\n" as *u8) }
20
21 // T2: robots "Disallow: /private" allows /public, forbids /private
22 total = total + 1
23 let r2: *u8 = "User-agent: *\nDisallow: /private\n" as *u8
24 let p_pub: *u8 = "/public/doc" as *u8
25 let p_priv: *u8 = "/private/x" as *u8
26 var t2: i64 = 1
27 if si_robots_allows(r2, it_len(r2), p_pub, it_len(p_pub)) != 1 { t2 = 0 }
28 if si_robots_allows(r2, it_len(r2), p_priv, it_len(p_priv)) != 0 { t2 = 0 }
29 if t2 == 1 { pass = pass + 1 } else { it_puts("T2 FAIL prefix-disallow\n" as *u8) }
30
31 // T3: empty Disallow (allow all) + no robots
32 total = total + 1
33 let r3: *u8 = "User-agent: *\nDisallow:\n" as *u8
34 var t3: i64 = 1
35 if si_robots_allows(r3, it_len(r3), p_priv, it_len(p_priv)) != 1 { t3 = 0 } // empty disallow = allow
36 if si_robots_allows("" as *u8, 0, p_priv, it_len(p_priv)) != 1 { t3 = 0 } // no robots = allow
37 if t3 == 1 { pass = pass + 1 } else { it_puts("T3 FAIL empty-disallow\n" as *u8) }
38
39 // T4: open-access signal detection
40 total = total + 1
41 let oa: *u8 = "This article is open access under CC BY and mirrored on arXiv" as *u8
42 var t4: i64 = 1
43 if si_open_signals(oa, it_len(oa)) < 2 { t4 = 0 } // "open access" + "CC BY" + "arXiv" >= 2
44 let closed: *u8 = "All rights reserved. Subscription required." as *u8
45 if si_open_signals(closed, it_len(closed)) != 0 { t4 = 0 }
46 if t4 == 1 { pass = pass + 1 } else { it_puts("T4 FAIL openacc=" as *u8); it_putn(si_open_signals(oa,it_len(oa))); it_puts("\n" as *u8) }
47
48 // T5: ingest verdict -- allowed+licensed -> OK; allowed+repo -> OK; allowed+unclear -> PARTIAL; forbidden -> FORBIDDEN
49 total = total + 1
50 var t5: i64 = 1
51 if si_ingest_verdict(1, 3, 0) != SI_INGEST_OK { t5 = 0 }
52 if si_ingest_verdict(1, 0, 1) != SI_INGEST_OK { t5 = 0 }
53 if si_ingest_verdict(1, 0, 0) != SI_INGEST_PARTIAL { t5 = 0 }
54 if si_ingest_verdict(0, 9, 1) != SI_INGEST_FORBIDDEN { t5 = 0 } // robots wins -- never ingest if disallowed
55 if t5 == 1 { pass = pass + 1 } else { it_puts("T5 FAIL verdict\n" as *u8) }
56
57 // T6: flag good site + admissibility (OK + paced) ; forbidden or unpaced -> not admissible
58 total = total + 1
59 var t6: i64 = 1
60 if si_flag_good_site(SI_INGEST_OK) != 1 { t6 = 0 }
61 if si_flag_good_site(SI_INGEST_PARTIAL) != 0 { t6 = 0 }
62 if si_ingest_admissible(SI_INGEST_OK, 1) != 1 { t6 = 0 } // OK + paced -> ingest
63 if si_ingest_admissible(SI_INGEST_OK, 0) != 0 { t6 = 0 } // not paced -> refuse
64 if si_ingest_admissible(SI_INGEST_FORBIDDEN, 1) != 0 { t6 = 0 } // forbidden -> refuse
65 if t6 == 1 { pass = pass + 1 } else { it_puts("T6 FAIL admissible\n" as *u8) }
66
67 // T7: sitemap enumeration -- count <loc> URLs
68 total = total + 1
69 let sm: *u8 = "<urlset><url><loc>http://a/1</loc></url><url><loc>http://a/2</loc></url><url><loc>http://a/3</loc></url></urlset>" as *u8
70 if si_sitemap_url_count(sm, it_len(sm)) == 3 { pass = pass + 1 } else { it_puts("T7 FAIL sitemap=" as *u8); it_putn(si_sitemap_url_count(sm,it_len(sm))); it_puts("\n" as *u8) }
71
72 // T8: ingest progress + STARVE-PROOF -- partial not starve-proof; fully mirrored IS
73 total = total + 1
74 var t8: i64 = 1
75 if si_ingest_progress_permil(50, 200) != 250 { t8 = 0 }
76 if si_fully_mirrored(50, 200) != 0 { t8 = 0 }
77 if si_starve_proof(si_fully_mirrored(50, 200)) != 0 { t8 = 0 } // half-mirrored: live site can still starve us
78 if si_fully_mirrored(200, 200) != 1 { t8 = 0 }
79 if si_starve_proof(si_fully_mirrored(200, 200)) != 1 { t8 = 0 } // fully local: starve-proof
80 if t8 == 1 { pass = pass + 1 } else { it_puts("T8 FAIL starveproof\n" as *u8) }
81
82 // T9: REAL local-library write -- mirror a page to disk and confirm bytes
83 total = total + 1
84 let page: *u8 = "MIRRORED PAGE: Zeloof Z2 has 100 transistors at a 10 um node.\n" as *u8
85 let w: i64 = si_library_write("knowledge/library/mirror/_ingest_probe.txt" as *u8, page, it_len(page))
86 if w == it_len(page) { pass = pass + 1 } else { it_puts("T9 FAIL write=" as *u8); it_putn(w); it_puts("\n" as *u8) }
87
88 it_puts("SITE-INGEST " as *u8); it_putn(pass); it_puts("/" as *u8); it_putn(total); it_puts("\n" as *u8)
89 if pass == total { it_puts("SITE-INGEST ALL-PASS\n" as *u8); sys_exit(0) }
90 sys_exit(1)
91 return 1
92}