code wiki / (root) / nx_task_gate.nx

nx_task_gate.nx source

↩ module page · 41 lines · 2502 B

1// nx_task_gate.nx -- proves MCP Tasks parity on real seg_store (test prefix): dispatch a task, POLL it through 2// pending -> running -> done, retrieve the RESULT, and confirm the payload survives the transitions (additive history). 3// license_tier: ORIGINAL 4import "nx_task.nx" 5import "nx_gate.nx" 6 7func streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } 8 9func main() -> i64 { 10 gw("=== nx_task_gate: sovereign dispatch + poll + result (MCP Tasks parity) ===\n" as *u8) 11 let TP: *u8 = "knowledge/taskq-test-" as *u8 12 let sbuf: *u8 = sys_mmap(64) 13 var pass: i64=0; var tot: i64=0 14 15 task_dispatch_pfx(TP, "t1" as *u8, "compress-archive-2003" as *u8) 16 task_status_pfx(TP, "t1" as *u8, sbuf) 17 tot=tot+1; if streq(sbuf, "pending" as *u8)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 18 gw("T1 dispatch -> poll status=pending (got a handle)\n" as *u8) 19 20 task_set_pfx(TP, "t1" as *u8, "running" as *u8, "" as *u8) 21 task_status_pfx(TP, "t1" as *u8, sbuf) 22 tot=tot+1; if streq(sbuf, "running" as *u8)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 23 gw("T2 worker picks it up -> poll status=running\n" as *u8) 24 25 task_set_pfx(TP, "t1" as *u8, "done" as *u8, "cid=615990068" as *u8) 26 task_status_pfx(TP, "t1" as *u8, sbuf) 27 tot=tot+1; if streq(sbuf, "done" as *u8)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 28 gw("T3 worker finishes -> poll status=done\n" as *u8) 29 30 let po: *i64=sys_mmap(16) as *i64; let lo: *i64=sys_mmap(16) as *i64; let f2: *i64=sys_mmap(16) as *i64 31 task_get_pfx(TP, "t1" as *u8, po, lo) 32 tot=tot+1; if tr_field_eq(po[0] as *u8, lo[0], 3, "cid=615990068" as *u8, f2)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 33 gw("T4 RESULT retrievable (field 3)\n" as *u8) 34 35 tot=tot+1; if tr_field_eq(po[0] as *u8, lo[0], 2, "compress-archive-2003" as *u8, f2)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 36 gw("T5 payload preserved across pending->running->done transitions\n" as *u8) 37 38 gw("\n=== nx_task_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8) 39 if pass==tot { gw("TASK verdict=GREEN -- sovereign dispatch+poll+result on seg_store (MCP Tasks parity; async via nx_daemon)\n" as *u8); sys_exit(0); return 0 } 40 gw("TASK RED\n" as *u8); sys_exit(1); return 1 41}