Skip to content
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

tests: tool runner #327

Merged
merged 6 commits into from
Dec 4, 2024
Merged

tests: tool runner #327

merged 6 commits into from
Dec 4, 2024

Conversation

maciejmajek
Copy link
Member

@maciejmajek maciejmajek commented Nov 28, 2024

Purpose

Tests are good.

Proposed Changes

  • test_tool_runner
  • test_tool_runner_multimodal

Issues

  • Links to relevant issues

Testing

  • How was it tested, what were the results?

Summary by CodeRabbit

  • New Features

    • Enhanced logging capabilities during testing with detailed command line output.
    • Implemented performance monitoring for tool execution with execution time logging.
    • Introduced a new tool function, get_image, for retrieving images from a camera.
  • Bug Fixes

    • Improved error logging for validation errors, including detailed JSON representations.
  • Tests

    • Added a new test suite for the ToolRunner class to validate tool interactions and outputs.

@maciejmajek maciejmajek changed the base branch from feat/debugging-tools to development November 28, 2024 20:01
@maciejmajek maciejmajek changed the base branch from development to feat/debugging-tools November 28, 2024 20:20
@maciejmajek
Copy link
Member Author

@CodeRabbit full review

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes in this pull request include modifications to the pyproject.toml file to enhance logging configurations for testing, specifically enabling command line logging at the DEBUG level. Additionally, the ToolRunner class in src/rai/rai/agents/tool_runner.py has been updated to implement a timing mechanism for tool execution and improved logging for output and validation errors. A new test file, tests/core/test_tool_runner.py, has been introduced to validate the functionality of the ToolRunner class, including tests for a new tool function that retrieves images.

Changes

File Change Summary
pyproject.toml Added log_cli = true and log_cli_level = "DEBUG" under [tool.pytest.ini_options].
src/rai/rai/agents/tool_runner.py Added timing mechanism using time.perf_counter() in _func, enhanced logging for execution time and output, improved validation error logging.
tests/core/test_tool_runner.py Introduced tests for ToolRunner, including get_image function and validation of message types in test_tool_runner and test_tool_runner_multimodal.

Suggested reviewers

  • adamdbrw

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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.

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 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.

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: 4

🧹 Outside diff range and nitpick comments (4)
pyproject.toml (1)

90-91: Consider environment-specific logging configuration.

While enabling CLI logging with DEBUG level is helpful for local development and debugging, it might generate excessive output in CI/CD environments.

Consider making the logging level configurable via environment variables:

-log_cli = true
-log_cli_level = "DEBUG"
+log_cli = "true"
+log_cli_level = "${LOG_LEVEL:DEBUG}"

This way, you can adjust the logging level (e.g., to INFO or WARNING) in CI/CD environments without modifying the configuration file.

tests/core/test_tool_runner.py (1)

26-31: Consider improving test data management and error handling

The get_image tool function has several areas for improvement:

  1. Move test image to a dedicated test fixtures directory
  2. Add error handling for missing image file
  3. Enhance docstring with parameters and return type information

Consider refactoring like this:

 @tool(response_format="content_and_artifact")
 def get_image():
-    """Get an image from the camera"""
+    """Simulate getting an image from a camera for testing purposes.
+
+    Returns:
+        tuple: A tuple containing:
+            - str: Status message
+            - dict: Dictionary with 'images' key containing preprocessed image data
+    """
+    test_image_path = "tests/fixtures/test_image.png"
+    try:
+        return "Image retrieved", {
+            "images": [preprocess_image(test_image_path)]
+        }
+    except FileNotFoundError:
+        raise FileNotFoundError(f"Test image not found at {test_image_path}")
src/rai/rai/agents/tool_runner.py (2)

Line range hint 76-94: Standardize error logging levels

While the error handling is comprehensive, consider standardizing the logging levels:

  • Use ERROR level for unexpected exceptions
  • Use WARNING level for validation errors
  • Use INFO level for expected operational events
  • Use DEBUG level for detailed output
-                self.logger.info(error_message)
+                self.logger.warning(error_message)
-                self.logger.info(f'Error in "{call["name"]}", error: {e}')
+                self.logger.error(f'Error in "{call["name"]}", error: {e}')

Line range hint 47-49: Consider implementing a proper task queueing mechanism

The current implementation forces max_concurrency=1 with a TODO comment. This could become a bottleneck as the system scales. Consider:

  1. Implementing a proper task queue (e.g., using asyncio or a dedicated queue system)
  2. Adding configurable concurrency limits
  3. Implementing priority queuing for different types of tools

Would you like help designing a more scalable task queueing solution?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d697931 and 8a9426e.

📒 Files selected for processing (3)
  • pyproject.toml (1 hunks)
  • src/rai/rai/agents/tool_runner.py (2 hunks)
  • tests/core/test_tool_runner.py (1 hunks)
🔇 Additional comments (3)
pyproject.toml (1)

90-91: Verify impact on CI pipeline logs.

The DEBUG level logging might significantly increase the size of CI pipeline logs.

✅ Verification successful

Setting DEBUG level logging is acceptable

The CI workflow uses poetry run pytest without any specific logging configuration flags. The DEBUG level logging set in pyproject.toml will only affect the local test output and won't impact CI logs, as GitHub Actions automatically manages and truncates large logs. Additionally, detailed logging during CI can be beneficial for debugging test failures.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the pytest configuration in CI workflow files

# Look for pytest configuration in CI workflow files
fd -e yml -e yaml . .github/workflows --exec grep -l 'pytest'

# Look for existing log level configurations in CI
fd -e yml -e yaml . .github/workflows --exec grep -i 'log.*level'

Length of output: 163


Script:

#!/bin/bash
# Check the content of the CI workflow file to understand how pytest is configured
cat .github/workflows/poetry-test.yml

Length of output: 1538

src/rai/rai/agents/tool_runner.py (2)

18-18: LGTM: Import placement follows PEP 8

The addition of the time module import is correctly placed in the import section, following the standard library imports.


69-72: LGTM: Proper implementation of performance timing

The implementation uses time.perf_counter() which is the recommended way to measure performance in Python as it provides monotonic timing with the highest available resolution.

@maciejmajek maciejmajek force-pushed the feat/debugging-tools branch 4 times, most recently from d1e9a9b to eb4cb6c Compare December 4, 2024 11:57
Base automatically changed from feat/debugging-tools to development December 4, 2024 12:01
Copy link
Member

@boczekbartek boczekbartek left a comment

Choose a reason for hiding this comment

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

@maciejmajek
Nice! I left 1 comment - please have a look

@maciejmajek maciejmajek merged commit 1b52bb3 into development Dec 4, 2024
5 checks passed
@maciejmajek maciejmajek deleted the test/tool-runner branch December 4, 2024 14:46
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.

2 participants