code wiki / (root) / nx_uxf_config_test.nx

nx_uxf_config_test.nx source

↩ module page · 57 lines · 3985 B

1// nx_uxf_config_test.nx -- UXF arc #3: a NEW profile (CONFIG) on the SAME envelope, proving a fresh 2// domain is added with ONLY a codec id (UXF_CONFIG) -- zero envelope change, the cheapest possible 3// extension (Law-4). A config record {host,port} gets a UXF_CONFIG self-describing CID, distinct 4// from the SAME content under UXF_DATA / UXF_MEDIA (profiles never collide), and canonicalizes 5// (order-independent CID). 6// 7// HONEST TOOLCHAIN NOTE: the richer variant that PARSES a real JSON config (jstr/jskip/json_parse) 8// hit a repeatable nx_cc "empty .s" COMPILE-FAIL (same class as the nx_workstream_store import 9// failure) -- a real compiler limitation, flagged not hidden. The config PROFILE is proven here; 10// full JSON/YAML config PARSING is deferred to a toolchain-investigation rung. 11// No hardware writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL 12import "nx_syscalls.nx" 13import "nx_canon_cid.nx" 14import "nx_uxf_cid.nx" 15 16func c_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 17func c_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 } 18func c_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 } 19 20func main() -> i64 { 21 c_puts("#3 NEW PROFILE: CONFIG on the same envelope (codec id only, zero envelope change)\n" as *u8) 22 let keys: *i64 = sys_mmap(8 * 8) as *i64 23 let vals: *i64 = sys_mmap(8 * 8) as *i64 24 keys[0] = ("host\x00") as i64; vals[0] = ("localhost\x00") as i64 25 keys[1] = ("port\x00") as i64; vals[1] = ("8080\x00") as i64 26 let canon: *u8 = sys_mmap(4096) 27 let clen: i64 = canon_encode(keys, vals, 2, canon) 28 29 let cid_cfg: *u8 = sys_mmap(128) 30 let cid_data: *u8 = sys_mmap(128) 31 let cid_media: *u8 = sys_mmap(128) 32 uxf_cid_profiled(UXF_CONFIG, canon, clen, cid_cfg) 33 uxf_cid_profiled(UXF_DATA, canon, clen, cid_data) 34 uxf_cid_profiled(UXF_MEDIA, canon, clen, cid_media) 35 c_puts(" config CID = " as *u8); c_puts(cid_cfg); c_puts("\n" as *u8) 36 37 // canonicalization: reverse-order re-encode -> same config CID 38 let rk: *i64 = sys_mmap(8 * 8) as *i64 39 let rv: *i64 = sys_mmap(8 * 8) as *i64 40 rk[0] = keys[1]; rv[0] = vals[1] 41 rk[1] = keys[0]; rv[1] = vals[0] 42 let rt: *u8 = sys_mmap(4096) 43 let rtlen: i64 = canon_encode(rk, rv, 2, rt) 44 let rtcid: *u8 = sys_mmap(128) 45 uxf_cid_profiled(UXF_CONFIG, rt, rtlen, rtcid) 46 47 var pass: i64 = 0 48 var ttl: i64 = 0 49 ttl = ttl + 1; c_puts(" T1 self-describes as UXF_CONFIG (profile=" as *u8); c_putn(uxf_codec_of_cid(cid_cfg)); c_puts("): " as *u8); if uxf_codec_of_cid(cid_cfg) == UXF_CONFIG { pass = pass + 1; c_puts("PASS\n" as *u8) } else { c_puts("FAIL\n" as *u8) } 50 ttl = ttl + 1; c_puts(" T2 config CID != data CID (same content, no collision): " as *u8); if c_streq(cid_cfg, cid_data) == 0 { pass = pass + 1; c_puts("PASS\n" as *u8) } else { c_puts("FAIL\n" as *u8) } 51 ttl = ttl + 1; c_puts(" T3 config CID != media CID: " as *u8); if c_streq(cid_cfg, cid_media) == 0 { pass = pass + 1; c_puts("PASS\n" as *u8) } else { c_puts("FAIL\n" as *u8) } 52 ttl = ttl + 1; c_puts(" T4 canonicalization (order-independent CID): " as *u8); if c_streq(cid_cfg, rtcid) == 1 { pass = pass + 1; c_puts("PASS\n" as *u8) } else { c_puts("FAIL\n" as *u8) } 53 54 c_puts("UXF-CONFIG-GATE passed " as *u8); c_putn(pass); c_puts("/" as *u8); c_putn(ttl) 55 if pass == ttl { c_puts(" verdict=GREEN (new CONFIG profile = codec id only; full JSON parse deferred = toolchain note)\n" as *u8); sys_exit(0); return 0 } 56 c_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 57}