nx_catalog_coverage_adopt_t75.nx source
↩ module page · 78 lines · 5327 B
1// nx_catalog_coverage_adopt_t75.nx -- Tests journaling behavior by writing and reading structured data to a file in the Nishi ecosystem.
2import "nx_catalog_lib.nx"
3import "nx_gate_verdict.nx"
4const CT_MODE:i64=420
5func ct_write(path:*u8,b:*u8,n:i64)->i64 {
6 let fd:i64=sys_openat_wr(path,CT_MODE)
7 if fd<0{return -1}
8 let w:i64=sys_write(fd,b,n);let closed:i64=sys_close(fd)
9 if w!=n||closed!=0{return -1}
10 return 1
11}
12func ct_fd(path:*u8,cap:i64,lp:*i64,c:*i64)->*u8 {
13 let fd:i64=sys_openat_rd(path)
14 if fd<0{return 0 as *u8}
15 let out:*u8=cl_slurp_tail_fd(fd,cap,lp,c);sys_close(fd);return out
16}
17func main(argc:i64,argv:*i64)->i64 {
18 ep_anchor()
19 let ctr:*i64=gv_ctr();gv_head("CATALOG-COVERAGE-PRIVATE")
20 let lp:*i64=sys_mmap(8) as *i64
21 let c:*i64=sys_mmap(CLC_N*8) as *i64
22 let row:*u8="1789000000\tmcp\tnx_curveskel\tcall\tok\tretained\n"
23 let rn:i64=cl_slen(row)
24 let path:*u8="/tmp/nx_catalog_cov_t75_fixture.jrnl"
25 let missing:*u8=cl_slurp_tail_covered("/tmp/nx_catalog_cov_t75_definitely_absent.jrnl",lp,c)
26 gv_check("missing journal is explicit open failure not empty history",missing as i64==0&&c[CLC_STATE]==CLC_OPEN&&c[CLC_ERRNO]<0&&c[CLC_EXTENT]==-1&&lp[0]==0,ctr)
27 gv_check("empty fixture created",ct_write(path,row,0)==1,ctr)
28 let empty:*u8=cl_slurp_tail_covered(path,lp,c)
29 gv_check("empty existing journal is observed zero-byte window",empty as i64>0&&c[CLC_STATE]==CLC_OK&&c[CLC_EXTENT]==0&&c[CLC_START]==0&&c[CLC_END]==0&&lp[0]==0,ctr)
30 gv_check("short real fixture created",ct_write(path,row,rn)==1,ctr)
31 let short:*u8=cl_slurp_tail_covered(path,lp,c)
32 gv_check("short journal exact extent and current completed match",c[CLC_STATE]==CLC_OK&&c[CLC_EXTENT]==rn&&c[CLC_END]==rn&&c[CLC_READ]==rn&&c[CLC_HEAD]==0&&c[CLC_TAIL]==0&&lp[0]==rn&&cl_actlog_completed(short,lp[0],"nx_curveskel")==1,ctr)
33 let exact:*u8=ct_fd(path,rn,lp,c)
34 gv_check("exact window capacity preserves whole complete row",c[CLC_STATE]==CLC_OK&&c[CLC_START]==0&&lp[0]==rn&&cl_actlog_completed(exact,lp[0],"nx_curveskel")==1,ctr)
35 let edge:*u8=sys_mmap(rn+8);edge[0]=88 as u8;var i:i64=0
36 while i<rn{edge[i+1]=row[i];i=i+1}
37 gv_check("partial-head fixture created",ct_write(path,edge,rn+1)==1,ctr)
38 let partial:*u8=ct_fd(path,rn,lp,c)
39 gv_check("plausible complete row inside cut physical record never counts",c[CLC_START]==1&&c[CLC_HEAD]==rn&&lp[0]==0&&cl_actlog_completed(partial,lp[0],"nx_curveskel")==0,ctr)
40 edge[0]=10 as u8
41 gv_check("aligned-tail fixture created",ct_write(path,edge,rn+1)==1,ctr)
42 let aligned:*u8=ct_fd(path,rn,lp,c)
43 gv_check("tail beginning after newline retains current match",c[CLC_START]==1&&c[CLC_HEAD]==0&&lp[0]==rn&&cl_actlog_completed(aligned,lp[0],"nx_curveskel")==1,ctr)
44 gv_check("partial-trailing fixture created",ct_write(path,row,rn-1)==1,ctr)
45 let trailing:*u8=cl_slurp_tail_covered(path,lp,c)
46 gv_check("incomplete last record explicitly discarded",c[CLC_STATE]==CLC_OK&&c[CLC_TAIL]==rn-1&&lp[0]==0&&cl_actlog_completed(trailing,lp[0],"nx_curveskel")==0,ctr)
47 let big:*u8=sys_mmap(CL_BUF+rn+8)
48 i=0;while i<rn{big[i]=row[i];i=i+1}
49 while i<CL_BUF+rn{big[i]=10 as u8;i=i+1}
50 gv_check("historical outside real production tail fixture created",ct_write(path,big,CL_BUF+rn)==1,ctr)
51 let tail:*u8=cl_slurp_tail_covered(path,lp,c)
52 gv_check("actual production reader reports bounded offset and misses only current window",c[CLC_STATE]==CLC_OK&&c[CLC_EXTENT]==CL_BUF+rn&&c[CLC_START]==rn&&c[CLC_END]==CL_BUF+rn&&lp[0]==CL_BUF&&cl_actlog_completed(tail,lp[0],"nx_curveskel")==0,ctr)
53 let whole_n:*i64=sys_mmap(8) as *i64
54 let whole:*u8=sys_map_file(path,whole_n)
55 gv_check("same actual file retains earlier completed historical invocation",whole_n[0]==CL_BUF+rn&&cl_actlog_completed(whole,whole_n[0],"nx_curveskel")==1,ctr)
56 sys_munmap(whole,whole_n[0])
57 i=0;while i<rn{big[CL_BUF+i]=row[i];i=i+1}
58 gv_check("recent matching fixture created",ct_write(path,big,CL_BUF+rn)==1,ctr)
59 let recent:*u8=cl_slurp_tail_covered(path,lp,c)
60 gv_check("actual full-size tail finds new completed invocation",c[CLC_STATE]==CLC_OK&&cl_actlog_completed(recent,lp[0],"nx_curveskel")==1,ctr)
61 let writer:i64=sys_openat_wr(path,CT_MODE)
62 let wrote:i64=sys_write(writer,row,rn)
63 let bad:*u8=cl_slurp_tail_fd(writer,CL_BUF,lp,c)
64 gv_check("real write-only descriptor read error never becomes no-match evidence",writer>=0&&wrote==rn&&c[CLC_STATE]==CLC_READ_ERROR&&c[CLC_ERRNO]<0&&lp[0]==0,ctr)
65 sys_close(writer)
66 let closed:*u8=cl_slurp_tail_fd(writer,CL_BUF,lp,c)
67 gv_check("closed descriptor seek failure is explicit",c[CLC_STATE]==CLC_SEEK&&c[CLC_ERRNO]<0&&lp[0]==0,ctr)
68 let zero:*u8=cl_slurp_tail_fd(-1,0,lp,c)
69 gv_check("invalid capacity refused before reading",zero as i64==0&&c[CLC_STATE]==CLC_INVALID&&lp[0]==0,ctr)
70 let failed:*u8="1789000000\tmcp\tnx_curveskel\tcall\tharness-fail\tx\n"
71 gv_check("failed terminal row remains non-success",cl_actlog_completed(failed,cl_slen(failed),"nx_curveskel")==0,ctr)
72 let use:*u8="1789000000\tclaude\tnx_curveskel\tuse\t-\tx\n"
73 gv_check("harvest request is not a completed MCP call",cl_actlog_completed(use,cl_slen(use),"nx_curveskel")==0,ctr)
74 gv_values_head();gv_kv("production_window_bytes",CL_BUF);gv_kv("history_fixture_bytes",CL_BUF+rn)
75 gv_puts("CATALOG-COVERAGE passed=");gv_num(ctr[0]);gv_puts("/");gv_num(ctr[1]);gv_puts("\n")
76 if ctr[0]!=ctr[1]{return 1}
77 return 0
78}