code wiki / (root) / nx_dr_corpus_gate.nx

nx_dr_corpus_gate.nx source

↩ module page · 87 lines · 3893 B

1// nx_dr_corpus_gate.nx -- KAT + neg-control for the file-backed corpus mode (DR-9). 2// Reads REAL files off disk (this organ's own source and a sibling organ) rather than a 3// fixture string, proving: a real document is read+tokenized, a phrase actually present in 4// it is covered, a different file yields a different token count (so it is genuinely reading 5// the file), per-file discrimination works, reads are deterministic, and the FAIL-LOUD 6// neg-control -- a nonexistent path returns -1 instead of silently scoring zero coverage. 7// Run from the nxc2 CWD (nx_sov_build_run). DRY nx_gate_verdict lib. 8import "nx_dr_corpus.nx" 9import "nx_dr_run.nx" 10import "nx_dr_verify.nx" 11import "nx_gate_verdict.nx" 12 13func main() -> i64 { 14 let ctr: *i64 = gv_ctr() 15 gv_head("nx_dr_corpus -- file-backed corpus mode, real documents off disk (DR-9)") 16 17 // ---- read this organ's own source as a REAL document 18 let docA: *i64 = sys_mmap(8192 * 8) as *i64 19 let pa: *u8 = "runtime/nx_dr_corpus.nx" as *u8 20 let na: i64 = corp_tokenize_file(pa, docA, 8192) 21 22 var ok1: i64 = 0 23 if na > 200 { ok1 = 1 } 24 gv_check("T1 real file read and tokenized (>200 tokens)", ok1, ctr) 25 26 // ---- a phrase genuinely present in that file is covered 27 let ins1: *i64 = sys_mmap(16 * 8) as *i64 28 let s1: *u8 = "sovereign corpus" as *u8 29 let n1: i64 = drr_tokenize(s1, drr_strlen(s1), ins1, 16) 30 var ok2: i64 = 0 31 if dv_entail(ins1, n1, docA, na) == 1000 { ok2 = 1 } 32 gv_check("T2 phrase present in the real file is covered", ok2, ctr) 33 34 // ---- nonsense is not 35 let ins2: *i64 = sys_mmap(16 * 8) as *i64 36 let s2: *u8 = "zzqq xxvv" as *u8 37 let n2: i64 = drr_tokenize(s2, drr_strlen(s2), ins2, 16) 38 var ok3: i64 = 0 39 if dv_entail(ins2, n2, docA, na) == 0 { ok3 = 1 } 40 gv_check("T3 nonsense phrase not covered", ok3, ctr) 41 42 // ---- NEG-CONTROL: an unreadable path FAILS LOUD (-1), never a silent zero 43 let docX: *i64 = sys_mmap(64 * 8) as *i64 44 let px: *u8 = "runtime/definitely_not_a_real_file_zzz.nx" as *u8 45 let nx: i64 = corp_tokenize_file(px, docX, 64) 46 var ok4: i64 = 0 47 if nx == (0 - 1) { ok4 = 1 } 48 gv_check("T4 neg-control unreadable path fails loud (-1)", ok4, ctr) 49 50 // ---- determinism: reading the same file twice yields the same token count 51 let docA2: *i64 = sys_mmap(8192 * 8) as *i64 52 let na2: i64 = corp_tokenize_file(pa, docA2, 8192) 53 var ok5: i64 = 0 54 if na2 == na { if docA2[0] == docA[0] { ok5 = 1 } } 55 gv_check("T5 file read deterministic", ok5, ctr) 56 57 // ---- a DIFFERENT file yields a different token count (really reading the file) 58 let docB: *i64 = sys_mmap(8192 * 8) as *i64 59 let pb: *u8 = "runtime/nx_dr_run.nx" as *u8 60 let nb: i64 = corp_tokenize_file(pb, docB, 8192) 61 var ok6: i64 = 0 62 if nb > 100 { if nb != na { ok6 = 1 } } 63 gv_check("T6 different file gives different token count", ok6, ctr) 64 65 // ---- per-file discrimination: a term in file A but not file B 66 let ins3: *i64 = sys_mmap(16 * 8) as *i64 67 let s3: *u8 = "corpus" as *u8 68 let n3: i64 = drr_tokenize(s3, drr_strlen(s3), ins3, 16) 69 var ok7: i64 = 0 70 if dv_entail(ins3, n3, docA, na) == 1000 { if dv_entail(ins3, n3, docB, nb) == 0 { ok7 = 1 } } 71 gv_check("T7 per-file discrimination (term in A not B)", ok7, ctr) 72 73 // ---- the file-sourced coverage aggregates through the chain's subset logic 74 let cov: *i64 = sys_mmap(8 * 8) as *i64 75 cov[0] = 1; cov[1] = 0 76 let sel: *i64 = sys_mmap(8 * 8) as *i64 77 sel[0] = 0; sel[1] = 1 78 let out: *i64 = sys_mmap(8 * 8) as *i64 79 chain_sel_cov(cov, sel, 2, 1, out) 80 var ok8: i64 = 0 81 if out[0] == 0 { ok8 = 1 } 82 gv_check("T8 unselected source contributes no coverage", ok8, ctr) 83 84 let rc: i64 = gv_verdict("DR-CORPUS", ctr, "real file read+tokenize+discriminate, fail-loud neg-control") 85 sys_exit(rc) 86 return rc 87}