Skip to content

tests: handle case of acceptance-test-config.yml with no valid test cases #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented May 2, 2025

This PR handles the case of missing config in acceptance-test-config.yml. Specifically, it now runs successfully on source-7shift, which has the following definition:

# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-7shifts:dev
acceptance_tests:
  spec:
    tests:
      - spec_path: "manifest.yaml"
  connection:
    bypass_reason: "This is a builder contribution, and we do not have secrets at this time"
  discovery:
    bypass_reason: "This is a builder contribution, and we do not have secrets at this time"
  basic_read:
    bypass_reason: "This is a builder contribution, and we do not have secrets at this time"
  incremental:
    bypass_reason: "This is a builder contribution, and we do not have secrets at this time"
  full_refresh:
    bypass_reason: "This is a builder contribution, and we do not have secrets at this time"

This test config file is especially useless because spec is not the same as manifest.yml and so it's not really helpful at all in defining test cases.

Nevertheless, we test what we can and the tests succeed now:

image

Summary by CodeRabbit

  • Tests
    • Improved handling of missing test scenarios in acceptance test configuration, returning an empty list instead of raising an error when no tests are found for a category.

Summary by CodeRabbit

  • New Features

    • Introduced a new standard test for validating connector specification output.
    • Added a property to easily access specification messages in test results.
  • Bug Fixes

    • Improved handling of test scenarios to support cases where no scenario is provided.
    • Enhanced test scenario aggregation to include multiple categories and handle missing data more gracefully.
    • Expanded test job support to include the "spec" verb and optional test scenarios.

@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 22:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request modifies the behavior of the function get_scenarios to handle cases where a declared category does not have a corresponding "tests" key in the acceptance tests configuration. The key changes include:

  • Updating the condition to check both for the existence of the category and the "tests" key.
  • Removing the ValueError in favor of returning an empty list when no tests are found.
Comments suppressed due to low confidence (1)

airbyte_cdk/test/standard_tests/connector_base.py:162

  • [nitpick] Consider adding a comment to explain why an empty list is returned when tests are absent for the category.
return []

@aaronsteers aaronsteers marked this pull request as draft May 2, 2025 22:22
Copy link
Contributor

coderabbitai bot commented May 2, 2025

📝 Walkthrough

Walkthrough

The update enhances the test framework for Airbyte connectors by extending scenario aggregation across multiple test categories, adding support for the "spec" verb in test jobs, and enabling optional test scenarios in connector creation and job execution. It also introduces a new standard test for connector specifications and adds a property to filter spec messages from entrypoint outputs. Additionally, it refines configuration handling in test scenarios to optionally allow empty configs.

Changes

File(s) Change Summary
airbyte_cdk/test/standard_tests/connector_base.py Modified get_scenarios to aggregate scenarios from multiple categories ("connection" and "spec") with filtering; updated create_connector to accept optional scenario.
airbyte_cdk/test/entrypoint_wrapper.py Added spec_messages property to EntrypointOutput to filter messages of type SPEC.
airbyte_cdk/test/standard_tests/_job_runner.py Updated run_test_job to accept "spec" verb and optional test_scenario; added logic to handle optional scenario and config handling.
airbyte_cdk/test/standard_tests/declarative_sources.py Updated create_connector to accept optional scenario and adjust config initialization accordingly.
airbyte_cdk/test/standard_tests/source_base.py Added test_spec method to SourceTestSuiteBase to run a standard test for the "spec" verb without a scenario.
airbyte_cdk/test/standard_tests/models/scenario.py Modified get_config_dict in ConnectorTestScenario to support returning an empty dict if config is missing via empty_if_missing parameter.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant ConnectorBase
    participant JobRunner
    participant EntrypointOutput

    TestRunner->>ConnectorBase: get_scenarios(config)
    ConnectorBase->>ConnectorBase: Aggregate scenarios from "connection" and "spec" categories
    ConnectorBase-->>TestRunner: Return combined filtered scenarios list

    TestRunner->>ConnectorBase: create_connector(scenario=None)
    ConnectorBase-->>TestRunner: Connector instance with config including manifest and optional scenario config

    TestRunner->>JobRunner: run_test_job(connector, verb="spec", test_scenario=None)
    JobRunner->>EntrypointOutput: _run_command(...)
    EntrypointOutput-->>JobRunner: Output messages

    JobRunner-->>TestRunner: EntrypointOutput

    TestRunner->>EntrypointOutput: spec_messages
    EntrypointOutput-->>TestRunner: Filtered SPEC messages list
