Skip to content

This and that II#19

Merged
amotl merged 6 commits intomainfrom
this-and-more
May 10, 2025
Merged

This and that II#19
amotl merged 6 commits intomainfrom
this-and-more

Conversation

@coderabbitai
Copy link

coderabbitai bot commented May 10, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new Apache 2.0 license file, update documentation with new badges and navigation, and clarify the changelog. The CrateDB conversation code is refactored and renamed to CrateDbKnowledgeConversation, with corresponding updates to imports and exports. New tests target the refactored conversation logic and related error handling. CI is enhanced to upload coverage reports.

Changes

File(s) Change Summary
LICENSE Added full Apache License, Version 2.0.
README.md Added badges, navigation bar, Python API usage example, and consolidated badge/link references.
CHANGES.md Updated changelog to note conversation code refactor and move to CrateDbKnowledgeConversation.
.github/workflows/tests.yml Added step to upload code coverage to Codecov in CI workflow.
pyproject.toml Declared license file and added pytest-mock<4 to optional test dependencies.
src/cratedb_about/init.py Imported and exported CrateDbKnowledgeConversation in __all__.
src/cratedb_about/cli.py Updated imports and usage from old conversation class to CrateDbKnowledgeConversation.
src/cratedb_about/query/init.py New module; imports and exports CrateDbKnowledgeConversation via __all__.
src/cratedb_about/query/core.py Renamed CrateDBConversation to CrateDbKnowledgeConversation; updated import for Settings.
src/cratedb_about/outline/cratedb-outline.yaml Improved header comments and metadata; no data changes.
tests/conftest.py Fixture now also removes "OPENAI_API_KEY" from environment before tests.
tests/test_query.py New tests for CrateDbKnowledgeConversation, Settings, Example, and OpenAI API key error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant CrateDbKnowledgeConversation
    participant OpenAI_API

    User->>CLI: ask "How do I use CrateDB?"
    CLI->>CrateDbKnowledgeConversation: Instantiate and forward question
    CrateDbKnowledgeConversation->>OpenAI_API: Send question (requires API key)
    OpenAI_API-->>CrateDbKnowledgeConversation: Return answer or error
    CrateDbKnowledgeConversation-->>CLI: Response or error
    CLI-->>User: Output answer or error message
Loading

Possibly related PRs

Poem

🐇
A license hops in, Apache and clear,
New badges and docs bring community near.
The knowledge conversation, renamed with care,
Now answers your queries with wisdom to share.
With coverage and tests, our garden will grow—
CrateDB’s about, and now you know!


📜 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 c4c0fab and 1f4cb68.

