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

450 lines · 14246 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/synapse/core/test.om: comprehensive behavioral test suite for all 5 Synapse core modules
3note (changeset, graph, lease, review, ledger) covering positive paths and every negative/refusal control.
4note Composed OM-2 test unit (compose after si/directives/om2.om, om/tls/sha2.om, and core modules).
5
6global g_tst_cnt ulong 8
7
8text tt_pass "PASS "
9text tt_fail "FAIL "
10text tt_nl "\n"
11text tt_sum1 "SYNAPSE-CORE-TEST PASS checks="
12text tt_sum2 "SYNAPSE-CORE-TEST FAIL checks="
13text tt_sumf " failures="
14
15note test fixtures
16text tf_alice "alice"
17text tf_bob "bob"
18text tf_carol "carol"
19text tf_main "main"
20text tf_feat1 "feat-1"
21text tf_feat2 "feat-2"
22text tf_featd "feat-div"
23text tf_featr "feat-rej"
24text tf_pa "src/a.om"
25text tf_pb "src/b.om"
26text tf_palpha "src/alpha.om"
27text tf_pbeta "src/beta.om"
28text tf_pshared "src/shared.om"
29text tf_pdir "pkg/mod"
30text tf_psub "pkg/mod/sub.om"
31text tf_psib "pkg/mod2/sub.om"
32text tf_pcore "src/core"
33text tf_pcoref "src/core/graph.om"
34text tf_pcoref2 "src/core/graph.om"
35text tf_bad1 "/abs/file.om"
36text tf_bad2 "dir/trail/"
37text tf_bad3 "a//b.om"
38text tf_bad4 "a/../b.om"
39text tf_bad5 "a/./b.om"
40text tf_bad6 ".git/config"
41text tf_sum "core change"
42text tf_lb1 "branch:feat-x"
43text tf_lp1 "path:src/core"
44text tf_lp2 "path:src/core/graph.om"
45text tf_lp3 "path:src"
46text tf_lp4 "path:src/core/*"
47text tf_lp5 "path:src/core2/x.om"
48text tf_lbad "invalid:target"
49text tf_fmerged "MERGED"
50
51text tn_cs_ser "changeset.canonical_bytes_match_direct_sha256"
52text tn_cs_det "changeset.canonical_sha256_deterministic_across_path_order"
53text tn_cs_uniq "changeset.distinct_content_distinct_digest"
54text tn_cs_pval "changeset.invalid_and_duplicate_paths_refused"
55text tn_cs_ov "changeset.exact_prefix_and_sibling_path_overlap"
56text tn_cs_st "changeset.state_machine_forward_and_refusals"
57
58text tn_gr_anc "graph.parent_child_and_ancestry_reachability"
59text tn_gr_lca "graph.lowest_common_ancestor_merge_base"
60text tn_gr_cyc "graph.cycle_and_self_parent_refused"
61text tn_gr_conf "graph.concurrent_branch_disjoint_exact_prefix_conflicts"
62
63text tn_ls_ov "lease.overlapping_branch_and_path_refused_status_2"
64text tn_ls_ren "lease.renewal_holder_only_and_extends_ttl"
65text tn_ls_exp "lease.expired_lease_reclaimable_and_renew_refused"
66text tn_ls_rel "lease.explicit_release_final_status_and_reclaim"
67
68text tn_rv_self "review.self_review_refused"
69text tn_rv_blk "review.unreviewed_and_changes_requested_and_reject_block_land"
70text tn_rv_inv "review.new_head_invalidates_prior_verdicts_and_stale_head_refused"
71text tn_rv_land "review.exact_head_merge_and_fast_forward_land_advances_main"
72text tn_rv_nff "review.non_fast_forward_land_refused_never_automerges"
73
74text tn_lg_ok "ledger.hash_chain_records_all_transitions_and_verifies"
75text tn_lg_t1 "ledger.tampered_subject_caught"
76text tn_lg_t2 "ledger.tampered_prev_hash_caught"
77text tn_lg_t3 "ledger.tampered_entry_hash_caught"
78text tn_lg_t4 "ledger.tampered_seq_caught"
79
80fn tst_check cond bool label view uchar * to void
81put g_tst_cnt 0 add get g_tst_cnt 0 1
82if cond
83syn_write_text 1 tt_pass
84syn_write_text 1 label
85syn_write_text 1 tt_nl
86else
87put g_tst_cnt 1 add get g_tst_cnt 1 1
88syn_write_text 1 tt_fail
89syn_write_text 1 label
90syn_write_text 1 tt_nl
91end
92end
93
94fn tst_set_par pidx ulong to void
95put g_tst_cnt 2 pidx
96end
97
98fn tst_next_ts to ulong
99t = add get g_tst_cnt 3 1
100put g_tst_cnt 3 t
101ret t
102end
103
104fn tst_cs_add auth view uchar * br view uchar * pth view uchar * to ulong
105pid = new uchar 32 0
106rc = cs_stage_begin auth br tst_next_ts
107if ne rc SYN_OK
108ret SYN_NONE
109end
110pidx = get g_tst_cnt 2
111if ne pidx SYN_NONE
112cs_get_id pidx pid
113rc = cs_stage_set_parent pid
114if ne rc SYN_OK
115ret SYN_NONE
116end
117end
118rc = cs_stage_add_path pth
119if ne rc SYN_OK
120ret SYN_NONE
121end
122rc = cs_stage_commit
123if ne rc SYN_OK
124ret SYN_NONE
125end
126ret cs_last_idx
127end
128
129note ======== Suite 1: changeset.om ========
130
131fn tst_cs_digest_checks to void
132id1 = new uchar 32 0
133id2 = new uchar 32 0
134ser = new uchar 1024 0
135dig = new uchar 32 0
136syn_reset_all
137ok = eq cs_stage_begin tf_alice tf_feat1 1000 SYN_OK
138ok = and ok eq cs_stage_set_summary tf_sum SYN_OK
139ok = and ok eq cs_stage_add_path tf_pb SYN_OK
140ok = and ok eq cs_stage_add_path tf_pa SYN_OK
141ok = and ok eq cs_stage_commit SYN_OK
142i1 = cs_last_idx
143cs_get_id i1 id1
144slen = cs_canonical_serialize i1 ser
145dl = sha2_digest 256 part ser 0 slen dig
146ok = and ok and eq dl 32 syn_digest_eq id1 dig
147tst_check ok tn_cs_ser
148
149syn_reset_all
150ok = eq cs_stage_begin tf_alice tf_feat1 1000 SYN_OK
151ok = and ok eq cs_stage_set_summary tf_sum SYN_OK
152ok = and ok eq cs_stage_add_path tf_pa SYN_OK
153ok = and ok eq cs_stage_add_path tf_pb SYN_OK
154ok = and ok eq cs_stage_commit SYN_OK
155cs_get_id cs_last_idx id2
156ok = and ok syn_digest_eq id1 id2
157tst_check ok tn_cs_det
158
159ok = eq cs_stage_begin tf_bob tf_feat1 1000 SYN_OK
160ok = and ok eq cs_stage_set_summary tf_sum SYN_OK
161ok = and ok eq cs_stage_add_path tf_pa SYN_OK
162ok = and ok eq cs_stage_add_path tf_pb SYN_OK
163ok = and ok eq cs_stage_commit SYN_OK
164cs_get_id cs_last_idx dig
165ok = and ok eq syn_digest_eq id2 dig false
166tst_check ok tn_cs_uniq
167end
168
169fn tst_cs_path_and_state_checks to void
170syn_reset_all
171ok = eq cs_path_valid tf_bad1 false
172ok = and ok eq cs_path_valid tf_bad2 false
173ok = and ok eq cs_path_valid tf_bad3 false
174ok = and ok eq cs_path_valid tf_bad4 false
175ok = and ok eq cs_path_valid tf_bad5 false
176ok = and ok eq cs_path_valid tf_bad6 false
177ok = and ok eq cs_stage_begin tf_alice tf_feat2 1001 SYN_OK
178ok = and ok eq cs_stage_add_path tf_pa SYN_OK
179ok = and ok eq cs_stage_add_path tf_pa SYN_ERR_DUPLICATE
180tst_check ok tn_cs_pval
181
182ok = eq cs_paths_overlap_view tf_pcoref tf_pcoref2 1
183ok = and ok eq cs_paths_overlap_view tf_pcore tf_pcoref 2
184ok = and ok eq cs_paths_overlap_view tf_pcoref tf_pcore 2
185ok = and ok eq cs_paths_overlap_view tf_pdir tf_psub 2
186ok = and ok eq cs_paths_overlap_view tf_pdir tf_psib 0
187tst_check ok tn_cs_ov
188
189tst_set_par SYN_NONE
190i1 = tst_cs_add tf_alice tf_feat1 tf_pa
191i2 = tst_cs_add tf_bob tf_feat2 tf_pb
192ok = eq cs_get_state i1 CS_STATE_DRAFT
193ok = and ok eq cs_transition i1 CS_STATE_LANDED 1010 SYN_ERR_STATE_INVALID
194ok = and ok eq cs_transition i1 CS_STATE_PROPOSED 1011 SYN_OK
195ok = and ok eq cs_transition i1 CS_STATE_DRAFT 1012 SYN_ERR_STATE_INVALID
196ok = and ok eq cs_transition i1 CS_STATE_REVIEWED 1013 SYN_OK
197ok = and ok eq cs_transition i1 CS_STATE_LANDED 1014 SYN_OK
198ok = and ok eq cs_transition i1 CS_STATE_ABANDONED 1015 SYN_ERR_STATE_INVALID
199ok = and ok eq cs_transition i2 CS_STATE_ABANDONED 1016 SYN_OK
200ok = and ok eq cs_transition i2 CS_STATE_PROPOSED 1017 SYN_ERR_STATE_INVALID
201tst_check ok tn_cs_st
202end
203
204note ======== Suite 2: graph.om ========
205
206fn tst_graph_suite to void
207syn_reset_all
208put g_tst_cnt 3 2000
209tst_set_par SYN_NONE
210root = tst_cs_add tf_alice tf_main tf_pa
211tst_set_par root
212a1 = tst_cs_add tf_alice tf_feat1 tf_palpha
213tst_set_par a1
214a2 = tst_cs_add tf_alice tf_feat1 tf_pcore
215tst_set_par root
216b1 = tst_cs_add tf_bob tf_feat2 tf_pbeta
217tst_set_par b1
218b2 = tst_cs_add tf_bob tf_feat2 tf_psib
219tst_set_par a1
220c1 = tst_cs_add tf_carol tf_featd tf_pcoref
221
222ok = and eq gr_child_count root 2 eq gr_child_count a1 2
223ok = and ok and eq gr_parent_count a2 1 eq gr_parent_at a2 0 a1
224ok = and ok gr_is_ancestor root a2
225ok = and ok gr_is_ancestor a1 c1
226ok = and ok gr_is_ancestor a2 a2
227ok = and ok eq gr_is_ancestor a2 root false
228ok = and ok eq gr_is_ancestor a2 b2 false
229tst_check ok tn_gr_anc
230
231ok = eq gr_lca a2 b2 root
232ok = and ok eq gr_lca a2 c1 a1
233ok = and ok eq gr_lca a1 a2 a1
234ok = and ok eq gr_lca b1 c1 root
235tst_check ok tn_gr_lca
236
237ok = eq gr_link_parent root a2 SYN_ERR_CYCLE
238ok = and ok eq gr_link_parent a1 a1 SYN_ERR_CYCLE
239ok = and ok eq gr_link_parent a1 c1 SYN_ERR_CYCLE
240ok = and ok eq gr_parent_count root 0
241tst_check ok tn_gr_cyc
242
243ok = eq gr_branches_conflict a2 b2 0
244ok = and ok eq gr_branches_conflict a1 a2 0
245ok = and ok eq gr_branches_conflict a2 c1 2
246tst_set_par root
247x1 = tst_cs_add tf_alice tf_feat1 tf_pshared
248tst_set_par root
249x2 = tst_cs_add tf_bob tf_feat2 tf_pshared
250ok = and ok eq gr_branches_conflict x1 x2 1
251ok = and ok and eq gr_conflict_cs_a x1 eq gr_conflict_cs_b x2
252tst_set_par root
253x1 = tst_cs_add tf_alice tf_feat1 tf_pdir
254tst_set_par root
255x2 = tst_cs_add tf_bob tf_feat2 tf_psub
256ok = and ok eq gr_branches_conflict x1 x2 2
257tst_check ok tn_gr_conf
258end
259
260note ======== Suite 3: lease.om ========
261
262fn tst_lease_suite to void
263syn_reset_all
264ok = eq ls_claim tf_alice tf_lb1 100 50 SYN_OK
265lid_br = ls_last_id
266ok = and ok eq ls_claim tf_alice tf_lp1 100 50 SYN_OK
267lid_pa = ls_last_id
268ok = and ok eq ls_claim tf_bob tf_lb1 110 50 SYN_ERR_LEASE_CONFLICT
269cidx = ls_conflict_idx
270if ne cidx SYN_NONE
271ok = and ok syn_arena_eq_view ls_holder_off cidx ls_holder_len cidx tf_alice
272else
273ok = false
274end
275ok = and ok eq ls_claim tf_bob tf_lp2 110 50 SYN_ERR_LEASE_CONFLICT
276ok = and ok eq ls_claim tf_bob tf_lp3 110 50 SYN_ERR_LEASE_CONFLICT
277ok = and ok eq ls_claim tf_bob tf_lp4 110 50 SYN_ERR_LEASE_CONFLICT
278ok = and ok eq ls_claim tf_bob tf_lp5 110 50 SYN_OK
279ok = and ok eq ls_claim tf_bob tf_lbad 110 50 SYN_ERR_MALFORMED
280tst_check ok tn_ls_ov
281
282ok = eq ls_renew lid_br tf_bob 120 60 SYN_ERR_NOT_HOLDER
283ok = and ok eq ls_renew lid_br tf_alice 140 60 SYN_OK
284ok = and ok eq ls_claim tf_bob tf_lb1 160 30 SYN_ERR_LEASE_CONFLICT
285tst_check ok tn_ls_ren
286
287ok = eq ls_is_active lid_pa 160 false
288ok = and ok eq ls_renew lid_pa tf_alice 160 50 SYN_ERR_LEASE_CLOSED
289ok = and ok eq ls_claim tf_bob tf_lp1 160 50 SYN_OK
290tst_check ok tn_ls_exp
291
292ok = eq ls_release lid_br tf_bob tf_fmerged 170 SYN_ERR_NOT_HOLDER
293ok = and ok eq ls_release lid_br tf_alice tf_fmerged 170 SYN_OK
294ok = and ok eq ls_release lid_br tf_alice tf_fmerged 171 SYN_ERR_LEASE_CLOSED
295ok = and ok eq ls_claim tf_bob tf_lb1 171 40 SYN_OK
296cidx = ls_find_by_id lid_br
297if ne cidx SYN_NONE
298ok = and ok syn_arena_eq_view ls_final_off cidx ls_final_len cidx tf_fmerged
299else
300ok = false
301end
302tst_check ok tn_ls_rel
303end
304
305note ======== Suite 4: review.om ========
306
307fn tst_review_suite to void
308id1 = new uchar 32 0
309id2 = new uchar 32 0
310syn_reset_all
311put g_tst_cnt 3 3000
312
313tst_set_par SYN_NONE
314root = tst_cs_add tf_alice tf_main tf_pa
315ok = eq gr_branch_set tf_main root SYN_OK
316tst_set_par root
317cs1 = tst_cs_add tf_alice tf_feat1 tf_palpha
318ok = and ok eq cs_transition cs1 CS_STATE_PROPOSED 3005 SYN_OK
319cs_get_id cs1 id1
320
321note 4a: self-review refused
322ok = and ok eq rv_record id1 tf_alice RV_MERGE 3006 SYN_ERR_SELF_REVIEW
323tst_check ok tn_rv_self
324
325note 4b: unreviewed blocked, CHANGES_REQUESTED blocks even with MERGE, REJECT blocks
326ok = eq rv_land cs1 id1 3007 SYN_ERR_REVIEW_BLOCKED
327ok = and ok eq rv_record id1 tf_carol RV_CHANGES_REQUESTED 3008 SYN_OK
328ok = and ok eq rv_record id1 tf_bob RV_MERGE 3009 SYN_OK
329ok = and ok eq rv_land cs1 id1 3010 SYN_ERR_REVIEW_BLOCKED
330tst_set_par root
331cs2 = tst_cs_add tf_alice tf_featr tf_pb
332ok = and ok eq cs_transition cs2 CS_STATE_PROPOSED 3011 SYN_OK
333cs_get_id cs2 id2
334ok = and ok eq rv_record id2 tf_bob RV_MERGE 3012 SYN_OK
335ok = and ok eq rv_record id2 tf_carol RV_REJECT 3013 SYN_OK
336ok = and ok eq rv_land cs2 id2 3014 SYN_ERR_REVIEW_BLOCKED
337tst_check ok tn_rv_blk
338
339note 4c: new head on feat-1 invalidates cs1 verdicts; stale-head verdict refused
340tst_set_par cs1
341cs2 = tst_cs_add tf_alice tf_feat1 tf_pcore
342ok = eq cs_transition cs2 CS_STATE_PROPOSED 3020 SYN_OK
343cs_get_id cs2 id2
344ok = and ok eq rv_valid_merge_count cs1 0
345ok = and ok eq rv_record id1 tf_bob RV_MERGE 3021 SYN_ERR_STALE_HEAD
346rv_set_time 3022
347ok = and ok eq rv_record_bound cs2 id1 tf_bob RV_MERGE SYN_ERR_STALE_HEAD
348ok = and ok eq rv_land cs2 id1 3023 SYN_ERR_STALE_HEAD
349ok = and ok eq rv_land cs2 id2 3024 SYN_ERR_REVIEW_BLOCKED
350tst_check ok tn_rv_inv
351
352note 4d: fresh exact-head MERGE + fast-forward from main -> LAND succeeds & advances main
353ok = eq rv_record id2 tf_bob RV_MERGE 3030 SYN_OK
354ok = and ok eq rv_land cs2 id2 3031 SYN_OK
355ok = and ok eq cs_get_state cs2 CS_STATE_LANDED
356ok = and ok eq gr_main_head cs2
357tst_check ok tn_rv_land
358
359note 4e: non-fast-forward land refused (never automerges!)
360tst_set_par root
361cs1 = tst_cs_add tf_bob tf_featd tf_pbeta
362ok = eq cs_transition cs1 CS_STATE_PROPOSED 3040 SYN_OK
363cs_get_id cs1 id1
364ok = and ok eq rv_record id1 tf_carol RV_MERGE 3041 SYN_OK
365ok = and ok eq rv_land cs1 id1 3042 SYN_ERR_NON_FF
366ok = and ok eq gr_main_head cs2
367tst_check ok tn_rv_nff
368end
369
370note ======== Suite 5: ledger.om ========
371
372fn tst_ledger_suite to void
373id1 = new uchar 32 0
374syn_reset_all
375put g_tst_cnt 3 4000
376
377tst_set_par SYN_NONE
378root = tst_cs_add tf_alice tf_main tf_pa
379ok = eq gr_branch_set tf_main root SYN_OK
380tst_set_par root
381cs1 = tst_cs_add tf_alice tf_feat1 tf_pb
382ok = and ok eq cs_transition cs1 CS_STATE_PROPOSED 4005 SYN_OK
383cs_get_id cs1 id1
384ok = and ok eq ls_claim tf_alice tf_lb1 4006 100 SYN_OK
385lid = ls_last_id
386ok = and ok eq ls_renew lid tf_alice 4010 100 SYN_OK
387ok = and ok eq rv_record id1 tf_bob RV_MERGE 4011 SYN_OK
388ok = and ok eq rv_land cs1 id1 4012 SYN_OK
389ok = and ok eq ls_release lid tf_alice tf_fmerged 4013 SYN_OK
390ok = and ok eq lg_verify SYN_OK
391ok = and ok ge lg_count 9
392tst_check ok tn_lg_ok
393
394lg_tamper_xor_subj 2 0 1
395ok = eq lg_verify SYN_ERR_LEDGER_TAMPER
396ok = and ok eq lg_bad_seq 3
397lg_tamper_xor_subj 2 0 1
398ok = and ok eq lg_verify SYN_OK
399tst_check ok tn_lg_t1
400
401lg_tamper_xor_prev 3 5 1
402ok = eq lg_verify SYN_ERR_LEDGER_TAMPER
403ok = and ok eq lg_bad_seq 4
404lg_tamper_xor_prev 3 5 1
405ok = and ok eq lg_verify SYN_OK
406tst_check ok tn_lg_t2
407
408lg_tamper_xor_hash 1 31 1
409ok = eq lg_verify SYN_ERR_LEDGER_TAMPER
410ok = and ok eq lg_bad_seq 2
411lg_tamper_xor_hash 1 31 1
412ok = and ok eq lg_verify SYN_OK
413tst_check ok tn_lg_t3
414
415lg_tamper_set_seq 0 99
416ok = eq lg_verify SYN_ERR_LEDGER_TAMPER
417ok = and ok eq lg_bad_seq 1
418lg_tamper_set_seq 0 1
419ok = and ok eq lg_verify SYN_OK
420tst_check ok tn_lg_t4
421end
422
423fn main to int
424put g_tst_cnt 0 0
425put g_tst_cnt 1 0
426put g_tst_cnt 2 SYN_NONE
427put g_tst_cnt 3 1000
428tst_cs_digest_checks
429tst_cs_path_and_state_checks
430tst_graph_suite
431tst_lease_suite
432tst_review_suite
433tst_ledger_suite
434tot = get g_tst_cnt 0
435fails = get g_tst_cnt 1
436if eq fails 0
437syn_write_text 1 tt_sum1
438syn_write_u64 1 tot
439syn_write_text 1 tt_sumf
440syn_write_u64 1 fails
441syn_write_text 1 tt_nl
442ret 0
443end
444syn_write_text 1 tt_sum2
445syn_write_u64 1 tot
446syn_write_text 1 tt_sumf
447syn_write_u64 1 fails
448syn_write_text 1 tt_nl
449ret 1
450end