nx_writer_probe.nx source
↩ module page · 35 lines · 2360 B
1// nx_writer_probe.nx -- sovereign one-shot probe of the LIVE nx_writer_serve (127.0.0.1:8098). Composes
2// nx_http_client (the same POST primitive as nx_writehub_seat) to prove the live API round-trip over the Nishi
3// ecosystem, no curl/shell. Probes BOTH endpoints (/score prose-scoring + /factcheck grounded fact-check) and
4// prints the server's real responses. license_tier: ORIGINAL
5import "nx_http_client.nx"
6import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host
7import "nx_gate.nx"
8const K_MAGIC_8098: i64 = 8098
9const K_MAGIC_65536: i64 = 65536
10const K_MAGIC_2097152: i64 = 2097152
11func wp_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12func wp_drain(fd: i64, buf: *u8, cap: i64) -> i64 { var off: i64=0; var go: i64=1; while go==1 { if off>=cap { go=0 } else { let r: i64=sys_read(fd, ((buf as i64)+off) as *u8, cap-off); if r<=0 { go=0 } else { off=off+r } } } return off }
13func wp_probe(path: *u8, pathlen: i64, body: *u8, label: *u8) -> i64 {
14 let addr: *u8 = sys_mmap(16)
15 nx_http_client_sockaddr_ipv4(addr, 127, 0, 0, 1, K_MAGIC_8098)
16 let fd: i64 = sys_socket(2, 1, 0)
17 if fd < 0 { gw("PROBE socket-fail\n" as *u8); return 2 }
18 if nx_connect_bounded(fd, addr, 16, NX_CONN_DEFAULT_MS) < 0 { sys_close(fd); gw("PROBE CONN-FAIL (writer not on :8098)\n" as *u8); return 2 }
19 let ct: *u8 = "text/plain" as *u8
20 let req: *u8 = sys_mmap(K_MAGIC_65536)
21 let reqlen: i64 = nx_http_client_build_request_post(path, pathlen, "localhost" as *u8, 9, ct, wp_strlen(ct), body, wp_strlen(body), req)
22 sys_write(fd, req, reqlen)
23 let buf: *u8 = sys_mmap(K_MAGIC_2097152)
24 let n: i64 = wp_drain(fd, buf, K_MAGIC_2097152)
25 sys_close(fd)
26 gw("=== " as *u8); gw(label); gw(" ===\n" as *u8)
27 sys_write(1, buf, n)
28 gw("\n" as *u8)
29 return 0
30}
31func main() -> i64 {
32 wp_probe("/score" as *u8, 6, "The door was opened slowly by the very frightened woman as she walked quietly and carefully through the extremely dark and absolutely silent hallway that seemed to stretch endlessly." as *u8, "LIVE POST 127.0.0.1:8098/score (weak fixture)" as *u8)
33 wp_probe("/factcheck" as *u8, 10, "narrative writing involves characters, scenes, and dialogue" as *u8, "LIVE POST 127.0.0.1:8098/factcheck (supported claim)" as *u8)
34 sys_exit(0); return 0
35}