nx_gaps_pass_gate.nx source
↩ module page · 128 lines · 9564 B
1// nx_gaps_pass_gate.nx -- GATE for gaps_pass (ecosystem EC38): the ONE renderer of the record census feed
2// (knowledge/recordgaps.conf.rows + its sibling .stamp) in the compare base lib, driven IN-PROCESS on a planted fixture
3// tree under /tmp/nx_gaps_pass_gate. The gate chdirs into the fixture root so the lib's estate-path probe resolves the feed
4// INSIDE the fixture (as-given wins over ../ and the roots) and never renders the real census. Controls: a board renders
5// ONLY its own directive rows plus the estate-wide organ COUNT; the ecosystem hub renders the un-boarded organs in full;
6// a MALFORMED row is counted and never rendered; an angle bracket in a name is escaped; a STALE stamp renders its rows
7// under the STALE state (a stale census is never "no gaps"); a BLIND stamp says sources read of declared; a FRESH one
8// says FRESH. The absent-feed tooth is named WEAK on purpose: the resolver probes the estate roots ABSOLUTELY, so on the
9// NAS an absent fixture feed legitimately falls through to the production feed -- the tooth accepts either outcome and
10// says so. Every fixture asserts it reached its condition before any outcome is judged. No network. license_tier: ORIGINAL
11import "nx_syscalls.nx"
12import "nx_gatekit_lib.nx"
13import "nx_swcompare_lib.nx"
14import "nx_gate_verdict.nx"
15
16const X_ROOT: *u8 = "/tmp/nx_gaps_pass_gate"
17const X_KDIR: *u8 = "/tmp/nx_gaps_pass_gate/knowledge"
18const X_FEED: *u8 = "/tmp/nx_gaps_pass_gate/knowledge/recordgaps.conf.rows"
19const X_STAMP: *u8 = "/tmp/nx_gaps_pass_gate/knowledge/recordgaps.conf.stamp"
20const X_EMPTY: *u8 = "/tmp/nx_gaps_pass_gate_empty"
21const X_EMPTY_K: *u8 = "/tmp/nx_gaps_pass_gate_empty/knowledge"
22const X_A_HTML: *u8 = "/tmp/nx_gaps_pass_gate/a.html"
23const X_A_JSON: *u8 = "/tmp/nx_gaps_pass_gate/a.json"
24const X_HUB_HTML: *u8 = "/tmp/nx_gaps_pass_gate/hub.html"
25const X_HUB_JSON: *u8 = "/tmp/nx_gaps_pass_gate/hub.json"
26const X_STALE_HTML: *u8 = "/tmp/nx_gaps_pass_gate/stale.html"
27const X_FRESH_HTML: *u8 = "/tmp/nx_gaps_pass_gate/fresh.html"
28const X_ABS_JSON: *u8 = "/tmp/nx_gaps_pass_gate/abs.json"
29const X_MODE_RW: i64 = 420
30const X_MODE_RWX: i64 = 493
31const X_CAP: i64 = 262144
32const X_CADENCE: i64 = 86400
33const X_STALE_BEATS: i64 = 5
34const X_TOTAL: i64 = 4
35const X_READ_BLIND: i64 = 3
36const X_DECLARED: i64 = 4
37// four valid rows (two UNASSIGNED organs, one of them carrying an angle bracket; one directive per board a and b) + one malformed
38const X_ROWS: *u8 = "# comparegaps rows ts=1 total=4 organ=2 directive=2 sources_read=3 sources_declared=4\norgan|nx_orphan_q|UNASSIGNED|invoked|count=3\norgan|nx_x<y|UNASSIGNED|invoked|count=1\ndirective|qq_sym|a|plan-queue|rung=A1\ndirective|zz_sym|b|plan-queue|rung=B1\nbad|row\n"
39
40func x_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
41func x_put(path: *u8, body: *u8) -> i64 {
42 sys_unlinkat(path)
43 let fd: i64 = sys_openat_wr(path, X_MODE_RW)
44 if fd < 0 { return 0 - 1 }
45 let w: i64 = sys_write(fd, body, x_slen(body))
46 sys_close(fd)
47 return w
48}
49func x_find(buf: *u8, n: i64, needle: *u8) -> i64 {
50 let m: i64 = x_slen(needle)
51 if m == 0 { return 0 }
52 var i: i64 = 0
53 while i + m <= n { var j: i64 = 0; var ok: i64 = 1; while j < m { if buf[i + j] != needle[j] { ok = 0 } j = j + 1 } if ok == 1 { return 1 } i = i + 1 }
54 return 0
55}
56// render one board in one mode into a capture file, read it back; returns bytes read (0 = the pass emitted nothing)
57func x_render(dom: *u8, mode: i64, out: *u8, buf: *u8) -> i64 {
58 sys_unlinkat(out)
59 let fd: i64 = sys_openat_wr(out, X_MODE_RW)
60 if fd < 0 { return 0 - 1 }
61 gaps_pass(dom, fd, mode)
62 sys_close(fd)
63 let n: i64 = c_read(out, buf, X_CAP - 1)
64 if n < 0 { return 0 }
65 buf[n] = 0 as u8
66 return n
67}
68
69func main(argc: i64, argv: *i64) -> i64 {
70 let ctr: *i64 = gv_ctr()
71 gv_head("NX-GAPS-PASS-GATE: the record-census render on a planted fixture -- own directives per board, un-boarded organs in full on the hub and as a count elsewhere, malformed counted never rendered, names escaped, STALE and BLIND stated never hidden" as *u8)
72 sys_mkdir(X_ROOT, X_MODE_RWX)
73 sys_mkdir(X_KDIR, X_MODE_RWX)
74 sys_mkdir(X_EMPTY, X_MODE_RWX)
75 sys_mkdir(X_EMPTY_K, X_MODE_RWX)
76 let fw: i64 = x_put(X_FEED, X_ROWS)
77 let now: i64 = sys_now_realtime_sec()
78 let sw: i64 = ga_stamp_write(X_STAMP, now, X_TOTAL, X_READ_BLIND, X_DECLARED, X_CADENCE)
79 if gv_need("fixture feed and BLIND stamp planted" as *u8, ((fw > 0) as i64) * ((sw > 0) as i64), ctr) == 0 { return gv_verdict("nx_gaps_pass_gate" as *u8, ctr, "could not plant the fixture" as *u8) }
80 if gv_need("fixture root entered" as *u8, (sys_chdir(X_ROOT) == 0) as i64, ctr) == 0 { return gv_verdict("nx_gaps_pass_gate" as *u8, ctr, "could not chdir into the fixture" as *u8) }
81 let buf: *u8 = sys_mmap(X_CAP)
82 // ---- board a, HTML ----
83 let na: i64 = x_render("a" as *u8, 1, X_A_HTML, buf)
84 gv_check("board-html-has-the-gaps-section" as *u8, x_find(buf, na, "<h2 id='gaps'>" as *u8), ctr)
85 gv_check("board-html-renders-its-own-directive-row" as *u8, x_find(buf, na, "<code>qq_sym</code>" as *u8), ctr)
86 gv_check("neg-control-board-html-never-renders-another-boards-directive" as *u8, (x_find(buf, na, "zz_sym" as *u8) == 0) as i64, ctr)
87 gv_check("neg-control-board-html-never-lists-the-estate-organs-in-full" as *u8, (x_find(buf, na, "nx_orphan_q" as *u8) == 0) as i64, ctr)
88 gv_check("board-html-carries-the-estate-organ-count-and-points-at-the-hub" as *u8, x_find(buf, na, "estate-wide un-boarded organs <b>2</b>" as *u8) * x_find(buf, na, "listed in full on" as *u8), ctr)
89 gv_check("board-html-states-BLIND-and-sources-read-of-declared" as *u8, x_find(buf, na, "Census state <b>BLIND</b>" as *u8) * x_find(buf, na, "sources read <b>3</b> of <b>4</b>" as *u8), ctr)
90 gv_check("malformed-row-counted-never-rendered" as *u8, x_find(buf, na, "malformed <b>1</b>" as *u8) * ((x_find(buf, na, "bad|row" as *u8) == 0) as i64), ctr)
91 // ---- board a, JSON ----
92 let ja: i64 = x_render("a" as *u8, 2, X_A_JSON, buf)
93 gv_check("board-json-partition-own-one-unassigned-two-total-four-malformed-one" as *u8, x_find(buf, ja, "\"own\":1,\"estate_unassigned\":2,\"total\":4,\"malformed\":1" as *u8), ctr)
94 gv_check("board-json-state-blind-hub-zero-and-only-its-own-row" as *u8, x_find(buf, ja, "\"state\":\"BLIND\"" as *u8) * x_find(buf, ja, "\"hub\":0" as *u8) * x_find(buf, ja, "\"name\":\"qq_sym\"" as *u8) * ((x_find(buf, ja, "\"name\":\"zz_sym\"" as *u8) == 0) as i64), ctr)
95 // ---- the hub ----
96 let nh: i64 = x_render("ecosystem" as *u8, 1, X_HUB_HTML, buf)
97 gv_check("hub-html-lists-the-un-boarded-organs-in-full" as *u8, x_find(buf, nh, "<code>nx_orphan_q</code>" as *u8), ctr)
98 gv_check("hub-html-escapes-an-angle-bracket-in-a-name" as *u8, x_find(buf, nh, "nx_x<y" as *u8) * ((x_find(buf, nh, "nx_x<y" as *u8) == 0) as i64), ctr)
99 gv_check("neg-control-hub-html-carries-no-other-boards-directive-and-no-pointer-to-itself" as *u8, ((x_find(buf, nh, "qq_sym" as *u8) == 0) as i64) * ((x_find(buf, nh, "listed in full on" as *u8) == 0) as i64), ctr)
100 let jh: i64 = x_render("ecosystem" as *u8, 2, X_HUB_JSON, buf)
101 gv_check("hub-json-hub-one-shown-two" as *u8, x_find(buf, jh, "\"hub\":1" as *u8) * x_find(buf, jh, "\"shown\":2" as *u8), ctr)
102 // ---- STALE: the stamp is five beats old; the rows still render under the STALE state ----
103 let sw2: i64 = ga_stamp_write(X_STAMP, now - (X_STALE_BEATS * X_CADENCE), X_TOTAL, X_DECLARED, X_DECLARED, X_CADENCE)
104 gv_need("stale stamp planted" as *u8, (sw2 > 0) as i64, ctr)
105 let ns: i64 = x_render("a" as *u8, 1, X_STALE_HTML, buf)
106 gv_check("stale-census-states-STALE-and-still-lists-its-rows-never-no-gaps" as *u8, x_find(buf, ns, "Census state <b>STALE</b>" as *u8) * x_find(buf, ns, "<code>qq_sym</code>" as *u8), ctr)
107 // ---- FRESH: every declared source read, stamped now ----
108 let sw3: i64 = ga_stamp_write(X_STAMP, now, X_TOTAL, X_DECLARED, X_DECLARED, X_CADENCE)
109 gv_need("fresh stamp planted" as *u8, (sw3 > 0) as i64, ctr)
110 let nf: i64 = x_render("a" as *u8, 1, X_FRESH_HTML, buf)
111 gv_check("fresh-census-states-FRESH" as *u8, x_find(buf, nf, "Census state <b>FRESH</b>" as *u8), ctr)
112 // ---- WEAK absent: from an empty root the probe falls through to ../ and the estate roots; on a host with no
113 // production feed the pass emits NOTHING, on the NAS it resolves the production feed -- either is the resolver's
114 // contract, so this tooth accepts both and cannot discriminate a broken absent path from a present production feed
115 gv_need("empty root entered" as *u8, (sys_chdir(X_EMPTY) == 0) as i64, ctr)
116 let nz: i64 = x_render("a" as *u8, 2, X_ABS_JSON, buf)
117 var absent_ok: i64 = 0
118 if nz == 0 { absent_ok = 1 }
119 if nz > 0 { if x_find(buf, nz, "/tmp/nx_gaps_pass_gate/" as *u8) == 0 { absent_ok = 1 } }
120 gv_check("WEAK-absent-feed-in-the-fixture-emits-nothing-or-resolves-outside-the-fixture" as *u8, absent_ok, ctr)
121 gv_values_head()
122 gv_kv("board_html_bytes" as *u8, na)
123 gv_kv("board_json_bytes" as *u8, ja)
124 gv_kv("hub_html_bytes" as *u8, nh)
125 gv_kv("hub_json_bytes" as *u8, jh)
126 gv_kv("absent_json_bytes" as *u8, nz)
127 return gv_verdict("nx_gaps_pass_gate" as *u8, ctr, "gaps_pass renders each board's own directives and the estate organ count, the hub renders the organs in full, malformed rows are counted never rendered, names are escaped, and STALE/BLIND/FRESH are stated from the one gauge ruler" as *u8)
128}