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 / si / agent-archive / test.om

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