1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(** Antithesis integration for Hegel.
See the [.mli] for the full description. *)open!Coretypetest_location={function_name:string;file:string;begin_line:int}(** Environment variable Antithesis injects when a workload runs inside it. *)letantithesis_output_dir_env="ANTITHESIS_OUTPUT_DIR"letis_running_in_antithesis()=matchSys.getenvantithesis_output_dir_envwith|None->false|Somedir->ifStdlib.Sys.file_existsdir&&Stdlib.Sys.is_directorydirthentrueelsefailwithf"Expected %s=%s to exist as a directory when running inside Antithesis"antithesis_output_dir_envdir();;letextract_file_basepath=letbase=Filename.basenamepathintryFilename.chop_extensionbasewith|Invalid_argument_->base;;letassertion_jsonloc~hit~condition=letid=Printf.sprintf"%s in %s passes properties"loc.function_name(extract_file_baseloc.file)inletlocation_obj:Yojson.Safe.t=`Assoc["function",`Stringloc.function_name;"file",`Stringloc.file;"begin_line",`Intloc.begin_line;"begin_column",`Int0]in`Assoc[("antithesis_assert",`Assoc["hit",`Boolhit;"must_hit",`Booltrue;"assert_type",`String"always";"display_type",`String"Always";"condition",`Boolcondition;"id",`Stringid;"message",`Stringid;"location",location_obj])];;letwrite_jsonl_linepathjson=letline=Yojson.Safe.to_stringjson^"\n"inletoc=Stdlib.open_out_gen[Open_wronly;Open_creat;Open_append;Open_binary]0o644pathinExn.protect~finally:(fun()->Stdlib.close_outoc)~f:(fun()->Stdlib.output_stringocline);;letemit_assertionloc~passed=ifis_running_in_antithesis()then(letdir=Sys.getenv_exnantithesis_output_dir_envinletpath=Filename.concatdir"sdk.jsonl"inwrite_jsonl_linepath(assertion_jsonloc~hit:false~condition:false);write_jsonl_linepath(assertion_jsonloc~hit:true~condition:passed));;