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