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 / core / sovereign-core / om / runtime / test.om

307 lines · 8089 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/sovereign-core/om/runtime/test.om
3note Comprehensive behavioral test suite with negative/refusal controls for the
4note pure-Omega aien-runtime, inference-abi, capability membrane, and execution journal.
5note Compose with:
6note si/directives/om2.om core/sovereign-core/om/runtime/inference_abi.om om/tls/sha2.om
7note core/sovereign-core/om/runtime/membrane.om core/sovereign-core/om/runtime/test.om
8
9text t_pass "PASS "
10text t_fail "FAIL "
11text t_nl "\n"
12text t_all_ok "SOVEREIGN-CORE RUNTIME TEST SUITE PASS\n"
13text t_all_bad "SOVEREIGN-CORE RUNTIME TEST SUITE FAIL\n"
14
15text t_n1 "abi_frame_roundtrip_and_negative"
16text t_n2 "abi_sampling_and_stop_token_guard"
17text t_n3 "world_store_fork_and_no_escalation"
18text t_n4 "controller_idempotency_and_negative"
19text t_n5 "membrane_authorize_and_containment_freeze"
20text t_n6 "journal_sha256_chain_and_negative_tamper"
21
22global t_fails ulong 1
23
24fn t_w s view uchar * to void
25n = len s
26off = ulong 0
27while lt off n bound 256
28k = write 1 s off sub n off
29if le k 0
30break
31end
32off = add off ulong k
33end
34end
35
36fn t_report name view uchar * ok bool to void
37if ok
38t_w t_pass
39else
40t_w t_fail
41put t_fails 0 add get t_fails 0 1
42end
43t_w name
44t_w t_nl
45end
46
47note Test 1: InferenceReqFrame & DecodeOutFrame wire roundtrip + negative magic/ver/len/bounds.
48fn test_abi_frames to bool
49req = new InferenceReqFrame 42 7 128 256 2 3
50wire = new uchar 48 0
51if ne abi_encode_req req wire ABI_OK
52ret false
53end
54dec = new InferenceReqFrame 0 0 0 0 0 0
55if ne abi_decode_req wire dec ABI_OK
56ret false
57end
58if or ne get dec req_id 42 or ne get dec model_handle 7 ne get dec prompt_tokens 128
59ret false
60end
61if or ne get dec max_tokens 256 or ne get dec priority 2 ne get dec flags 3
62ret false
63end
64note NEGATIVE: truncated buffer, bad magic, bad version, max_tokens=0
65if ne abi_decode_req part wire 0 30 dec ABI_ERR_TRUNCATED
66ret false
67end
68put wire 0 xor get wire 0 uchar 1
69if ne abi_decode_req wire dec ABI_ERR_BAD_MAGIC
70ret false
71end
72put wire 0 xor get wire 0 uchar 1
73put wire 4 uchar 99
74if ne abi_decode_req wire dec ABI_ERR_BAD_VERSION
75ret false
76end
77req_bad = new InferenceReqFrame 1 1 10 0 1 0
78if ne abi_encode_req req_bad wire ABI_ERR_BAD_LIMITS
79ret false
80end
81note DecodeOutFrame roundtrip + bad finish_reason negative
82out_f = new DecodeOutFrame 42 151645 FINISH_STOP_TOKEN 64
83owire = new uchar 32 0
84if ne abi_encode_out out_f owire ABI_OK
85ret false
86end
87odec = new DecodeOutFrame 0 0 0 0
88if ne abi_decode_out owire odec ABI_OK
89ret false
90end
91if ne get odec req_id 42
92ret false
93end
94if ne get odec token_id 151645
95ret false
96end
97if ne get odec finish_reason FINISH_STOP_TOKEN
98ret false
99end
100if ne get odec total_tokens 64
101ret false
102end
103out_bad = new DecodeOutFrame 42 1 99 1
104if ne abi_encode_out out_bad owire ABI_ERR_BAD_LIMITS
105ret false
106end
107ret true
108end
109
110note Test 2: SamplingParams validation (incl. NaN/range) and StopTokenGuard state machine.
111fn test_sampling_and_stop to bool
112sp = new SamplingParams 0.7f32 0.95f32 3 40 2 uint 2 uint 151645 uint 0 uint 0
113if ne abi_validate_sampling sp ABI_OK
114ret false
115end
116note NEGATIVE: NaN temperature, temp > 2.0, top_p == 0.0, top_p > 1.0, max_tokens == 0
117nan_f = bitcast f32 uint 0x7fc00000
118sp_nan = new SamplingParams nan_f 0.9f32 16 40 0 uint 0 uint 0 uint 0 uint 0
119if ne abi_validate_sampling sp_nan ABI_ERR_BAD_TEMP
120ret false
121end
122sp_hi = new SamplingParams 2.5f32 0.9f32 16 40 0 uint 0 uint 0 uint 0 uint 0
123if ne abi_validate_sampling sp_hi ABI_ERR_BAD_TEMP
124ret false
125end
126sp_tp0 = new SamplingParams 0.7f32 0.0f32 16 40 0 uint 0 uint 0 uint 0 uint 0
127if ne abi_validate_sampling sp_tp0 ABI_ERR_BAD_TOP_P
128ret false
129end
130sp_tp2 = new SamplingParams 0.7f32 1.1f32 16 40 0 uint 0 uint 0 uint 0 uint 0
131if ne abi_validate_sampling sp_tp2 ABI_ERR_BAD_TOP_P
132ret false
133end
134note StopGuard: hits stop token 151645 on step 2, then refuses step 3
135g = new StopGuard 0 0 0 0 0 uint 0 uint 0 uint 0 uint 0
136if ne abi_stop_guard_init g sp ABI_OK
137ret false
138end
139if ne abi_stop_guard_step g uint 100 ABI_OK
140ret false
141end
142if ne get g finished 0
143ret false
144end
145if ne abi_stop_guard_step g uint 151645 ABI_OK
146ret false
147end
148if or ne get g finished 1 ne get g reason FINISH_STOP_TOKEN
149ret false
150end
151if ne abi_stop_guard_step g uint 101 ABI_ERR_ALREADY_FINISHED
152ret false
153end
154note StopGuard: length finish after 3 non-stop tokens
155if ne abi_stop_guard_init g sp ABI_OK
156ret false
157end
158if ne abi_stop_guard_step g uint 10 ABI_OK
159ret false
160end
161if ne abi_stop_guard_step g uint 11 ABI_OK
162ret false
163end
164if ne abi_stop_guard_step g uint 12 ABI_OK
165ret false
166end
167if or ne get g finished 1 ne get g reason FINISH_LENGTH
168ret false
169end
170ret true
171end
172
173note Test 3: Persistent WorldStore fork & strict capability non-escalation.
174fn test_world_fork_and_escalation to bool
175rt_init
176pcaps = or RT_CAP_INFER or RT_CAP_FORK_WORLD RT_CAP_READ_FS
177root = rt_world_create_root 1001 pcaps 500
178if eq root 0
179ret false
180end
181note Attenuated child fork succeeds
182child = rt_world_fork root RT_CAP_INFER 501
183if or eq child 0 ne rt_world_parent child root
184ret false
185end
186if ne rt_world_caps child RT_CAP_INFER
187ret false
188end
189note NEGATIVE: child without RT_CAP_FORK_WORLD cannot fork again
190if ne rt_world_fork child RT_CAP_INFER 502 0
191ret false
192end
193note NEGATIVE: requesting RT_CAP_EXEC_CMD not held by parent is refused (anti-escalation)
194if ne rt_world_fork root or RT_CAP_INFER RT_CAP_EXEC_CMD 503 0
195ret false
196end
197note NEGATIVE: unknown parent refused
198if ne rt_world_fork 999 RT_CAP_INFER 504 0
199ret false
200end
201if ne rt_world_count 2
202ret false
203end
204ret true
205end
206
207note Test 4: RuntimeController idempotency & protocol version validation.
208fn test_controller_idempotency to bool
209rt_init
210if ne rt_ctrl_begin_op 1 777 RT_OK
211ret false
212end
213if not rt_ctrl_is_processed 777
214ret false
215end
216note NEGATIVE: replay of operation_id 777 refused
217if ne rt_ctrl_begin_op 1 777 RT_ERR_DUPLICATE_OP
218ret false
219end
220note NEGATIVE: wrong protocol version or op_id 0 refused
221if ne rt_ctrl_begin_op 2 778 RT_ERR_BAD_PROTO
222ret false
223end
224if ne rt_ctrl_begin_op 1 0 RT_ERR_BAD_PROTO
225ret false
226end
227ret true
228end
229
230note Test 5: Capability membrane authorization, denial, and containment freeze.
231fn test_membrane_and_freeze to bool
232rt_init
233w1 = rt_world_create_root 10 or RT_CAP_INFER RT_CAP_ADMIN 100
234w2 = rt_world_create_root 20 RT_CAP_INFER 101
235note Authorized infer succeeds
236if ne rt_authorize_effect 1 1001 w1 RT_EFF_INFER RT_OK
237ret false
238end
239note NEGATIVE: unauthorized exec_cmd denied
240if ne rt_authorize_effect 1 1002 w2 RT_EFF_EXEC_CMD RT_ERR_UNAUTHORIZED
241ret false
242end
243note NEGATIVE: unknown world denied
244if ne rt_authorize_effect 1 1003 999 RT_EFF_INFER RT_ERR_NOT_FOUND
245ret false
246end
247note Enable emergency containment freeze -> non-admin infer denied, admin still allowed
248rt_set_freeze 1
249if ne rt_authorize_effect 1 1004 w2 RT_EFF_INFER RT_ERR_CONTAINED
250ret false
251end
252if ne rt_authorize_effect 1 1005 w1 RT_EFF_ADMIN RT_OK
253ret false
254end
255if ne rt_journal_count 5
256ret false
257end
258if ne rt_journal_verify_chain RT_OK
259ret false
260end
261ret true
262end
263
264note Test 6 (NEGATIVE): SHA-256 execution journal chain verification catches status & prev_hash tampering.
265fn test_journal_tamper_negative to bool
266rt_init
267w = rt_world_create_root 1 RT_CAP_INFER 1
268for i ulong 4
269if ne rt_authorize_effect 1 add ulong 500 i w RT_EFF_INFER RT_OK
270ret false
271end
272end
273if ne rt_journal_verify_chain RT_OK
274ret false
275end
276note Tamper with record 1 status -> must fail with RT_ERR_JRN_HASH
277rt_jrn_tamper_status 1 RT_ERR_UNAUTHORIZED
278if ne rt_journal_verify_chain RT_ERR_JRN_HASH
279ret false
280end
281note Restore status, then tamper with record 2 prev_hash -> must fail with RT_ERR_JRN_PREV
282rt_jrn_tamper_status 1 RT_OK
283if ne rt_journal_verify_chain RT_OK
284ret false
285end
286rt_jrn_tamper_prev 2 5 uchar 0x40
287if ne rt_journal_verify_chain RT_ERR_JRN_PREV
288ret false
289end
290ret true
291end
292
293fn main to int
294put t_fails 0 0
295t_report t_n1 test_abi_frames
296t_report t_n2 test_sampling_and_stop
297t_report t_n3 test_world_fork_and_escalation
298t_report t_n4 test_controller_idempotency
299t_report t_n5 test_membrane_and_freeze
300t_report t_n6 test_journal_tamper_negative
301if eq get t_fails 0 0
302t_w t_all_ok
303ret 0
304end
305t_w t_all_bad
306ret 1
307end