@@ -1033,6 +1033,63 @@ def fake_run(cmd, cwd=None, env=None):
10331033 self .assertTrue ((out_dir / "sample" / "sample.nt" ).exists ())
10341034 self .assertTrue ((out_dir / "sample" / "sample.hdt" ).exists ())
10351035
1036+ def test_main_full_mode_refuses_rdf_cleanup_until_all_methods_succeed (self ):
1037+ """Raw RDF is not deleted if any requested compression method is missing/failed."""
1038+ with tempfile .TemporaryDirectory () as td :
1039+ tmp_path = Path (td )
1040+ input_dir , rules_path = prepare_inputs (tmp_path )
1041+ out_dir = tmp_path / "out"
1042+
1043+ def fake_run (cmd , cwd = None , env = None ):
1044+ if "/opt/vcf-rdfizer/run_conversion.sh" in cmd :
1045+ output_name = output_name_from_command (cmd ) or "sample"
1046+ out_sample_dir = out_dir / output_name
1047+ out_sample_dir .mkdir (parents = True , exist_ok = True )
1048+ (out_sample_dir / f"{ output_name } .nt" ).write_text ("<s> <p> <o> .\n " )
1049+ return 0
1050+
1051+ # Simulate partial compression bookkeeping: gzip recorded, brotli missing.
1052+ def fake_compress (* , rdf_path , out_dir , target_out_dir , image_ref , methods , wrapper_log_path , status_indent ):
1053+ return True , {
1054+ "gzip" : {
1055+ "exit_code" : 0 ,
1056+ "wall_seconds" : 0.01 ,
1057+ "output_path" : str ((target_out_dir or out_dir ) / f"{ rdf_path .name } .gz" ),
1058+ "output_size_bytes" : 12 ,
1059+ }
1060+ }
1061+
1062+ old_cwd = os .getcwd ()
1063+ os .chdir (tmp_path )
1064+ try :
1065+ with mock .patch .object (vcf_rdfizer , "run" , side_effect = fake_run ), mock .patch .object (
1066+ vcf_rdfizer , "check_docker" , return_value = True
1067+ ), mock .patch .object (
1068+ vcf_rdfizer , "docker_image_exists" , return_value = True
1069+ ), mock .patch .object (
1070+ vcf_rdfizer , "discover_tsv_triplets" , return_value = mocked_triplets ()
1071+ ), mock .patch .object (
1072+ vcf_rdfizer , "run_compression_methods_for_rdf" , side_effect = fake_compress
1073+ ):
1074+ rc = invoke_main (
1075+ [
1076+ "--input" ,
1077+ str (input_dir ),
1078+ "--rules" ,
1079+ str (rules_path ),
1080+ "--out" ,
1081+ str (out_dir ),
1082+ "--compression" ,
1083+ "gzip,brotli" ,
1084+ "--keep-tsv" ,
1085+ ]
1086+ )
1087+ finally :
1088+ os .chdir (old_cwd )
1089+
1090+ self .assertEqual (rc , 1 )
1091+ self .assertTrue ((out_dir / "sample" / "sample.nt" ).exists ())
1092+
10361093 def test_main_full_mode_writes_compression_metrics_artifacts (self ):
10371094 """Full mode writes compression metrics JSON/time artifacts and updates metrics.csv row."""
10381095 with tempfile .TemporaryDirectory () as td :
0 commit comments