nx_uxf_config_gate.nx source
↩ module page · 87 lines · 5020 B
1// nx_uxf_config_gate.nx -- the D001 MIGRATION of nx_uxf_config_test onto nx_gate_verdict (2026-09-06).
2//
3// WHAT IT PROVES, AND WHY IT IS THE CHEAPEST EXTENSION IN THE FAMILY: a brand-new domain joins the envelope
4// with ONLY a codec id and ZERO envelope change. A config record gets a self-describing UXF_CONFIG CID that
5// cannot collide with the SAME CONTENT under UXF_DATA or UXF_MEDIA, and the canonical encode makes field
6// order irrelevant. That is law 4 (extensible, data and functionality on independent clocks) at its cheapest.
7//
8// This gate is ALSO the evidence behind the FM1 matrix row's claim that one envelope carries every profile:
9// FM1 asserts DATA is nxc1-01, DOC nxc1-02, MEDIA nxc1-03 and CONFIG nxc1-04, and the profile-collision teeth
10// here are what make that a measurement rather than a description.
11//
12// ALL FOUR ORIGINAL TEETH PRESERVED IN ORDER AND PREDICATE, plus the values emitted for outside adjudication.
13// HONEST NOTE CARRIED FORWARD FROM THE ORIGINAL, NOT QUIETLY DROPPED: the richer variant that PARSES a real
14// JSON config hit a repeatable nx_cc empty-.s compile failure, so the config PROFILE is proven here and full
15// JSON and YAML config PARSING remains a separate toolchain rung. Nothing below claims otherwise.
16// license_tier: ORIGINAL No hw writes (Rule 26).
17import "nx_gate_verdict.nx"
18import "nx_syscalls.nx"
19import "nx_canon_cid.nx"
20import "nx_uxf_cid.nx"
21
22const UC_PTRTAB: i64 = 64
23const UC_CANON: i64 = 4096
24const UC_CIDBUF: i64 = 128
25const UC_NFIELDS: i64 = 2
26
27func uc_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 }
28
29func main(argc: i64, argv: *i64) -> i64 {
30 let ctr: *i64 = gv_ctr()
31 gv_head("nx_uxf_cid CONFIG profile -- a new domain costs a codec id and nothing else" as *u8)
32
33 let keys: *i64 = sys_mmap(UC_PTRTAB) as *i64
34 let vals: *i64 = sys_mmap(UC_PTRTAB) as *i64
35 keys[0] = ("host\x00") as i64; vals[0] = ("localhost\x00") as i64
36 keys[1] = ("port\x00") as i64; vals[1] = ("8080\x00") as i64
37 let canon: *u8 = sys_mmap(UC_CANON)
38 let clen: i64 = canon_encode(keys, vals, UC_NFIELDS, canon)
39
40 let cid_cfg: *u8 = sys_mmap(UC_CIDBUF)
41 let cid_data: *u8 = sys_mmap(UC_CIDBUF)
42 let cid_media: *u8 = sys_mmap(UC_CIDBUF)
43 uxf_cid_profiled(UXF_CONFIG, canon, clen, cid_cfg)
44 uxf_cid_profiled(UXF_DATA, canon, clen, cid_data)
45 uxf_cid_profiled(UXF_MEDIA, canon, clen, cid_media)
46
47 // canonicalisation: the SAME two fields encoded in REVERSE order must yield the SAME config CID
48 let rk: *i64 = sys_mmap(UC_PTRTAB) as *i64
49 let rv: *i64 = sys_mmap(UC_PTRTAB) as *i64
50 rk[0] = keys[1]; rv[0] = vals[1]
51 rk[1] = keys[0]; rv[1] = vals[0]
52 let rt: *u8 = sys_mmap(UC_CANON)
53 let rtlen: i64 = canon_encode(rk, rv, UC_NFIELDS, rt)
54 let rtcid: *u8 = sys_mmap(UC_CIDBUF)
55 uxf_cid_profiled(UXF_CONFIG, rt, rtlen, rtcid)
56
57 let read_profile: i64 = uxf_codec_of_cid(cid_cfg)
58
59 gv_check_eq("T1 the CID self-describes as UXF_CONFIG, readable without rehashing" as *u8, read_profile, UXF_CONFIG, ctr)
60 gv_check("T2 the config CID differs from the DATA CID over identical content, so profiles cannot collide" as *u8, 1 - uc_streq(cid_cfg, cid_data), ctr)
61 gv_check("T3 the config CID differs from the MEDIA CID over identical content" as *u8, 1 - uc_streq(cid_cfg, cid_media), ctr)
62 gv_check("T4 canonicalisation: the same fields in reverse order give the SAME config CID" as *u8, uc_streq(cid_cfg, rtcid), ctr)
63
64 // neg-control: the ruler must not answer identical to everything, or T4 would pass vacuously.
65 // DATA and MEDIA over the same bytes must themselves differ from each other.
66 gv_check("neg-control-DATA-and-MEDIA-also-differ-so-the-comparator-is-not-answering-equal-to-everything" as *u8, 1 - uc_streq(cid_data, cid_media), ctr)
67
68 gv_values_head()
69 gv_kv("canon_len" as *u8, clen)
70 gv_kv("canon_len_reversed" as *u8, rtlen)
71 gv_kv("profile_read_from_config_cid" as *u8, read_profile)
72 gv_kv("UXF_CONFIG" as *u8, UXF_CONFIG)
73 gv_kv("UXF_DATA" as *u8, UXF_DATA)
74 gv_kv("UXF_MEDIA" as *u8, UXF_MEDIA)
75 gv_kv("cfg_eq_data" as *u8, uc_streq(cid_cfg, cid_data))
76 gv_kv("cfg_eq_media" as *u8, uc_streq(cid_cfg, cid_media))
77 gv_kv("data_eq_media" as *u8, uc_streq(cid_data, cid_media))
78 gv_kv("cfg_eq_reversed" as *u8, uc_streq(cid_cfg, rtcid))
79 gv_puts(" cid_config = " as *u8); gv_puts(cid_cfg); gv_puts("\n" as *u8)
80 gv_puts(" cid_data = " as *u8); gv_puts(cid_data); gv_puts("\n" as *u8)
81 gv_puts(" cid_media = " as *u8); gv_puts(cid_media); gv_puts("\n" as *u8)
82 gv_puts(" cid_reversed = " as *u8); gv_puts(rtcid); gv_puts("\n" as *u8)
83
84 let rc: i64 = gv_verdict("UXF-CONFIG-PROFILE-GATE" as *u8, ctr, "a new domain joins the envelope with only a codec id, its CID cannot collide with the same content under another profile, and field order does not change identity" as *u8)
85 sys_exit(rc)
86 return rc
87}