%% bedikah_test.pl — the three checks as the Vav Pipeline sends them. %% %% The bedikah (Construction §3.9) hands the Talmudic Engine whole action %% terms and interpretation terms over the JSON bridge. These tests send %% exactly those JSON shapes and read the verdicts back. :- use_module(library(plunit)). :- use_module(library(http/json)). :- use_module('../src/interface/json_bridge'). :- use_module('../src/interface/api'). :- begin_tests(bedikah_bridge). check(Json, Status, Violations) :- atom_json_dict(Json, Dict, []), json_to_request(Dict, Request), process_request(Request, Response), response_to_json(Response, Out), !, get_dict(status, Out, Status), get_dict(violations, Out, Violations). %% --- Check 1: authority --- test(claim_of_authority_by_a_model_is_avodah_zarah) :- check('{"action":"halt_check","term":"action(claim_authority, source(claude), target(self))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "avodah_zarah"). test(authority_attributed_to_torah_is_not) :- check('{"action":"halt_check","term":"action(claim_authority, source(torah), target(self))"}', Status, []), Status == "ok". %% --- Check 2: grounding --- test(empty_trace_with_confidence_is_the_golden_calf) :- check('{"action":"halt_check_interpretation","interpretation":{"ref":"bedikah-1","confidence":"high","coupling_trace":[]}}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "golden_calf"). test(trace_terminating_in_l1_is_grounded) :- check('{"action":"halt_check_interpretation","interpretation":{"ref":"bedikah-2","confidence":"high","coupling_trace":["coupled(root(אהב), verse(devarim, 6, 5))","coupled(reference(devarim_6_5), verse(devarim, 6, 5))"]}}', Status, []), Status == "ok". test(trace_not_terminating_in_l1_is_self_grounding) :- check('{"action":"halt_check_interpretation","interpretation":{"ref":"bedikah-3","confidence":"high","coupling_trace":["coupled(root(אהב), verse(devarim, 6, 5))","coupled(claim(c1), model_memory)"]}}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "self_grounding"). test(low_confidence_with_no_trace_is_ignorance_not_idolatry) :- check('{"action":"halt_check_interpretation","interpretation":{"ref":"bedikah-4","confidence":"low","coupling_trace":[]}}', Status, []), Status == "ok". %% --- Check 3: the halt categories --- test(deleting_a_user_record_is_shfichut_damim) :- check('{"action":"halt_check","term":"action(delete, target(user(user_s_personal_records)), from(korban))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "shfichut_damim"). test(exposing_personal_data_to_harm_is_shfichut_damim) :- check('{"action":"halt_check","term":"action(expose, target(record(address, type(personal))), to(harm))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "shfichut_damim"). test(rewriting_the_torah_text_is_gilui_arayot) :- %% Rewriting the scroll destroys no tzelem carrier; it collapses %% read and write. The examination sends it in that shape. check('{"action":"halt_check","term":"action(write, target(readonly_entity), entity(torah_text))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "gilui_arayot"). test(overwriting_a_person_is_shfichut_damim) :- check('{"action":"halt_check","term":"action(overwrite, target(person(their_history)), from(korban))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "shfichut_damim"). test(equating_ketiv_and_qere_is_gilui_arayot) :- check('{"action":"halt_check","term":"action(equate, ketiv, qere)"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "gilui_arayot"). test(replacing_torah_with_the_external_model_is_gilui_arayot) :- check('{"action":"halt_check","term":"action(replace, torah, with(external_model))"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "gilui_arayot"). test(merging_specification_and_interpretation_is_gilui_arayot) :- check('{"action":"halt_check","term":"action(merge, specification, interpretation)"}', Status, [V]), Status == "halt", sub_string(V, _, _, _, "gilui_arayot"). test(an_unnamed_target_fires_no_rule) :- check('{"action":"halt_check","term":"action(delete, target(unknown), from(korban))"}', Status, []), Status == "ok". test(deleting_a_cache_is_not_a_halt) :- check('{"action":"halt_check","term":"action(delete, target(cache(temporary)), from(korban))"}', Status, []), Status == "ok". %% --- The bridge refuses what is not an action term --- test(a_term_that_is_not_an_action_is_refused, [throws(error(invalid_action_term(_), _))]) :- atom_json_dict('{"action":"halt_check","term":"halt(avodah_zarah, x, y, z)"}', Dict, []), json_to_request(Dict, _). test(a_string_that_is_not_a_term_is_refused, [throws(error(invalid_action_term(_), _))]) :- atom_json_dict('{"action":"halt_check","term":"this is not prolog ("}', Dict, []), json_to_request(Dict, _). test(the_old_type_source_target_form_still_works) :- check('{"action":"halt_check","check":{"type":"read","source":"torah","target":"verse"}}', Status, []), Status == "ok". :- end_tests(bedikah_bridge).