nx_unread_sensor_gate.nx source
↩ module page · 131 lines · 7179 B
1// nx_unread_sensor_gate.nx -- proves the unread-sensor census, BOTH POLARITIES.
2//
3// A NEW DETECTOR IS GUILTY UNTIL PROVEN, and this one had two false-positive classes on its first two
4// live runs -- both found by hand-adjudicating the hits rather than by reading the count:
5// run 1: 238 of 257 rows were seg-store shards, addressed by a prefix computed at runtime, so a
6// literal reference to one is impossible BY CONSTRUCTION. 93 percent of the output was a single
7// known-uninteresting shape, which is a false-positive machine.
8// run 2: the ratchet went RED on the organ OWN baseline file, which it writes into the directory it
9// censuses. An instrument that counts its own bookkeeping measures itself.
10// Neither was fixed by widening a match or suppressing a hit: each became its own NAMED bucket, which is
11// the only way the taxonomy survives contact with the next reader.
12// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).
13import "nx_syscalls.nx"
14import "nx_gate_verdict.nx"
15import "nx_unread_sensor_lib.nx"
16
17const UG_BUF: i64 = 4096
18const UG_SLASH: i64 = 47
19
20func ug_cpy(d: *u8, s: *u8) -> i64 {
21 var i: i64 = 0
22 while s[i] != (0 as u8) { d[i] = s[i]; i = i + 1 }
23 d[i] = 0 as u8
24 return i
25}
26
27func main() -> i64 {
28 let ctr: *i64 = gv_ctr()
29 gv_head("nx_unread_sensor_gate -- the status-artifact reference census, and its two false-positive classes" as *u8)
30
31 // T1 -- '/' MUST NOT be a name character. If it were, a match on knowledge/status/ would swallow the
32 // rest of a deeper path and invent an artifact name that exists nowhere.
33 var t1bad: i64 = 0
34 if us_isnamechar(UG_SLASH) == 0 { t1bad = 1 }
35 var t1good: i64 = 1
36 if us_isnamechar(97) == 1 { if us_isnamechar(48) == 1 { if us_isnamechar(US_DOT) == 1 { t1good = 0 } } }
37 gv_bite("T1 a path separator is NOT a name character, while letters digits and dot are" as *u8,
38 t1bad, t1good, ctr)
39
40 // T2 -- extraction stops at the boundary and NUL-terminates.
41 let b: *u8 = sys_mmap(UG_BUF)
42 let out: *u8 = sys_mmap(UG_BUF)
43 let n: i64 = ug_cpy(b, "see knowledge/status/procchurn.jrnl and knowledge/status/resmon.log here" as *u8)
44 let h1: i64 = us_find_from(b, n, 0, "knowledge/status/" as *u8)
45 let l1: i64 = us_name_at(b, n, h1 + 17, out, US_NAMECAP)
46 gv_check_eq("T2 the extracted token is exactly the artifact filename" as *u8, l1, 14, ctr)
47 gv_check("T2b and it reads back as procchurn.jrnl" as *u8, us_streq(out, "procchurn.jrnl" as *u8) == 1, ctr)
48
49 // T3 -- EVERY occurrence, not just the first. A scan that stopped at the first hit would credit one
50 // artifact per source no matter how many that source actually names, and the census would undercount
51 // readers in exactly the direction that flatters the estate.
52 let h2: i64 = us_find_from(b, n, h1 + 17, "knowledge/status/" as *u8)
53 var t3bad: i64 = 0
54 if h2 > h1 {
55 let l2: i64 = us_name_at(b, n, h2 + 17, out, US_NAMECAP)
56 if l2 > 0 { if us_streq(out, "resmon.log" as *u8) == 1 { t3bad = 1 } }
57 }
58 var t3good: i64 = 1
59 if us_find_from(b, n, 0, "knowledge/status/" as *u8) == h1 { t3good = 0 }
60 gv_bite("T3 the scan advances to the SECOND occurrence and still finds the first from zero" as *u8,
61 t3bad, t3good, ctr)
62
63 // T4 -- the store family, every member, against a plain artifact that must NOT join it.
64 var t4bad: i64 = 0
65 if us_is_store_shard("comparewatch-seg-3.docs" as *u8) == 1 {
66 if us_is_store_shard("toolreg-slock" as *u8) == 1 {
67 if us_is_store_shard("sgfixs-plock" as *u8) == 1 {
68 if us_is_store_shard("sghealthy-manifest.txt" as *u8) == 1 { t4bad = 1 }
69 }
70 }
71 }
72 var t4good: i64 = 0
73 if us_is_store_shard("procchurn.jrnl" as *u8) == 1 { t4good = 1 }
74 if us_is_store_shard("resmon.log" as *u8) == 1 { t4good = 1 }
75 if us_is_store_shard("segment-report.txt" as *u8) == 1 { t4good = 1 }
76 gv_bite("T4 every store-family shape is recognised and an ordinary artifact is NOT" as *u8,
77 t4bad, t4good, ctr)
78
79 // T5 -- the store test outranks the reference count, because it is decided by the name alone and no
80 // number of accidental namers makes a shard something else.
81 var t5: i64 = 0
82 if us_classify("comparewatch-seg-3.docs" as *u8, 7) == US_CLASS_SHARD {
83 if us_classify("procchurn.jrnl" as *u8, 0) == US_CLASS_NONE {
84 if us_classify("procchurn.jrnl" as *u8, 1) == US_CLASS_SINGLE {
85 if us_classify("procchurn.jrnl" as *u8, 2) == US_CLASS_SEVERAL { t5 = 1 }
86 }
87 }
88 }
89 gv_check("T5 classify maps 0 1 and many, and a shard stays a shard at any reference count" as *u8, t5, ctr)
90
91 // T6 -- self-bookkeeping, matched EXACTLY. A prefix match here would silently exclude a real artifact
92 // whose name merely starts the same way, which is a detector quietly deleting its own findings.
93 var t6bad: i64 = 0
94 if us_is_self("unread_sensor.baseline" as *u8, "unread_sensor.baseline" as *u8) == 1 { t6bad = 1 }
95 var t6good: i64 = 0
96 if us_is_self("unread_sensor.baseline.old" as *u8, "unread_sensor.baseline" as *u8) == 1 { t6good = 1 }
97 if us_is_self("unread_sensor" as *u8, "unread_sensor.baseline" as *u8) == 1 { t6good = 1 }
98 gv_bite("T6 self-bookkeeping matches the whole name and NOT a longer or shorter neighbour" as *u8,
99 t6bad, t6good, ctr)
100
101 // T7 -- table lookup, and a control that must miss. Without it a finder that returned 0 for
102 // everything would score full marks and every artifact would be credited with a reader.
103 let tbl: *u8 = sys_mmap(UG_BUF)
104 ug_cpy(((tbl as i64) + 0) as *u8, "alpha.log" as *u8)
105 ug_cpy(((tbl as i64) + 96) as *u8, "beta.jrnl" as *u8)
106 var t7: i64 = 0
107 if us_tbl_find(tbl, 96, 2, "beta.jrnl" as *u8) == 1 {
108 if us_tbl_find(tbl, 96, 2, "alpha.log" as *u8) == 0 {
109 if us_tbl_find(tbl, 96, 2, "gamma.txt" as *u8) < 0 { t7 = 1 }
110 }
111 }
112 gv_check("neg-control-T7 the table finds both members and REFUSES a non-member" as *u8, t7, ctr)
113
114 // T8 -- an empty needle must not match everything. A zero-length search that returned 0 would credit
115 // every source with naming every artifact and the census would read 100 percent healthy.
116 var t8: i64 = 0
117 if us_find_from(b, n, 0, "" as *u8) < 0 { t8 = 1 }
118 gv_check("neg-control-T8 an EMPTY needle finds nothing rather than matching at offset zero" as *u8, t8, ctr)
119
120 gv_values_head()
121 gv_kv("token_len_procchurn_jrnl" as *u8, l1)
122 gv_kv("first_occurrence_off" as *u8, h1)
123 gv_kv("second_occurrence_off" as *u8, h2)
124 gv_kv("class_shard_at_refs_7" as *u8, us_classify("comparewatch-seg-3.docs" as *u8, 7))
125 gv_kv("class_plain_at_refs_1" as *u8, us_classify("procchurn.jrnl" as *u8, 1))
126
127 let rc: i64 = gv_verdict("UNREAD-SENSOR-GATE" as *u8, ctr,
128 "the census extracts artifact names at their real boundary, walks every occurrence, keeps the prefix-addressed store family and its own bookkeeping out of the suspicious buckets, and refuses an empty needle" as *u8)
129 sys_exit(rc)
130 return rc
131}