📒 Files selected for processing (10)
  • .github/workflows/tests.yml (1 hunks)
  • CHANGES.md (1 hunks)
  • README.md (3 hunks)
  • pyproject.toml (2 hunks)
  • src/cratedb_about/__init__.py (1 hunks)
  • src/cratedb_about/cli.py (2 hunks)
  • src/cratedb_about/query/__init__.py (1 hunks)
  • src/cratedb_about/query/core.py (2 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_query.py (1 hunks)
✨ 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.

@amotl amotl changed the title This and more This and that II May 10, 2025
Copy link

@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: 1

🧹 Nitpick comments (2)
README.md (1)

129-156: Fix duplicate and unused link references.

There are several issues with the link references:

  1. Duplicate link reference definition for "CrateDB"
  2. Unused link reference definitions for "issue tracker", "managed on GitHub", "badge-package-version", "badge-python-versions", and "project-pypi"

Consider removing the duplicate and unused link references to clean up the documentation:

-[CrateDB]: https://cratedb.com/database
-[issue tracker]: https://github.com/crate/about/issues
-[managed on GitHub]: https://github.com/crate/about
-[badge-package-version]: https://img.shields.io/pypi/v/cratedb-about.svg
-[badge-python-versions]: https://img.shields.io/pypi/pyversions/cratedb-about.svg
-[project-pypi]: https://pypi.org/project/cratedb-about
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

129-129: Link and image reference definitions should be needed
Duplicate link or image reference definition: "cratedb"

(MD053, link-image-reference-definitions)


130-130: Link and image reference definitions should be needed
Unused link or image reference definition: "issue tracker"

(MD053, link-image-reference-definitions)


136-136: Link and image reference definitions should be needed
Unused link or image reference definition: "managed on github"

(MD053, link-image-reference-definitions)


145-145: Link and image reference definitions should be needed
Unused link or image reference definition: "badge-package-version"

(MD053, link-image-reference-definitions)


146-146: Link and image reference definitions should be needed
Unused link or image reference definition: "badge-python-versions"

(MD053, link-image-reference-definitions)


155-155: Link and image reference definitions should be needed
Unused link or image reference definition: "project-pypi"

(MD053, link-image-reference-definitions)

tests/test_query.py (1)

39-48: Excellent mocking of environment for invalid API key test.

This test effectively uses mocking to simulate an invalid API key scenario and verifies the correct exception and message.

Consider adding tests for the actual conversation functionality with a mocked OpenAI response to verify that questions are processed correctly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1df9679 and ee49fcd.

📒 Files selected for processing (12)
  • .github/workflows/tests.yml (1 hunks)
  • CHANGES.md (1 hunks)
  • LICENSE (1 hunks)
  • README.md (3 hunks)
  • pyproject.toml (2 hunks)
  • src/cratedb_about/__init__.py (1 hunks)
  • src/cratedb_about/cli.py (2 hunks)
  • src/cratedb_about/outline/cratedb-outline.yaml (1 hunks)
  • src/cratedb_about/query/__init__.py (1 hunks)
  • src/cratedb_about/query/core.py (2 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_query.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
README.md (3)
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:16:33.171Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
🧬 Code Graph Analysis (3)
src/cratedb_about/query/core.py (1)
src/cratedb_about/query/model.py (1)
  • Settings (34-66)
src/cratedb_about/__init__.py (1)
src/cratedb_about/query/core.py (1)
  • CrateDbKnowledgeConversation (32-155)
src/cratedb_about/query/__init__.py (1)
src/cratedb_about/query/core.py (1)
  • CrateDbKnowledgeConversation (32-155)
🪛 LanguageTool
README.md

[style] ~7-~7: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 2115 characters long)
Context: ...license] [![CI][badge-ci]][project-ci] [![Coverage][badge-coverage]][project-coverage] [![Downloads per month][badge-downloads-per-month]][project-downloads] [![License][badge-license]][project-licens...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.17.2)
README.md

129-129: Link and image reference definitions should be needed
Duplicate link or image reference definition: "cratedb"

(MD053, link-image-reference-definitions)


130-130: Link and image reference definitions should be needed
Unused link or image reference definition: "issue tracker"

(MD053, link-image-reference-definitions)


136-136: Link and image reference definitions should be needed
Unused link or image reference definition: "managed on github"

(MD053, link-image-reference-definitions)


145-145: Link and image reference definitions should be needed
Unused link or image reference definition: "badge-package-version"

(MD053, link-image-reference-definitions)


146-146: Link and image reference definitions should be needed
Unused link or image reference definition: "badge-python-versions"

(MD053, link-image-reference-definitions)


155-155: Link and image reference definitions should be needed
Unused link or image reference definition: "project-pypi"

(MD053, link-image-reference-definitions)

🪛 GitHub Check: codecov/patch
src/cratedb_about/cli.py

[warning] 66-66: src/cratedb_about/cli.py#L66
Added line #L66 was not covered by tests

🔇 Additional comments (21)
pyproject.toml (2)

17-17: Clear license specification added

Adding explicit license-files entry ensures better packaging compatibility and makes the license file more discoverable.


101-101: Adding pytest-mock dependency

Good addition of pytest-mock for the new tests. The version constraint (<4) follows the same pattern as other dependencies.

.github/workflows/tests.yml (1)

60-67: Great addition of Codecov integration

Adding code coverage reporting to Codecov is valuable for monitoring test coverage over time. The configuration is properly set up with:

  • Official Codecov action
  • Proper token handling through secrets
  • Environment variables passed to provide context
  • Fail-on-error to ensure coverage reporting works
tests/conftest.py (1)

9-9: Good environment isolation practice

Removing the OpenAI API key from the test environment ensures tests run consistently regardless of local environment configuration, particularly important for testing error handling around missing credentials.

LICENSE (1)

1-178: Complete Apache 2.0 license added

The standard Apache License 2.0 text has been properly added verbatim, which aligns with the license specified in pyproject.toml. This is critical for open source projects to clearly communicate usage terms.

CHANGES.md (1)

13-13: Changelog entry clearly documents refactoring

