nx_companion_render_gate.nx source
↩ module page · 93 lines · 6626 B
1// nx_companion_render_gate.nx -- GATE for nx_companion_render: the visual arc composes into a real image-gen
2// API request. Proves: (T1) the body carries the persona's identity anchor + current outfit (grounded person);
3// (T2) variety flows through -- body@step0 and body@step1 request DIFFERENT outfits; (T3) render_request
4// ADVANCES the arc so two successive live calls send two different prompts (the fix, end to end); (T4) the HTTP
5// wrapper is a well-formed POST /v1/images/generations with Content-Length; (T5) JSON escaping -- a quoted term
6// in the identity is escaped in the body. Timestamp-fresh /tmp store. license_tier: ORIGINAL expect_exit: 0
7import "nx_companion_render.nx"
8import "nx_gate_verdict.nx"
9
10func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func gn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
12func gfind(hay: *u8, hlen: i64, needle: *u8) -> i64 {
13 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
14 if nl==0 { return 1 }
15 if hlen<nl { return 0 }
16 var i: i64=0
17 while i<=hlen-nl { var m: i64=1; var c: i64=0; while c<nl { if hay[i+c]!=needle[c]{m=0;c=nl} else {c=c+1} } if m==1 {return 1} i=i+1 }
18 return 0
19}
20func gpeq(a: *u8, al: i64, b: *u8, bl: i64) -> i64 { if al!=bl {return 0} var i: i64=0; while i<al { if a[i]!=b[i]{return 0} i=i+1 } return 1 }
21
22func main() -> i64 {
23 gw("=== nx_companion_render_gate (visual arc -> live image-gen API request) ===\n" as *u8)
24 let VP: *u8 = sys_mmap(256)
25 var po: i64=0; var i: i64=0; let pre: *u8="/tmp/render-test-" as *u8; while pre[i]!=(0 as u8){VP[po]=pre[i];po=po+1;i=i+1}
26 var ms: i64 = sys_now_ms() % 100000000; var dd: i64=7; while dd>=0 { VP[po+dd]=(48+(ms%10)) as u8; ms=ms/10; dd=dd-1 } po=po+8
27 VP[po]=0x2D as u8; po=po+1; VP[po]=0 as u8
28
29 // Aria -- anchor includes a QUOTED nickname to exercise JSON escaping
30 vid_put_pfx(VP, "aria" as *u8,
31 "Aria, twenty-two, long dark chestnut beach-wave hair, hazel eyes, they call her \"sunlight\", fair freckled skin" as *u8,
32 "wearing a loose oversized cotton tee|wearing a sheer sundress|natural and unclothed, at ease|wearing a silk robe" as *u8,
33 "in a sunlit bedroom|in a golden-hour garden|in a warm kitchen at morning|on a quiet beach at dawn" as *u8,
34 "curled up reading|stretching in the light|laughing over her shoulder" as *u8)
35
36 var pass: i64 = 0
37 var tot: i64 = 0
38 let a: *u8 = sys_mmap(32768); let b: *u8 = sys_mmap(32768)
39
40 // T1 body carries identity + current outfit
41 tot=tot+1
42 let la: i64 = render_body_at_pfx(VP, "aria" as *u8, 0, a, 32768)
43 var t1: i64 = 0
44 if a[0]==(0x7B as u8) { if gfind(a, la, "\"prompt\":\"" as *u8)==1 { if gfind(a, la, "chestnut" as *u8)==1 { if gfind(a, la, "oversized cotton tee" as *u8)==1 { t1=1 } } } }
45 if t1==1 { pass=pass+1; gw("PASS T1 body: {\"prompt\":...} carries identity(chestnut) + current outfit(cotton tee)\n" as *u8) } else { gw("FAIL T1 (len=" as *u8); gn(la); gw(")\n" as *u8) }
46
47 // T2 variety flows into the request
48 tot=tot+1
49 let lb: i64 = render_body_at_pfx(VP, "aria" as *u8, 1, b, 32768)
50 var t2: i64 = 0
51 if gfind(a, la, "oversized cotton tee" as *u8)==1 { if gfind(b, lb, "sheer sundress" as *u8)==1 { if gpeq(a, la, b, lb)==0 { t2=1 } } }
52 if t2==1 { pass=pass+1; gw("PASS T2 variety in the request: step0 body=cotton tee, step1 body=sheer sundress\n" as *u8) } else { gw("FAIL T2\n" as *u8) }
53
54 // T3 render_request ADVANCES -- two live calls send two different prompts
55 tot=tot+1
56 varc_reset_pfx(VP, "aria" as *u8)
57 let sp: *i64 = sys_mmap(16) as *i64
58 let r1: i64 = render_request_pfx(VP, "aria" as *u8, a, 32768, sp); let s1: i64 = sp[0]
59 let r2: i64 = render_request_pfx(VP, "aria" as *u8, b, 32768, sp); let s2: i64 = sp[0]
60 var t3: i64 = 0
61 if s2 == s1 + 1 { if gpeq(a, r1, b, r2)==0 { t3=1 } }
62 if t3==1 { pass=pass+1; gw("PASS T3 render_request advances: 2 successive calls -> steps " as *u8); gn(s1); gw("," as *u8); gn(s2); gw(" with DIFFERENT prompts\n" as *u8) } else { gw("FAIL T3 s1=" as *u8); gn(s1); gw(" s2=" as *u8); gn(s2); gw("\n" as *u8) }
63
64 // T4 HTTP wrapper well-formed
65 tot=tot+1
66 let lh: i64 = render_http_at_pfx(VP, "aria" as *u8, 0, "gen.nishi:7861" as *u8, a, 32768)
67 var t4: i64 = 0
68 if gfind(a, lh, "POST /v1/images/generations HTTP/1.1" as *u8)==1 { if gfind(a, lh, "Host: gen.nishi:7861" as *u8)==1 { if gfind(a, lh, "Content-Length: " as *u8)==1 { if gfind(a, lh, "\"prompt\":\"" as *u8)==1 { t4=1 } } } }
69 if t4==1 { pass=pass+1; gw("PASS T4 HTTP: POST /v1/images/generations, Host, Content-Length, body -- ready for the sovereign client\n" as *u8) } else { gw("FAIL T4\n" as *u8) }
70
71 // T5 JSON escaping of the quoted nickname
72 tot=tot+1
73 let l5: i64 = render_body_at_pfx(VP, "aria" as *u8, 0, a, 32768)
74 if gfind(a, l5, "they call her \\\"sunlight\\\"" as *u8)==1 { pass=pass+1; gw("PASS T5 JSON escaping: quoted nickname escaped as \\\"sunlight\\\" (valid JSON)\n" as *u8) } else { gw("FAIL T5\n" as *u8) }
75
76 // T6 EXISTING-PIPELINE integration: the orchestrator (/gen/api/generate) shape carries the grounded prompt
77 tot=tot+1
78 let l6: i64 = render_gen_http_at_pfx(VP, "aria" as *u8, 0, "nishifamily.com" as *u8, a, 32768)
79 var t6: i64 = 0
80 if gfind(a, l6, "POST /gen/api/generate HTTP/1.1" as *u8)==1 { if gfind(a, l6, "chestnut" as *u8)==1 { if gfind(a, l6, "oversized cotton tee" as *u8)==1 { if gfind(a, l6, "\"negative\":" as *u8)==1 { t6=1 } } } }
81 if t6==1 { pass=pass+1; gw("PASS T6 feeds the EXISTING NAS pipeline: POST /gen/api/generate carries the grounded persona prompt\n" as *u8) } else { gw("FAIL T6\n" as *u8) }
82
83 gw("nx_companion_render_gate pass=" as *u8); gn(pass); gw("/" as *u8); gn(tot)
84 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
85 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
86 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
87 let ctr__dry: *i64 = gv_ctr()
88 ctr__dry[0] = pass
89 ctr__dry[1] = tot
90 let rc__dry: i64 = gv_verdict("COMPANION-RENDER-GATE" as *u8, ctr__dry, "persona -> advancing arc -> real /v1/images/generations request: same person, new scene every render)" as *u8)
91 sys_exit(rc__dry)
92 return rc__dry
93}