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 / protocol / aien-protocols / core / test.om

484 lines · 12590 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/aien-protocols/core/test.om: positive and negative control test suite
3note for aien-protocols core (types, provenance, action_event).
4note Compose with:
5note si/directives/om2.om om/tls/sha2.om protocol/aien-protocols/core/types.om
6note protocol/aien-protocols/core/provenance.om protocol/aien-protocols/core/action_event.om
7note protocol/aien-protocols/core/test.om
8
9text t_pass "PASS "
10text t_fail "FAIL "
11text t_nl "\n"
12
13text t_c1 "protocol_version_compat_and_format"
14text t_c2 "digest32_hex_roundtrip_and_negative_controls"
15text t_c3 "uuid16_rfc4122_roundtrip_v4_and_negative_controls"
16text t_c4 "seq_saturating_and_artifact_ref_validation"
17text t_c5 "provenance_sha256_vectors_and_combine_digests"
18text t_c6 "provenance_permissions_license_expiry_and_digest"
19text t_c7 "action_containment_and_capability_grant_controls"
20text t_c8 "agent_execution_status_transitions_and_negative_controls"
21text t_c9 "event_envelope_digest_sequence_and_resource_budget"
22text t_done "PASS aien-protocols-core all 9 test suites passed\n"
23
24text t_v12 "1.2"
25text t_abc "abc"
26text t_sha_empty "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
27text t_sha_abc "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
28text t_hex_ab "abababababababababababababababababababababababababababababababab"
29text t_hex_AB "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"
30text t_hex_short "abababab"
31text t_hex_bad "zbababababababababababababababababababababababababababababababab"
32text t_sha_ab_fmt "sha256:abababababababababababababababababababababababababababababababab"
33
34text t_uuid_v4 "550e8400-e29b-41d4-a716-446655440000"
35text t_uuid_v1 "550e8400-e29b-11d4-a716-446655440000"
36text t_uuid_bad_dash "550e8400xe29b-41d4-a716-446655440000"
37text t_uuid_bad_hex "550e8400-e29b-41d4-a716-44665544000g"
38text t_uuid_short "550e8400-e29b-41d4"
39text t_media "application/json"
40
41text t_uri "https://huggingface.co/datasets/aien/benchmark"
42text t_lic_apache "Apache-2.0"
43text t_lic_apache_lc "apache-2.0"
44text t_lic_gpl "GPL-3.0"
45text t_allowed_csv "Apache-2.0,MIT"
46text t_allowed_gpl "GPL-3.0"
47text t_issuer "Atlas Provenance Authority"
48
49text t_cap_fs "fs.read"
50text t_scope_ws "/workspace"
51text t_topic "agent.run.started"
52text t_producer "atlas-runtime"
53
54fn report_case name view uchar * ok bool to int
55if ok
56w1 = pt_write_all int 1 t_pass
57w2 = pt_write_all int 1 name
58w3 = pt_write_all int 1 t_nl
59if and w1 and w2 w3
60ret int 0
61end
62ret int 1
63end
64w4 = pt_write_all int 1 t_fail
65w5 = pt_write_all int 1 name
66w6 = pt_write_all int 1 t_nl
67if and w4 and w5 w6
68ret int 1
69end
70ret int 1
71end
72
73fn test_protocol_version to bool
74note 1.0 compatible with 1.2; 1.2 NOT compatible with 1.0; 1.0 NOT compatible with 2.0
75if not pv_is_compatible ushort 1 ushort 0 ushort 1 ushort 2
76ret false
77end
78if pv_is_compatible ushort 1 ushort 2 ushort 1 ushort 0
79ret false
80end
81if pv_is_compatible ushort 1 ushort 0 ushort 2 ushort 0
82ret false
83end
84if not pv_eq ushort 1 ushort 2 ushort 1 ushort 2
85ret false
86end
87if ne pv_cmp ushort 1 ushort 0 ushort 1 ushort 2 int -1
88ret false
89end
90if ne pv_cmp ushort 2 ushort 0 ushort 1 ushort 9 int 1
91ret false
92end
93buf = new uchar 16 0
94n = pv_format ushort 1 ushort 2 buf
95if not pt_slice_eq part buf 0 n t_v12
96ret false
97end
98ret true
99end
100
101fn test_digest32 to bool
102d1 = new uchar 32 0
103d2 = new uchar 32 0
104hx = new uchar 64 0
105fmt = new uchar 71 0
106if not digest_is_zero d1
107ret false
108end
109for i ulong 32
110put d1 i uchar 0xab
111end
112if digest_is_zero d1
113ret false
114end
115digest_to_hex d1 hx
116if not pt_slice_eq hx t_hex_ab
117ret false
118end
119if ne digest_from_hex hx d2 PT_OK
120ret false
121end
122if not digest_eq d1 d2
123ret false
124end
125note Uppercase hex decode must also succeed
126digest_zero d2
127if ne digest_from_hex t_hex_AB d2 PT_OK
128ret false
129end
130if not digest_eq d1 d2
131ret false
132end
133note Display format sha256:<hex>
134fl = digest_format_sha256 d1 fmt
135if ne fl ulong 71
136ret false
137end
138if not pt_slice_eq fmt t_sha_ab_fmt
139ret false
140end
141note Negative controls: wrong length and invalid hex char
142if ne digest_from_hex t_hex_short d2 PT_ERR_BAD_LEN
143ret false
144end
145if ne digest_from_hex t_hex_bad d2 PT_ERR_BAD_HEX
146ret false
147end
148ret true
149end
150
151fn test_uuid16 to bool
152u1 = new uchar 16 0
153u2 = new uchar 16 0
154sbuf = new uchar 36 0
155if not uuid_is_nil u1
156ret false
157end
158if ne uuid_from_str t_uuid_v4 u1 PT_OK
159ret false
160end
161if uuid_is_nil u1
162ret false
163end
164if not uuid_is_v4 u1
165ret false
166end
167uuid_to_str u1 sbuf
168if not pt_slice_eq sbuf t_uuid_v4
169ret false
170end
171if ne uuid_from_str sbuf u2 PT_OK
172ret false
173end
174if not uuid_eq u1 u2
175ret false
176end
177note Negative controls: v1 is not v4, bad dash, bad hex, short length
178if ne uuid_from_str t_uuid_v1 u2 PT_OK
179ret false
180end
181if uuid_is_v4 u2
182ret false
183end
184if ne uuid_from_str t_uuid_bad_dash u2 PT_ERR_BAD_UUID
185ret false
186end
187if ne uuid_from_str t_uuid_bad_hex u2 PT_ERR_BAD_HEX
188ret false
189end
190if ne uuid_from_str t_uuid_short u2 PT_ERR_BAD_UUID
191ret false
192end
193ret true
194end
195
196fn test_seq_and_artifact to bool
197if ne seq_next ulong 0 ulong 1
198ret false
199end
200if ne seq_next ulong 41 ulong 42
201ret false
202end
203note Negative/boundary control: saturating_add at U64_MAX must NOT wrap to 0
204if ne seq_next U64_MAX U64_MAX
205ret false
206end
207if ts_is_expired ulong 1000 false ulong 500
208ret false
209end
210if ts_is_expired ulong 1000 true ulong 1000
211ret false
212end
213if not ts_is_expired ulong 1001 true ulong 1000
214ret false
215end
216u = new uchar 16 0
217d = new uchar 32 0
218note Negative controls: nil UUID, zero digest, empty media_type
219if ne artifact_ref_validate u d t_media PT_ERR_NIL_UUID
220ret false
221end
222rc = uuid_from_str t_uuid_v4 u
223if ne rc PT_OK
224ret false
225end
226if ne artifact_ref_validate u d t_media PT_ERR_ZERO_DIGEST
227ret false
228end
229put d 0 uchar 1
230if ne artifact_ref_validate u d part t_media 0 0 PT_ERR_EMPTY_FIELD
231ret false
232end
233if ne artifact_ref_validate u d t_media PT_OK
234ret false
235end
236ret true
237end
238
239fn test_provenance_sha256 to bool
240d1 = new uchar 32 0
241d2 = new uchar 32 0
242c1 = new uchar 32 0
243c2 = new uchar 32 0
244hx = new uchar 64 0
245prov_compute_sha256 part t_abc 0 0 d1
246digest_to_hex d1 hx
247if not pt_slice_eq hx t_sha_empty
248ret false
249end
250prov_compute_sha256 t_abc d2
251digest_to_hex d2 hx
252if not pt_slice_eq hx t_sha_abc
253ret false
254end
255note combine_digests must be deterministic and order-sensitive
256prov_combine_digests d1 d2 c1
257prov_combine_digests d1 d2 c2
258if not digest_eq c1 c2
259ret false
260end
261prov_combine_digests d2 d1 c2
262if digest_eq c1 c2
263ret false
264end
265ret true
266end
267
268fn test_provenance_grant to bool
269perms = or PERM_READ or PERM_EVALUATE PERM_TRAIN
270if ne grant_verify_permission perms PERM_TRAIN PROV_OK
271ret false
272end
273note Negative controls: missing DISTILL bit, invalid high bit
274if ne grant_verify_permission perms PERM_DISTILL PROV_ERR_PERM_DENIED
275ret false
276end
277if ne grant_verify_permission uint 128 PERM_READ PROV_ERR_BAD_PERMS
278ret false
279end
280note Case-insensitive license verification + negative control
281if ne grant_verify_license_csv t_lic_apache t_allowed_csv PROV_OK
282ret false
283end
284if ne grant_verify_license_csv t_lic_apache_lc t_allowed_csv PROV_OK
285ret false
286end
287if ne grant_verify_license_csv t_lic_apache t_allowed_gpl PROV_ERR_BAD_LICENSE
288ret false
289end
290if ne grant_verify_license_csv t_lic_gpl t_allowed_csv PROV_ERR_BAD_LICENSE
291ret false
292end
293note Expiration boundary & signature presence controls
294if ne grant_verify_window true ulong 1000 ulong 999 true true ulong 64 PROV_OK
295ret false
296end
297if ne grant_verify_window true ulong 1000 ulong 1000 true true ulong 64 PROV_OK
298ret false
299end
300if ne grant_verify_window true ulong 1000 ulong 1001 true true ulong 64 PROV_ERR_EXPIRED
301ret false
302end
303if ne grant_verify_window true ulong 1000 ulong 950 true false ulong 0 PROV_ERR_MISSING_SIG
304ret false
305end
306if ne grant_verify_window true ulong 1000 ulong 950 true true ulong 32 PROV_ERR_BAD_SIG_FMT
307ret false
308end
309note Unsigned grant digest determinism & sensitivity to expiration
310gid = new uchar 16 0
311rc = uuid_from_str t_uuid_v4 gid
312if ne rc PT_OK
313ret false
314end
315ctx = new ulong 40 0
316d1 = new uchar 32 0
317d2 = new uchar 32 0
318grant_hash_header ctx gid t_uri
319grant_hash_policy ctx t_lic_apache perms t_issuer
320grant_hash_finish ctx true ulong 1000 d1
321grant_hash_header ctx gid t_uri
322grant_hash_policy ctx t_lic_apache perms t_issuer
323grant_hash_finish ctx true ulong 1000 d2
324if not digest_eq d1 d2
325ret false
326end
327grant_hash_header ctx gid t_uri
328grant_hash_policy ctx t_lic_apache perms t_issuer
329grant_hash_finish ctx false ulong 0 d2
330if digest_eq d1 d2
331ret false
332end
333ret true
334end
335
336fn test_containment_and_cap to bool
337if ne containment_require_strict true true SECCOMP_STRICT ulong 0 AE_OK
338ret false
339end
340note Negative controls: network not isolated, writable fs, permissive seccomp, subprocesses allowed
341if ne containment_require_strict false true SECCOMP_STRICT ulong 0 AE_ERR_CONTAINMENT_WEAK
342ret false
343end
344if ne containment_require_strict true false SECCOMP_STRICT ulong 0 AE_ERR_CONTAINMENT_WEAK
345ret false
346end
347if ne containment_require_strict true true SECCOMP_PERMISSIVE ulong 0 AE_ERR_CONTAINMENT_WEAK
348ret false
349end
350if ne containment_require_strict true true SECCOMP_STRICT ulong 1 AE_ERR_CONTAINMENT_WEAK
351ret false
352end
353note CapabilityGrant positive & negative controls
354if ne cap_grant_check t_cap_fs t_scope_ws AE_OK
355ret false
356end
357if ne cap_grant_check part t_cap_fs 0 0 t_scope_ws AE_ERR_CAP_EMPTY
358ret false
359end
360if ne cap_grant_window_check ulong 1000 true ulong 2000 ulong 1500 AE_OK
361ret false
362end
363if ne cap_grant_window_check ulong 1000 true ulong 900 ulong 950 AE_ERR_CAP_BAD_WINDOW
364ret false
365end
366if ne cap_grant_window_check ulong 1000 true ulong 2000 ulong 2001 AE_ERR_CAP_EXPIRED
367ret false
368end
369ret true
370end
371
372fn test_exec_transitions to bool
373if ne exec_transition_check EXEC_IDLE EXEC_RUNNING AE_OK
374ret false
375end
376if ne exec_transition_check EXEC_RUNNING EXEC_AWAITING_APPROVAL AE_OK
377ret false
378end
379if ne exec_transition_check EXEC_AWAITING_APPROVAL EXEC_RUNNING AE_OK
380ret false
381end
382if ne exec_transition_check EXEC_RUNNING EXEC_SUSPENDED AE_OK
383ret false
384end
385if ne exec_transition_check EXEC_SUSPENDED EXEC_RUNNING AE_OK
386ret false
387end
388if ne exec_transition_check EXEC_RUNNING EXEC_TERMINATED AE_OK
389ret false
390end
391note Negative controls: Terminated is absorbing; Idle cannot jump to Suspended; out-of-range status rejected
392if ne exec_transition_check EXEC_TERMINATED EXEC_IDLE AE_ERR_BAD_TRANSITION
393ret false
394end
395if ne exec_transition_check EXEC_TERMINATED EXEC_TERMINATED AE_ERR_BAD_TRANSITION
396ret false
397end
398if ne exec_transition_check EXEC_IDLE EXEC_SUSPENDED AE_ERR_BAD_TRANSITION
399ret false
400end
401if ne exec_transition_check ulong 99 EXEC_IDLE AE_ERR_BAD_STATUS
402ret false
403end
404ret true
405end
406
407fn test_event_and_budget to bool
408if ne event_seq_check ulong 1 ulong 2 AE_OK
409ret false
410end
411note Negative controls: duplicate or regressing sequence number rejected
412if ne event_seq_check ulong 2 ulong 2 AE_ERR_SEQ_REGRESS
413ret false
414end
415if ne event_seq_check ulong 5 ulong 3 AE_ERR_SEQ_REGRESS
416ret false
417end
418eid = new uchar 16 0
419rc = uuid_from_str t_uuid_v4 eid
420if ne rc PT_OK
421ret false
422end
423pdig = new uchar 32 0
424prov_compute_sha256 t_abc pdig
425ctx = new ulong 40 0
426d1 = new uchar 32 0
427d2 = new uchar 32 0
428event_hash_meta ctx eid t_topic
429event_hash_body ctx t_producer ulong 1 ulong 1000
430event_hash_finish ctx pdig d1
431event_hash_meta ctx eid t_topic
432event_hash_body ctx t_producer ulong 1 ulong 1000
433event_hash_finish ctx pdig d2
434if not digest_eq d1 d2
435ret false
436end
437event_hash_meta ctx eid t_topic
438event_hash_body ctx t_producer ulong 2 ulong 1000
439event_hash_finish ctx pdig d2
440if digest_eq d1 d2
441ret false
442end
443note ResourceBudget positive & negative controls
444if ne budget_check_tokens ulong 4096 ulong 4096 AE_OK
445ret false
446end
447if ne budget_check_tokens ulong 4097 ulong 4096 AE_ERR_BUDGET_TOKENS
448ret false
449end
450if ne budget_check_cost ulong 500000 ulong 0 AE_OK
451ret false
452end
453if ne budget_check_cost ulong 500001 ulong 500000 AE_ERR_BUDGET_COST
454ret false
455end
456if ne budget_check_duration ulong 61 ulong 60 AE_ERR_BUDGET_DURATION
457ret false
458end
459if ne budget_check_subagents ulong 5 ulong 4 AE_ERR_BUDGET_SUBAGENTS
460ret false
461end
462ret true
463end
464
465fn main to int
466fail = int 0
467fail = add fail report_case t_c1 test_protocol_version
468fail = add fail report_case t_c2 test_digest32
469fail = add fail report_case t_c3 test_uuid16
470fail = add fail report_case t_c4 test_seq_and_artifact
471fail = add fail report_case t_c5 test_provenance_sha256
472fail = add fail report_case t_c6 test_provenance_grant
473fail = add fail report_case t_c7 test_containment_and_cap
474fail = add fail report_case t_c8 test_exec_transitions
475fail = add fail report_case t_c9 test_event_and_budget
476if ne fail int 0
477ret int 1
478end
479ok = pt_write_all int 1 t_done
480if not ok
481ret int 1
482end
483ret int 0
484end