@@ -57,6 +57,11 @@ def test_v6e_default_options_split_megascale_and_xla(self):
5757 self .assertEqual (len (megascale_options ) + len (xla_options ), len (default_options ))
5858
5959
60+ class MockUserCommandPatcher (jobset_utils .UserCommandPatcher ):
61+ def patch (self , command : str , ** kwargs : dict ) -> str :
62+ return f"./prefix_command.sh; { command } "
63+
64+
6065class PathwaysReplicatedJobTest (TestCase ):
6166 """Tests PathwaysReplicatedJob."""
6267
@@ -408,18 +413,23 @@ def _job_config(self, bundler_cls: type[Bundler], num_replicas: int, **kwargs):
408413 bundler_cfg = bundler_cls .from_spec ([], fv = fv ).set (image = "test-image" )
409414 yield cfg , bundler_cfg
410415
411- @parameterized .parameters ([1 , 2 ])
412- def test_replicated_job (self , num_replicas ):
416+ @parameterized .product (
417+ num_replicas = [1 , 2 ], user_command_patcher = [None , MockUserCommandPatcher .default_config ()]
418+ )
419+ def test_replicated_job (self , num_replicas , user_command_patcher ):
413420 with (self ._job_config (CloudBuildBundler , num_replicas ) as (cfg , bundler_cfg ),):
421+ command = "test_command"
414422 cfg .inner .set (
415423 project = "test-project" ,
416424 name = "test" ,
417- command = "test_command" ,
425+ command = command ,
418426 output_dir = "FAKE" ,
419- ).instantiate (bundler = bundler_cfg .instantiate ())
427+ )
428+ if user_command_patcher :
429+ cfg .inner .set (user_command_patcher = user_command_patcher )
430+ cfg .instantiate (bundler = bundler_cfg .instantiate ())
420431
421432 builder = cfg .instantiate (bundler = bundler_cfg .instantiate ())
422-
423433 replicated_jobs = builder ()
424434
425435 self .assertEqual (len (replicated_jobs ), num_replicas + 1 )
@@ -449,6 +459,29 @@ def test_replicated_job(self, num_replicas):
449459 elif replicated_job_name .startswith ("pwwk" ):
450460 self .assertEqual (replicated_job ["replicas" ], 1 )
451461
462+ command_was_patched = False
463+
464+ if replicated_job_name .startswith ("pwhd" ):
465+ containers = (
466+ job_spec .get ("spec" , {})
467+ .get ("template" , {})
468+ .get ("spec" , {})
469+ .get ("containers" , [])
470+ )
471+ if containers and len (containers ) > 0 :
472+ command_parts = containers [0 ].get ("command" , [])
473+ if command_parts and len (command_parts ) > 0 :
474+ the_command = command_parts [- 1 ]
475+ if user_command_patcher :
476+ self .assertEqual (f"./prefix_command.sh; { command } " , the_command )
477+ command_was_patched = True
478+ else :
479+ self .assertEqual (command , the_command )
480+ self .assertEqual (
481+ user_command_patcher is not None and replicated_job_name .startswith ("pwhd" ),
482+ command_was_patched ,
483+ )
484+
452485 def test_validate_head_name (self ):
453486 with self ._job_config (CloudBuildBundler , 2 ) as (cfg , bundler_cfg ):
454487 cfg .inner .set (
0 commit comments