@@ -95,3 +95,86 @@ def test_explicit_strings_preserved(setup_env_vars):
9595 data = {"port" : "8080" , "enabled" : "true" , "count" : "123" , "ratio" : "3.14" }
9696 expected = {"port" : "8080" , "enabled" : "true" , "count" : "123" , "ratio" : "3.14" }
9797 assert replace_env_vars (data ) == expected
98+
99+
100+ def test_resource_with_empty_benchmark_id_skipped (setup_env_vars ):
101+ """Test that resources with empty benchmark_id from conditional env vars are skipped."""
102+ data = {
103+ "benchmarks" : [
104+ {"benchmark_id" : "${env.BENCHMARK_ID:+my-benchmark}" , "dataset_id" : "test-dataset" },
105+ {"benchmark_id" : "always-present" , "dataset_id" : "another-dataset" },
106+ ]
107+ }
108+ # BENCHMARK_ID is not set, so first benchmark should be skipped
109+ result = replace_env_vars (data )
110+ assert len (result ["benchmarks" ]) == 1
111+ assert result ["benchmarks" ][0 ]["benchmark_id" ] == "always-present"
112+
113+
114+ def test_resource_with_set_benchmark_id_not_skipped (setup_env_vars ):
115+ """Test that resources with set benchmark_id are not skipped."""
116+ os .environ ["BENCHMARK_ID" ] = "enabled"
117+ try :
118+ data = {
119+ "benchmarks" : [
120+ {"benchmark_id" : "${env.BENCHMARK_ID:+my-benchmark}" , "dataset_id" : "test-dataset" },
121+ {"benchmark_id" : "always-present" , "dataset_id" : "another-dataset" },
122+ ]
123+ }
124+ result = replace_env_vars (data )
125+ assert len (result ["benchmarks" ]) == 2
126+ assert result ["benchmarks" ][0 ]["benchmark_id" ] == "my-benchmark"
127+ assert result ["benchmarks" ][1 ]["benchmark_id" ] == "always-present"
128+ finally :
129+ del os .environ ["BENCHMARK_ID" ]
130+
131+
132+ def test_resource_with_empty_model_id_skipped (setup_env_vars ):
133+ """Test that resources with empty model_id from conditional env vars are skipped."""
134+ data = {
135+ "models" : [
136+ {"model_id" : "${env.MODEL_ID:+my-model}" , "provider_id" : "test-provider" },
137+ {"model_id" : "always-present" , "provider_id" : "another-provider" },
138+ ]
139+ }
140+ # MODEL_ID is not set, so first model should be skipped
141+ result = replace_env_vars (data )
142+ assert len (result ["models" ]) == 1
143+ assert result ["models" ][0 ]["model_id" ] == "always-present"
144+
145+
146+ def test_resource_with_empty_shield_id_skipped (setup_env_vars ):
147+ """Test that resources with empty shield_id from conditional env vars are skipped."""
148+ data = {
149+ "shields" : [
150+ {"shield_id" : "${env.SHIELD_ID:+my-shield}" , "provider_id" : "test-provider" },
151+ {"shield_id" : "always-present" , "provider_id" : "another-provider" },
152+ ]
153+ }
154+ # SHIELD_ID is not set, so first shield should be skipped
155+ result = replace_env_vars (data )
156+ assert len (result ["shields" ]) == 1
157+ assert result ["shields" ][0 ]["shield_id" ] == "always-present"
158+
159+
160+ def test_multiple_resources_with_conditional_ids (setup_env_vars ):
161+ """Test that multiple resource types with conditional IDs are handled correctly."""
162+ os .environ ["INCLUDE_BENCHMARK" ] = "yes"
163+ try :
164+ data = {
165+ "benchmarks" : [
166+ {"benchmark_id" : "${env.INCLUDE_BENCHMARK:+included-benchmark}" , "dataset_id" : "ds1" },
167+ {"benchmark_id" : "${env.EXCLUDE_BENCHMARK:+excluded-benchmark}" , "dataset_id" : "ds2" },
168+ ],
169+ "models" : [
170+ {"model_id" : "${env.EXCLUDE_MODEL:+excluded-model}" , "provider_id" : "p1" },
171+ ],
172+ }
173+ result = replace_env_vars (data )
174+ # Only the benchmark with INCLUDE_BENCHMARK set should remain
175+ assert len (result ["benchmarks" ]) == 1
176+ assert result ["benchmarks" ][0 ]["benchmark_id" ] == "included-benchmark"
177+ # Model with unset env var should be skipped
178+ assert len (result ["models" ]) == 0
179+ finally :
180+ del os .environ ["INCLUDE_BENCHMARK" ]
0 commit comments