code wiki / _hdl_build / nx_compare_feed_gate.nx
nx_compare_feed_gate.nx source
↩ module page · 135 lines · 10732 B
1// nx_compare_feed_gate.nx -- teeth for nx_compare_feed_lib (ecosystem EC47, 2026-09-16): the /compare daily feed built
2// from a FIXTURE root under /tmp/nx_compare_feed_gate/ (the gate-fixture law: scratch in /tmp/<gate>/, created at setup,
3// never a production shard). Three boards are listed: alpha (three players, two spine days inside the window and one
4// outside it, a malformed spine row, two log rows on different days, one carrying markup that must be escaped), beta
5// (one spine day -> "first day on the map", no plan file), gamma (listed, no spine -> no item). Today is pinned to day
6// 20712 (2026-09-16) so every date in the expectations is a known answer, not the clock. Every count the lib publishes
7// is asserted against the fixture it was built from, the quadrant words are the map's own, and the negative control is
8// an empty list that must still yield a well-formed, item-free feed. Declared in organ_gate.conf. expect_exit: 0
9import "nx_gate_verdict.nx"
10import "nx_compare_feed_lib.nx"
11
12const FG_ROOT: *u8 = "/tmp/nx_compare_feed_gate/" as *u8
13const FG_TODAY: i64 = 20712 // 2026-09-16
14const FG_MODE_DIR: i64 = 493
15const FG_MODE_FILE: i64 = 420
16const FG_OUT_CAP: i64 = 65536
17
18func fg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
19func fg_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } return p }
20func fg_path(dst: *u8, rel: *u8) -> i64 { var o: i64 = fg_cat(dst, 0, FG_ROOT); o = fg_cat(dst, o, rel); dst[o] = 0 as u8; return o }
21func fg_mkdir(rel: *u8) -> i64 { let p: *u8 = sys_mmap(512); fg_path(p, rel); let rc: i64 = sys_mkdir(p, FG_MODE_DIR); sys_munmap(p, 512); return rc }
22// (re)write a fixture file: unlink, then create by append so every run reads exactly this content
23func fg_write_c(rel: *u8, body: *u8, comment_first: i64) -> i64 {
24 let p: *u8 = sys_mmap(512)
25 fg_path(p, rel)
26 sys_unlinkat(p)
27 let fd: i64 = sys_openat_append(p, FG_MODE_FILE)
28 if fd < 0 { sys_munmap(p, 512); return 0 - 1 }
29 let hb: *u8 = sys_mmap(8)
30 hb[0] = 35 as u8
31 if comment_first == 1 { sys_write(fd, hb, 1) }
32 sys_munmap(hb, 8)
33 let n: i64 = fg_slen(body)
34 sys_write(fd, body, n)
35 sys_close(fd)
36 sys_munmap(p, 512)
37 return n
38}
39func fg_write(rel: *u8, body: *u8) -> i64 { return fg_write_c(rel, body, 0) }
40func fg_find(hay: *u8, n: i64, needle: *u8) -> i64 {
41 let m: i64 = fg_slen(needle)
42 if m == 0 { return 0 }
43 var i: i64 = 0
44 while i + m <= n {
45 var j: i64 = 0
46 var ok: i64 = 1
47 while j < m { if hay[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } }
48 if ok == 1 { return i }
49 i = i + 1
50 }
51 return 0 - 1
52}
53func fg_count(hay: *u8, n: i64, needle: *u8) -> i64 {
54 let m: i64 = fg_slen(needle)
55 var c: i64 = 0
56 var i: i64 = 0
57 while i + m <= n {
58 var j: i64 = 0
59 var ok: i64 = 1
60 while j < m { if hay[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } }
61 if ok == 1 { c = c + 1; i = i + m } else { i = i + 1 }
62 }
63 return c
64}
65func fg_ends(hay: *u8, n: i64, tail: *u8) -> i64 {
66 let m: i64 = fg_slen(tail)
67 if n < m { return 0 }
68 var i: i64 = 0
69 while i < m { if hay[n - m + i] != tail[i] { return 0 } i = i + 1 }
70 return 1
71}
72func fg_same(a: *u8, b: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { if a[i] != b[i] { return 0 } i = i + 1 } return 1 }
73
74func main(argc: i64, argv: *i64) -> i64 {
75 let ctr: *i64 = gv_ctr()
76 gv_head("NX-COMPARE-FEED-GATE: the /compare daily feed from a fixture root -- positions, quadrants, moves, board rows, escaping, window, order, the empty-list control" as *u8)
77 // ---- fixture root (created at setup; a run that crashes leaves it, the next run rewrites every file) ----
78 fg_mkdir("" as *u8)
79 fg_mkdir("knowledge" as *u8)
80 fg_mkdir("knowledge/compare" as *u8)
81 fg_mkdir("knowledge/status" as *u8)
82 fg_mkdir("knowledge/status/cdmap" as *u8)
83 let wl: i64 = fg_write_c("knowledge/compare/regen.list" as *u8, " fixture boards\nalpha\nbeta\ngamma\n" as *u8, 1)
84 // alpha: day 20690 (outside the 14-day window), 20711 and 20712; a malformed row; players Nishi, Rival1, Rival2
85 let ws: i64 = fg_write("knowledge/status/cdmap/alpha.spine" as *u8,
86 "cd|1787616000|20690|Nishi|600|250|80|60|3|40\ncd|1787616000|20690|Rival1|900|100|90|60|3|50\ncd|1787616000|20690|Rival2|850|90|85|60|3|48\ncd|1789430500|20711|Nishi|700|300|90|60|3|44\ncd|1789430500|20711|Rival1|900|100|90|60|3|50\ncd|1789430500|20711|Rival2|850|90|85|60|3|48\ncd|x|y\ncd|1789516900|20712|Nishi|720|310|92|60|3|45\ncd|1789516900|20712|Rival1|900|100|90|60|3|50\ncd|1789516900|20712|Rival2|850|90|85|60|3|48\n" as *u8)
87 let wp: i64 = fg_write_c("knowledge/compare/alpha.plan" as *u8,
88 " a plan\nrung|S7|a rung row|sym|note|Organ|1|-\nlog|1789516900|S7|land|A row with <b>bold</b> & ampersand that must be escaped\nlog|1789450000|S5|measure|older row on the previous day\nlog|notanumber|S1|lesson|refused row\n" as *u8, 1)
89 let wb: i64 = fg_write("knowledge/status/cdmap/beta.spine" as *u8, "cd|1789516900|20712|Nishi|500|400|70|30|2|20\ncd|1789516900|20712|Other|950|50|95|30|2|30\n" as *u8)
90 let pb: *u8 = sys_mmap(512)
91 fg_path(pb, "knowledge/compare/beta.plan" as *u8); sys_unlinkat(pb)
92 fg_path(pb, "knowledge/status/cdmap/gamma.spine" as *u8); sys_unlinkat(pb)
93 gv_check("T0 fixture written: the list, two spines and one plan landed" as *u8, ((wl > 0) as i64) * ((ws > 0) as i64) * ((wp > 0) as i64) * ((wb > 0) as i64), ctr)
94
95 let st: *i64 = sys_mmap(8 * CF_ST_SLOTS) as *i64
96 let outp: *i64 = sys_mmap(8) as *i64
97 let n: i64 = cf_build(FG_ROOT, "knowledge/compare/regen.list" as *u8, FG_TODAY, st, outp)
98 let out: *u8 = outp[0] as *u8
99 gv_check("T1 three items: alpha on 2026-09-16 and 2026-09-15 and beta on 2026-09-16, and the count equals the item tags" as *u8, ((st[CF_ST_ITEMS] == 3) as i64) * ((fg_count(out, n, "<item>" as *u8) == 3) as i64), ctr)
100 gv_check("T2 the alpha title carries Nishi's position, the map's quadrant word and the move since the previous day" as *u8, (fg_find(out, n, "alpha 2026-09-16: Nishi C720 D310 Unconventional, moved +20/+10 since 2026-09-15" as *u8) >= 0) as i64, ctr)
101 gv_check("T3 rivals are placed by the same rule: Rival1 and Rival2 read Mainstream (central, undistinctive) on the day's means" as *u8, ((fg_find(out, n, "Rival1: C 900, D 100, Mainstream, moved +0/+0" as *u8) >= 0) as i64) * ((fg_find(out, n, "Rival2: C 850, D 90, Mainstream, moved +0/+0" as *u8) >= 0) as i64), ctr)
102 gv_check("T4 a quoted board row is escaped: the markup and the ampersand survive as entities, never as tags" as *u8, ((fg_find(out, n, "<b>bold</b> & ampersand" as *u8) >= 0) as i64) * ((fg_find(out, n, "<b>bold</b>" as *u8) < 0) as i64), ctr)
103 gv_check("T5 the row's kind and rung are quoted with it" as *u8, (fg_find(out, n, "<li>[land] S7: A row with" as *u8) >= 0) as i64, ctr)
104 gv_check("T6 a board whose spine has one day says so instead of inventing a move" as *u8, (fg_find(out, n, "beta 2026-09-16: Nishi C500 D400 Unconventional, first day on the map" as *u8) >= 0) as i64, ctr)
105 gv_check("T7 window: the alpha day outside 14 days (2026-08-25) is not an item, though the 2026-09-15 item still measures its move against it" as *u8, ((fg_find(out, n, "alpha 2026-08-25:" as *u8) < 0) as i64) * ((fg_find(out, n, "since 2026-08-25" as *u8) >= 0) as i64), ctr)
106 gv_check("T8 order inside a board is newest first, boards in list order" as *u8, ((fg_find(out, n, "alpha 2026-09-16" as *u8) < fg_find(out, n, "alpha 2026-09-15" as *u8)) as i64) * ((fg_find(out, n, "alpha 2026-09-15" as *u8) < fg_find(out, n, "beta 2026-09-16" as *u8)) as i64), ctr)
107 gv_check("T9 well-formed: the feed opens with the xml declaration and closes the rss element" as *u8, ((fg_find(out, n, "<?xml version=" as *u8) == 0) as i64) * fg_ends(out, n, "</rss>\n" as *u8), ctr)
108 gv_check("T10 counts partition the fixture: 3 boards listed, 2 spines read, 2 rows quoted, 1 malformed spine row refused, nothing short" as *u8, ((st[CF_ST_DOMAINS] == 3) as i64) * ((st[CF_ST_SPINES] == 2) as i64) * ((st[CF_ST_ROWS] == 2) as i64) * ((st[CF_ST_MALFORMED] == 1) as i64) * ((st[CF_ST_SHORT] == 0) as i64), ctr)
109 gv_check("T11 the channel pubDate is the newest spine epoch, formatted as an RFC 822 date" as *u8, ((st[CF_ST_NEWEST] == 1789516900) as i64) * ((fg_find(out, n, "<pubDate>Wed, 16 Sep 2026 00:01:40 GMT</pubDate>" as *u8) >= 0) as i64), ctr)
110 gv_check("T12 the guid is the board link plus the day, so a reader keys one item per board-day" as *u8, ((fg_find(out, n, "cd-20712</guid>" as *u8) >= 0) as i64) * ((fg_find(out, n, "<guid>https://nishifamily.com/compare/alpha/" as *u8) >= 0) as i64), ctr)
111 // determinism: a second build is byte-identical
112 let st2: *i64 = sys_mmap(8 * CF_ST_SLOTS) as *i64
113 let outp2: *i64 = sys_mmap(8) as *i64
114 let n2: i64 = cf_build(FG_ROOT, "knowledge/compare/regen.list" as *u8, FG_TODAY, st2, outp2)
115 gv_check("T13 determinism: the same root builds the identical feed twice" as *u8, ((n2 == n) as i64) * fg_same(out, outp2[0] as *u8, n), ctr)
116 // neg-control: an empty list must still be a well-formed feed with zero items, never a crash or a half feed
117 fg_write_c("knowledge/compare/empty.list" as *u8, " nothing listed
118" as *u8, 1)
119 let st3: *i64 = sys_mmap(8 * CF_ST_SLOTS) as *i64
120 let outp3: *i64 = sys_mmap(8) as *i64
121 let n3: i64 = cf_build(FG_ROOT, "knowledge/compare/empty.list" as *u8, FG_TODAY, st3, outp3)
122 let out3: *u8 = outp3[0] as *u8
123 gv_check("T14 neg-control-empty-list: zero items, zero boards, and the feed is still well-formed" as *u8, ((st3[CF_ST_ITEMS] == 0) as i64) * ((st3[CF_ST_DOMAINS] == 0) as i64) * ((n3 > 0) as i64) * ((fg_find(out3, n3, "<?xml version=" as *u8) == 0) as i64) * fg_ends(out3, n3, "</rss>\n" as *u8) * ((fg_count(out3, n3, "<item>" as *u8) == 0) as i64), ctr)
124 gv_values_head()
125 gv_kv("items" as *u8, st[CF_ST_ITEMS])
126 gv_kv("bytes" as *u8, n)
127 gv_kv("domains" as *u8, st[CF_ST_DOMAINS])
128 gv_kv("spines" as *u8, st[CF_ST_SPINES])
129 gv_kv("rows_quoted" as *u8, st[CF_ST_ROWS])
130 gv_kv("malformed" as *u8, st[CF_ST_MALFORMED])
131 gv_kv("overflow" as *u8, st[CF_ST_OVERFLOW])
132 gv_kv("window_days" as *u8, st[CF_ST_WINDOW])
133 gv_kv("newest_epoch" as *u8, st[CF_ST_NEWEST])
134 return gv_verdict("NX-COMPARE-FEED-GATE" as *u8, ctr, "the /compare daily feed lib builds one item per board per spine day inside the window with the map's own quadrant words, escaped board rows and a well-formed empty feed for an empty list" as *u8)
135}