code wiki / (root) / nx_wflow_capacity_candidate_gate_t278.nx

nx_wflow_capacity_candidate_gate_t278.nx source

↩ module page · 94 lines · 5652 B

1import "nx_wflow_engine_capacity_candidate_t278.nx" 2import "nx_gate_verdict.nx" 3func main(argc:i64,argv:*i64)->i64{ 4 if argc!=3{return 2} 5 let n:i64=wf_atoi(argv[1] as *u8) 6 if n<=0{return 2} 7 let value:*u8=sys_mmap_try(n+1) 8 if (value as i64)<=0{return 3} 9 var i:i64=0;while i<n{value[i]=(65+i%26) as u8;i=i+1};value[n]=0 10 let path:*u8=argv[2] as *u8 11 let fresh:i64=sys_openat_exclusive(path,MODE_0600) 12 if fresh<0{p("WFLOW-GATE journal not fresh; refusing reuse\n");return 4} 13 if sys_close(fresh)!=0{return 4} 14 let c:*i64=gv_ctr() 15 gv_check_eq("actual journal append",wf_emit_var(path,"review","value",value),0,c) 16 let cx:*i64=sys_mmap_try(3*__size_of(i64)) as *i64 17 let out:*u8=sys_mmap_try(n+1) 18 if (cx as i64)<=0{return 3};if (out as i64)<=0{return 3} 19 cx[2]=path as i64 20 gv_check_eq("variable found",wf_var_get(cx,"review","value",out,n+1),1,c) 21 gv_check_eq("direct variable complete",slen(out),n,c) 22 out[0]=0 23 let result:i64=wf_subst(cx,"review","{value}",out,n+1) 24 gv_check_eq("substitution complete",result,n,c) 25 gv_check_eq("substitution output complete",slen(out),n,c) 26 var equal:i64=1;i=0 27 while i<n{if out[i]!=value[i]{equal=0};i=i+1} 28 gv_check("all substitution bytes retained",equal==1,c) 29 gv_check_eq("short caller rejected",wf_subst(cx,"review","{value}",out,n),0-1,c) 30 gv_check_eq("short caller output empty",out[0] as i64,0,c) 31 out[0]=90 as u8 32 gv_check_eq("zero capacity rejected",wf_subst(cx,"review","{value}",out,0),0-1,c) 33 gv_check_eq("zero capacity not written",out[0] as i64,90,c) 34 gv_check_eq("missing variable rejected",wf_subst(cx,"review","{absent}",out,n+1),0-1,c) 35 gv_check_eq("missing output empty",out[0] as i64,0,c) 36 gv_check_eq("unclosed variable rejected",wf_subst(cx,"review","{value",out,n+1),0-1,c) 37 gv_check_eq("short getter rejected",wf_var_get(cx,"review","value",out,n),0-1,c) 38 gv_check_eq("short getter output empty",out[0] as i64,0,c) 39 let doubled:*WfOwnedText=wf_subst_owned(cx,"review","{value}|{value}") 40 gv_check("owned output exists",doubled!=(0 as *WfOwnedText),c) 41 if doubled!=(0 as *WfOwnedText){ 42 gv_check_eq("owned output exact measured allocation",doubled.bytes,n*2+2,c) 43 gv_check_eq("owned repeated length",doubled.len,n*2+1,c) 44 equal=1;i=0 45 while i<n{if doubled.data[i]!=value[i]{equal=0};if doubled.data[n+1+i]!=value[i]{equal=0};i=i+1} 46 gv_check("owned repeated values retained",equal==1,c) 47 gv_check_eq("owned literal separator",doubled.data[n] as i64,124,c) 48 gv_check_eq("owned free",wf_text_free(doubled),0,c) 49 } 50 gv_check_eq("long key append",wf_emit_var(path,"review",value,"complete"),0,c) 51 let tpl:*u8=sys_mmap_try(n+3) 52 if (tpl as i64)<=0{return 3} 53 tpl[0]=123 as u8;i=0;while i<n{tpl[i+1]=value[i];i=i+1};tpl[n+1]=125 as u8;tpl[n+2]=0 54 let longkey:*WfOwnedText=wf_subst_owned(cx,"review",tpl) 55 gv_check("long key resolved",longkey!=(0 as *WfOwnedText),c) 56 if longkey!=(0 as *WfOwnedText){gv_check("long key exact value",seq(longkey.data,"complete")==1,c);wf_text_free(longkey)} 57 sys_munmap(tpl,n+3) 58 gv_check_eq("empty value append",wf_emit_var(path,"review","empty",""),0,c) 59 gv_check_eq("empty value substitution",wf_subst(cx,"review","{empty}",out,n+1),0,c) 60 gv_check_eq("latest value append",wf_emit_var(path,"review","value","replacement"),0,c) 61 gv_check_eq("latest value found",wf_var_get(cx,"review","value",out,n+1),1,c) 62 gv_check("latest value exact",seq(out,"replacement")==1,c) 63 gv_check_eq("restore long source",wf_emit_var(path,"review","value",value),0,c) 64 let rowprefix:*u8="flow|2|set-var|-|direct=" 65 let rowsuffix:*u8="|1" 66 let row:*WfOwnedText=wf_text_new(slen(rowprefix)+n+slen(rowsuffix),1) 67 if row==(0 as *WfOwnedText){return 3} 68 var pos:i64=wf_cat(row.data,0,rowprefix);pos=wf_cat(row.data,pos,value);pos=wf_cat(row.data,pos,rowsuffix);row.data[pos]=0 69 let condition:*WfOwnedText=wf_text_new(slen("direct=")+n,1) 70 if condition==(0 as *WfOwnedText){return 3} 71 pos=wf_cat(condition.data,0,"direct=");pos=wf_cat(condition.data,pos,value);condition.data[pos]=0 72 let steps:*i64=sys_mmap_try(2*__size_of(i64)) as *i64 73 if (steps as i64)<=0{return 3} 74 steps[0]="flow|1|set-var|-|copied={value}|1" as *u8 as i64;steps[1]=row.data as i64 75 cx[0]=steps as i64;cx[1]=2 76 gv_check_eq("actual workflow long arguments complete",wf_run_from(cx,"review","flow",0),2,c) 77 gv_check_eq("workflow copied found",wf_var_get(cx,"review","copied",out,n+1),1,c) 78 gv_check("workflow copied exact bytes",seq(out,value)==1,c) 79 gv_check_eq("workflow direct found",wf_var_get(cx,"review","direct",out,n+1),1,c) 80 gv_check("workflow direct exact bytes",seq(out,value)==1,c) 81 gv_check_eq("long condition matches",wf_cond_ok(cx,"review",condition.data),1,c) 82 gv_check_eq("iteration writer long value",wf_emit_iter(path,"review",1,value),0,c) 83 let ledger_size:*i64=sys_mmap_try(__size_of(i64)) as *i64 84 if (ledger_size as i64)<=0{return 3} 85 let ledger:*u8=wf_readall(path,ledger_size) 86 let expected:*WfOwnedText=wf_text_new(slen("WFITER rid=review n=1 item=")+n+1,1) 87 if expected==(0 as *WfOwnedText){return 3} 88 pos=wf_cat(expected.data,0,"WFITER rid=review n=1 item=");pos=wf_cat(expected.data,pos,value);expected.data[pos]=10 as u8;expected.data[pos+1]=0 89 gv_check("iteration full serialized bytes",wf_has_rng(ledger,0,ledger_size[0],expected.data)==1,c) 90 sys_munmap(ledger,WF_LEDCAP);sys_munmap(ledger_size as *u8,__size_of(i64));wf_text_free(expected) 91 wf_text_free(row);wf_text_free(condition);sys_munmap(steps as *u8,2*__size_of(i64)) 92 sys_munmap(value,n+1);sys_munmap(out,n+1);sys_munmap(cx as *u8,3*__size_of(i64)) 93 return gv_verdict("WFLOW-CAPACITY-COUNTEREXAMPLE-T278",c,"Actual journal and native run consumer preserve complete variable data; external connector limits remain") 94}