nx_yt_transcript_gate.nx source
↩ module page · 95 lines · 5901 B
1// nx_yt_transcript_gate.nx -- proves nx_yt_captions_lib's timedtext parsers and the empty-body refusal.
2// Parser teeth run on PLANTED json3 and srv1/XML bodies (assembled as literals here, not scanned): exact
3// segment count, monotonic timestamps, entity decode, non-empty text. The neg-control asserts the exact
4// defect the research lane hit: an empty 200 body must classify as REFUSED-EMPTY-BODY (code 2), never as
5// an empty transcript. One live tooth behind gv_need fetches qKz3LmaxKuE's caption track over the network
6// and requires >= 1 segment; offline it SKIPs (never RED). Values via gv_kv for outside adjudication.
7// license_tier: ORIGINAL No hw writes (Rule 26).
8import "nx_syscalls.nx"
9import "nx_gate_verdict.nx"
10import "nx_yt_captions_lib.nx"
11
12// live path for qKz3LmaxKuE: returns segment count (>=1 on success, 0 on any precondition miss), kind in out_kind.
13func g_live_segments(out_kind: *u8, kcap: i64) -> i64 {
14 let r: i64 = ytc_load_store()
15 if r <= 0 { return 0 }
16 let store: *TrustStore = r as *TrustStore
17 let url: *u8 = "https://www.youtube.com/watch?v=qKz3LmaxKuE" as *u8
18 var ul: i64 = 0; while url[ul] != (0 as u8) { ul = ul + 1 }
19 let player: *u8 = sys_mmap(YTC_PLAYER_CAP)
20 let pnn: i64 = ytc_player(url, ul, store, player, YTC_PLAYER_CAP)
21 if pnn <= 0 { return 0 }
22 let arr: *u8 = sys_mmap(YTC_PLAYER_CAP)
23 let alen: i64 = ytc_ct_array(player, pnn, arr, YTC_PLAYER_CAP)
24 if alen < 0 { return 0 }
25 let baseurl: *u8 = sys_mmap(YTC_URL_CAP); let kind: *u8 = sys_mmap(64)
26 let pick: i64 = ytc_pick(arr, alen, "en" as *u8, 2, baseurl, YTC_URL_CAP, out_kind, kcap)
27 if pick != 1 { return 0 }
28 let j3: *u8 = sys_mmap(YTC_URL_CAP); var o: i64 = 0; while baseurl[o] != (0 as u8) { j3[o] = baseurl[o]; o = o + 1 }
29 var kk: i64 = 0
30 let add: *u8 = "&fmt=json3" as *u8
31 while add[kk] != (0 as u8) { j3[o] = add[kk]; o = o + 1; kk = kk + 1 }
32 j3[o] = 0 as u8
33 let status: *i64 = sys_mmap(8) as *i64
34 let body: *u8 = sys_mmap(YTC_BODY_CAP)
35 let bn: i64 = ytc_fetch(j3, store, body, YTC_BODY_CAP, status)
36 if ytc_classify_body(body, bn) != 0 { return 0 }
37 let ns: *i64 = sys_mmap(8) as *i64
38 let tsv: *u8 = sys_mmap(YTC_BODY_CAP)
39 ytc_json3_to_tsv(body, bn, tsv, YTC_BODY_CAP, ns)
40 return ns[0]
41}
42
43func main() -> i64 {
44 let ctr: *i64 = gv_ctr()
45 gv_head("nx_yt_transcript -- timedtext json3/srv1 parsers, empty-body refusal, live caption fetch" as *u8)
46
47 // ---- planted json3 body (\\u0026 -> & after decode; third event has no utf8 -> skipped) ----
48 let J: *u8 = "{\"wireMagic\":\"pb3\",\"events\":[{\"tStartMs\":0,\"dDurationMs\":1000,\"segs\":[{\"utf8\":\"hello \\u0026 world\"}]},{\"tStartMs\":1000,\"dDurationMs\":2000,\"segs\":[{\"utf8\":\"second\"},{\"utf8\":\" line\"}]},{\"tStartMs\":9000,\"aAppend\":1}]}" as *u8
49 var jl: i64 = 0; while J[jl] != (0 as u8) { jl = jl + 1 }
50 let jns: *i64 = sys_mmap(8) as *i64
51 let jtsv: *u8 = sys_mmap(1048576)
52 let jbytes: i64 = ytc_json3_to_tsv(J, jl, jtsv, 1048576, jns)
53 gv_check_eq("json3-segment-count-exact" as *u8, jns[0], 2, ctr)
54 gv_check("json3-timestamps-monotonic" as *u8, ytc_tsv_monotonic(jtsv, jbytes), ctr)
55 gv_check("json3-ampersand-entity-decoded" as *u8, (ms_find(jtsv, jbytes, "hello & world" as *u8, 13, 0) >= 0) as i64, ctr)
56 gv_check("json3-escape-not-left-literal" as *u8, (ms_find(jtsv, jbytes, "u0026" as *u8, 5, 0) < 0) as i64, ctr)
57 gv_check("json3-multi-seg-concatenated" as *u8, (ms_find(jtsv, jbytes, "second line" as *u8, 11, 0) >= 0) as i64, ctr)
58 gv_check_eq("json3-classify-body" as *u8, ytc_classify_body(J, jl), 0, ctr)
59
60 // ---- planted srv1/XML body (& -> & , < -> <) ----
61 let X: *u8 = "<?xml version=\"1.0\"?><transcript><text start=\"0\" dur=\"1.5\">a & b</text><text start=\"1.5\" dur=\"2.0\">x < y</text></transcript>" as *u8
62 var xl: i64 = 0; while X[xl] != (0 as u8) { xl = xl + 1 }
63 let xns: *i64 = sys_mmap(8) as *i64
64 let xtsv: *u8 = sys_mmap(1048576)
65 let xbytes: i64 = ytc_xml_to_tsv(X, xl, xtsv, 1048576, xns)
66 gv_check_eq("xml-segment-count-exact" as *u8, xns[0], 2, ctr)
67 gv_check("xml-timestamps-monotonic" as *u8, ytc_tsv_monotonic(xtsv, xbytes), ctr)
68 gv_check("xml-amp-entity-decoded" as *u8, (ms_find(xtsv, xbytes, "a & b" as *u8, 5, 0) >= 0) as i64, ctr)
69 gv_check("xml-lt-entity-decoded" as *u8, (ms_find(xtsv, xbytes, "x < y" as *u8, 5, 0) >= 0) as i64, ctr)
70 gv_check("xml-entity-not-left-literal" as *u8, (ms_find(xtsv, xbytes, "amp;" as *u8, 4, 0) < 0) as i64, ctr)
71 // 1.5s must convert to 1500 ms (leading integer of row 1)
72 let xr1: *u8 = sys_mmap(4096); let xr1l: i64 = ytc_row_text(xtsv, xbytes, 1, xr1, 4096)
73 gv_check("xml-second-row-text-nonempty" as *u8, (xr1l > 0) as i64, ctr)
74 gv_check_eq("xml-classify-body" as *u8, ytc_classify_body(X, xl), 1, ctr)
75
76 // ---- the empty-200 defect the research lane hit ----
77 let empty: *u8 = sys_mmap(16)
78 gv_check_eq("neg-control-empty-body-refused-by-name" as *u8, ytc_classify_body(empty, 0), 2, ctr)
79
80 // ---- live: fetch qKz3LmaxKuE's caption track (network precondition -> SKIP offline, never RED) ----
81 let kind: *u8 = sys_mmap(64)
82 let live: i64 = g_live_segments(kind, 64)
83 let present: i64 = gv_need("network+ANDROID-caption for qKz3LmaxKuE" as *u8, (live >= 1) as i64, ctr)
84 if present == 1 { gv_check("live-qKz3LmaxKuE-has-segments" as *u8, (live >= 1) as i64, ctr) }
85
86 gv_values_head()
87 gv_kv("json3_fixture_segments" as *u8, jns[0])
88 gv_kv("xml_fixture_segments" as *u8, xns[0])
89 gv_kv("live_qKz3_segments" as *u8, live)
90 gv_puts(" live_qKz3_kind=" as *u8); gv_puts(kind); gv_puts("\n" as *u8)
91
92 let rc: i64 = gv_verdict("YT-TRANSCRIPT-GATE" as *u8, ctr, "json3/srv1 parsers + empty-body refusal proven; live caption fetch behind gv_need" as *u8)
93 sys_exit(rc)
94 return rc
95}