@@ -8739,3 +8739,96 @@ def test_run_workflow_use_cached_job_format_source_pick_param(self):
87398739 ).strip ()
87408740 == "2"
87418741 )
8742+
8743+ def test_run_workflow_use_cached_job_implicit_conversion_send_to_new_history (self ):
8744+ wf = """class: GalaxyWorkflow
8745+ inputs:
8746+ fastq_input:
8747+ type: data
8748+ steps:
8749+ grep:
8750+ # Grep1 requires fastqsanger, so fastqsanger.gz will be implicitly converted
8751+ tool_id: Grep1
8752+ in:
8753+ input: fastq_input
8754+ """
8755+ with self .dataset_populator .test_history () as history_id :
8756+ # Create a fastqsanger.gz dataset
8757+ compressed_path = self .test_data_resolver .get_filename ("1.fastqsanger.gz" )
8758+ with open (compressed_path , "rb" ) as fh :
8759+ dataset = self .dataset_populator .new_dataset (
8760+ history_id , content = fh , file_type = "fastqsanger.gz" , wait = True
8761+ )
8762+
8763+ # Upload workflow
8764+ workflow_id = self .workflow_populator .upload_yaml_workflow (wf )
8765+
8766+ # Run workflow first time
8767+ workflow_request : Dict [str , Any ] = {
8768+ "inputs" : json .dumps ({"fastq_input" : self ._ds_entry (dataset )}),
8769+ "history" : f"hist_id={ history_id } " ,
8770+ "inputs_by" : "name" ,
8771+ }
8772+ first_invocation_summary = self .workflow_populator .invoke_workflow_and_wait (
8773+ workflow_id , request = workflow_request
8774+ ).json ()
8775+ self .workflow_populator .wait_for_invocation_and_jobs (
8776+ history_id = first_invocation_summary ["history_id" ],
8777+ workflow_id = workflow_id ,
8778+ invocation_id = first_invocation_summary ["id" ],
8779+ assert_ok = True ,
8780+ )
8781+ first_invocation = self .workflow_populator .get_invocation (first_invocation_summary ["id" ], step_details = True )
8782+ first_job_id = first_invocation ["steps" ][1 ]["jobs" ][0 ]["id" ]
8783+ first_job_details = self .dataset_populator .get_job_details (first_job_id , full = True ).json ()
8784+ assert first_job_details ["state" ] == "ok"
8785+ assert not first_job_details ["copied_from_job_id" ]
8786+
8787+ # Verify implicit conversion happened (input to Grep1 should be fastqsanger, not fastqsanger.gz)
8788+ grep_input_id = first_job_details ["inputs" ]["input" ]["id" ]
8789+ grep_input = self .dataset_populator .get_history_dataset_details (
8790+ history_id = first_job_details ["history_id" ], content_id = grep_input_id
8791+ )
8792+ assert grep_input ["extension" ] == "fastqsanger" , "Expected implicit conversion to fastqsanger"
8793+ assert grep_input_id != dataset ["id" ], "Input should be implicitly converted dataset"
8794+
8795+ # Run workflow second time with use_cached_job and new_history_name
8796+ # Remove history parameter since we're specifying new_history_name
8797+ workflow_request .pop ("history" , None )
8798+ workflow_request ["use_cached_job" ] = True
8799+ workflow_request ["new_history_name" ] = self .dataset_populator .get_random_name ()
8800+ second_invocation_response = self .workflow_populator .invoke_workflow (workflow_id , request = workflow_request )
8801+ second_invocation_summary = second_invocation_response .json ()
8802+ second_history_id = second_invocation_summary ["history_id" ]
8803+ # Wait for the workflow to complete
8804+ self .workflow_populator .wait_for_invocation_and_jobs (
8805+ history_id = second_history_id ,
8806+ workflow_id = workflow_id ,
8807+ invocation_id = second_invocation_summary ["id" ],
8808+ assert_ok = True ,
8809+ )
8810+ second_invocation = self .workflow_populator .get_invocation (
8811+ second_invocation_summary ["id" ], step_details = True
8812+ )
8813+ second_job_id = second_invocation ["steps" ][1 ]["jobs" ][0 ]["id" ]
8814+ second_job_details = self .dataset_populator .get_job_details (second_job_id , full = True ).json ()
8815+
8816+ # Verify job was cached
8817+ assert second_job_details ["state" ] == "ok"
8818+ assert second_job_details ["copied_from_job_id" ] == first_job_id , "Second job should be cached from first"
8819+
8820+ # Verify the second invocation is in a different history
8821+ assert (
8822+ second_job_details ["history_id" ] != first_job_details ["history_id" ]
8823+ ), "Second invocation should be in a new history"
8824+
8825+ # Verify implicit conversion dataset was copied to the new history
8826+ cached_grep_input_id = second_job_details ["inputs" ]["input" ]["id" ]
8827+ cached_grep_input = self .dataset_populator .get_history_dataset_details (
8828+ history_id = second_job_details ["history_id" ], content_id = cached_grep_input_id
8829+ )
8830+ assert cached_grep_input ["extension" ] == "fastqsanger"
8831+ # The implicitly converted dataset should have a different HDA ID but same underlying dataset
8832+ assert (
8833+ cached_grep_input_id != grep_input_id
8834+ ), "Cached run should have copied the implicitly converted dataset to the new history"
0 commit comments