nx_uxf_wms_bridge_test.nx source
↩ module page · 109 lines · 5250 B
1// nx_uxf_wms_bridge_test.nx -- UXF arc #1 rung-2: WMS<->envelope integration, READ-ONLY.
2// Reads a REAL live workstream record from the WMS segment store (ss_get over the knowledge/store/ws-
3// prefix -- read-only; the SSOT is never written), represents its 7 TAB-fields as a UXF canonical
4// record, stamps a content-addressed UXF_DATA CID, and proves canonicalization (order-independent
5// CID) + faithful field carriage. Uses nx_seg_store directly (proven to compile with the canon/uxf
6// stack). LIVE write-registration into the SSOT is the GATED next step. No hardware writes (Rule 26).
7// expect_exit: 0 license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_canon_cid.nx"
10import "nx_uxf_cid.nx"
11import "nx_seg_store.nx"
12
13func b_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func b_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 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 }
15func b_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while 1 == 1 { if a[i] != b[i] { return 0 } if a[i] == (0 as u8) { return 1 } i = i + 1 } return 1 }
16
17// extract the f-th TAB-separated field of rec[0..rlen) into out (NUL-terminated); returns its length.
18func bx_field(rec: *u8, rlen: i64, f: i64, out: *u8) -> i64 {
19 var cur: i64 = 0
20 var i: i64 = 0
21 var o: i64 = 0
22 while cur < f {
23 if i >= rlen { out[0] = 0 as u8; return 0 }
24 if rec[i] == (9 as u8) { cur = cur + 1 }
25 i = i + 1
26 }
27 var go: i64 = 1
28 while go == 1 {
29 if i >= rlen { go = 0 } else {
30 if rec[i] == (9 as u8) { go = 0 } else { out[o] = rec[i]; o = o + 1; i = i + 1 }
31 }
32 }
33 out[o] = 0 as u8
34 return o
35}
36
37func main() -> i64 {
38 b_puts("#1 rung-2 WMS<->ENVELOPE BRIDGE (read-only ss_get over the live SSOT)\n" as *u8)
39 let WSP: *u8 = "knowledge/store/ws-\x00"
40 let pp: *i64 = sys_mmap(8) as *i64
41 let ll: *i64 = sys_mmap(8) as *i64
42 var pass: i64 = 0
43 var total: i64 = 0
44
45 let g1: i64 = ss_get(WSP, "ws:ids\x00" as *u8, pp, ll)
46 total = total + 1
47 b_puts(" T1 live WMS ws:ids readable: " as *u8)
48 if g1 == 1 { pass = pass + 1; b_puts("PASS\n" as *u8) } else { b_puts("FAIL (store absent here)\n" as *u8) }
49 if g1 != 1 {
50 b_puts("UXF-WMS-BRIDGE-GATE passed " as *u8); b_putn(pass); b_puts("/" as *u8); b_putn(total); b_puts(" verdict=RED\n" as *u8)
51 sys_exit(1)
52 return 1
53 }
54 let ids: *u8 = (pp[0]) as *u8
55 let idslen: i64 = ll[0]
56 let firstid: *u8 = sys_mmap(256)
57 bx_field(ids, idslen, 0, firstid)
58 b_puts(" first live stream id = " as *u8); b_puts(firstid); b_puts("\n" as *u8)
59
60 let key: *u8 = sys_mmap(512)
61 key[0] = 119 as u8; key[1] = 115 as u8; key[2] = 58 as u8
62 var ki: i64 = 0
63 while firstid[ki] != (0 as u8) { key[3 + ki] = firstid[ki]; ki = ki + 1 }
64 key[3 + ki] = 0 as u8
65 let g2: i64 = ss_get(WSP, key, pp, ll)
66 total = total + 1
67 b_puts(" T2 live record retrievable: " as *u8)
68 if g2 == 1 { pass = pass + 1; b_puts("PASS\n" as *u8) } else { b_puts("FAIL\n" as *u8) }
69 let rec: *u8 = (pp[0]) as *u8
70 let rlen: i64 = ll[0]
71
72 let keys: *i64 = sys_mmap(8 * 8) as *i64
73 let vals: *i64 = sys_mmap(8 * 8) as *i64
74 keys[0] = ("id\x00") as i64
75 keys[1] = ("empire\x00") as i64
76 keys[2] = ("state\x00") as i64
77 keys[3] = ("last_touched\x00") as i64
78 keys[4] = ("memory_link\x00") as i64
79 keys[5] = ("code_link\x00") as i64
80 keys[6] = ("deps\x00") as i64
81 var ff: i64 = 0
82 while ff < 7 { let vb: *u8 = sys_mmap(512); bx_field(rec, rlen, ff, vb); vals[ff] = vb as i64; ff = ff + 1 }
83 let canon: *u8 = sys_mmap(8192)
84 let clen: i64 = canon_encode(keys, vals, 7, canon)
85 let cid: *u8 = sys_mmap(128)
86 uxf_cid_profiled(UXF_DATA, canon, clen, cid)
87 b_puts(" live WMS record -> UXF CID = " as *u8); b_puts(cid); b_puts("\n" as *u8)
88
89 let rk: *i64 = sys_mmap(8 * 8) as *i64
90 let rv: *i64 = sys_mmap(8 * 8) as *i64
91 var q: i64 = 0
92 while q < 7 { rk[q] = keys[6 - q]; rv[q] = vals[6 - q]; q = q + 1 }
93 let rt: *u8 = sys_mmap(8192)
94 let rtlen: i64 = canon_encode(rk, rv, 7, rt)
95 let rtcid: *u8 = sys_mmap(128)
96 uxf_cid_profiled(UXF_DATA, rt, rtlen, rtcid)
97 total = total + 1
98 b_puts(" T3 field-order-independent CID (canonicalization): " as *u8)
99 if b_streq(cid, rtcid) == 1 { pass = pass + 1; b_puts("PASS\n" as *u8) } else { b_puts("FAIL\n" as *u8) }
100
101 let got_id: *u8 = (vals[0]) as *u8
102 total = total + 1
103 b_puts(" T4 id field carried faithfully: " as *u8)
104 if b_streq(got_id, firstid) == 1 { pass = pass + 1; b_puts("PASS\n" as *u8) } else { b_puts("FAIL\n" as *u8) }
105
106 b_puts("UXF-WMS-BRIDGE-GATE passed " as *u8); b_putn(pass); b_puts("/" as *u8); b_putn(total)
107 if pass == total { b_puts(" verdict=GREEN (live WMS record unifies with the UXF envelope; LIVE write = gated next)\n" as *u8); sys_exit(0); return 0 }
108 b_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1
109}