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 / si / agent-archive / test.om
| 1 | note agent-archive unit tests: SHA-256 NIST vectors, FNV-1a dedup, privacy & redaction, |
| 2 | note hash-chain linking, and tamper detection negative controls. |
| 3 | note Compose: si/directives/om2.om + si/agent-archive/lib.om + si/agent-archive/test.om |
| 4 | |
| 5 | text aa_ts_pass "PASS " |
| 6 | text aa_ts_fail "FAIL " |
| 7 | text aa_ts_nl "\n" |
| 8 | text aa_ts_ok "SUMMARY agent-archive PASS all=8 fail=0\n" |
| 9 | text aa_ts_bad "SUMMARY agent-archive FAIL\n" |
| 10 | |
| 11 | text aa_tn_1 "sha256_nist_vectors" |
| 12 | text aa_tn_2 "sha256_multiblock" |
| 13 | text aa_tn_3 "fnv_dedup_and_privacy_mode" |
| 14 | text aa_tn_4 "secret_redaction_filter" |
| 15 | text aa_tn_5 "private_record_export_refusal" |
| 16 | text aa_tn_6 "hash_chain_build_and_verify" |
| 17 | text aa_tn_7 "tamper_detect_payload_flip" |
| 18 | text aa_tn_8 "tamper_detect_broken_link_and_rollback" |
| 19 | |
| 20 | text aa_v_empty "" |
| 21 | text aa_v_empty_sha "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" |
| 22 | text aa_v_abc "abc" |
| 23 | text aa_v_abc_sha "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" |
| 24 | text aa_v_multi "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" |
| 25 | text aa_v_multi_sha "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" |
| 26 | |
| 27 | text aa_bad_agent "../records" |
| 28 | text aa_sec_in "Auth Bearer tok12345 and ghp_abc999xyz and password=mysecret123 ok" |
| 29 | text aa_sec_exp "Auth Bearer [REDACTED] and [REDACTED] and password=[REDACTED] ok" |
| 30 | text aa_clean_in "Pure Omega build succeeded with zero warnings." |
| 31 | |
| 32 | text aa_m1 "Check the live Spark build." |
| 33 | text aa_m2 "Running with Bearer secret_token_99 now." |
| 34 | text aa_m3 "Private draft notes do not export." |
| 35 | text aa_chk_redacted "[REDACTED]" |
| 36 | text aa_chk_secret "secret_token_99" |
| 37 | |
| 38 | fn aa_t_print s view uchar * to void |
| 39 | k = write 1 s 0 len s |
| 40 | if lt k 0 |
| 41 | exit 2 |
| 42 | end |
| 43 | end |
| 44 | |
| 45 | fn aa_t_report name view uchar * ok bool to int |
| 46 | if ok |
| 47 | aa_t_print aa_ts_pass |
| 48 | aa_t_print name |
| 49 | aa_t_print aa_ts_nl |
| 50 | ret 0 |
| 51 | end |
| 52 | aa_t_print aa_ts_fail |
| 53 | aa_t_print name |
| 54 | aa_t_print aa_ts_nl |
| 55 | ret 1 |
| 56 | end |
| 57 | |
| 58 | fn aa_t_contains hay view uchar * ned view uchar * to bool |
| 59 | hl = len hay |
| 60 | nl = len ned |
| 61 | if eq nl 0 |
| 62 | ret true |
| 63 | end |
| 64 | if lt hl nl |
| 65 | ret false |
| 66 | end |
| 67 | lim = add sub hl nl 1 |
| 68 | i = ulong 0 |
| 69 | while lt i lim bound 4096 |
| 70 | if aa_eq_bytes part hay i nl ned |
| 71 | ret true |
| 72 | end |
| 73 | i = add i 1 |
| 74 | end |
| 75 | ret false |
| 76 | end |
| 77 | |
| 78 | fn aa_t_sha_nist to bool |
| 79 | d1 = new uchar 32 0 |
| 80 | h1 = new uchar 64 0 |
| 81 | aa_sha256 part aa_v_empty 0 0 d1 |
| 82 | aa_hex_encode d1 h1 |
| 83 | if not aa_eq_bytes h1 aa_v_empty_sha |
| 84 | ret false |
| 85 | end |
| 86 | d2 = new uchar 32 0 |
| 87 | h2 = new uchar 64 0 |
| 88 | aa_sha256 aa_v_abc d2 |
| 89 | aa_hex_encode d2 h2 |
| 90 | ret aa_eq_bytes h2 aa_v_abc_sha |
| 91 | end |
| 92 | |
| 93 | fn aa_t_sha_multi to bool |
| 94 | d = new uchar 32 0 |
| 95 | h = new uchar 64 0 |
| 96 | aa_sha256 aa_v_multi d |
| 97 | aa_hex_encode d h |
| 98 | ret aa_eq_bytes h aa_v_multi_sha |
| 99 | end |
| 100 | |
| 101 | fn aa_t_dedup_priv to bool |
| 102 | k1 = aa_record_dedup_key AA_AGENT_CLAUDE AA_ROLE_USER 0 aa_m1 |
| 103 | k2 = aa_record_dedup_key AA_AGENT_CLAUDE AA_ROLE_USER 0 aa_m1 |
| 104 | k3 = aa_record_dedup_key AA_AGENT_CLAUDE AA_ROLE_USER 1 aa_m1 |
| 105 | if ne k1 k2 |
| 106 | ret false |
| 107 | end |
| 108 | if eq k1 k3 |
| 109 | ret false |
| 110 | end |
| 111 | if ge aa_parse_agent aa_bad_agent 0 |
| 112 | ret false |
| 113 | end |
| 114 | if ne aa_parse_agent aa_t_ag_omp long AA_AGENT_OMP |
| 115 | ret false |
| 116 | end |
| 117 | if not aa_path_is_private 1000 1000 384 false |
| 118 | ret false |
| 119 | end |
| 120 | if aa_path_is_private 1000 1000 420 false |
| 121 | ret false |
| 122 | end |
| 123 | if aa_path_is_private 1000 1001 384 false |
| 124 | ret false |
| 125 | end |
| 126 | if aa_path_is_private 1000 1000 384 true |
| 127 | ret false |
| 128 | end |
| 129 | ret true |
| 130 | end |
| 131 | |
| 132 | fn aa_t_redaction to bool |
| 133 | dst = new uchar 512 0 |
| 134 | n1 = aa_redact_text aa_sec_in dst |
| 135 | if lt n1 0 |
| 136 | ret false |
| 137 | end |
| 138 | if not aa_eq_bytes part dst 0 ulong n1 aa_sec_exp |
| 139 | ret false |
| 140 | end |
| 141 | n2 = aa_redact_text aa_clean_in dst |
| 142 | if lt n2 0 |
| 143 | ret false |
| 144 | end |
| 145 | ret aa_eq_bytes part dst 0 ulong n2 aa_clean_in |
| 146 | end |
| 147 | |
| 148 | fn aa_t_append_helper meta edit AaArchiveMeta entries edit ulong 288 hashes edit uchar 4096 text_buf edit uchar 4096 to bool |
| 149 | r = new AaChainEntry 0 1000 AA_AGENT_CLAUDE AA_ROLE_USER 0 0 0 0 0 |
| 150 | if ne aa_stage_record meta r aa_m1 text_buf 0 |
| 151 | ret false |
| 152 | end |
| 153 | if ne aa_commit_record meta r entries 0 |
| 154 | ret false |
| 155 | end |
| 156 | if not aa_link_record 0 r hashes text_buf |
| 157 | ret false |
| 158 | end |
| 159 | r2 = new AaChainEntry 0 2000 AA_AGENT_CLAUDE AA_ROLE_ASSISTANT 0 64 0 0 0 |
| 160 | if ne aa_stage_record meta r2 aa_m2 text_buf 0 |
| 161 | ret false |
| 162 | end |
| 163 | if ne aa_commit_record meta r2 entries 0 |
| 164 | ret false |
| 165 | end |
| 166 | if not aa_link_record 1 r2 hashes text_buf |
| 167 | ret false |
| 168 | end |
| 169 | r3 = new AaChainEntry 0 3000 AA_AGENT_CODEX AA_ROLE_USER 1 128 0 0 0 |
| 170 | if ne aa_stage_record meta r3 aa_m3 text_buf 0 |
| 171 | ret false |
| 172 | end |
| 173 | if ne aa_commit_record meta r3 entries 0 |
| 174 | ret false |
| 175 | end |
| 176 | ret aa_link_record 2 r3 hashes text_buf |
| 177 | end |
| 178 | |
| 179 | fn aa_t_private_export to bool |
| 180 | meta = new AaArchiveMeta 0 0 0 |
| 181 | entries = new ulong 288 0 |
| 182 | hashes = new uchar 4096 0 |
| 183 | text_buf = new uchar 4096 0 |
| 184 | if not aa_t_append_helper meta entries hashes text_buf |
| 185 | ret false |
| 186 | end |
| 187 | rec = new AaChainEntry 0 0 0 0 0 0 0 0 0 |
| 188 | outln = new uchar 2048 0 |
| 189 | note Record 2 is private: default export MUST refuse (-2). |
| 190 | aa_load_entry entries 2 rec |
| 191 | n_priv = aa_export_jsonl rec hashes text_buf false outln |
| 192 | if ne n_priv -2 |
| 193 | ret false |
| 194 | end |
| 195 | note Explicit allow_private=true permits export. |
| 196 | n_allow = aa_export_jsonl rec hashes text_buf true outln |
| 197 | if le n_allow 0 |
| 198 | ret false |
| 199 | end |
| 200 | note Record 1 is public with secret: exported JSONL MUST redact secret. |
| 201 | aa_load_entry entries 1 rec |
| 202 | n_pub = aa_export_jsonl rec hashes text_buf false outln |
| 203 | if le n_pub 0 |
| 204 | ret false |
| 205 | end |
| 206 | if not aa_t_contains part outln 0 ulong n_pub aa_chk_redacted |
| 207 | ret false |
| 208 | end |
| 209 | if aa_t_contains part outln 0 ulong n_pub aa_chk_secret |
| 210 | ret false |
| 211 | end |
| 212 | ret true |
| 213 | end |
| 214 | |
| 215 | fn aa_t_chain_verify to bool |
| 216 | meta = new AaArchiveMeta 0 0 0 |
| 217 | entries = new ulong 288 0 |
| 218 | hashes = new uchar 4096 0 |
| 219 | text_buf = new uchar 4096 0 |
| 220 | if not aa_t_append_helper meta entries hashes text_buf |
| 221 | ret false |
| 222 | end |
| 223 | if ne aa_verify_chain get meta cnt entries hashes text_buf 0 |
| 224 | ret false |
| 225 | end |
| 226 | note Negative control: duplicate dedup_key is skipped (returns 1, cnt unchanged). |
| 227 | dup = new AaChainEntry 0 4000 AA_AGENT_CLAUDE AA_ROLE_USER 0 0 0 0 0 |
| 228 | if ne aa_stage_record meta dup aa_m1 text_buf 0 |
| 229 | ret false |
| 230 | end |
| 231 | if ne aa_commit_record meta dup entries 1 |
| 232 | ret false |
| 233 | end |
| 234 | ret eq get meta cnt 3 |
| 235 | end |
| 236 | |
| 237 | fn aa_t_tamper_payload to bool |
| 238 | meta = new AaArchiveMeta 0 0 0 |
| 239 | entries = new ulong 288 0 |
| 240 | hashes = new uchar 4096 0 |
| 241 | text_buf = new uchar 4096 0 |
| 242 | if not aa_t_append_helper meta entries hashes text_buf |
| 243 | ret false |
| 244 | end |
| 245 | note Flip 1 byte in record 0 text payload -> verifier MUST catch digest mismatch (-4). |
| 246 | orig = get text_buf 0 |
| 247 | put text_buf 0 xor orig uchar 1 |
| 248 | rc = aa_verify_chain get meta cnt entries hashes text_buf |
| 249 | ret eq rc -4 |
| 250 | end |
| 251 | |
| 252 | fn aa_t_tamper_link_rollback to bool |
| 253 | meta = new AaArchiveMeta 0 0 0 |
| 254 | entries = new ulong 288 0 |
| 255 | hashes = new uchar 4096 0 |
| 256 | text_buf = new uchar 4096 0 |
| 257 | if not aa_t_append_helper meta entries hashes text_buf |
| 258 | ret false |
| 259 | end |
| 260 | note Negative control 1: timestamp rollback refused at stage (-3). |
| 261 | rb = new AaChainEntry 0 2500 AA_AGENT_CLAUDE AA_ROLE_USER 0 200 0 0 0 |
| 262 | if ne aa_stage_record meta rb aa_m1 text_buf -3 |
| 263 | ret false |
| 264 | end |
| 265 | note Negative control 2: corrupt prev_hash of record 1 -> verifier catches broken chain (-3). |
| 266 | orig = get hashes 128 |
| 267 | put hashes 128 xor orig uchar 1 |
| 268 | rc = aa_verify_chain get meta cnt entries hashes text_buf |
| 269 | ret eq rc -3 |
| 270 | end |
| 271 | |
| 272 | fn main to int |
| 273 | fails = int 0 |
| 274 | fails = add fails aa_t_report aa_tn_1 aa_t_sha_nist |
| 275 | fails = add fails aa_t_report aa_tn_2 aa_t_sha_multi |
| 276 | fails = add fails aa_t_report aa_tn_3 aa_t_dedup_priv |
| 277 | fails = add fails aa_t_report aa_tn_4 aa_t_redaction |
| 278 | fails = add fails aa_t_report aa_tn_5 aa_t_private_export |
| 279 | fails = add fails aa_t_report aa_tn_6 aa_t_chain_verify |
| 280 | fails = add fails aa_t_report aa_tn_7 aa_t_tamper_payload |
| 281 | fails = add fails aa_t_report aa_tn_8 aa_t_tamper_link_rollback |
| 282 | if eq fails 0 |
| 283 | aa_t_print aa_ts_ok |
| 284 | ret 0 |
| 285 | end |
| 286 | aa_t_print aa_ts_bad |
| 287 | ret 1 |
| 288 | end |