code wiki / (root) / nx_teacher_gate.nx

nx_teacher_gate.nx source

↩ module page · 55 lines · 2456 B

1// nx_teacher_gate.nx -- gate the NISHI TEACHER lesson processor. 2// (a) a VALID fixture (all required sections; 2 cardinals, 3 drills, 1 evidence) -> OK 3// (b) a NEG-CONTROL fixture (missing ## DRILLS) -> REJECTED (NX_TEACH_MISSING) 4// (c) a missing file -> NX_TEACH_NO_FILE 5// Exit 0 GREEN / 1 RED. Log knowledge/status/teacher_gate.log. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_teacher.nx" 8import "nx_teacher_lesson.nx" // nx_teacher_ingest -- the lesson organ the 2026-07-21 dedupe deleted 9 10func gp(fd: i64, s: *u8) -> i64 { 11 var n: i64 = 0 12 while s[n] != (0 as u8) { n = n + 1 } 13 sys_write(1, s, n); if fd > 0 { sys_write(fd, s, n) } 14 return 0 15} 16func gn(fd: i64, v: i64) -> i64 { 17 let bb: *u8 = sys_mmap(28); var m: i64 = v 18 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if fd > 0 { sys_write(fd, "-\x00" as *u8, 1) } m = 0 - m } 19 let t: *u8 = sys_mmap(28); var k: i64 = 0 20 if m == 0 { t[0] = 48 as u8; k = 1 } 21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 22 var i: i64 = 0 23 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 24 sys_write(1, bb, k); if fd > 0 { sys_write(fd, bb, k) } 25 return 0 26} 27 28func main() -> i64 { 29 let fd: i64 = sys_openat_append("knowledge/status/teacher_gate.log\x00" as *u8, 0x1a4) 30 gp(fd, "NX-TEACHER-GATE\n\x00" as *u8) 31 var ok: i64 = 1 32 33 let rv: i64 = nx_teacher_ingest("knowledge/lessons/_kat_valid.md\x00" as *u8, "kat-valid\x00" as *u8, "test\x00" as *u8) 34 gp(fd, " valid fixture verdict=\x00" as *u8); gn(fd, rv); gp(fd, " (expect 0)\n\x00" as *u8) 35 if rv != 0 { ok = 0 } 36 37 let ri: i64 = nx_teacher_ingest("knowledge/lessons/_kat_invalid.md\x00" as *u8, "kat-invalid\x00" as *u8, "test\x00" as *u8) 38 gp(fd, " invalid(no DRILLS) verdict=\x00" as *u8); gn(fd, ri); gp(fd, " (expect -3 MISSING)\n\x00" as *u8) 39 if ri != (0 - 3) { ok = 0 } 40 41 let rm: i64 = nx_teacher_ingest("knowledge/lessons/_does_not_exist.md\x00" as *u8, "kat-missing\x00" as *u8, "test\x00" as *u8) 42 gp(fd, " missing file verdict=\x00" as *u8); gn(fd, rm); gp(fd, " (expect -1 NO_FILE)\n\x00" as *u8) 43 if rm != (0 - 1) { ok = 0 } 44 45 if ok == 1 { 46 gp(fd, "NX-TEACHER-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 47 if fd > 0 { sys_close(fd) } 48 sys_exit(0) 49 return 0 50 } 51 gp(fd, "NX-TEACHER-GATE result=FAIL verdict=RED\n\x00" as *u8) 52 if fd > 0 { sys_close(fd) } 53 sys_exit(1) 54 return 1 55}