Loading

Suggested reviewers

  • aldogonzalez8
  • aaronsteers

Would you like me to help draft a quick summary for the changelog or release notes as well? Wdyt?


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 345b3d2 and e168342.

📒 Files selected for processing (2)
  • airbyte_cdk/test/standard_tests/models/scenario.py (1 hunks)
  • airbyte_cdk/test/standard_tests/source_base.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • airbyte_cdk/test/standard_tests/source_base.py
  • airbyte_cdk/test/standard_tests/models/scenario.py
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Analyze (python)
  • GitHub Check: preview_docs
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
airbyte_cdk/test/standard_tests/connector_base.py (1)

145-150: Minor observation about documentation vs implementation.

The comment says "Get acceptance tests for a given category" but the function hardcodes the category to "connection". Would it make sense to either update the docstring or make the category configurable through a parameter? This isn't related to your current change, just something I noticed while reviewing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f11bfa and d3ae744.

📒 Files selected for processing (1)
  • airbyte_cdk/test/standard_tests/connector_base.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
airbyte_cdk/test/standard_tests/connector_base.py (1)

157-162: Good refactoring to handle missing 'tests' gracefully!

This change nicely handles the case where a category exists but has no 'tests' key (which happens when 'bypass_reason' is present). Would it help debugging to add a debug log when this specific case is encountered? Maybe something like:

if (
    category not in all_tests_config["acceptance_tests"]
    or "tests" not in all_tests_config["acceptance_tests"][category]
):
+   if category in all_tests_config["acceptance_tests"] and "tests" not in all_tests_config["acceptance_tests"][category]:
+       logging.debug(f"Category '{category}' exists but has no 'tests' key. Returning empty list.")
    return []

Just a thought - wdyt?

@aaronsteers aaronsteers marked this pull request as ready for review May 6, 2025 23:46
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
airbyte_cdk/test/standard_tests/connector_base.py (1)

1-180: ⚠️ Potential issue

Fix Ruff formatting issue

The linter reports a formatting issue in this file. Run 'ruff format' to address it.

🧰 Tools
🪛 GitHub Actions: Linters

[error] 1-1: Ruff formatting check failed. File would be reformatted. Run 'ruff format' to fix code style issues.

🧹 Nitpick comments (1)
airbyte_cdk/test/standard_tests/source_base.py (1)

67-86: Improved test coverage with new spec test method

This addition introduces a nice standardized test for the spec verb, which runs without requiring a test scenario. Good error handling and clear assertion messages.

I'm wondering if the tuple formatting in line 83-84 might need attention? It seems the f-string prefix is used with the error message, but the result is in a tuple which might not format as expected.

-        assert len(result.spec_messages) == 1, (
-            "Expected exactly 1 spec message but got {len(result.spec_messages)}",
-            result.errors,
-        )
+        assert len(result.spec_messages) == 1, (
+            f"Expected exactly 1 spec message but got {len(result.spec_messages)}",
+            result.errors,
+        )

What do you think?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3ae744 and e48df37.

📒 Files selected for processing (5)
  • airbyte_cdk/test/entrypoint_wrapper.py (1 hunks)
  • airbyte_cdk/test/standard_tests/_job_runner.py (6 hunks)
  • airbyte_cdk/test/standard_tests/connector_base.py (2 hunks)
  • airbyte_cdk/test/standard_tests/declarative_sources.py (2 hunks)
  • airbyte_cdk/test/standard_tests/source_base.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • airbyte_cdk/test/entrypoint_wrapper.py
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/test/standard_tests/connector_base.py

[error] 1-1: Ruff formatting check failed. File would be reformatted. Run 'ruff format' to fix code style issues.

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (12)
airbyte_cdk/test/standard_tests/declarative_sources.py (2)

67-67: LGTM! Added support for optional scenarios

The parameter update correctly makes scenario optional, aligning with the new test_spec method requirements.


77-82: Good defensive implementation for handling optional scenarios

This restructuring safely initializes the config with the manifest and conditionally updates it with scenario data if provided. Clean, defensive programming.

airbyte_cdk/test/standard_tests/connector_base.py (2)

92-92: LGTM! Added support for optional scenarios

The parameter update correctly makes scenario optional, aligning with the new test_spec method requirements.


150-180:

❓ Verification inconclusive

Improved test scenario discovery across multiple categories