The changelog entry effectively communicates the API refactoring that moved the LLM conversations code to the new CrateDbKnowledgeConversation class. This provides good documentation for users updating from previous versions.

src/cratedb_about/query/core.py (2)

7-7: Import path updated correctly

The import path has been properly updated to reflect the new module structure, importing Settings from the query-specific model module.


32-32: Class name improves consistency and clarity

The renaming from CrateDBConversation to CrateDbKnowledgeConversation is a good improvement for two reasons:

  1. It follows Python naming conventions with Db instead of DB
  2. The addition of Knowledge better describes the purpose of the class

This change maintains the same functionality while improving code clarity.

src/cratedb_about/__init__.py (1)

4-8: Public API updated appropriately

The package's public API is correctly updated to import and expose the renamed CrateDbKnowledgeConversation class, ensuring backward compatibility for any code that will use this new class name.

src/cratedb_about/query/__init__.py (1)

1-5: New module structure follows best practices

The new query module is correctly structured with a clear __init__.py that imports and exports only the necessary public interface (CrateDbKnowledgeConversation). This is a good practice for modular design and encapsulation.

src/cratedb_about/cli.py (1)

10-11: Import statements updated to reflect refactored code structure.

The imports correctly reference the new locations following the refactoring of the LLM conversations code, with CrateDbKnowledgeConversation now coming from cratedb_about.query.core and Example from cratedb_about.query.model.

src/cratedb_about/outline/cratedb-outline.yaml (3)

1-4: Improved header metadata with source and target URLs.

The updates to the header comments improve clarity and provide valuable information about the source and target locations of the outline.


7-11: Enhanced clarity in section naming conventions.

The wording adjustments to the comments describing standard section names and attribute naming conventions improve clarity without changing the meaning.


14-14: Added trailing blank comment line for better readability.

This minor formatting change improves the visual separation between header comments and the YAML content.

README.md (3)

3-11: Well-structured badges improve project presentation.

The addition of these badges provides valuable information about the project's status, CI, coverage, license, and more, enhancing the README's informativeness at first glance.

🧰 Tools
🪛 LanguageTool

