@@ -188,6 +188,60 @@ def test_create_codefresh_configuration_multienv():
188188 shutil .rmtree (BUILD_MERGE_DIR )
189189
190190
191+ def test_test_images_built_only_when_tests_exist_in_project_apps ():
192+ """Test images are built iff the corresponding test type is enabled on at least one app.
193+
194+ Positive case: app in RESOURCES (not CH) with e2e enabled → test-e2e must be built even
195+ though the test image lives in cloud-harness (root_paths[0]).
196+
197+ Negative case: same app without e2e enabled → test-e2e must NOT be built.
198+
199+ Regression: the test image search was done per root_path, so if the apps with tests are in
200+ root_path[1] (project) and the test images are in root_path[0] (cloud-harness), the images
201+ were never found because scale was empty when root_path[0] was scanned.
202+ """
203+ def _build_steps (e2e_enabled ):
204+ values = create_helm_chart (
205+ [CLOUDHARNESS_ROOT , RESOURCES ],
206+ output_path = OUT ,
207+ include = ['myapp' ],
208+ exclude = ['events' ],
209+ domain = "my.local" ,
210+ namespace = 'test' ,
211+ env = ['dev' , 'test' ],
212+ local = False ,
213+ tag = 1 ,
214+ registry = 'reg'
215+ )
216+ root_paths = preprocess_build_overrides (
217+ root_paths = [CLOUDHARNESS_ROOT , RESOURCES ],
218+ helm_values = values ,
219+ merge_build_path = BUILD_MERGE_DIR
220+ )
221+ build_included = [app ['harness' ]['name' ]
222+ for app in values ['apps' ].values () if 'harness' in app ]
223+ values .apps ["myapp" ].harness .test .e2e .enabled = e2e_enabled
224+ cf = create_codefresh_deployment_scripts (root_paths , include = build_included ,
225+ envs = ['dev' , 'test' ],
226+ base_image_name = values ['name' ],
227+ helm_values = values , save = False )
228+ l1_steps = cf ['steps' ]
229+ return {name : step for build_step in [STEP_0 , STEP_1 , STEP_2 , STEP_3 ]
230+ if build_step in l1_steps
231+ for name , step in l1_steps [build_step ]['steps' ].items ()}
232+
233+ try :
234+ with_tests = _build_steps (e2e_enabled = True )
235+ assert "test-e2e" in with_tests , \
236+ "test-e2e image must be built when a project app has e2e tests, even if the image lives in cloud-harness"
237+
238+ without_tests = _build_steps (e2e_enabled = False )
239+ assert "test-e2e" not in without_tests , \
240+ "test-e2e image must NOT be built when no app has e2e tests enabled"
241+ finally :
242+ shutil .rmtree (BUILD_MERGE_DIR , ignore_errors = True )
243+
244+
191245def test_create_codefresh_configuration_tests ():
192246 values = create_helm_chart (
193247 [CLOUDHARNESS_ROOT , RESOURCES ],
0 commit comments