nx_uxf_media_asset_gate.nx source
↩ module page · 118 lines · 6647 B
1// nx_uxf_media_asset_gate.nx -- the D001 MIGRATION of nx_uxf_media_asset_test onto nx_gate_verdict (2026-09-06).
2//
3// THIS IS THE ONE THAT TIES THE FAMILY TOGETHER. A media descriptor becomes a canonical record, is stamped
4// with a self-describing UXF_MEDIA profiled CID, is TOLERANT-DECODED by a consumer that did not write it, and
5// the decoded fields then drive endpoint negotiation. It proves the unified claim end to end: the SAME
6// envelope that carried migrated TSV rows carries media and decides what to emit.
7//
8// ALL FIVE ORIGINAL TEETH PRESERVED IN ORDER AND PREDICATE, plus two the original lacked. It looked up the
9// chrome capability row and NEVER asserted the lookup succeeded, and it decoded the descriptor without ever
10// asserting how many fields came back -- so a failed lookup or a short decode could only have been judged
11// indirectly through the plan. T0a and T0b assert the fixture reached its condition first.
12// license_tier: ORIGINAL No hw writes (Rule 26).
13import "nx_gate_verdict.nx"
14import "nx_syscalls.nx"
15import "nx_canon_cid.nx"
16import "nx_uxf_cid.nx"
17import "nx_uxf_decode.nx"
18import "nx_uxf_negotiate.nx"
19
20const UM_PTRTAB: i64 = 64
21const UM_CANON: i64 = 8192
22const UM_CIDBUF: i64 = 128
23const UM_CAPBUF: i64 = 256
24const UM_FIELDS: i64 = 3
25const UM_MAXDEC: i64 = 16
26const UM_CAPS_OK: i64 = 1
27
28func um_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 }
29
30// a media descriptor {container, vcodec, acodec} encoded canonically
31func um_descriptor(container: *u8, vcodec: *u8, acodec: *u8, canon: *u8) -> i64 {
32 let keys: *i64 = sys_mmap(UM_PTRTAB) as *i64
33 let vals: *i64 = sys_mmap(UM_PTRTAB) as *i64
34 keys[0] = ("container\x00") as i64; vals[0] = (container as i64)
35 keys[1] = ("vcodec\x00") as i64; vals[1] = (vcodec as i64)
36 keys[2] = ("acodec\x00") as i64; vals[2] = (acodec as i64)
37 return canon_encode(keys, vals, UM_FIELDS, canon)
38}
39
40func um_find(dkeys: *i64, dvals: *i64, nf: i64, key: *u8) -> *u8 {
41 var i: i64 = 0
42 while i < nf { if um_streq((dkeys[i]) as *u8, key) == 1 { return (dvals[i]) as *u8 } i = i + 1 }
43 return 0 as *u8
44}
45
46func main(argc: i64, argv: *i64) -> i64 {
47 let ctr: *i64 = gv_ctr()
48 gv_head("the UXF envelope end to end -- a media asset stored once and emitted per endpoint" as *u8)
49
50 let lenp: *i64 = sys_mmap(8) as *i64
51 let tsv: *u8 = sys_read_file("knowledge/registry/endpoint_caps.tsv\x00" as *u8, lenp)
52 if (tsv as i64) == 0 {
53 gv_puts(" UM-UNREADABLE knowledge/registry/endpoint_caps.tsv could not be read, so NOTHING below could be judged\n" as *u8)
54 let rcx: i64 = gv_verdict("UXF-MEDIA-ASSET-GATE" as *u8, ctr, "capability table unreadable" as *u8)
55 sys_exit(rcx)
56 return rcx
57 }
58 let tn: i64 = lenp[0]
59 let chrome_c: *u8 = sys_mmap(UM_CAPBUF)
60 let chrome_k: *u8 = sys_mmap(UM_CAPBUF)
61 let okc: i64 = ng_caps_lookup(tsv, tn, "chrome\x00" as *u8, chrome_c, chrome_k)
62
63 // asset 1: MKV carrying H.264 and AAC -- the container-only mismatch
64 let c1: *u8 = sys_mmap(UM_CANON)
65 let l1: i64 = um_descriptor("mkv\x00" as *u8, "h264\x00" as *u8, "aac\x00" as *u8, c1)
66 let cid1: *u8 = sys_mmap(UM_CIDBUF)
67 uxf_cid_profiled(UXF_MEDIA, c1, l1, cid1)
68
69 // a CONSUMER that did not write it tolerantly decodes and negotiates from the decoded fields
70 let dk: *i64 = sys_mmap(UM_PTRTAB) as *i64
71 let dv: *i64 = sys_mmap(UM_PTRTAB) as *i64
72 let nf: i64 = canon_decode(c1, l1, dk, dv, UM_MAXDEC)
73 let plan1: i64 = ng_negotiate(um_find(dk, dv, nf, "container\x00" as *u8), um_find(dk, dv, nf, "vcodec\x00" as *u8), um_find(dk, dv, nf, "acodec\x00" as *u8), chrome_c, chrome_k)
74
75 // the descriptor re-encoded from the DECODED fields must reproduce the same CID
76 let rt: *u8 = sys_mmap(UM_CANON)
77 let rtlen: i64 = canon_encode(dk, dv, nf, rt)
78 let rtcid: *u8 = sys_mmap(UM_CIDBUF)
79 uxf_cid_profiled(UXF_MEDIA, rt, rtlen, rtcid)
80
81 // asset 2: WebM carrying VP9 and Opus -- nothing to do
82 let c2: *u8 = sys_mmap(UM_CANON)
83 let l2: i64 = um_descriptor("webm\x00" as *u8, "vp9\x00" as *u8, "opus\x00" as *u8, c2)
84 let cid2: *u8 = sys_mmap(UM_CIDBUF)
85 uxf_cid_profiled(UXF_MEDIA, c2, l2, cid2)
86 let dk2: *i64 = sys_mmap(UM_PTRTAB) as *i64
87 let dv2: *i64 = sys_mmap(UM_PTRTAB) as *i64
88 let nf2: i64 = canon_decode(c2, l2, dk2, dv2, UM_MAXDEC)
89 let plan2: i64 = ng_negotiate(um_find(dk2, dv2, nf2, "container\x00" as *u8), um_find(dk2, dv2, nf2, "vcodec\x00" as *u8), um_find(dk2, dv2, nf2, "acodec\x00" as *u8), chrome_c, chrome_k)
90
91 gv_check_eq("T0a fixture reached the condition: the chrome capability row loaded" as *u8, okc, UM_CAPS_OK, ctr)
92 gv_check_eq("T0b fixture reached the condition: the consumer decoded all three descriptor fields" as *u8, nf, UM_FIELDS, ctr)
93 gv_check_eq("T1 the stored asset self-describes as UXF_MEDIA, readable without rehashing" as *u8, uxf_codec_of_cid(cid1), UXF_MEDIA, ctr)
94 gv_check_eq("T2 the FULL PATH store then tolerant-decode then negotiate resolves mkv h264 aac at chrome to REMUX" as *u8, plan1, PLAN_REMUX, ctr)
95 gv_check("T3 the descriptor round-trips: re-encoding the DECODED fields reproduces the same CID" as *u8, um_streq(rtcid, cid1), ctr)
96 gv_check_eq("T4 a second asset webm vp9 opus at chrome resolves to DIRECT through the same path" as *u8, plan2, PLAN_DIRECT, ctr)
97 gv_check("neg-control-two-DISTINCT-assets-under-one-profile-give-DISTINCT-CIDs" as *u8, 1 - um_streq(cid1, cid2), ctr)
98
99 gv_values_head()
100 gv_kv("caps_tsv_bytes" as *u8, tn)
101 gv_kv("chrome_caps_loaded" as *u8, okc)
102 gv_kv("asset1_canon_len" as *u8, l1)
103 gv_kv("asset1_fields_decoded" as *u8, nf)
104 gv_kv("asset1_profile" as *u8, uxf_codec_of_cid(cid1))
105 gv_kv("UXF_MEDIA" as *u8, UXF_MEDIA)
106 gv_kv("asset1_plan" as *u8, plan1)
107 gv_kv("asset2_plan" as *u8, plan2)
108 gv_kv("PLAN_REMUX" as *u8, PLAN_REMUX)
109 gv_kv("PLAN_DIRECT" as *u8, PLAN_DIRECT)
110 gv_kv("roundtrip_cid_equals_original" as *u8, um_streq(rtcid, cid1))
111 gv_kv("asset1_cid_equals_asset2_cid" as *u8, um_streq(cid1, cid2))
112 gv_puts(" asset1 CID = " as *u8); gv_puts(cid1); gv_puts("\n" as *u8)
113 gv_puts(" asset2 CID = " as *u8); gv_puts(cid2); gv_puts("\n" as *u8)
114
115 let rc: i64 = gv_verdict("UXF-MEDIA-ASSET-GATE" as *u8, ctr, "one envelope stores a media asset once, a consumer that did not write it decodes it without losing anything, and the decoded fields alone decide a lossless rewrap for one endpoint and a direct serve for another" as *u8)
116 sys_exit(rc)
117 return rc
118}