2222 ConfiguredAirbyteCatalog ,
2323 ConfiguredAirbyteStream ,
2424 DestinationSyncMode ,
25+ Status ,
2526 SyncMode ,
2627)
2728from airbyte_cdk .models .connector_metadata import MetadataFile
@@ -210,15 +211,16 @@ def test_docker_image_build_and_check(
210211 """Run `docker_image` acceptance tests.
211212
212213 This test builds the connector image and runs the `check` command inside the container.
214+ It validates that the connector emits exactly one `CONNECTION_STATUS` message whose
215+ status matches the scenario's expected outcome (`SUCCEEDED` or `FAILED`). Scenarios
216+ whose `acceptance-test-config.yml` entry has `status: "failed"` are exercised too,
217+ so that `check` against bad configs is validated end-to-end rather than skipped.
213218
214219 Note:
215220 - It is expected for docker image caches to be reused between test runs.
216221 - In the rare case that image caches need to be cleared, please clear
217222 the local docker image cache using `docker image prune -a` command.
218223 """
219- if scenario .expected_outcome .expect_exception ():
220- pytest .skip ("Skipping test_docker_image_build_and_check (expected to fail)." )
221-
222224 tag = "dev-latest"
223225 connector_root = self .get_connector_root_dir ()
224226 metadata = MetadataFile .from_file (connector_root / "metadata.yaml" )
@@ -233,11 +235,14 @@ def test_docker_image_build_and_check(
233235 no_verify = False ,
234236 )
235237
238+ expect_success = scenario .expected_outcome .expect_success ()
239+ expect_exception = scenario .expected_outcome .expect_exception ()
240+
236241 container_config_path = "/secrets/config.json"
237242 with scenario .with_temp_config_file (
238243 connector_root = connector_root ,
239244 ) as temp_config_file :
240- _ = run_docker_airbyte_command (
245+ result = run_docker_airbyte_command (
241246 [
242247 "docker" ,
243248 "run" ,
@@ -249,7 +254,50 @@ def test_docker_image_build_and_check(
249254 "--config" ,
250255 container_config_path ,
251256 ],
252- raise_if_errors = True ,
257+ # Only raise on trace errors when we expect a successful check. When the
258+ # scenario expects the check to fail, the connector is supposed to exit
259+ # cleanly with a `CONNECTION_STATUS: FAILED` message rather than raising.
260+ raise_if_errors = expect_success ,
261+ )
262+
263+ self ._assert_check_result_matches_expected_outcome (result , scenario )
264+
265+ @staticmethod
266+ def _assert_check_result_matches_expected_outcome (
267+ result : EntrypointOutput ,
268+ scenario : ConnectorTestScenario ,
269+ ) -> None :
270+ """Assert that the `check` output matches the scenario's expected outcome.
271+
272+ The connector must emit exactly one `CONNECTION_STATUS` message. When the scenario
273+ expects success, the status must be `SUCCEEDED`; when it expects an exception (i.e.
274+ `acceptance-test-config.yml` declares `status: "failed"` or `status: "exception"`),
275+ the status must be `FAILED`. When the expected outcome is `ALLOW_ANY`, only the
276+ presence of a single `CONNECTION_STATUS` message is validated.
277+ """
278+ status_messages = result .connection_status_messages
279+ assert len (status_messages ) == 1 , (
280+ "Expected exactly one CONNECTION_STATUS message but got "
281+ f"{ len (status_messages )} :\n "
282+ + "\n " .join (str (msg ) for msg in status_messages )
283+ + result .get_formatted_error_message ()
284+ )
285+
286+ connection_status = status_messages [0 ].connectionStatus
287+ assert connection_status is not None , (
288+ "Expected CONNECTION_STATUS message to have a connectionStatus payload. Got: \n "
289+ + "\n " .join (str (msg ) for msg in status_messages )
290+ )
291+
292+ if scenario .expected_outcome .expect_success ():
293+ assert connection_status .status == Status .SUCCEEDED , (
294+ "Expected CONNECTION_STATUS to be SUCCEEDED but got "
295+ f"{ connection_status .status } . Message: { connection_status .message !r} "
296+ )
297+ elif scenario .expected_outcome .expect_exception ():
298+ assert connection_status .status == Status .FAILED , (
299+ "Expected CONNECTION_STATUS to be FAILED but got "
300+ f"{ connection_status .status } . Message: { connection_status .message !r} "
253301 )
254302
255303 @pytest .mark .skipif (
0 commit comments