Skip to content

test(tools): add unit tests for ClickHouseQueryActivity and ClickHous…#1025

Merged
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
Davidson3556:test/clickhouse-tool-unit-tests
Apr 28, 2026
Merged

test(tools): add unit tests for ClickHouseQueryActivity and ClickHous…#1025
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
Davidson3556:test/clickhouse-tool-unit-tests

Conversation

@Davidson3556
Copy link
Copy Markdown
Contributor

Closes #995

Describe the changes you have made in this PR -

Added unit tests for ClickHouseQueryActivityTool and ClickHouseSystemHealthTool, which previously had no test coverage. Created two new test files:

  • tests/tools/test_clickhouse_query_activity_tool.py — 13 tests
  • tests/tools/test_clickhouse_system_health_tool.py — 15 tests

Each file covers contract validation, is_available, extract_params, run happy path, and run error path. No live ClickHouse instance needed — integration calls are patched.

Demo/Screenshot for feature changes and bug fixes -

Screenshot 2026-04-28 at 00 11 19

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:
Both tools are function-based @tool decorated functions that delegate to app/integrations/clickhouse.py. The tests follow the same pattern used in similar tool tests in this repo (e.g. test_cloudwatch_logs_tool.py) — accessing __opensre_registered_tool__ for contract checks and patching the integration functions at the tool module level so no real database connection is needed. The system health test also covers the include_table_stats branching logic and verifies get_table_stats is never called when health returns unavailable.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

…eSystemHealth tools

Covers contract, is_available, extract_params, run happy path, and
run error path for both tools. No live ClickHouse instance required.

Closes Tracer-Cloud#995
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

Adds unit tests for ClickHouseQueryActivityTool and ClickHouseSystemHealthTool, two previously untested function-based @tool-decorated tools. The 28 new tests follow the project's established pattern — using BaseToolContract for contract assertions and patching integration functions at the tool module level — and require no live ClickHouse connection.

Confidence Score: 5/5

Safe to merge — all findings are P2 style suggestions that do not affect test correctness or production behaviour.

Both test files are structurally correct, follow the established project pattern, patch at the right module level, and provide solid coverage of the branching logic. The two P2 findings (missing assert_not_called in the include_table_stats=False case, and a missing edge-case test for table-stats failure) are quality improvements, not correctness defects, so they do not reduce the score below 5.

tests/tools/test_clickhouse_system_health_tool.py — the include_table_stats=False happy-path test could be hardened with a get_table_stats assert_not_called check.

Important Files Changed

Filename Overview
tests/tools/test_clickhouse_query_activity_tool.py 13 well-structured tests covering contract metadata, is_available (3 cases), extract_params (2 cases), happy path, and error path; patches are correctly placed at module level, following the project's established tool testing pattern.
tests/tools/test_clickhouse_system_health_tool.py 15 tests covering the system health tool including the include_table_stats branching; the include_table_stats=False happy-path test does not patch or assert-not-called for get_table_stats (unlike the unavailable-health case), and the get_table_stats failure-while-health-available edge case is untested.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Test Suite] --> B[TestClickHouseQueryActivityToolContract\nBaseToolContract mixin]
    A --> C[TestClickHouseSystemHealthToolContract\nBaseToolContract mixin]
    A --> D[Standalone test functions\nQueryActivity: 7 tests]
    A --> E[Standalone test functions\nSystemHealth: 10 tests]

    B --> B1[test_metadata_has_valid_name]
    B --> B2[test_metadata_has_valid_description]
    B --> B3[test_metadata_has_input_schema]
    B --> B4[test_metadata_has_valid_source]
    B --> B5[test_is_available_returns_bool]
    B --> B6[test_extract_params_returns_dict]

    D --> D1[is_available: 3 cases]
    D --> D2[extract_params: maps fields / defaults]
    D --> D3[run happy path]
    D --> D4[run error path]

    D3 --> P1[patch get_query_activity\nat tool module level]
    D4 --> P1

    E --> E1[is_available: 3 cases]
    E --> E2[extract_params: maps fields / defaults]
    E --> E3[run with table_stats=True\nhealth available]
    E --> E4[run with table_stats=False]
    E --> E5[run skips table_stats\nwhen health unavailable]
    E --> E6[run error path]

    E3 --> P2[patch get_system_health\n+ get_table_stats]
    E5 --> P3[patch both\nassert_not_called on table_stats]
    E4 --> P4[patch get_system_health only\nno assert_not_called ⚠️]
Loading

Reviews (1): Last reviewed commit: "test(tools): add unit tests for ClickHou..." | Re-trigger Greptile

Comment thread tests/tools/test_clickhouse_system_health_tool.py Outdated
Comment thread tests/tools/test_clickhouse_system_health_tool.py
@Davidson3556
Copy link
Copy Markdown
Contributor Author

Davidson3556 commented Apr 28, 2026

@Devesh36 @rrajan94 @yashksaini-coder kindly review

@muddlebee muddlebee merged commit f6df5c3 into Tracer-Cloud:main Apr 28, 2026
7 checks passed
@muddlebee
Copy link
Copy Markdown
Collaborator

thank you @Davidson3556 looks good

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.

Add unit tests for ClickHouse tools (QueryActivity, SystemHealth)

2 participants