[style] ~7-~7: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 2115 characters long)
Context: ...license] [![CI][badge-ci]][project-ci] [![Coverage][badge-coverage]][project-coverage] [![Downloads per month][badge-downloads-per-month]][project-downloads] [![License][badge-license]][project-licens...

(EN_EXCESSIVE_EXCLAMATION)


13-19: Added navigation bar for improved usability.

The navigation bar provides convenient access to key resources, improving the user experience.


98-111: Excellent addition of Python API example.

The Python API example for asking questions about CrateDB demonstrates the usage of the refactored CrateDbKnowledgeConversation class, providing users with a clear code sample.

tests/test_query.py (4)

8-14: Good test for basic Settings attributes.

This test validates key attributes of the Settings class, ensuring they contain expected values.


16-21: Verifies prompt content appropriately.

The test ensures that expected CrateDB information is present in the prompt content.


23-28: Validates example questions correctly.

This test confirms that the Example class contains expected question content.


30-37: Good error handling test for missing API key.

This test properly validates that the conversation class raises the appropriate exception when the OpenAI API key is missing.

Copy link

@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: 1

🔭 Outside diff range comments (1)
tests/test_query.py (1)

1-70: 🛠️ Refactor suggestion

Add test for custom backend and knowledge parameters.

While there are tests for basic instantiation and error cases, there's no test that explicitly verifies the behavior when custom backend and knowledge parameters are provided.

Add a test that verifies the class correctly handles custom parameters:

def test_custom_parameters():
    """
    Validate that custom backend and knowledge parameters are correctly applied.
    """
    mocker.patch.dict("os.environ", {"OPENAI_API_KEY": "test_key"})
    
    # Test with custom backend
    knowledge = CrateDbKnowledgeConversation(backend="openai", use_knowledge=False)
    
    # Verify internal state reflects the parameters
    assert knowledge.backend == "openai"
    assert knowledge.use_knowledge is False
    
    # Optional: If there's a way to check the actual behavior difference when 
    # use_knowledge=False, add assertions for that
🧰 Tools
🪛 GitHub Actions: Tests

[error] 55-55: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_no_api_key.


[error] 66-66: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_invalid_api_key.

♻️ Duplicate comments (1)
src/cratedb_about/cli.py (1)

66-69: Tests needed for the instantiation with custom parameters.

While there is now test coverage for CrateDbKnowledgeConversation in the new tests file, we still need tests that specifically cover instantiation with custom backend and knowledge parameters.

#!/bin/bash
# Check for test coverage of custom parameters
echo "Checking for tests with custom parameters for CrateDbKnowledgeConversation"
rg -A 5 "CrateDbKnowledgeConversation\(.*use_knowledge=\w+.*\)" tests/
rg -A 5 "CrateDbKnowledgeConversation\(.*backend=(?:\"|')[a-z]+(?:\"|').*\)" tests/
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 66-66: src/cratedb_about/cli.py#L66
Added line #L66 was not covered by tests

🧹 Nitpick comments (1)
README.md (1)

162-162: Remove unused link reference.

The "project-github" reference definition is not used anywhere in the document and should be removed.

-[project-github]: https://github.com/crate/about
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

162-162: Link and image reference definitions should be needed
Unused link or image reference definition: "project-github"

(MD053, link-image-reference-definitions)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee49fcd and c4c0fab.

📒 Files selected for processing (10)
  • .github/workflows/tests.yml (1 hunks)
  • CHANGES.md (1 hunks)
  • README.md (3 hunks)
  • pyproject.toml (2 hunks)
  • src/cratedb_about/__init__.py (1 hunks)
  • src/cratedb_about/cli.py (2 hunks)
  • src/cratedb_about/query/__init__.py (1 hunks)
  • src/cratedb_about/query/core.py (2 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_query.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/cratedb_about/query/init.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/cratedb_about/query/core.py
  • tests/conftest.py
  • pyproject.toml
  • src/cratedb_about/init.py
  • CHANGES.md
  • .github/workflows/tests.yml
🧰 Additional context used
🧠 Learnings (1)
README.md (3)
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:16:33.171Z
Learning: When creating content for an `llms.txt` file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.
🪛 GitHub Actions: Tests
tests/test_query.py

[error] 55-55: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_no_api_key.


[error] 66-66: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_invalid_api_key.

🪛 LanguageTool
README.md

[style] ~10-~10: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 2408 characters long)
Context: ...[![Status][badge-status]][project-pypi] [![PyPI Version][badge-package-version]][project-pypi] [![Python Versions][badge-python-versions]...

(EN_EXCESSIVE_EXCLAMATION)


[uncategorized] ~130-~130: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...uting The cratedb-about package is an open source project, and is [managed on GitHub]. Co...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🪛 markdownlint-cli2 (0.17.2)
README.md

162-162: Link and image reference definitions should be needed
Unused link or image reference definition: "project-github"

(MD053, link-image-reference-definitions)

🪛 GitHub Check: codecov/patch
src/cratedb_about/cli.py

[warning] 66-66: src/cratedb_about/cli.py#L66
Added line #L66 was not covered by tests

🔇 Additional comments (5)
src/cratedb_about/cli.py (1)

10-11: Import path changes look good.

The imports have been properly updated to reflect the refactored code structure. The conversation class has been moved to its own module in query, which aligns with the PR objectives.

README.md (2)

3-21: Great documentation enhancements!

The added badges and navigation links significantly improve the README's professionalism and navigability, making it easier for users to access key project resources.

🧰 Tools
🪛 LanguageTool

[style] ~10-~10: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 2408 characters long)
Context: ...[![Status][badge-status]][project-pypi] [![PyPI Version][badge-package-version]][project-pypi] [![Python Versions][badge-python-versions]...

(EN_EXCESSIVE_EXCLAMATION)


106-113: Clear API usage example.

Good addition of the Python API example that demonstrates how to use the refactored CrateDbKnowledgeConversation class. This aligns with the PR objective of improving documentation.

tests/test_query.py (2)

1-28: Good test coverage for CrateDbKnowledgeConversation settings and examples.

These tests effectively validate the basic functionality of the Settings class and Example questions, providing solid baseline coverage.


30-47: Thorough error handling tests for OpenAI backend.

Excellent tests for validating the behavior when OpenAI API key is missing or invalid. These tests ensure robust error handling.

Comment on lines +50 to +73
def test_ask_claude_no_api_key():
"""
Validate inquiry with Anthropic Claude, failing without an API key.
"""
with pytest.raises(ValueError) as ex:
CrateDbKnowledgeConversation(backend="claude")
assert ex.match(
"ANTHROPIC_API_KEY environment variable is required when using 'claude' backend"
)


def test_ask_claude_invalid_api_key(mocker):
"""
Validate inquiry with Anthropic Claude, failing when using an invalid API key.
"""
mocker.patch.dict("os.environ", {"ANTHROPIC_API_KEY": "foo"})
knowledge = CrateDbKnowledgeConversation(backend="claude")
with pytest.raises(RuntimeError) as ex:
knowledge.ask("CrateDB does not seem to provide an AUTOINCREMENT feature?")
assert ex.match("Claude API error:.*authentication_error.*invalid x-api-key")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix dependency issue for Claude backend tests.

The pipeline is failing due to missing 'claudette' package dependency for the Claude backend tests.

These tests need to have proper dependency handling. Either:

  1. Add 'claudette' as a test dependency in pyproject.toml, or
  2. Skip these tests when the package is not available
@pytest.mark.parametrize("backend", ["claude"])
-def test_ask_claude_no_api_key():
+def test_ask_claude_no_api_key(backend):
    """
    Validate inquiry with Anthropic Claude, failing without an API key.
    """
+    try:
+        import claudette  # noqa: F401
+    except ImportError:
+        pytest.skip("claudette package not installed")
    with pytest.raises(ValueError) as ex:
        CrateDbKnowledgeConversation(backend=backend)
    assert ex.match(
        "ANTHROPIC_API_KEY environment variable is required when using 'claude' backend"
    )

Apply a similar pattern to test_ask_claude_invalid_api_key.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_ask_claude_no_api_key():
"""
Validate inquiry with Anthropic Claude, failing without an API key.
"""
with pytest.raises(ValueError) as ex:
CrateDbKnowledgeConversation(backend="claude")
assert ex.match(
"ANTHROPIC_API_KEY environment variable is required when using 'claude' backend"
)
def test_ask_claude_invalid_api_key(mocker):
"""
Validate inquiry with Anthropic Claude, failing when using an invalid API key.
"""
mocker.patch.dict("os.environ", {"ANTHROPIC_API_KEY": "foo"})
knowledge = CrateDbKnowledgeConversation(backend="claude")
with pytest.raises(RuntimeError) as ex:
knowledge.ask("CrateDB does not seem to provide an AUTOINCREMENT feature?")
assert ex.match("Claude API error:.*authentication_error.*invalid x-api-key")
import pytest
@pytest.mark.parametrize("backend", ["claude"])
def test_ask_claude_no_api_key(backend):
"""
Validate inquiry with Anthropic Claude, failing without an API key.
"""
try:
import claudette # noqa: F401
except ImportError:
pytest.skip("claudette package not installed")
with pytest.raises(ValueError) as ex:
CrateDbKnowledgeConversation(backend=backend)
assert ex.match(
"ANTHROPIC_API_KEY environment variable is required when using 'claude' backend"
)
@pytest.mark.parametrize("backend", ["claude"])
def test_ask_claude_invalid_api_key(backend, mocker):
"""
Validate inquiry with Anthropic Claude, failing when using an invalid API key.
"""
try:
import claudette # noqa: F401
except ImportError:
pytest.skip("claudette package not installed")
mocker.patch.dict("os.environ", {"ANTHROPIC_API_KEY": "foo"})
knowledge = CrateDbKnowledgeConversation(backend=backend)
with pytest.raises(RuntimeError) as ex:
knowledge.ask("CrateDB does not seem to provide an AUTOINCREMENT feature?")
assert ex.match("Claude API error:.*authentication_error.*invalid x-api-key")
🧰 Tools
🪛 GitHub Actions: Tests

[error] 55-55: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_no_api_key.


[error] 66-66: ImportError: The 'claudette' package is required when using the Claude backend in test_ask_claude_invalid_api_key.

🤖 Prompt for AI Agents (early access)
In tests/test_query.py around lines 50 to 69, the tests for the Claude backend
fail if the 'claudette' package is not installed. To fix this, add a check at
the start of each test to skip the test if 'claudette' is not importable, using
pytest's skip functionality. This ensures the tests only run when the required
dependency is present, preventing pipeline failures due to missing packages.

@amotl amotl marked this pull request as ready for review May 10, 2025 03:38
@amotl amotl merged commit 0b99d96 into main May 10, 2025
5 of 6 checks passed
@amotl amotl deleted the this-and-more branch May 10, 2025 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant