Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/apps/readings-window/test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / apps / readings-window / test.om` 333 lines ยท 6722 bytes Raw Blame History 1 note readings-window unit tests: ring wrap, monotonicity refusal, stats/percentiles, alarms, auth, clamp, format. 2 note Compose: si/directives/om2.om + apps/readings-window/lib.om + apps/readings-window/test.om 3 4 text rw_ts_pass "PASS " 5 text rw_ts_fail "FAIL " 6 text rw_ts_nl "\n" 7 text rw_ts_ok "SUMMARY readings-window PASS all=8 fail=0\n" 8 text rw_ts_bad "SUMMARY readings-window FAIL\n" 9 10 text rw_tn_1 "ring_wrap_bounded" 11 text rw_tn_2 "monotonicity_and_bounds_refusal" 12 text rw_tn_3 "stats_sorted_p50_p95_and_cutoff" 13 text rw_tn_4 "threshold_alarms" 14 text rw_tn_5 "constant_time_bearer_auth" 15 text rw_tn_6 "query_clamps_hours_lines" 16 text rw_tn_7 "exposure_and_agent_allowlist" 17 text rw_tn_8 "deterministic_json_and_text_format" 18 19 text rw_tok "spark-secret-token-2026" 20 text rw_hdr_ok "Bearer spark-secret-token-2026" 21 text rw_hdr_bad "Bearer spark-secret-token-2025" 22 text rw_hdr_nopfx "spark-secret-token-2026" 23 24 text rw_q_h5 "hours=5" 25 text rw_q_h0 "hours=0" 26 text rw_q_hmax "hours=99999" 27 text rw_q_hbad "hours=abc" 28 text rw_q_l0 "lines=0" 29 text rw_q_lmax "lines=60000" 30 text rw_q_linj "lines=1;rm" 31 32 text rw_ag_bad1 "other" 33 text rw_ag_bad2 "../claude" 34 text rw_ag_bad3 "Claude" 35 36 text rw_exp_json "{\"count\":10,\"min\":10,\"max\":100,\"sum\":550,\"mean\":55,\"p50\":50,\"p95\":100,\"alarms\":3}\n" 37 text rw_exp_text "count=10 min=10 max=100 sum=550 mean=55 p50=50 p95=100 alarms=3\n" 38 39 fn rw_t_print s view uchar * to void 40 k = write 1 s 0 len s 41 if lt k 0 42 exit 2 43 end 44 end 45 46 fn rw_t_report name view uchar * ok bool to int 47 if ok 48 rw_t_print rw_ts_pass 49 rw_t_print name 50 rw_t_print rw_ts_nl 51 ret 0 52 end 53 rw_t_print rw_ts_fail 54 rw_t_print name 55 rw_t_print rw_ts_nl 56 ret 1 57 end 58 59 fn rw_t_ring_wrap to bool 60 ring = new RwRing 0 0 0 0 0 61 rbuf = new ulong 512 0 62 rw_ring_init ring 63 s = new RwSample 0 0 0 0 0 0 0 64 i = ulong 1 65 while le i 80 bound 100 66 put s ts mul i 10 67 put s gpu_util rem i 100 68 put s gpu_temp add 30 rem i 40 69 put s gpu_power add 100 i 70 put s cpu_temp ulong 45 71 put s mem_used ulong 4096 72 put s mem_total ulong 128000 73 if ne rw_ingest ring rbuf s 0 74 ret false 75 end 76 i = add i 1 77 end 78 if ne get ring cnt RW_CAP 79 ret false 80 end 81 if ne get ring total 80 82 ret false 83 end 84 if ne get ring last_ts 800 85 ret false 86 end 87 stats = new RwStats 0 0 0 0 0 0 0 88 if not rw_compute_stats ring rbuf RW_METRIC_GPU_POWER 0 stats 89 ret false 90 end 91 if ne get stats n 64 92 ret false 93 end 94 if ne get stats vmin 117 95 ret false 96 end 97 if ne get stats vmax 180 98 ret false 99 end 100 ret true 101 end 102 103 fn rw_t_refusals to bool 104 ring = new RwRing 0 0 0 0 0 105 rbuf = new ulong 512 0 106 rw_ring_init ring 107 s = new RwSample 0 50 60 120 55 8000 128000 108 if ne rw_ingest ring rbuf s -1 109 ret false 110 end 111 put s ts ulong 1000 112 if ne rw_ingest ring rbuf s 0 113 ret false 114 end 115 put s ts ulong 999 116 if ne rw_ingest ring rbuf s -2 117 ret false 118 end 119 put s ts ulong 1010 120 put s gpu_util ulong 101 121 if ne rw_ingest ring rbuf s -3 122 ret false 123 end 124 put s gpu_util ulong 50 125 put s mem_used ulong 200000 126 if ne rw_ingest ring rbuf s -4 127 ret false 128 end 129 put s mem_used ulong 8000 130 put s gpu_temp ulong 200 131 if ne rw_ingest ring rbuf s -5 132 ret false 133 end 134 if ne get ring cnt 1 135 ret false 136 end 137 ret true 138 end 139 140 fn rw_t_stats to bool 141 ring = new RwRing 0 0 0 0 0 142 rbuf = new ulong 512 0 143 rw_ring_init ring 144 temps = new ulong 10 0 145 put temps 0 ulong 70 146 put temps 1 ulong 20 147 put temps 2 ulong 100 148 put temps 3 ulong 40 149 put temps 4 ulong 10 150 put temps 5 ulong 90 151 put temps 6 ulong 30 152 put temps 7 ulong 80 153 put temps 8 ulong 50 154 put temps 9 ulong 60 155 s = new RwSample 0 50 0 150 50 10000 128000 156 i = ulong 0 157 while lt i 10 bound 16 158 put s ts add 1000 mul i 60 159 put s gpu_temp get temps i 160 if ne rw_ingest ring rbuf s 0 161 ret false 162 end 163 i = add i 1 164 end 165 st = new RwStats 0 0 0 0 0 0 0 166 if not rw_compute_stats ring rbuf RW_METRIC_GPU_TEMP 0 st 167 ret false 168 end 169 if ne get st n 10 170 ret false 171 end 172 if ne get st vmin 10 173 ret false 174 end 175 if ne get st vmax 100 176 ret false 177 end 178 if ne get st vsum 550 179 ret false 180 end 181 if ne get st vmean 55 182 ret false 183 end 184 if ne get st vp50 50 185 ret false 186 end 187 if ne get st vp95 100 188 ret false 189 end 190 note Time-window cutoff test: ts >= 1360 selects indices 6..9 (30, 80, 50, 60). 191 st2 = new RwStats 0 0 0 0 0 0 0 192 if not rw_compute_stats ring rbuf RW_METRIC_GPU_TEMP 1360 st2 193 ret false 194 end 195 if ne get st2 n 4 196 ret false 197 end 198 if ne get st2 vmin 30 199 ret false 200 end 201 if ne get st2 vmax 80 202 ret false 203 end 204 ret true 205 end 206 207 fn rw_t_alarms to bool 208 ring = new RwRing 0 0 0 0 0 209 rbuf = new ulong 512 0 210 rw_ring_init ring 211 th = new RwThresh 85 250 90 98 115000 212 s1 = new RwSample 100 50 65 180 60 32000 128000 213 if ne rw_ingest ring rbuf s1 0 214 ret false 215 end 216 if ne rw_check_alarms ring rbuf th 0 217 ret false 218 end 219 s2 = new RwSample 200 99 88 260 65 120000 128000 220 if ne rw_ingest ring rbuf s2 0 221 ret false 222 end 223 note Tripped: gpu_temp(1) + gpu_power(2) + gpu_util(8) + mem_used(16) = 27. 224 if ne rw_check_alarms ring rbuf th 27 225 ret false 226 end 227 ret true 228 end 229 230 fn rw_t_auth to bool 231 if not rw_auth_ok rw_hdr_ok rw_tok 232 ret false 233 end 234 if rw_auth_ok rw_hdr_bad rw_tok 235 ret false 236 end 237 if rw_auth_ok rw_hdr_nopfx rw_tok 238 ret false 239 end 240 ret true 241 end 242 243 fn rw_t_clamps to bool 244 if ne rw_clamp_hours rw_q_h5 5 245 ret false 246 end 247 if ne rw_clamp_hours rw_q_h0 1 248 ret false 249 end 250 if ne rw_clamp_hours rw_q_hmax 720 251 ret false 252 end 253 if ne rw_clamp_hours rw_q_hbad 24 254 ret false 255 end 256 if ne rw_clamp_lines rw_q_l0 1 257 ret false 258 end 259 if ne rw_clamp_lines rw_q_lmax 50000 260 ret false 261 end 262 if ne rw_clamp_lines rw_q_linj 500 263 ret false 264 end 265 ret true 266 end 267 268 fn rw_t_exp_agents to bool 269 if ne rw_exposure_state 9940 RW_EXP_OK 10000 RW_EXP_OK 270 ret false 271 end 272 if ne rw_exposure_state 9940 RW_EXP_CHANGED 10000 RW_EXP_CHANGED 273 ret false 274 end 275 if ne rw_exposure_state 6000 RW_EXP_OK 10000 RW_EXP_UNKNOWN 276 ret false 277 end 278 if ne rw_exposure_state 0 RW_EXP_OK 10000 RW_EXP_UNKNOWN 279 ret false 280 end 281 if not rw_chat_agent_allowed rw_t_ag_claude 282 ret false 283 end 284 if not rw_chat_agent_allowed rw_t_ag_muse 285 ret false 286 end 287 if rw_chat_agent_allowed rw_ag_bad1 288 ret false 289 end 290 if rw_chat_agent_allowed rw_ag_bad2 291 ret false 292 end 293 if rw_chat_agent_allowed rw_ag_bad3 294 ret false 295 end 296 ret true 297 end 298 299 fn rw_t_format to bool 300 st = new RwStats 10 10 100 550 55 50 100 301 jb = new uchar 256 0 302 tb = new uchar 256 0 303 jn = rw_format_stats_json jb st 3 304 if lt jn 0 305 ret false 306 end 307 if not rw_eq_bytes part jb 0 ulong jn rw_exp_json 308 ret false 309 end 310 tn = rw_format_stats_text tb st 3 311 if lt tn 0 312 ret false 313 end 314 ret rw_eq_bytes part tb 0 ulong tn rw_exp_text 315 end 316 317 fn main to int 318 fails = int 0 319 fails = add fails rw_t_report rw_tn_1 rw_t_ring_wrap 320 fails = add fails rw_t_report rw_tn_2 rw_t_refusals 321 fails = add fails rw_t_report rw_tn_3 rw_t_stats 322 fails = add fails rw_t_report rw_tn_4 rw_t_alarms 323 fails = add fails rw_t_report rw_tn_5 rw_t_auth 324 fails = add fails rw_t_report rw_tn_6 rw_t_clamps 325 fails = add fails rw_t_report rw_tn_7 rw_t_exp_agents 326 fails = add fails rw_t_report rw_tn_8 rw_t_format 327 if eq fails 0 328 rw_t_print rw_ts_ok 329 ret 0 330 end 331 rw_t_print rw_ts_bad 332 ret 1 333 end