nx_swcompare_shape_gate.nx source
↩ module page · 173 lines · 11134 B
1// nx_swcompare_shape_gate.nx -- END-TO-END gate for the /compare matrix ROW SHAPE (operator 2026-09-05:
2// "you have random shit in the compare that makes no sense to a human ... make it sound like a positive
3// ... improve the /compare emitter to be more intelligent like a pros vs cons instead of single shaping
4// everything"). The generator used to render every row as a glyph strip plus a raw adoption token styled
5// like a badge. This gate builds a FIXTURE domain in /tmp/<gate>/ (the fixture-ratchet law: never a
6// production file), forks the SUBJECT generator on it with CWD inside the fixture, and asserts the
7// derived Pros / Cons strip says the right thing, signed the right way, for each row shape:
8// A Nishi present, one rival LEADS, one rival present, two absent -> ahead of two, behind the leader
9// B an open watch contract (_ABSENT_:) -> "open contract" con
10// C Nishi present, every rival absent -> NO rival con (neg-control)
11// Named for the PROPERTY (row shape), not the organ; organ_gate.conf binds it to nx_swcompare_matrix.
12// exit: 0 GREEN / 1 RED (gv_verdict law).
13import "nx_syscalls.nx"
14import "nx_gate_verdict.nx"
15import "nx_tool_run.nx"
16
17const SG_OUT: i64 = 1048576
18const SG_PATH: i64 = 512
19const SG_MODE_755: i64 = 493
20const SG_MODE_644: i64 = 420
21const SG_DIR: *u8 = "/tmp/nx_swcompare_shape_gate" as *u8
22
23func sg_find(q: *u8, n: i64, lit: *u8) -> i64 {
24 var ll: i64 = 0
25 while lit[ll] != (0 as u8) { ll = ll + 1 }
26 if ll == 0 { return 0 }
27 var i: i64 = 0
28 while i + ll <= n {
29 var j: i64 = 0
30 var ok: i64 = 1
31 while j < ll { if q[i + j] != lit[j] { ok = 0; j = ll } else { j = j + 1 } }
32 if ok == 1 { return 1 }
33 i = i + 1
34 }
35 return 0
36}
37
38func sg_pos(q: *u8, from: i64, n: i64, lit: *u8) -> i64 {
39 var ll: i64 = 0
40 while lit[ll] != (0 as u8) { ll = ll + 1 }
41 if ll == 0 { return 0 - 1 }
42 var i: i64 = from
43 while i + ll <= n {
44 var j: i64 = 0
45 var ok: i64 = 1
46 while j < ll { if q[i + j] != lit[j] { ok = 0; j = ll } else { j = j + 1 } }
47 if ok == 1 { return i }
48 i = i + 1
49 }
50 return 0 - 1
51}
52
53func sg_exists(path: *u8) -> i64 {
54 let fd: i64 = sys_openat_rd(path)
55 if fd < 0 { return 0 }
56 sys_close(fd)
57 return 1
58}
59
60func sg_write_text(path: *u8, s: *u8) -> i64 {
61 let fd: i64 = sys_openat_wr(path, SG_MODE_644)
62 if fd < 0 { return 0 - 1 }
63 var n: i64 = 0
64 while s[n] != (0 as u8) { n = n + 1 }
65 sys_write(fd, s, n)
66 sys_close(fd)
67 return n
68}
69
70func main(argc: i64, argv: *i64) -> i64 {
71 let ctr: *i64 = gv_ctr()
72 gv_head("nx_swcompare_shape_gate -- the matrix row shape: a derived Pros / Cons strip, signed correctly, on a fixture domain" as *u8)
73 // subject: the just-built artifact first (PROVE runs before promote), the promoted second, announced
74 let built: *u8 = "buildroot/_build/nx_swcompare_matrix.sov.elf" as *u8
75 let promoted: *u8 = "./nx_swcompare_matrix.elf" as *u8
76 // two hosts, two ladders: the NAS ship loop builds to buildroot/_build/, the laptop farm to _build/
77 let built_local: *u8 = "_build/nx_swcompare_matrix.sov.elf" as *u8
78 var subject: *u8 = promoted
79 var which: *u8 = "PROMOTED" as *u8
80 if sg_exists(built_local) == 1 { subject = built_local; which = "JUST-BUILT-local" as *u8 }
81 if sg_exists(built) == 1 { subject = built; which = "JUST-BUILT" as *u8 }
82 gv_puts("SUBJECT " as *u8); gv_puts(which); gv_puts(" " as *u8); gv_puts(subject); gv_puts("\n" as *u8)
83 gv_check("T1 subject generator artifact resolved" as *u8, sg_exists(subject), ctr)
84 if sg_exists(subject) == 0 { return gv_verdict("nx_swcompare_shape_gate" as *u8, ctr, "no subject at either root; nothing proven" as *u8) }
85 // fixture tree under /tmp/<gate>/ -- SETUP creates it, never a teardown (a crash skips teardowns)
86 sys_mkdir(SG_DIR, SG_MODE_755)
87 sys_mkdir("/tmp/nx_swcompare_shape_gate/knowledge" as *u8, SG_MODE_755)
88 sys_mkdir("/tmp/nx_swcompare_shape_gate/knowledge/compare" as *u8, SG_MODE_755)
89 sys_mkdir("/tmp/nx_swcompare_shape_gate/runtime" as *u8, SG_MODE_755)
90 let wo: i64 = sg_write_text("/tmp/nx_swcompare_shape_gate/runtime/fxorg.nx" as *u8, "// fixture organ\nfunc fx_sym() -> i64 { return 0 }\n" as *u8)
91 let wm: i64 = sg_write_text("/tmp/nx_swcompare_shape_gate/knowledge/compare/fx.matrix" as *u8,
92 "# fixture\n@title Shape Fixture\n@cols RivalOne|RivalTwo|RivalThree|RivalFour\nRow A present with a leader|runtime/fxorg.nx|fx_sym|0|0|2|1|0|note a\nRow B open contract|runtime/fxorg.nx|_ABSENT_:fx_missing|0|1|0|0|0|note b\nRow C present over all|runtime/fxorg.nx|fx_sym|0|0|0|0|0|note c\nRow D cited rival|runtime/fxorg.nx|fx_sym|0|2|0|0|0|note d [@fxref]\n" as *u8)
93 // NAS /tmp is NOEXEC (measured 2026-09-05: gen_exit=127 on the copied subject, 11/11 on the laptop whose
94 // /tmp executes). Never copy-and-exec from the fixture: resolve the subject to an ABSOLUTE path before
95 // chdir and fork it in place, with only the CWD inside the fixture.
96 let cwd: *u8 = sys_mmap(SG_PATH * 8)
97 let cl: i64 = sys_getcwd(cwd, SG_PATH * 8 - 1)
98 let absub: *u8 = sys_mmap(SG_PATH * 8)
99 var ao: i64 = 0
100 var ci: i64 = 0
101 while cwd[ci] != (0 as u8) { absub[ao] = cwd[ci]; ao = ao + 1; ci = ci + 1 }
102 absub[ao] = 47 as u8
103 ao = ao + 1
104 var si: i64 = 0
105 if subject[0] == (46 as u8) { if subject[1] == (47 as u8) { si = 2 } }
106 while subject[si] != (0 as u8) { absub[ao] = subject[si]; ao = ao + 1; si = si + 1 }
107 absub[ao] = 0 as u8
108 gv_puts("SUBJECT-ABS " as *u8); gv_puts(absub); gv_puts("\n" as *u8)
109 gv_check("T2 fixture written (organ, matrix) and the subject resolved to an absolute path (never exec'd from /tmp)" as *u8, ((wo > 0) as i64) * ((wm > 0) as i64) * ((cl > 0) as i64), ctr)
110 // run the generator INSIDE the fixture (it reads knowledge/compare/<dom>.matrix and runtime/ relative to CWD)
111 let cd: i64 = sys_chdir(SG_DIR)
112 gv_check("T3 chdir into the fixture" as *u8, (cd == 0) as i64, ctr)
113 let av: *i64 = sys_mmap(64) as *i64
114 av[0] = absub as i64
115 av[1] = "fx" as *u8 as i64
116 av[2] = "html" as *u8 as i64
117 av[3] = 0
118 let cout: *u8 = sys_mmap(SG_OUT)
119 let colen: *i64 = sys_mmap(16) as *i64
120 colen[0] = 0
121 let ex: i64 = tr_run_capture(absub, av, cout, SG_OUT - 8, colen)
122 let n: i64 = colen[0]
123 gv_kv("gen_exit" as *u8, ex)
124 gv_kv("gen_bytes" as *u8, n)
125 gv_check("T4 generator ran on the fixture and emitted a page" as *u8, ((ex == 0) as i64) * ((n > 0) as i64), ctr)
126 gv_check("T5 the Pros / Cons strip is emitted (div.pc) and its CSS rule is referenced, not merely defined" as *u8, sg_find(cout, n, "<div class='pc'>" as *u8) * sg_find(cout, n, ".pc{" as *u8), ctr)
127 // Row A: present (2 pts) vs rivals 0,2,1,0 -> ahead of RivalOne and RivalFour, behind RivalTwo (leads)
128 gv_check("T6 row A: ahead of the two absent rivals is stated as a PRO" as *u8, sg_find(cout, n, "ahead of RivalOne, RivalFour" as *u8), ctr)
129 gv_check("T7 row A: behind the leading rival is stated as a CON, signed as a lead" as *u8, sg_find(cout, n, "behind RivalTwo (leads)" as *u8), ctr)
130 gv_check("T8 row B: an open watch contract reads as a CON in plain words" as *u8, sg_find(cout, n, "open contract, nothing on disk yet" as *u8), ctr)
131 // Row C, ROW-SCOPED (the fixture organ is unadopted on any host without a catalog census, so its only
132 // legitimate con is the adoption one): inside row C's strip there is NO rival con, the PRO names all four
133 // rivals, and the con is either "none on the measured axes" or the adoption remedy -- never a fabricated lead.
134 let c_at: i64 = sg_pos(cout, 0, n, "Row C present over all" as *u8)
135 var c_ok: i64 = 0
136 if c_at >= 0 {
137 let s_at: i64 = sg_pos(cout, c_at, n, "<div class='pc'>" as *u8)
138 if s_at >= 0 {
139 let e_at: i64 = sg_pos(cout, s_at, n, "</div>" as *u8)
140 if e_at > s_at {
141 let seg: *u8 = ((cout as i64) + s_at) as *u8
142 let sn: i64 = e_at - s_at
143 let nobehind: i64 = (sg_find(seg, sn, "behind " as *u8) == 0) as i64
144 let allahead: i64 = sg_find(seg, sn, "ahead of RivalOne, RivalTwo, RivalThree, RivalFour" as *u8)
145 var honest: i64 = sg_find(seg, sn, "none on the measured axes" as *u8)
146 if honest == 0 { honest = sg_find(seg, sn, "not adopted yet:" as *u8) }
147 c_ok = nobehind * allahead * honest
148 }
149 }
150 }
151 gv_check("T9 row C (row-scoped): ahead of all four rivals, NO rival con, and the con is honest (none measured or the adoption remedy) -- never a victory claim" as *u8, c_ok, ctr)
152 // RIVAL-CLAIM PROVENANCE (2026-09-05): rows A and B grade rivals with no mark (UNCITED), row D grades a rival and
153 // cites [@fxref] (CITED), row C grades no rival (NONE). The band prints the split and the badge sits only on
154 // uncited rows -- asserted per row SEGMENT, never by one global find that a single badge anywhere would satisfy.
155 gv_check("T12 the rival-claim provenance band prints rows 3, cited 1, uncited 2 for this fixture" as *u8, sg_find(cout, n, "rows with rival marks 3 · cited 1 · uncited 2" as *u8), ctr)
156 let a_at: i64 = sg_pos(cout, 0, n, "Row A present with a leader" as *u8)
157 let b_at: i64 = sg_pos(cout, 0, n, "Row B open contract" as *u8)
158 let d_at: i64 = sg_pos(cout, 0, n, "Row D cited rival" as *u8)
159 var a_badge: i64 = 0
160 var c_badge: i64 = 0
161 var d_badge: i64 = 0
162 if a_at >= 0 { if b_at > a_at { a_badge = sg_find(((cout as i64) + a_at) as *u8, b_at - a_at, "rival marks uncited" as *u8) } }
163 if c_at >= 0 { if d_at > c_at { c_badge = sg_find(((cout as i64) + c_at) as *u8, d_at - c_at, "rival marks uncited" as *u8) } }
164 if d_at >= 0 { d_badge = sg_find(((cout as i64) + d_at) as *u8, n - d_at, "rival marks uncited" as *u8) }
165 gv_check("T13 row A (rival codes 0,2,1,0 and no mark) carries the uncited badge inside its own row" as *u8, a_badge, ctr)
166 gv_check("neg-control-row-C-grades-no-rival-and-carries-no-uncited-badge" as *u8, (c_badge == 0) as i64, ctr)
167 gv_check("neg-control-row-D-cites-a-reference-and-carries-no-uncited-badge" as *u8, (d_badge == 0) as i64, ctr)
168 // neg-control: the strip must never print the RAW ladder token as a visible badge (the old shape)
169 gv_check("neg-control-no-raw-adoption-badge: the old visible chip shape 'adoption <b>' is gone" as *u8, (sg_find(cout, n, "class='watch'>adoption <b>" as *u8) == 0) as i64, ctr)
170 // non-vacuity: a page that contains no strip at all cannot pass T5..T9 -- and the fixture has exactly 3 rows
171 gv_check("T11 non-vacuity: four strips for four rows (rows C and D both rendered)" as *u8, sg_find(cout, n, "Row C present over all" as *u8) * sg_find(cout, n, "Row D cited rival" as *u8), ctr)
172 return gv_verdict("nx_swcompare_shape_gate" as *u8, ctr, "row shape derived from the cells: has / ahead / behind / open / not-adopted, signed; rival marks are documented presence and the strip says so" as *u8)
173}