interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / apps / readings-window / test.om

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