code wiki / _hdl_build / nx_work_pulse_test.nx

nx_work_pulse_test.nx source

↩ module page · 62 lines · 3128 B

1// nx_work_pulse_test.nx -- ENGINEER's gate for the standing work loop. A synthetic backlog file with 2// every row hazard (comments, prose without pipes, a DONE row, padded fields) must parse to exactly 3// the data rows; the gap pick must follow the Researcher's math (priority x under-coverage, NOT raw 4// priority); the directive line must carry the topic text verbatim. license_tier: ORIGINAL 5import "nx_work_pulse.nx" 6 7func wt_find(b: *u8, n: i64, s: *u8) -> i64 { 8 var i: i64 = 0 9 while i < n { 10 var k: i64 = 0 11 var ok: i64 = 1 12 while s[k] != (0 as u8) { 13 if i + k >= n { ok = 0 } 14 if ok == 1 { if b[i+k] != s[k] { ok = 0 } } 15 k = k + 1 16 } 17 if ok == 1 { return 1 } 18 i = i + 1 19 } 20 return 0 21} 22 23func main() -> i64 { 24 var pass: i64 = 0 25 let bp: *u8 = "/tmp/_wp_backlog_kat.txt" as *u8 26 let lp: *u8 = "/tmp/_wp_worknext_kat.log" as *u8 27 let f: i64 = sys_openat_wr(bp, 0x1a4) 28 if f < 0 { sys_exit(9) } 29 wp_w(f, "HEADER prose line, no pipes, must be skipped\n" as *u8) 30 wp_w(f, "# a comment | with | pipes | PENDING -- still skipped\n" as *u8) 31 wp_w(f, "alpha topic | 9 | 8 | PENDING\n" as *u8) // gap = 9*(10-8)/10 -> 1800 32 wp_w(f, "beta topic (deep) | 7 | 0 | PENDING\n" as *u8) // gap = 7*10/10 -> 7000 <- the pick 33 wp_w(f, "gamma topic | 9 | 9 | DONE\n" as *u8) // done -> never picked 34 wp_w(f, "broken row | only-two-pipes\n" as *u8) // malformed -> skipped 35 wp_w(f, "delta topic | 8 | 4 | PENDING\n" as *u8) // gap = 8*6/10 -> 4800 36 sys_close(f) 37 38 let out: *i64 = sys_mmap(64) as *i64 39 // KAT 1: the unit runs and writes a directive 40 if wp_run(bp, lp, out) == 1 { pass = pass + 1 } 41 // KAT 2: exactly the 4 data rows parsed (prose/comment/malformed skipped) 42 if out[0] == 4 { pass = pass + 1 } 43 // KAT 3: the pick is beta (highest GAP, not highest priority -- alpha has pri 9 but tiny gap) 44 if out[1] == 1 { pass = pass + 1 } 45 if out[2] == 7000 { pass = pass + 1 } 46 // KAT 4: progress = 1 done of 4 = 250 permil 47 if out[3] == 250 { pass = pass + 1 } 48 // KAT 5: the directive carries the topic text verbatim + the verdict 49 let lenp: *i64 = sys_mmap(16) as *i64 50 let lb: *u8 = sys_read_file(lp, lenp) 51 if wt_find(lb, lenp[0], "topic=beta topic (deep) priority=7 hits=0 gap=7000" as *u8) == 1 { pass = pass + 1 } 52 if wt_find(lb, lenp[0], "verdict=RESEARCH-NEXT" as *u8) == 1 { pass = pass + 1 } 53 // KAT 6: PRODUCTION -- the real backlog parses and yields a real directive 54 let rout: *i64 = sys_mmap(64) as *i64 55 if wp_run("knowledge/library/research_backlog.txt" as *u8, "knowledge/status/work_next.log" as *u8, rout) == 1 { pass = pass + 1 } 56 if rout[0] >= 20 { pass = pass + 1 } // the seed file's ~26 topics actually parsed 57 wp_w(1, "WORK PULSE KATs passed=" as *u8); wp_wn(1, pass); wp_w(1, "/9 (real backlog rows=" as *u8); wp_wn(1, rout[0]) 58 wp_w(1, " pick_gap=" as *u8); wp_wn(1, rout[2]); wp_w(1, ")\n" as *u8) 59 if pass == 9 { sys_exit(0) } 60 sys_exit(1) 61 return 1 62}