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 / aienux / crates / aienos-explain / explain_test.om

1468 lines · 37377 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/aienos-explain/explain_test.om: Behavioral self-test for aienos-explain.
3note Ports all behavioral tests from tests/explain.rs and tests/rsi_and_cli.rs.
4note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-explain/explain.om aienux/crates/aienos-explain/explain_test.om
5
6note Common test texts
7text t_prod "test"
8text t_sys "test"
9text t_art "Node"
10text t_dig64 "abababababababababababababababababababababababababababababababab"
11
12note Linear chain texts
13text t_lc_obs_s "allocator queue depth 900"
14text t_lc_obs_p "telemetry:kv"
15text t_lc_obs_e "900"
16text t_lc_i1_s "allocator is saturated"
17text t_lc_i1_p "rule:queue>512"
18text t_lc_i2_s "p95 latency is allocator bound"
19text t_lc_i2_p "rule:join"
20
21note Branching / diamond / cycle / missing / unsupported texts
22text t_id_a "a"
23text t_id_c "c"
24text t_id_m "m"
25text t_id_z "z"
26text t_id_A "A"
27text t_id_B "B"
28text t_id_C "C"
29text t_id_concl "concl"
30text t_id_i1 "i1"
31text t_id_i2 "i2"
32text t_id_obs "obs"
33text t_id_ghost "ghost"
34text t_id_lonely "lonely"
35text t_id_zz "zz"
36text t_st_concl "statement of concl"
37text t_st_i1 "statement of i1"
38text t_st_i2 "statement of i2"
39text t_st_obs "statement of obs"
40text t_st_a "statement of a"
41text t_st_c "statement of c"
42text t_st_m "statement of m"
43text t_st_z "statement of z"
44text t_st_A "statement of A"
45text t_st_B "statement of B"
46text t_st_C "statement of C"
47text t_st_lonely "statement of lonely"
48text t_w_circular "circular"
49text t_w_noev "no evidence for that link"
50
51note Imported cycle texts
52text t_cy1 "claim 1"
53text t_cy2 "claim 2"
54text t_cy3 "claim 3"
55
56note Contradiction texts
57text t_co_o1_s "sensor A says 70C"
58text t_co_o1_p "sensor:a"
59text t_co_o1_e "70"
60text t_co_o2_s "sensor B says 40C"
61text t_co_o2_p "sensor:b"
62text t_co_o2_e "40"
63text t_co_fl_s "A and B disagree"
64text t_co_in_s "die is hot"
65text t_co_in_p "rule:max"
66text t_w_conflicts "Conflicts:"
67text t_w_munc "Main uncertainty"
68text t_w_contra "contradiction"
69
70note Hypothesis texts
71text t_hy_o_s "cache misses up 40%"
72text t_hy_o_p "perf:llc"
73text t_hy_o_e "40"
74text t_hy_h_s "prefetcher is mis-trained"
75text t_hy_h_p "agent:rsi"
76text t_hy_i_s "retune prefetcher"
77text t_hy_i_p "planner"
78text t_w_chkfact "checked fact"
79text t_w_verfact "VerifiedFact"
80text t_w_obsbr "observed]"
81text t_w_notest "not yet established"
82
83note Branch scope texts
84text t_br_u_s "link 3 dropped 2% packets"
85text t_br_u_p "nic:3"
86text t_br_u_e "2"
87text t_br_d_s "link 3 is flaky"
88text t_br_d_p "rule:loss>1"
89text t_br_un_s "firmware 1.2 is signed"
90text t_br_un_p "boot"
91text t_br_un_v "sha256"
92text t_br_un_e "sig"
93
94note Analogy & determinism texts
95text t_an_o_s "x"
96text t_an_o_p "s"
97text t_an_h_s "y"
98text t_an_h_p "agent"
99text t_w_illus "illustration only, not evidence"
100text t_w_evself "The evidence itself:"
101text t_w_mech "mechanic"
102text t_dt_o "o"
103text t_dt_i "i"
104text t_dt_m "m"
105
106note Limits & malformed texts
107text t_bad_json "{not json"
108text t_good_json "{\"format\":\"aien.explain.evidence-graph\",\"version\":1}"
109text t_bad_fmt "wrong.format"
110text t_id_top "top"
111text t_id_m0 "m0"
112text t_id_m1 "m1"
113text t_id_m2 "m2"
114text t_id_n49 "n49"
115text t_id_n1 "n1"
116
117note Session clarification texts
118text t_w_rests1 "rests on step 1"
119text t_w_startpt "starting point"
120text t_w_testnode "test (Node)"
121text t_w_step1obs "step 1 id=obs"
122text t_w_concl "Conclusion:"
123text t_w_inferred "inferred"
124text t_w_noalt "No alternative"
125
126note Bidirectional contradiction texts
127text t_bi_obs "t:obs"
128text t_bi_riv "t:rival"
129text t_bi_clm "t:claim"
130text t_bi_oth "t:other"
131
132note RSI KV-cache cycle fixture texts (tests/fixtures/rsi_kv_cycle.evidence.json)
133text r_prod "spark-rsi/explain"
134text r_sys "spark-rsi"
135text r_art_cap "CapabilityNode"
136text r_art_bn "BottleneckRank"
137text r_art_hc "HypothesisContract"
138text r_art_dc "DiagnosticContext"
139text r_art_er "EvaluationReceipt"
140text r_art_rr "RatificationRecord"
141text r_art_rc "RsiCycle"
142text r_id_kv "rsi:capability:kv_allocator"
143text r_id_mk "rsi:capability:mojo_kernel"
144text r_id_rg "rsi:capability:req_gateway"
145text r_id_sp "rsi:capability:sampler"
146text r_id_sc "rsi:capability:scheduler"
147text r_id_bn "rsi:bottleneck:cycle-kv-0001"
148text r_id_a1 "rsi:alternative:cycle-kv-0001:mojo_kernel"
149text r_id_a2 "rsi:alternative:cycle-kv-0001:scheduler"
150text r_id_a3 "rsi:alternative:cycle-kv-0001:sampler"
151text r_id_hy "rsi:hypothesis:hypo-kv-0001"
152text r_id_pr "rsi:hypothesis:hypo-kv-0001:prediction"
153text r_id_fa "rsi:hypothesis:hypo-kv-0001:falsification"
154text r_id_di "rsi:diagnostic:cycle-kv-0001"
155text r_id_re "rsi:receipt:cycle-kv-0001:cand-kv-0001"
156text r_id_rs "rsi:receipt:cycle-kv-0001:cand-kv-0001:summary"
157text r_id_ra "rsi:ratification:cand-kv-0001"
158text r_id_co "rsi:conclusion:cycle-kv-0001"
159text r_st_kv "'Unified LPDDR5x KV Allocator' (memory) has measured median latency 4200.0 us over 20 samples"
160text r_st_mk "'Mojo Blackwell GEMM Kernel' (compute) has measured median latency 1800.0 us over 5 samples"
161text r_st_rg "'Request Gateway' (network) has measured median latency 120.0 us over 5 samples"
162text r_st_sp "'Greedy Token Sampler' (inference) has measured median latency 150.0 us over 5 samples"
163text r_st_sc "'Batch Scheduler' (scheduling) has measured median latency 340.0 us over 5 samples"
164text r_st_bn "The capability graph ranks 'Unified LPDDR5x KV Allocator' (memory) as bottleneck #1 of 5"
165text r_st_a1 "Alternative bottleneck candidate #2: 'Mojo Blackwell GEMM Kernel' (compute), score 0.6546"
166text r_st_a2 "Alternative bottleneck candidate #3: 'Batch Scheduler' (scheduling), score 0.2029"
167text r_st_a3 "Alternative bottleneck candidate #4: 'Greedy Token Sampler' (inference), score 0.0454"
168text r_st_hy "Suspected root cause: High latency on 'Unified LPDDR5x KV Allocator'"
169text r_st_pr "Predicts latency_median_us improves by 5.0% from baseline 4200.000"
170text r_st_fa "Refuted if this check fails: assert!(receipt.passed_all_hard_invariants)"
171text r_st_di "Diagnosis for src/kv_allocator.rs: primary defect PerformanceRegression"
172text r_st_re "Evaluation of candidate cand-kv-0001 (parent parent): admitted=true, 2 evaluation layer result(s)"
173text r_st_rs "The evaluator reports: hard invariants passed=true, statistical gates passed=true"
174text r_st_ra "Ratification record for proposal cand-kv-0001: status Ratified (test record)"
175text r_st_co "RSI proposes changing src/kv_allocator.rs to address PerformanceRegression (cycle cycle-kv-0001)"
176text r_ref_kv "kv_allocator"
177text r_ref_cy "cycle-kv-0001"
178text r_ref_hy "hypo-kv-0001"
179text r_ref_ca "cand-kv-0001"
180text r_dig_re "c0cae9f3e257ef2f7b46f5cd3770f9fe1c21f8b6dfb2ee2e2449714b0c7e99d0"
181text r_m_lat "latency_median_us"
182text r_m_4200 "4200.000"
183text r_m_us "us"
184text r_cbas "declared in the HypothesisContract, not measured"
185text r_miss_e "an artifact linking candidate cand-kv-0001 to hypothesis hypo-kv-0001"
186text r_miss_r "no RSI artifact records that the candidate was generated from this hypothesis"
187text r_note_co "this explanation is observational; it does not authorize promotion or any change"
188text r_note_rs "these fields are not covered by the receipt digest, so they are reported, not verified"
189
190note CLI parse test texts
191text t_cli_hex_raw "0102030405060708090a0b0c0d0e0f10"
192text t_cli_hex_pfx "cortex:0102030405060708090a0b0c0d0e0f10"
193text t_cli_hex_bad "no:such"
194text t_cli_aud_se "systems-engineer"
195text t_cli_aud_bad "alien"
196
197note Scratch buffers for comparing saved renders / journals
198global t_buf_a uchar 16384
199global t_buf_b uchar 16384
200global t_jbuf uchar 8192
201
202fn t_bytes_eq a view uchar * b view uchar * to bool
203if ne len a len b
204ret false
205end
206for i ulong len a bound 16384
207if ne get a i get b i
208ret false
209end
210end
211ret true
212end
213
214fn t_add_std_node id view uchar * kd ulong st ulong stmt view uchar * to ulong
215nid = exp_g_add_node id kd st stmt
216exp_g_set_source_sa nid t_sys t_art
217exp_g_set_source_ref nid id
218ret nid
219end
220
221fn t_add_simple_node id view uchar * kd ulong st ulong to ulong
222io = exp_str_add_view id
223nid = exp_g_add_node_raw io len id kd st
224put exp_gn_stmt_off nid io
225put exp_gn_stmt_len nid len id
226exp_g_set_source_sa nid t_sys t_art
227exp_g_set_source_ref nid id
228ret nid
229end
230
231fn t_cx_node_id_eq step1 ulong rec_idx ulong to bool
232id = new uchar 16 0
233exp_cx_get_id rec_idx id
234nid = get exp_bs_nid sub step1 1
235want_o = exp_cx_node_id_str id
236ret exp_str_eq get exp_gn_id_off nid get exp_gn_id_len nid want_o 39
237end
238
239note 1. linear_chain_is_ordered_parents_first
240fn t_01_linear_chain to int
241exp_cx_reset
242obs = exp_cx_add_rec EXP_ST_DIRECT_OBS t_lc_obs_s t_lc_obs_p
243exp_cx_set_ev obs t_lc_obs_e
244exp_cx_set_meta obs 10 0 0
245obs_id = new uchar 16 0
246exp_cx_get_id obs obs_id
247i1 = exp_cx_add_rec EXP_ST_INFERENCE t_lc_i1_s t_lc_i1_p
248exp_cx_set_meta i1 20 1 900
249exp_cx_add_parent i1 obs_id
250i1_id = new uchar 16 0
251exp_cx_get_id i1 i1_id
252i2 = exp_cx_add_rec EXP_ST_INFERENCE t_lc_i2_s t_lc_i2_p
253exp_cx_set_meta i2 30 1 800
254exp_cx_add_parent i2 i1_id
255i2_id = new uchar 16 0
256exp_cx_get_id i2 i2_id
257rc = exp_cx_graph_for_record i2_id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
258if ne rc EXP_OK
259ret 1
260end
261tgt_o = exp_cx_node_id_str i2_id
262rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
263if ne rc EXP_OK
264ret 2
265end
266if ne get exp_b_scnt 0 3
267ret 3
268end
269if not t_cx_node_id_eq 1 obs
270ret 4
271end
272if not t_cx_node_id_eq 2 i1
273ret 5
274end
275if not t_cx_node_id_eq 3 i2
276ret 6
277end
278if ne get exp_bs_sup_step get exp_bs_sup_off 1 1
279ret 7
280end
281if ne get exp_bs_sup_step get exp_bs_sup_off 2 2
282ret 8
283end
284if eq get exp_bs_gnd 0 0
285ret 9
286end
287if ne get exp_bs_role 0 EXP_ROLE_OBSERVED
288ret 10
289end
290if exp_bundle_has_unc EXP_UK_MISSING_PARENT
291ret 11
292end
293if not exp_bundle_verify_digest
294ret 12
295end
296ret 0
297end
298
299note 2. branching_support_is_deterministic_regardless_of_input_order
300fn t_02_branching_determinism to int
301exp_g_reset_prod t_prod
302nc = t_add_std_node t_id_c EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_c
303exp_g_add_edge nc t_id_z EXP_REL_SUPPORTED_BY
304exp_g_add_edge nc t_id_a EXP_REL_SUPPORTED_BY
305exp_g_add_edge nc t_id_m EXP_REL_SUPPORTED_BY
306nz = t_add_std_node t_id_z EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS t_st_z
307na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_VERIFIED_FACT t_st_a
308nm = t_add_std_node t_id_m EXP_KD_CORTEX_RECORD EXP_ST_OPERATOR_DECISION t_st_m
309rc = exp_build_bundle t_id_c EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
310if ne rc EXP_OK
311ret 13
312end
313if ne get exp_b_scnt 0 4
314ret 14
315end
316if not exp_bundle_step_eq 1 t_id_a
317ret 15
318end
319if not exp_bundle_step_eq 2 t_id_z
320ret 16
321end
322if not exp_bundle_step_eq 3 t_id_m
323ret 17
324end
325if not exp_bundle_step_eq 4 t_id_c
326ret 18
327end
328note Reversed input order produces identical step sequence
329exp_g_reset_prod t_prod
330nm2 = t_add_std_node t_id_m EXP_KD_CORTEX_RECORD EXP_ST_OPERATOR_DECISION t_st_m
331na2 = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_VERIFIED_FACT t_st_a
332nz2 = t_add_std_node t_id_z EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS t_st_z
333nc2 = t_add_std_node t_id_c EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_c
334exp_g_add_edge nc2 t_id_m EXP_REL_SUPPORTED_BY
335exp_g_add_edge nc2 t_id_a EXP_REL_SUPPORTED_BY
336exp_g_add_edge nc2 t_id_z EXP_REL_SUPPORTED_BY
337rc = exp_build_bundle t_id_c EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
338if ne rc EXP_OK
339ret 19
340end
341if not exp_bundle_step_eq 1 t_id_a
342ret 20
343end
344if not exp_bundle_step_eq 2 t_id_z
345ret 21
346end
347if not exp_bundle_step_eq 3 t_id_m
348ret 22
349end
350if not exp_bundle_step_eq 4 t_id_c
351ret 23
352end
353ret 0
354end
355
356note 3. shared_parent_appears_once
357fn t_03_shared_parent to int
358exp_g_reset_prod t_prod
359n0 = t_add_std_node t_id_concl EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_concl
360exp_g_add_edge n0 t_id_i1 EXP_REL_SUPPORTED_BY
361exp_g_add_edge n0 t_id_i2 EXP_REL_SUPPORTED_BY
362n1 = t_add_std_node t_id_i1 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_i1
363exp_g_add_edge n1 t_id_obs EXP_REL_SUPPORTED_BY
364n2 = t_add_std_node t_id_i2 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_i2
365exp_g_add_edge n2 t_id_obs EXP_REL_SUPPORTED_BY
366n3 = t_add_std_node t_id_obs EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS t_st_obs
367exp_g_set_digest n3 t_dig64
368rc = exp_build_bundle t_id_concl EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
369if ne rc EXP_OK
370ret 24
371end
372if ne get exp_b_scnt 0 4
373ret 25
374end
375if ne get exp_be_cnt 0 1
376ret 26
377end
378if not exp_bundle_step_eq 1 t_id_obs
379ret 27
380end
381ret 0
382end
383
384note 4. cycle_terminates_and_is_reported
385fn t_04_cycle_direct to int
386exp_g_reset_prod t_prod
387na = t_add_std_node t_id_A EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_A
388exp_g_add_edge na t_id_B EXP_REL_SUPPORTED_BY
389nb = t_add_std_node t_id_B EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_B
390exp_g_add_edge nb t_id_C EXP_REL_SUPPORTED_BY
391nc = t_add_std_node t_id_C EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_C
392exp_g_add_edge nc t_id_A EXP_REL_SUPPORTED_BY
393rc = exp_build_bundle t_id_A EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
394if ne rc EXP_OK
395ret 28
396end
397if ne get exp_b_scnt 0 3
398ret 29
399end
400if not exp_bundle_step_eq 3 t_id_A
401ret 30
402end
403ccnt = ulong 0
404cidx = EXP_NONE
405uc = get exp_bu_cnt 0
406for i ulong uc bound 512
407if eq get exp_bu_kind i EXP_UK_CYCLE
408ccnt = add ccnt 1
409cidx = i
410end
411end
412if ne ccnt 1
413ret 31
414end
415if not exp_str_eq_view get exp_bu_nid_off cidx get exp_bu_nid_len cidx t_id_C
416ret 32
417end
418if not exp_str_eq_view get exp_bu_rel_off cidx get exp_bu_rel_len cidx t_id_A
419ret 33
420end
421ol = exp_render EXP_MODE_STEP_BY_STEP EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
422if not exp_out_contains t_w_circular
423ret 34
424end
425ret 0
426end
427
428note 5. cycle_through_imported_cortex_journal_terminates
429fn t_05_cycle_cortex to int
430exp_cx_reset
431id1 = new uchar 16 1
432id2 = new uchar 16 2
433id3 = new uchar 16 3
434r1 = exp_cx_add_rec EXP_ST_INFERENCE t_cy1 t_prod
435exp_cx_set_id r1 id1
436exp_cx_add_parent r1 id2
437r2 = exp_cx_add_rec EXP_ST_INFERENCE t_cy2 t_prod
438exp_cx_set_id r2 id2
439exp_cx_add_parent r2 id3
440r3 = exp_cx_add_rec EXP_ST_INFERENCE t_cy3 t_prod
441exp_cx_set_id r3 id3
442exp_cx_add_parent r3 id1
443rc = exp_cx_graph_for_record id1 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
444if ne rc EXP_OK
445ret 35
446end
447tgt_o = exp_cx_node_id_str id1
448rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
449if ne rc EXP_OK
450ret 36
451end
452if ne get exp_b_scnt 0 3
453ret 37
454end
455if not exp_bundle_has_unc EXP_UK_CYCLE
456ret 38
457end
458ret 0
459end
460
461note 6 & 7. missing_parent_stays_missing and unsupported_claim_is_flagged
462fn t_06_07_missing_and_unsupported to int
463exp_g_reset_prod t_prod
464nc = t_add_std_node t_id_concl EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_concl
465exp_g_add_edge nc t_id_obs EXP_REL_SUPPORTED_BY
466exp_g_add_edge nc t_id_ghost EXP_REL_SUPPORTED_BY
467no = t_add_std_node t_id_obs EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS t_st_obs
468rc = exp_build_bundle t_id_concl EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
469if ne rc EXP_OK
470ret 39
471end
472if ne get exp_b_scnt 0 2
473ret 40
474end
475if not exp_bundle_step_eq 1 t_id_obs
476ret 41
477end
478if not exp_bundle_step_eq 2 t_id_concl
479ret 42
480end
481found_ghost = false
482uc = get exp_bu_cnt 0
483for i ulong uc bound 512
484if eq get exp_bu_kind i EXP_UK_MISSING_PARENT
485if exp_str_eq_view get exp_bu_rel_off i get exp_bu_rel_len i t_id_ghost
486found_ghost = true
487end
488end
489end
490if not found_ghost
491ret 43
492end
493ol = exp_render EXP_MODE_SUMMARY EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
494if not exp_out_contains t_w_noev
495ret 44
496end
497note Unsupported claim
498exp_g_reset_prod t_prod
499nl = t_add_std_node t_id_lonely EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_lonely
500rc = exp_build_bundle t_id_lonely EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
501if ne rc EXP_OK
502ret 45
503end
504if not exp_bundle_has_unc EXP_UK_UNSUPPORTED
505ret 46
506end
507ret 0
508end
509
510note 8. contradiction_remains_visible
511fn t_08_contradiction to int
512exp_cx_reset
513o1 = exp_cx_add_rec EXP_ST_DIRECT_OBS t_co_o1_s t_co_o1_p
514exp_cx_set_ev o1 t_co_o1_e
515o1_id = new uchar 16 0
516exp_cx_get_id o1 o1_id
517o2 = exp_cx_add_rec EXP_ST_DIRECT_OBS t_co_o2_s t_co_o2_p
518exp_cx_set_ev o2 t_co_o2_e
519o2_id = new uchar 16 0
520exp_cx_get_id o2 o2_id
521fl = exp_cx_add_rec EXP_ST_CONTRADICTION t_co_fl_s t_prod
522exp_cx_add_parent fl o1_id
523exp_cx_add_parent fl o2_id
524inf = exp_cx_add_rec EXP_ST_INFERENCE t_co_in_s t_co_in_p
525exp_cx_set_meta inf 4 1 700
526exp_cx_add_parent inf o1_id
527inf_id = new uchar 16 0
528exp_cx_get_id inf inf_id
529rc = exp_cx_graph_for_record inf_id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
530if ne rc EXP_OK
531ret 47
532end
533tgt_o = exp_cx_node_id_str inf_id
534rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
535if ne rc EXP_OK
536ret 48
537end
538if ne get exp_bc_cnt 0 1
539ret 49
540end
541if ne get exp_bc_inv_cnt 0 1
542ret 50
543end
544if not exp_bundle_has_unc EXP_UK_CONFLICT
545ret 51
546end
547if ne get exp_b_scnt 0 2
548ret 52
549end
550ol = exp_render EXP_MODE_STEP_BY_STEP EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
551if not exp_out_contains t_w_conflicts
552ret 53
553end
554if not exp_out_contains t_co_fl_s
555ret 54
556end
557ol = exp_render EXP_MODE_SUMMARY EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
558if not exp_out_contains t_w_munc
559ret 55
560end
561if not exp_out_contains t_w_contra
562ret 56
563end
564ret 0
565end
566
567note 9. hypothesis_is_never_rendered_as_fact
568fn t_09_hypothesis_never_fact to int
569exp_cx_reset
570o = exp_cx_add_rec EXP_ST_DIRECT_OBS t_hy_o_s t_hy_o_p
571exp_cx_set_ev o t_hy_o_e
572o_id = new uchar 16 0
573exp_cx_get_id o o_id
574h = exp_cx_add_rec EXP_ST_HYPOTHESIS t_hy_h_s t_hy_h_p
575exp_cx_add_parent h o_id
576h_id = new uchar 16 0
577exp_cx_get_id h h_id
578inf = exp_cx_add_rec EXP_ST_INFERENCE t_hy_i_s t_hy_i_p
579exp_cx_set_meta inf 3 1 600
580exp_cx_add_parent inf h_id
581inf_id = new uchar 16 0
582exp_cx_get_id inf inf_id
583rc = exp_cx_graph_for_record inf_id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
584if ne rc EXP_OK
585ret 57
586end
587tgt_o = exp_cx_node_id_str inf_id
588rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
589if ne rc EXP_OK
590ret 58
591end
592if not exp_bundle_has_unc EXP_UK_HYPO_NOT_FALSIFIED
593ret 59
594end
595for md ulong 4
596for a_i ulong 2
597aud = EXP_AUD_GENERAL
598if eq a_i 1
599aud = EXP_AUD_DEVELOPER
600end
601ol = exp_render md 4 aud
602if exp_out_any_line_has_both t_hy_h_s t_w_chkfact
603ret 60
604end
605if exp_out_any_line_has_both t_hy_h_s t_w_verfact
606ret 61
607end
608if exp_out_any_line_has_both t_hy_h_s t_w_obsbr
609ret 62
610end
611end
612end
613exp_out_reset
614exp_out_status_words EXP_ST_HYPOTHESIS
615if not exp_out_contains t_w_notest
616ret 63
617end
618ret 0
619end
620
621fn t_10_check_steps u ulong d ulong un ulong to int
622found_u = false
623found_d = false
624found_un = false
625sc = get exp_b_scnt 0
626for i ulong sc bound 320
627if t_cx_node_id_eq add i 1 u
628found_u = true
629if ne get exp_bs_bref i 0
630ret 67
631end
632end
633if t_cx_node_id_eq add i 1 d
634found_d = true
635if eq get exp_bs_bref i 0
636ret 68
637end
638end
639if t_cx_node_id_eq add i 1 un
640found_un = true
641end
642end
643if not found_u
644ret 69
645end
646if not found_d
647ret 70
648end
649if found_un
650ret 71
651end
652ret 0
653end
654
655fn t_10_setup to ulong
656exp_cx_reset
657exp_br_reset
658id = new uchar 16 0
659u = exp_cx_add_rec EXP_ST_DIRECT_OBS t_br_u_s t_br_u_p
660exp_cx_set_ev u t_br_u_e
661exp_cx_get_id u id
662d = exp_cx_add_rec EXP_ST_INFERENCE t_br_d_s t_br_d_p
663exp_cx_set_meta d 2 1 700
664exp_cx_add_parent d id
665exp_cx_get_id d id
666un = exp_cx_add_rec EXP_ST_VERIFIED_FACT t_br_un_s t_br_un_p
667exp_cx_set_ev un t_br_un_e
668exp_cx_set_verified_by un t_br_un_v
669bid = new uchar 16 0x42
670br = exp_br_create bid 1 10
671exp_br_add_ref br id
672ret br
673end
674
675fn t_10_11_tokens_and_scope br ulong to int
676dig_before = new uchar 32 0
677dig_after = new uchar 32 0
678exp_bundle_get_digest dig_before
679exp_br_append_token br 11
680exp_br_append_token br 22
681exp_br_append_token br 33
682exp_br_append_token br 44
683bnid = exp_br_build_graph br EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
684rc = exp_build_bundle_raw get exp_gn_id_off bnid get exp_gn_id_len bnid EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
685if ne rc EXP_OK
686ret 72
687end
688exp_bundle_get_digest dig_after
689if not t_bytes_eq dig_before dig_after
690ret 73
691end
692id = new uchar 16 0
693exp_cx_get_id 2 id
694rc = exp_br_graph_for_record br id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
695if ne rc EXP_ERR_NOT_IN_BRANCH_SCOPE
696ret 74
697end
698exp_cx_get_id 0 id
699rc = exp_br_graph_for_record br id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
700if ne rc EXP_OK
701ret 75
702end
703ret 0
704end
705
706note 10 & 11. branch_explanation_uses_only_what_branch_depended_on + token_history_never_enters
707fn t_10_11_branch_scope_and_tokens to int
708br = t_10_setup
709bnid = exp_br_build_graph br EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
710rc = exp_build_bundle_raw get exp_gn_id_off bnid get exp_gn_id_len bnid EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
711if ne rc EXP_OK
712ret 64
713end
714if ne get exp_b_scnt 0 3
715ret 65
716end
717if ne get exp_gn_kind get exp_bs_nid sub get exp_b_concl_step 0 1 EXP_KD_AGENT_BRANCH
718ret 66
719end
720rc = t_10_check_steps 0 1 2
721if ne rc 0
722ret rc
723end
724ret t_10_11_tokens_and_scope br
725end
726
727fn t_12_check_analogy_renders to int
728ol = exp_render EXP_MODE_ANALOGY EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
729if not exp_out_contains t_w_illus
730ret 79
731end
732if not exp_out_contains t_w_evself
733ret 80
734end
735if not exp_out_contains t_w_mech
736ret 81
737end
738if not exp_out_contains t_an_o_s
739ret 82
740end
741if not exp_out_contains t_an_h_s
742ret 83
743end
744ol = exp_render EXP_MODE_TECHNICAL 4 EXP_AUD_OPERATOR
745if exp_out_contains t_w_mech
746ret 84
747end
748if not exp_bundle_verify_digest
749ret 85
750end
751ret 0
752end
753
754note 12. analogy_is_isolated_from_evidence
755fn t_12_analogy_isolated to int
756exp_cx_reset
757id = new uchar 16 0
758r = exp_cx_add_rec EXP_ST_DIRECT_OBS t_an_o_s t_an_o_p
759exp_cx_set_ev r t_an_o_s
760exp_cx_get_id r id
761r = exp_cx_add_rec EXP_ST_HYPOTHESIS t_an_h_s t_an_h_p
762exp_cx_add_parent r id
763exp_cx_get_id r id
764j1 = new uchar 1024 0
765jl1 = exp_cx_export_journal j1
766if eq jl1 0
767ret 76
768end
769rc = exp_cx_graph_for_record id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
770if ne rc EXP_OK
771ret 77
772end
773tgt_o = exp_cx_node_id_str id
774rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
775if ne rc EXP_OK
776ret 78
777end
778dig1 = new uchar 32 0
779exp_bundle_get_digest dig1
780rc = t_12_check_analogy_renders
781if ne rc 0
782ret rc
783end
784dig2 = new uchar 32 0
785exp_bundle_get_digest dig2
786if not t_bytes_eq dig1 dig2
787ret 86
788end
789j2 = new uchar 1024 0
790jl2 = exp_cx_export_journal j2
791if ne jl1 jl2
792ret 87
793end
794if not t_bytes_eq part j1 0 jl1 part j2 0 jl2
795ret 88
796end
797if ne get exp_cx_cnt 0 2
798ret 89
799end
800ret 0
801end
802
803fn t_13_build_and_render rec_id view uchar * dig edit uchar * txt edit uchar * to ulong
804rc = exp_cx_graph_for_record rec_id EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
805if ne rc EXP_OK
806ret EXP_NONE
807end
808tgt_o = exp_cx_node_id_str rec_id
809rc = exp_build_bundle_raw tgt_o 39 EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
810if ne rc EXP_OK
811ret EXP_NONE
812end
813exp_bundle_get_digest dig
814ol = exp_render EXP_MODE_TECHNICAL 4 EXP_AUD_OPERATOR
815ret exp_out_copy txt
816end
817
818fn t_13_setup id edit uchar * to void
819exp_cx_reset
820r = exp_cx_add_rec EXP_ST_DIRECT_OBS t_dt_o t_an_o_p
821exp_cx_set_ev r t_dt_o
822exp_cx_get_id r id
823r = exp_cx_add_rec EXP_ST_INFERENCE t_dt_i t_dt_m
824exp_cx_set_meta r 2 1 500
825exp_cx_add_parent r id
826exp_cx_get_id r id
827end
828
829note 13. identical_input_gives_identical_bundle_and_text (via sealed journal round-trip)
830fn t_13_identical_roundtrip to int
831id = new uchar 16 0
832t_13_setup id
833jbuf = new uchar 2048 0
834jlen = exp_cx_export_journal jbuf
835if eq jlen 0
836ret 90
837end
838d1 = new uchar 32 0
839r1 = new uchar 2048 0
840c1 = t_13_build_and_render id d1 r1
841if eq c1 EXP_NONE
842ret 91
843end
844if ne exp_cx_import_journal part jbuf 0 jlen EXP_OK
845ret 93
846end
847d2 = new uchar 32 0
848r2 = new uchar 2048 0
849c2 = t_13_build_and_render id d2 r2
850if eq c2 EXP_NONE
851ret 94
852end
853if not t_bytes_eq d1 d2
854ret 96
855end
856if ne c1 c2
857ret 97
858end
859for i ulong c1 bound 2048
860if ne get r1 i get r2 i
861ret 98
862end
863end
864ret 0
865end
866
867fn t_14_wide_fanin to int
868exp_g_reset_prod t_prod
869top = t_add_simple_node t_id_top EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE
870exp_g_add_edge top t_id_m0 EXP_REL_SUPPORTED_BY
871exp_g_add_edge top t_id_m1 EXP_REL_SUPPORTED_BY
872exp_g_add_edge top t_id_m2 EXP_REL_SUPPORTED_BY
873m0 = t_add_simple_node t_id_m0 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE
874m1 = t_add_simple_node t_id_m1 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE
875m2 = t_add_simple_node t_id_m2 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE
876for k ulong 180
877po = exp_str_mark
878exp_str_put_b uchar 112
879exp_str_add_u64 k
880pl = sub exp_str_mark po
881pn = exp_g_add_node_raw po pl EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS
882put exp_gn_stmt_off pn po
883put exp_gn_stmt_len pn pl
884if lt k 60
885exp_g_add_edge_raw m0 po pl EXP_REL_SUPPORTED_BY
886else
887if lt k 120
888exp_g_add_edge_raw m1 po pl EXP_REL_SUPPORTED_BY
889else
890exp_g_add_edge_raw m2 po pl EXP_REL_SUPPORTED_BY
891end
892end
893end
894rc = exp_build_bundle t_id_top 32 100
895if ne rc EXP_OK
896ret 104
897end
898if gt get exp_b_scnt 0 100
899ret 105
900end
901if not exp_bundle_has_unc EXP_UK_TRUNCATED
902ret 106
903end
904ret 0
905end
906
907note 14. depth_and_node_limits_bound_the_walk
908fn t_14_limits_bound_walk to int
909note 50-node linear chain n0..n49
910exp_g_reset_prod t_prod
911for k ulong 50
912io = exp_str_mark
913exp_str_put_b uchar 110
914exp_str_add_u64 k
915il = sub exp_str_mark io
916st = EXP_ST_INFERENCE
917if eq k 0
918st = EXP_ST_DIRECT_OBS
919end
920nid = exp_g_add_node_raw io il EXP_KD_CORTEX_RECORD st
921put exp_gn_stmt_off nid io
922put exp_gn_stmt_len nid il
923if gt k 0
924po = exp_str_mark
925exp_str_put_b uchar 110
926exp_str_add_u64 sub k 1
927pl = sub exp_str_mark po
928exp_g_add_edge_raw nid po pl EXP_REL_SUPPORTED_BY
929end
930end
931rc = exp_build_bundle t_id_n49 3 256
932if ne rc EXP_OK
933ret 99
934end
935if ne get exp_b_scnt 0 4
936ret 100
937end
938if not exp_bundle_has_unc EXP_UK_TRUNCATED
939ret 101
940end
941rc = exp_build_bundle t_id_n1 0 1
942if ne rc EXP_ERR_INVALID_LIMITS
943ret 102
944end
945rc = exp_build_bundle t_id_n1 1 1000000
946if ne rc EXP_ERR_INVALID_LIMITS
947ret 103
948end
949ret t_14_wide_fanin
950end
951
952note 15. malformed_input_fails_safely
953fn t_15_malformed_inputs to int
954if ne exp_json_check t_bad_json EXP_ERR_BAD_FORMAT
955ret 107
956end
957if ne exp_json_check t_good_json EXP_OK
958ret 108
959end
960exp_g_reset_prod t_prod
961na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_a
962exp_g_set_version 2
963if ne exp_g_validate EXP_ERR_UNSUPPORTED_VERSION
964ret 109
965end
966exp_g_set_version 1
967exp_g_set_format t_bad_fmt
968if ne exp_g_validate EXP_ERR_UNSUPPORTED_VERSION
969ret 110
970end
971exp_g_reset_prod t_prod
972na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD 9 t_st_a
973if ne exp_build_bundle t_id_a EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES EXP_ERR_UNKNOWN_CODE
974ret 111
975end
976exp_g_reset_prod t_prod
977na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_a
978exp_g_set_conf na 1001 t_prod
979if ne exp_g_validate EXP_ERR_UNKNOWN_CODE
980ret 112
981end
982exp_g_reset_prod t_prod
983na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_a
984nb = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_a
985if ne exp_build_bundle t_id_a EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES EXP_ERR_DUPLICATE_NODE_ID
986ret 113
987end
988exp_g_reset_prod t_prod
989na = t_add_std_node t_id_a EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_a
990if ne exp_build_bundle t_id_zz EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES EXP_ERR_TARGET_NOT_FOUND
991ret 114
992end
993put exp_g_decl_ncnt 0 65537
994if ne exp_g_validate EXP_ERR_GRAPH_TOO_LARGE
995ret 115
996end
997note Tampered sealed journal fails with E9
998exp_cx_reset
999o = exp_cx_add_rec EXP_ST_DIRECT_OBS t_dt_o t_an_o_p
1000exp_cx_set_ev o t_dt_o
1001jbuf = new uchar 1024 0
1002jl = exp_cx_export_journal jbuf
1003if eq jl 0
1004ret 116
1005end
1006mid = div jl 2
1007put jbuf mid xor get jbuf mid uchar 1
1008if ne exp_cx_import_journal part jbuf 0 jl EXP_ERR_JOURNAL
1009ret 117
1010end
1011ret 0
1012end
1013
1014note 16. clarification_reads_the_same_bundle
1015fn t_16_clarification_session to int
1016exp_g_reset_prod t_prod
1017nc = t_add_std_node t_id_concl EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_concl
1018exp_g_add_edge nc t_id_i1 EXP_REL_SUPPORTED_BY
1019ni = t_add_std_node t_id_i1 EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE t_st_i1
1020exp_g_add_edge ni t_id_obs EXP_REL_SUPPORTED_BY
1021no = t_add_std_node t_id_obs EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS t_st_obs
1022rc = exp_build_bundle t_id_concl EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
1023if ne rc EXP_OK
1024ret 118
1025end
1026dig1 = new uchar 32 0
1027exp_bundle_get_digest dig1
1028exp_sess_init EXP_AUD_OPERATOR
1029ol = exp_sess_explain
1030if not exp_out_contains t_st_concl
1031ret 119
1032end
1033if exp_out_contains t_st_obs
1034ret 120
1035end
1036ol = exp_sess_deeper
1037if not exp_out_contains t_st_i1
1038ret 121
1039end
1040if exp_out_contains t_st_obs
1041ret 122
1042end
1043ol = exp_sess_deeper
1044if not exp_out_contains t_st_obs
1045ret 123
1046end
1047if ne exp_sess_level 2
1048ret 124
1049end
1050ol = exp_sess_shallower
1051if ne exp_sess_level 1
1052ret 125
1053end
1054rc = exp_sess_step 2
1055if ne rc EXP_OK
1056ret 126
1057end
1058if not exp_out_contains t_w_rests1
1059ret 127
1060end
1061rc = exp_sess_step 1
1062if ne rc EXP_OK
1063ret 128
1064end
1065if not exp_out_contains t_w_startpt
1066ret 129
1067end
1068rc = exp_sess_source 1
1069if ne rc EXP_OK
1070ret 130
1071end
1072if not exp_out_contains t_w_testnode
1073ret 131
1074end
1075rc = exp_sess_step 9
1076if ne rc EXP_ERR_STEP_OUT_OF_RANGE
1077ret 132
1078end
1079ol = exp_sess_technical
1080if not exp_out_contains t_w_step1obs
1081ret 133
1082end
1083ol = exp_sess_simple
1084if not exp_out_contains t_w_concl
1085ret 134
1086end
1087ol = exp_sess_analogy
1088if not exp_out_contains t_w_evself
1089ret 135
1090end
1091ol = exp_sess_uncertainties
1092if not exp_out_contains t_w_inferred
1093ret 136
1094end
1095ol = exp_sess_alternatives
1096if not exp_out_contains t_w_noalt
1097ret 137
1098end
1099dig2 = new uchar 32 0
1100exp_bundle_get_digest dig2
1101if not t_bytes_eq dig1 dig2
1102ret 138
1103end
1104ret 0
1105end
1106
1107note 17. rsi_cycle_explains_in_causal_order (tests/rsi_and_cli.rs)
1108fn t_build_rsi_fixture to void
1109exp_g_reset_prod r_prod
1110nid = exp_g_add_node r_id_kv EXP_KD_CAP_METRIC EXP_ST_DIRECT_OBS r_st_kv
1111exp_g_set_source_sa nid r_sys r_art_cap
1112exp_g_set_source_ref nid r_ref_kv
1113m0 = exp_g_add_meas nid r_m_lat r_m_4200
1114exp_g_meas_set_unit m0 r_m_us
1115nid = exp_g_add_node r_id_mk EXP_KD_CAP_METRIC EXP_ST_DIRECT_OBS r_st_mk
1116exp_g_set_source_sa nid r_sys r_art_cap
1117nid = exp_g_add_node r_id_rg EXP_KD_CAP_METRIC EXP_ST_DIRECT_OBS r_st_rg
1118exp_g_set_source_sa nid r_sys r_art_cap
1119nid = exp_g_add_node r_id_sp EXP_KD_CAP_METRIC EXP_ST_DIRECT_OBS r_st_sp
1120exp_g_set_source_sa nid r_sys r_art_cap
1121nid = exp_g_add_node r_id_sc EXP_KD_CAP_METRIC EXP_ST_DIRECT_OBS r_st_sc
1122exp_g_set_source_sa nid r_sys r_art_cap
1123nid = exp_g_add_node r_id_bn EXP_KD_CAP_ANALYSIS EXP_ST_INFERENCE r_st_bn
1124exp_g_set_source_sa nid r_sys r_art_bn
1125exp_g_add_edge nid r_id_kv EXP_REL_SUPPORTED_BY
1126exp_g_add_edge nid r_id_mk EXP_REL_SUPPORTED_BY
1127exp_g_add_edge nid r_id_rg EXP_REL_SUPPORTED_BY
1128exp_g_add_edge nid r_id_sp EXP_REL_SUPPORTED_BY
1129exp_g_add_edge nid r_id_sc EXP_REL_SUPPORTED_BY
1130nid = exp_g_add_node r_id_a1 EXP_KD_ALTERNATIVE EXP_ST_INFERENCE r_st_a1
1131exp_g_set_source_sa nid r_sys r_art_bn
1132exp_g_add_edge nid r_id_bn EXP_REL_ALTERNATIVE_TO
1133nid = exp_g_add_node r_id_a2 EXP_KD_ALTERNATIVE EXP_ST_INFERENCE r_st_a2
1134exp_g_set_source_sa nid r_sys r_art_bn
1135exp_g_add_edge nid r_id_bn EXP_REL_ALTERNATIVE_TO
1136nid = exp_g_add_node r_id_a3 EXP_KD_ALTERNATIVE EXP_ST_INFERENCE r_st_a3
1137exp_g_set_source_sa nid r_sys r_art_bn
1138exp_g_add_edge nid r_id_bn EXP_REL_ALTERNATIVE_TO
1139nid = exp_g_add_node r_id_hy EXP_KD_HYPOTHESIS EXP_ST_HYPOTHESIS r_st_hy
1140exp_g_set_source_sa nid r_sys r_art_hc
1141exp_g_set_source_ref nid r_ref_hy
1142exp_g_set_conf nid 850 r_cbas
1143exp_g_add_edge nid r_id_bn EXP_REL_REFERENCES
1144nid = exp_g_add_node r_id_pr EXP_KD_PREDICTION EXP_ST_HYPOTHESIS r_st_pr
1145exp_g_set_source_sa nid r_sys r_art_hc
1146exp_g_add_edge nid r_id_hy EXP_REL_PART_OF
1147nid = exp_g_add_node r_id_fa EXP_KD_FALSIFICATION EXP_ST_HYPOTHESIS r_st_fa
1148exp_g_set_source_sa nid r_sys r_art_hc
1149exp_g_add_edge nid r_id_hy EXP_REL_PART_OF
1150nid = exp_g_add_node r_id_di EXP_KD_DIAGNOSTIC EXP_ST_INFERENCE r_st_di
1151exp_g_set_source_sa nid r_sys r_art_dc
1152exp_g_add_edge nid r_id_hy EXP_REL_SUPPORTED_BY
1153nid = exp_g_add_node r_id_re EXP_KD_EVAL_RECEIPT EXP_ST_VERIFIED_FACT r_st_re
1154exp_g_set_source_sa nid r_sys r_art_er
1155exp_g_set_source_ref nid r_ref_ca
1156exp_g_set_digest nid r_dig_re
1157nid = exp_g_add_node r_id_rs EXP_KD_EVAL_RECEIPT EXP_ST_UNCLASSIFIED r_st_rs
1158exp_g_set_source_sa nid r_sys r_art_er
1159exp_g_add_edge nid r_id_re EXP_REL_PART_OF
1160exp_g_add_note nid r_note_rs
1161nid = exp_g_add_node r_id_ra EXP_KD_PROMOTION_STATE EXP_ST_DIRECT_OBS r_st_ra
1162exp_g_set_source_sa nid r_sys r_art_rr
1163exp_g_add_edge nid r_id_re EXP_REL_SUPPORTED_BY
1164nid = exp_g_add_node r_id_co EXP_KD_CONCLUSION EXP_ST_INFERENCE r_st_co
1165exp_g_set_source_sa nid r_sys r_art_rc
1166exp_g_set_source_ref nid r_ref_cy
1167exp_g_add_edge nid r_id_di EXP_REL_SUPPORTED_BY
1168exp_g_add_edge nid r_id_pr EXP_REL_SUPPORTED_BY
1169exp_g_add_edge nid r_id_fa EXP_REL_SUPPORTED_BY
1170exp_g_add_edge nid r_id_re EXP_REL_SUPPORTED_BY
1171exp_g_add_edge nid r_id_rs EXP_REL_SUPPORTED_BY
1172exp_g_add_edge nid r_id_ra EXP_REL_SUPPORTED_BY
1173exp_g_add_missing nid r_miss_e r_miss_r
1174exp_g_add_note nid r_note_co
1175end
1176
1177fn t_first_role_pos rl ulong to ulong
1178sc = get exp_b_scnt 0
1179for i ulong sc bound 320
1180if eq get exp_bs_role i rl
1181ret i
1182end
1183end
1184ret EXP_NONE
1185end
1186
1187fn t_17_check_roles ci ulong to int
1188prev = t_first_role_pos EXP_ROLE_OBSERVED
1189cur = t_first_role_pos EXP_ROLE_ANALYSIS
1190if ge prev cur
1191ret 141
1192end
1193prev = cur
1194cur = t_first_role_pos EXP_ROLE_HYPOTHESIS
1195if ge prev cur
1196ret 141
1197end
1198prev = cur
1199cur = t_first_role_pos EXP_ROLE_PREDICTION
1200if ge prev cur
1201ret 142
1202end
1203prev = cur
1204cur = t_first_role_pos EXP_ROLE_FALSIFICATION
1205if ge prev cur
1206ret 142
1207end
1208prev = cur
1209cur = t_first_role_pos EXP_ROLE_EVALUATION
1210if ge prev cur
1211ret 143
1212end
1213prev = cur
1214cur = t_first_role_pos EXP_ROLE_DECISION
1215if ge prev cur
1216ret 143
1217end
1218cur = t_first_role_pos EXP_ROLE_CONCLUSION
1219if ne cur ci
1220ret 144
1221end
1222ret 0
1223end
1224
1225fn t_17_rsi_cycle to int
1226t_build_rsi_fixture
1227rc = exp_build_bundle r_id_co EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
1228if ne rc EXP_OK
1229ret 139
1230end
1231ci = sub get exp_b_concl_step 0 1
1232if not exp_bundle_step_eq add ci 1 r_id_co
1233ret 140
1234end
1235rc = t_17_check_roles ci
1236if ne rc 0
1237ret rc
1238end
1239if not exp_bundle_has_unc EXP_UK_MISSING_LINK
1240ret 145
1241end
1242if not exp_bundle_has_unc EXP_UK_HYPO_NOT_FALSIFIED
1243ret 146
1244end
1245if not exp_bundle_has_unc EXP_UK_UNKNOWN
1246ret 147
1247end
1248if ne get exp_ba_cnt 0 3
1249ret 148
1250end
1251st = exp_bundle_find_step r_id_re
1252if eq st 0
1253ret 149
1254end
1255if ne get exp_gn_status get exp_bs_nid sub st 1 EXP_ST_VERIFIED_FACT
1256ret 150
1257end
1258st = exp_bundle_find_step r_id_rs
1259if eq st 0
1260ret 151
1261end
1262if ne get exp_gn_status get exp_bs_nid sub st 1 EXP_ST_UNCLASSIFIED
1263ret 152
1264end
1265st = exp_bundle_find_step r_id_hy
1266if eq st 0
1267ret 153
1268end
1269if ne get exp_gn_status get exp_bs_nid sub st 1 EXP_ST_HYPOTHESIS
1270ret 154
1271end
1272ol = exp_render EXP_MODE_STEP_BY_STEP EXP_LEVEL_DEFAULT EXP_AUD_OPERATOR
1273if not exp_out_contains exp_rh_0
1274ret 155
1275end
1276if not exp_out_contains exp_rh_1
1277ret 156
1278end
1279if not exp_out_contains exp_rh_2
1280ret 157
1281end
1282if not exp_out_contains exp_rh_3
1283ret 158
1284end
1285if not exp_out_contains exp_rh_4
1286ret 159
1287end
1288if not exp_out_contains exp_rh_5
1289ret 160
1290end
1291if not exp_out_contains exp_rh_6
1292ret 161
1293end
1294if not exp_out_contains exp_rh_7
1295ret 162
1296end
1297d1 = new uchar 32 0
1298exp_bundle_get_digest d1
1299t_build_rsi_fixture
1300rc = exp_build_bundle r_id_co EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
1301if ne rc EXP_OK
1302ret 163
1303end
1304d2 = new uchar 32 0
1305exp_bundle_get_digest d2
1306if not t_bytes_eq d1 d2
1307ret 164
1308end
1309ret 0
1310end
1311
1312note 18. contradiction_disclosed_in_both_directions
1313fn t_18_bidirectional_contra to int
1314exp_g_reset_prod t_prod
1315n0 = t_add_simple_node t_bi_obs EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS
1316n1 = t_add_simple_node t_bi_riv EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS
1317exp_g_add_edge n1 t_bi_obs EXP_REL_CONTRADICTS
1318n2 = t_add_simple_node t_bi_clm EXP_KD_CORTEX_RECORD EXP_ST_INFERENCE
1319exp_g_add_edge n2 t_bi_obs EXP_REL_SUPPORTED_BY
1320exp_g_add_edge n2 t_bi_oth EXP_REL_CONTRADICTS
1321n3 = t_add_simple_node t_bi_oth EXP_KD_CORTEX_RECORD EXP_ST_DIRECT_OBS
1322rc = exp_build_bundle t_bi_clm EXP_DEFAULT_MAX_DEPTH EXP_DEFAULT_MAX_NODES
1323if ne rc EXP_OK
1324ret 165
1325end
1326has_riv = false
1327has_clm = false
1328cc = get exp_bc_cnt 0
1329for i ulong cc bound 128
1330nid = get exp_bc_nid i
1331if exp_str_eq_view get exp_gn_id_off nid get exp_gn_id_len nid t_bi_riv
1332has_riv = true
1333end
1334if exp_str_eq_view get exp_gn_id_off nid get exp_gn_id_len nid t_bi_clm
1335has_clm = true
1336end
1337end
1338if not has_riv
1339ret 166
1340end
1341if not has_clm
1342ret 167
1343end
1344if ne exp_bundle_find_step t_bi_riv 0
1345ret 168
1346end
1347if ne exp_bundle_find_step t_bi_oth 0
1348ret 169
1349end
1350ret 0
1351end
1352
1353note 19 & 20. CLI helpers + tampered bundle digest rejection
1354fn t_19_20_cli_and_tamper to int
1355if ne exp_cli_exit_code EXP_OK 0
1356ret 170
1357end
1358if ne exp_cli_exit_code EXP_ERR_TARGET_NOT_FOUND 15
1359ret 171
1360end
1361if ne exp_parse_audience t_cli_aud_se EXP_AUD_SYSTEMS_ENG
1362ret 172
1363end
1364if ne exp_parse_audience t_cli_aud_bad EXP_AUD_INVALID
1365ret 173
1366end
1367cid1 = new uchar 16 0
1368cid2 = new uchar 16 0
1369if ne exp_parse_cortex_id t_cli_hex_raw cid1 EXP_OK
1370ret 174
1371end
1372if ne exp_parse_cortex_id t_cli_hex_pfx cid2 EXP_OK
1373ret 175
1374end
1375if not t_bytes_eq cid1 cid2
1376ret 176
1377end
1378if ne get cid1 0 1
1379ret 177
1380end
1381if ne get cid1 15 16
1382ret 178
1383end
1384if ne exp_parse_cortex_id t_cli_hex_bad cid1 EXP_ERR_TARGET_NOT_FOUND
1385ret 179
1386end
1387note Tampering a built bundle breaks digest verification
1388if not exp_bundle_verify_digest
1389ret 180
1390end
1391put exp_bs_depth 0 add get exp_bs_depth 0 1
1392if exp_bundle_verify_digest
1393ret 181
1394end
1395ret 0
1396end
1397
1398fn main to int
1399rc = t_01_linear_chain
1400if ne rc 0
1401ret rc
1402end
1403rc = t_02_branching_determinism
1404if ne rc 0
1405ret rc
1406end
1407rc = t_03_shared_parent
1408if ne rc 0
1409ret rc
1410end
1411rc = t_04_cycle_direct
1412if ne rc 0
1413ret rc
1414end
1415rc = t_05_cycle_cortex
1416if ne rc 0
1417ret rc
1418end
1419rc = t_06_07_missing_and_unsupported
1420if ne rc 0
1421ret rc
1422end
1423rc = t_08_contradiction
1424if ne rc 0
1425ret rc
1426end
1427rc = t_09_hypothesis_never_fact
1428if ne rc 0
1429ret rc
1430end
1431rc = t_10_11_branch_scope_and_tokens
1432if ne rc 0
1433ret rc
1434end
1435rc = t_12_analogy_isolated
1436if ne rc 0
1437ret rc
1438end
1439rc = t_13_identical_roundtrip
1440if ne rc 0
1441ret rc
1442end
1443rc = t_14_limits_bound_walk
1444if ne rc 0
1445ret rc
1446end
1447rc = t_15_malformed_inputs
1448if ne rc 0
1449ret rc
1450end
1451rc = t_16_clarification_session
1452if ne rc 0
1453ret rc
1454end
1455rc = t_17_rsi_cycle
1456if ne rc 0
1457ret rc
1458end
1459rc = t_18_bidirectional_contra
1460if ne rc 0
1461ret rc
1462end
1463rc = t_19_20_cli_and_tamper
1464if ne rc 0
1465ret rc
1466end
1467ret 0
1468end