The refactored get_scenarios method now aggregates test scenarios from multiple categories and handles missing "tests" sections gracefully. This is a nice enhancement that supports the PR's objective of handling cases where a declared category doesn't have 'tests'.


🏁 Script executed:

#!/bin/bash
# Check for the existence of acceptance test config files in the repo
# and look for categories that might be missing 'tests' sections

rg --type yaml "acceptance_tests:" -A 20

Length of output: 2280


Consider dynamic test category discovery

Currently, the code hard-codes

categories = ["connection", "spec"]

which will skip other sections like discovery, basic_read or incremental even when they have tests (and your sample YAML shows them present). Would you consider deriving this list directly from the config—e.g.:

categories = list(all_tests_config["acceptance_tests"].keys())

—so that any new or custom categories are automatically picked up? wdyt?

• File: airbyte_cdk/test/standard_tests/connector_base.py
– Line ~151: categories = ["connection", "spec"]

airbyte_cdk/test/standard_tests/_job_runner.py (8)

59-59: LGTM! Added 'spec' verb support

The addition of "spec" to the list of accepted verbs supports the new test_spec method.


61-61: LGTM! Made test_scenario parameter optional

Making the test_scenario parameter optional (defaulting to None) correctly supports the new spec test flow.


84-93: LGTM! Added safety checks for optional test_scenario

The added conditionals properly check for test_scenario before accessing its attributes, preventing potential NoneType errors.


115-120: Good refactoring of exception handling logic

Creating a local expect_exception variable centralizes the exception expectation logic and makes the code more maintainable. Nice clean-up!


124-124: LGTM! Updated exception handling with optional scenario support

The modified logic for setting expecting_exception parameter properly handles the case when test_scenario is None.


126-127: LGTM! Added safety check for exception handling

The added check for test_scenario in the conditional properly handles scenarios where test_scenario is None.


141-141: LGTM! Updated to use local expect_exception variable

Using the local expect_exception variable here makes the code more consistent and readable.


155-155: LGTM! Updated to use local expect_exception variable

Using the local expect_exception variable here makes the code more consistent and readable.

@aaronsteers aaronsteers requested a review from dbgold17 May 6, 2025 23:49
@aaronsteers aaronsteers changed the title handle case of declared category with no 'tests' (usually 'bypass_rea… tests: handle case of acceptance-test-config.yml with no valid test cases. May 6, 2025
@aaronsteers aaronsteers changed the title tests: handle case of acceptance-test-config.yml with no valid test cases. tests: handle case of acceptance-test-config.yml with no valid test cases May 6, 2025
@aaronsteers
Copy link
Contributor Author

aaronsteers commented May 6, 2025

/autofix

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

@aaronsteers
Copy link
Contributor Author

aaronsteers commented May 7, 2025

/autofix

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

Copy link
Contributor

@dbgold17 dbgold17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving with some comments

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
airbyte_cdk/test/standard_tests/models/scenario.py (1)

16-16: Unused import detected.

The empty import from numpy doesn't appear to be used anywhere in this file. Would you consider removing this unused import to keep the imports clean? wdyt?

- from numpy import empty
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b883a55 and 345b3d2.

📒 Files selected for processing (3)
  • airbyte_cdk/test/standard_tests/_job_runner.py (2 hunks)
  • airbyte_cdk/test/standard_tests/declarative_sources.py (2 hunks)
  • airbyte_cdk/test/standard_tests/models/scenario.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • airbyte_cdk/test/standard_tests/declarative_sources.py
  • airbyte_cdk/test/standard_tests/_job_runner.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
airbyte_cdk/test/standard_tests/models/scenario.py (1)

47-70: Nice enhancement to handle optional configuration gracefully!

I like the addition of the empty_if_missing parameter to allow callers to decide how to handle missing configurations. This aligns well with the PR objective of handling test cases where valid configurations may not exist. The documentation for the parameter is clear and helpful too.

This change should successfully address the issue with connectors like source-7shift that have acceptance test configurations without valid test cases.

@aaronsteers aaronsteers enabled auto-merge (squash) May 7, 2025 00:37
@aaronsteers
Copy link
Contributor Author

aaronsteers commented May 7, 2025

/autofix

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

PR auto-fix job started... Check job output.

🟦 Job completed successfully (no changes).

@aaronsteers aaronsteers merged commit 8906ed2 into main May 7, 2025
25 of 27 checks passed
@aaronsteers aaronsteers deleted the aj-and-david/tests/improve-fast-standard-test-coverage branch May 7, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants