nx_field_gate.nx source
↩ module page · 189 lines · 11607 B
1// nx_field_gate.nx -- THE GATE FOR THE FIELD DISCOVERY CORE (nx_field_lib, /compare/fieldwatch FW1).
2//
3// Drives the extractors IN-PROCESS on fixtures assembled at RUNTIME (no network, no evidence-store writes), so every
4// tooth is mutation-provable and none can find its pattern in source. What it must catch: a wiki extractor that
5// harvests citation links (a CNET reference is not a rival), one that harvests namespace links (Category: File:),
6// a dedupe that lets case variants through as two rivals, a seeds mask that cannot tell one seed from two, an emit
7// order that ignores the evidence, and a GitHub extractor that reads any anchor as a repository.
8// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11import "nx_field_lib.nx"
12
13const FG_WORD: i64 = 8
14const FG_CAP: i64 = 65536
15const FG_SEED_A: i64 = 0
16const FG_SEED_B: i64 = 1
17const FG_SEED_C: i64 = 2
18const FG_WIKI: *u8 = "Modding tools include [[BepInEx]] and [[MelonLoader|Melon Loader]] and [[BepInEx]] again.<ref>{{cite web |title=x |publisher=[[CNET]]}}</ref>\n{{Infobox software | name = [[Template link]] }}\n* [[Category:Video game mods]]\n* [[File:Icon.png]]\n* [[Nexus Mods]] hosts files; see [[Nexus Mods#History]].\n<ref name=a/> tail [[LOOT]]\n"
19const FG_WIKI_B: *u8 = "Loaders: [[bepinex]] and [[LOOT]].\n"
20const FG_GH: *u8 = "<a href=\x22/BepInEx/BepInEx\x22 data-view-component=\x22true\x22 class=\x22Link text-bold wb-break-word\x22>BepInEx</a> junk <a href=\x22/sponsors/x\x22 class=\x22Link\x22>sponsor</a> <a href=\x22/ebkr/r2modmanPlus\x22 data-view-component=\x22true\x22 class=\x22Link text-bold wb-break-word\x22>r2modmanPlus</a>"
21const FG_MD: *u8 = "# awesome\n- [Vortex](https://example.org/vortex) - a manager\n* [LOOT](https://example.org/loot)\nnot an item [Nope](x)\n"
22const FG_NS_ONLY: *u8 = "* [[Category:Only]] and [[File:Only.png]] and [[Help:Only]]\n"
23const FG_REF_ONLY: *u8 = "text<ref>[[Inside Ref]]</ref> and {{cite|[[Inside Template]]}}\n"
24const FG_OUT: *u8 = "/tmp/nx_field_gate.out"
25const FG_MODEDIR: i64 = 493
26
27func fg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
28func fg_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
29// index of a candidate by exact name, or -1
30func fg_idx(t: *i64, name: *u8) -> i64 {
31 var i: i64 = 0
32 while i < fl_count(t) { if fg_streq(fl_name_at(t, i), name) == 1 { return i } i = i + 1 }
33 return 0 - 1
34}
35func fg_has(t: *i64, name: *u8) -> i64 { if fg_idx(t, name) >= 0 { return 1 } return 0 }
36
37func main(argc: i64, argv: *i64) -> i64 {
38 let ctr: *i64 = gv_ctr()
39 gv_head("nx_field gate -- the discovered field is a measurement of public lists, never a seat's pick" as *u8)
40
41 // ---- wiki-raw ----
42 let t: *i64 = fl_tbl_new()
43 let added: i64 = fl_wiki_scan(t, FG_WIKI, fg_slen(FG_WIKI), FG_SEED_A)
44 gv_puts(" [T1] wiki occurrences accepted=" as *u8); gv_num(added); gv_puts(" distinct=" as *u8); gv_num(fl_count(t)); gv_puts("\n" as *u8)
45 var t1: i64 = 0
46 if fg_has(t, "BepInEx" as *u8) == 1 { if fg_has(t, "MelonLoader" as *u8) == 1 { if fg_has(t, "Nexus Mods" as *u8) == 1 { if fg_has(t, "LOOT" as *u8) == 1 { t1 = 1 } } } }
47 gv_check("wiki-links-in-prose-and-lists-become-candidates (target kept, display text dropped)" as *u8, t1, ctr)
48 var t2: i64 = 0
49 if fg_has(t, "CNET" as *u8) == 0 { if fg_has(t, "Template link" as *u8) == 0 { t2 = 1 } }
50 gv_check("neg-control-links-inside-ref-and-template-blocks-are-NOT-candidates" as *u8, t2, ctr)
51 var t3: i64 = 0
52 if fg_has(t, "Category:Video game mods" as *u8) == 0 { if fg_has(t, "File:Icon.png" as *u8) == 0 { t3 = 1 } }
53 gv_check("neg-control-namespace-links-excluded-by-their-colon" as *u8, t3, ctr)
54 let bi: i64 = fg_idx(t, "BepInEx" as *u8)
55 var t4: i64 = 0
56 if bi >= 0 { if fl_rec(t, bi, 0) == 2 { t4 = 1 } }
57 gv_check("repeated-link-counts-mentions (BepInEx twice = 2)" as *u8, t4, ctr)
58 var t5: i64 = 0
59 if fg_has(t, "Nexus Mods#History" as *u8) == 0 { t5 = 1 }
60 gv_check("section-anchor-links-are-not-a-second-rival" as *u8, t5, ctr)
61 var t5b: i64 = 0
62 if fg_has(t, "LOOT" as *u8) == 1 { t5b = 1 }
63 gv_check("a-self-closing-ref-tag-does-not-swallow-the-rest-of-the-page" as *u8, t5b, ctr)
64
65 // ---- second seed: dedupe across case, seeds mask ----
66 let before: i64 = fl_count(t)
67 fl_wiki_scan(t, FG_WIKI_B, fg_slen(FG_WIKI_B), FG_SEED_B)
68 var t6: i64 = 0
69 if fl_count(t) == before { t6 = 1 }
70 gv_check("case-variant-of-a-known-rival-dedupes-into-it (bepinex == BepInEx)" as *u8, t6, ctr)
71 var t7: i64 = 0
72 if bi >= 0 { if fl_popcount(fl_rec(t, bi, 1)) == 2 { if fl_rec(t, bi, 0) == 3 { t7 = 1 } } }
73 gv_check("seeds-hit-mask-counts-distinct-seeds-while-mentions-count-occurrences (2 seeds, 3 mentions)" as *u8, t7, ctr)
74 let mi: i64 = fg_idx(t, "MelonLoader" as *u8)
75 var t8: i64 = 0
76 if mi >= 0 { if fl_popcount(fl_rec(t, mi, 1)) == 1 { t8 = 1 } }
77 gv_check("a-rival-seen-in-one-seed-carries-one-seed-bit" as *u8, t8, ctr)
78
79 // ---- gh-topic ----
80 let g: *i64 = fl_tbl_new()
81 let gadd: i64 = fl_gh_scan(g, FG_GH, fg_slen(FG_GH), FG_SEED_C)
82 gv_puts(" [T9] github repos accepted=" as *u8); gv_num(gadd); gv_puts("\n" as *u8)
83 var t9: i64 = 0
84 if gadd == 2 { if fg_has(g, "BepInEx" as *u8) == 1 { if fg_has(g, "r2modmanPlus" as *u8) == 1 { if fg_has(g, "sponsor" as *u8) == 0 { t9 = 1 } } } }
85 gv_check("github-repo-anchors-become-candidates-and-other-anchors-do-not" as *u8, t9, ctr)
86 let ri: i64 = fg_idx(g, "r2modmanPlus" as *u8)
87 var t10: i64 = 0
88 if ri >= 0 { if fg_streq(fl_link_at(g, ri), "/ebkr/r2modmanPlus" as *u8) == 1 { t10 = 1 } }
89 gv_check("github-candidate-carries-its-two-segment-href-as-the-link" as *u8, t10, ctr)
90
91 // ---- md-list ----
92 let m: *i64 = fl_tbl_new()
93 let madd: i64 = fl_md_scan(m, FG_MD, fg_slen(FG_MD), FG_SEED_A)
94 var t11: i64 = 0
95 if madd == 2 { if fg_has(m, "Vortex" as *u8) == 1 { if fg_has(m, "LOOT" as *u8) == 1 { if fg_has(m, "Nope" as *u8) == 0 { t11 = 1 } } } }
96 gv_check("markdown-list-items-become-candidates-and-inline-links-do-not" as *u8, t11, ctr)
97 let vi: i64 = fg_idx(m, "Vortex" as *u8)
98 var t12: i64 = 0
99 if vi >= 0 { if fg_streq(fl_link_at(m, vi), "https://example.org/vortex" as *u8) == 1 { t12 = 1 } }
100 gv_check("markdown-candidate-carries-its-link" as *u8, t12, ctr)
101
102 // ---- emit order and grammar ----
103 let keys: *i64 = sys_mmap(FG_WORD * 4) as *i64
104 keys[0] = "seedA" as *u8 as i64
105 keys[1] = "seedB" as *u8 as i64
106 keys[2] = "seedC" as *u8 as i64
107 sys_unlinkat(FG_OUT)
108 let fd: i64 = sys_openat_wr(FG_OUT, MODE_0644)
109 var rows: i64 = 0 - 1
110 if fd >= 0 { rows = fl_emit(t, fd, keys, 3); sys_close(fd) }
111 let lp: *i64 = sys_mmap(16) as *i64
112 let ob: *u8 = sys_read_file(FG_OUT, lp)
113 var t13: i64 = 0
114 if rows == fl_count(t) { if (ob as i64) != 0 { if lp[0] > 0 {
115 // the first row must be the rival with the most seeds then mentions: BepInEx (2 seeds, 3 mentions)
116 let first: *u8 = "rival|BepInEx|2|3|seedA|" as *u8
117 var ok: i64 = 1
118 var i: i64 = 0
119 while first[i] != (0 as u8) { if i >= lp[0] { ok = 0; break } if ob[i] != first[i] { ok = 0; break } i = i + 1 }
120 if ok == 1 { t13 = 1 }
121 } } }
122 gv_check("emit-orders-by-seeds-then-mentions-and-writes-the-row-grammar (first row = BepInEx 2 seeds 3 mentions)" as *u8, t13, ctr)
123 // every emitted row has exactly 6 pipes
124 var t14: i64 = 0
125 if (ob as i64) != 0 {
126 var bad: i64 = 0
127 var lines: i64 = 0
128 var p: i64 = 0
129 var pipes: i64 = 0
130 while p < lp[0] {
131 if (ob[p] as i64) == 124 { pipes = pipes + 1 }
132 if (ob[p] as i64) == 10 { lines = lines + 1; if pipes != 6 { bad = bad + 1 } pipes = 0 }
133 p = p + 1
134 }
135 if lines == rows { if bad == 0 { t14 = 1 } }
136 }
137 gv_check("every-row-carries-exactly-six-pipes (a pipe inside a name is neutralised)" as *u8, t14, ctr)
138
139 // ---- bites ----
140 let z: *i64 = fl_tbl_new()
141 let zadd: i64 = fl_wiki_scan(z, FG_NS_ONLY, fg_slen(FG_NS_ONLY), FG_SEED_A)
142 var fired_bad: i64 = 0
143 if zadd == 0 { if fl_count(z) == 0 { fired_bad = 1 } }
144 var fired_good: i64 = 0
145 if added == 0 { fired_good = 1 }
146 gv_bite("neg-control-a-page-of-only-namespace-links-yields-zero-while-the-real-page-yields-rivals" as *u8, fired_bad, fired_good, ctr)
147 let r: *i64 = fl_tbl_new()
148 let radd: i64 = fl_wiki_scan(r, FG_REF_ONLY, fg_slen(FG_REF_ONLY), FG_SEED_A)
149 var fb2: i64 = 0
150 if radd == 0 { fb2 = 1 }
151 gv_bite("neg-control-a-page-whose-only-links-sit-in-refs-and-templates-yields-zero" as *u8, fb2, fired_good, ctr)
152
153 // ---- named: the DECLARED population (operator correction 2026-09-05) ----
154 let d: *i64 = fl_tbl_new()
155 fl_wiki_scan(d, FG_WIKI, fg_slen(FG_WIKI), FG_SEED_A)
156 let nb: i64 = fl_count(d)
157 let nrc: i64 = fl_named_add(d, "nexus mods" as *u8, "https://www.nexusmods.com/" as *u8, FG_SEED_C)
158 var t15: i64 = 0
159 if nrc >= 0 { if fl_count(d) == nb { let ni: i64 = fg_idx(d, "Nexus Mods" as *u8); if ni >= 0 { if fl_popcount(fl_rec(d, ni, 1)) == 2 { t15 = 1 } } } }
160 gv_check("a-declared-member-dedupes-into-the-public-list-rival-and-carries-both-seed-bits (nexus mods == Nexus Mods, 2 seeds)" as *u8, t15, ctr)
161 let nb2: i64 = fl_count(d)
162 fl_named_add(d, "LoversLab" as *u8, "https://www.loverslab.com/" as *u8, FG_SEED_C)
163 let li: i64 = fg_idx(d, "LoversLab" as *u8)
164 var t16: i64 = 0
165 if fl_count(d) == nb2 + 1 { if li >= 0 { if fl_rec(d, li, 3) == FL_KIND_NAMED { if fg_streq(fl_link_at(d, li), "https://www.loverslab.com/" as *u8) == 1 { if fg_streq(fl_kind_name(FL_KIND_NAMED), "named" as *u8) == 1 { t16 = 1 } } } } }
166 gv_check("a-declared-member-absent-from-every-list-is-still-in-the-population-with-its-url-and-kind-named" as *u8, t16, ctr)
167 var t17: i64 = 0
168 if fl_named_add(d, "" as *u8, "https://example.org/" as *u8, FG_SEED_C) < 0 { if fl_count(d) == nb2 + 1 { t17 = 1 } }
169 gv_check("neg-control-an-empty-declared-name-is-refused-and-adds-nothing" as *u8, t17, ctr)
170
171 gv_kv("wiki_distinct" as *u8, fl_count(t))
172 // declared members rank as a tier above every lead, whatever the mention counts say
173 let dord: *i64 = sys_mmap(FG_WORD * (fl_count(d) + 1)) as *i64
174 fl_order(d, dord)
175 var t18: i64 = 0
176 if fl_count(d) >= 3 { if fg_streq(fl_name_at(d, dord[0]), "Nexus Mods" as *u8) == 1 { if fg_streq(fl_name_at(d, dord[1]), "LoversLab" as *u8) == 1 { if fg_streq(fl_name_at(d, dord[2]), "BepInEx" as *u8) == 1 { t18 = 1 } } } }
177 gv_check("declared-members-order-first-as-a-tier (Nexus Mods 2 seeds, LoversLab 1 seed and 1 mention, then BepInEx with 2 mentions)" as *u8, t18, ctr)
178 var t19: i64 = 0
179 let nxi: i64 = fg_idx(d, "Nexus Mods" as *u8)
180 if nxi >= 0 { if fl_rec(d, nxi, 3) == FL_KIND_NAMED { t19 = 1 } }
181 gv_check("a-merged-declared-member-carries-kind-named-so-the-page-can-tell-population-from-lead" as *u8, t19, ctr)
182 gv_kv("named_distinct" as *u8, fl_count(d))
183 gv_kv("wiki_mentions" as *u8, fl_mentions_total(t))
184 gv_kv("gh_distinct" as *u8, fl_count(g))
185 gv_kv("md_distinct" as *u8, fl_count(m))
186 let rc: i64 = gv_verdict("NX-FIELD" as *u8, ctr, "the field extractors read public lists mechanically, exclude citations and namespaces, dedupe across case, and emit evidence-ordered rows" as *u8)
187 sys_exit(rc)
188 return rc
189}