code wiki / (root) / nx_tools_guidance_gate_t140.nx

nx_tools_guidance_gate_t140.nx source

↩ module page · 26 lines · 1711 B

1// Exercises canonical denial routing without minting credentials or editing the registry/allowlist. 2import "nx_tools_api.nx" 3func gh_case(req:*u8,presented:*u8,out:*u8)->i64{ 4 let n:i64=ta_handle(req,ta_slen(req),out) 5 if ta_indexof(out,n,"\"code\":-32001")<0{return 1} 6 if ta_indexof(out,n,presented)<0{return 2} 7 if ta_indexof(out,n,"management API POST /api/cap/mint allow=<tool>&confirm=yes")<0{return 3} 8 if ta_indexof(out,n,"optional days=<lifetime-days> and nonce=<positive-integer>")<0{return 4} 9 if ta_indexof(out,n,"public tools API origin, not the management API")<0{return 5} 10 if ta_indexof(out,n,"exp=<epoch>")>=0{return 6} 11 if ta_indexof(out,n,"\"exit_code\"")>=0{return 7} 12 return 0 13} 14func main()->i64{ 15 let out:*u8=sys_mmap(TA_MAGIC_1048576) as *u8 16 if (out as i64)<=0{return 3} 17 let absent:*u8="POST /mcp HTTP/1.1\r\nHost: x\r\nContent-Type: application/json\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"nx_comparestale\"}}" 18 let invalid:*u8="POST /mcp HTTP/1.1\r\nHost: x\r\nContent-Type: application/json\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\",\"params\":{\"name\":\"nx_comparestale\",\"_cap\":\"invalid-test-capability\"}}" 19 let a:i64=gh_case(absent,"\"presented\":0",out) 20 let b:i64=gh_case(invalid,"\"presented\":1",out) 21 let c:i64=gh_case(absent,"\"presented\":0",out) 22 sys_munmap(out,TA_MAGIC_1048576) 23 if a!=0||b!=0||c!=0{let bad:*u8="GUIDANCE GATE FAIL: canonical denial contract mismatch\n";sys_write(1,bad,ta_slen(bad));return 1} 24 let ok:*u8="GUIDANCE GATE PASS 3/3: absent, malformed, repeated; corrected mint and origin; no tool execution result\n" 25 if sys_write(1,ok,ta_slen(ok))!=ta_slen(ok){return 4};return 0 26}