test: add unit tests for ClickHouse QueryActivity and SystemHealth tools#1008
test: add unit tests for ClickHouse QueryActivity and SystemHealth tools#1008kespineira wants to merge 2 commits intoTracer-Cloud:mainfrom
Conversation
Greptile SummaryAdds 40 new unit tests across three files covering both ClickHouse tool wrappers ( Confidence Score: 5/5Safe to merge — tests are correct and comprehensive with no logic errors. All findings are P2 (minor style/clarity issue around a dead mock attribute). No incorrect assertions, missing error path coverage, or mismatched implementation/test logic was found. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Test
participant Tool as get_clickhouse_query_activity /<br/>get_clickhouse_system_health
participant Integration as app.integrations.clickhouse
participant Client as ClickHouse Client
Test->>Tool: call(host, port, database, ...)
Tool->>Integration: ClickHouseConfig(...)
Tool->>Integration: get_query_activity(config, limit) / get_system_health(config)
Integration->>Integration: config.is_configured?
alt not configured
Integration-->>Tool: {available: false, error: Not configured.}
else configured
Integration->>Client: _get_client(config)
Integration->>Client: client.query(SQL)
alt success
Client-->>Integration: QueryResult
Integration->>Integration: parse rows / truncate queries
Integration-->>Tool: {available: true, queries/metrics/...}
else exception
Client-->>Integration: raise Exception
end
Integration->>Client: client.close() [finally]
Integration-->>Tool: {available: false, error: str(err)}
end
Tool-->>Test: result dict
Reviews (1): Last reviewed commit: "test: add unit tests for ClickHouse Quer..." | Re-trigger Greptile |
fb68ec6 to
7ac3fc1
Compare
Add comprehensive unit tests for both ClickHouse function-based tools (get_clickhouse_query_activity, get_clickhouse_system_health) and extend integration tests for clickhouse helpers (is_available, extract_params, get_query_activity, get_system_health, get_table_stats). Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
7ac3fc1 to
74e9239
Compare
Fixes #995
Describe the changes you have made in this PR -
Added comprehensive unit tests for both ClickHouse function-based tools (
get_clickhouse_query_activity,get_clickhouse_system_health) and extended integration tests for ClickHouse helper functions.Files changed:
tests/tools/test_clickhouse_query_activity_tool.py— new file (7 tests)tests/tools/test_clickhouse_system_health_tool.py— new file (10 tests)tests/integrations/test_clickhouse.py— extended with 23 new testsTest coverage includes:
is_availabletests — verifiesclickhouse_is_availablereturns correct boolean based on config presenceextract_paramstests — verifies parameter extraction and validation with missing/invalid fieldsruntests — happy path with mocked integration helpers returning sample data, and error paths with mocked exceptionsget_clickhouse_system_healthreturnstable_statswhen query succeedsIntegration helper tests (23 new):
clickhouse_is_available— configured vs unconfigured, missing fieldsclickhouse_extract_params— valid params, missing host, missing passwordget_query_activity— happy path, error propagation, unconfiguredget_system_health— happy path, error propagation, unconfiguredget_table_stats— happy path, error propagation, unconfiguredTotal: 63 ClickHouse tests (30 tool tests + 33 integration tests)
Demo/Screenshot for feature changes and bug fixes -
Tests pass locally:
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
The ClickHouse tools use the lightweight
@tooldecorator pattern (function-based), not the class-basedBaseToolpattern. This means:Tool metadata is stored on the
__opensre_registered_tool__attribute set by the@tooldecorator, not on class attributes likename/description.is_availablefor both tools delegates toclickhouse_is_availablefromapp/integrations/clickhouse.py, which checks if a ClickHouse config entry exists in the agent state. I mock this at the tool module level where it's imported.extract_paramsdelegates toclickhouse_extract_params, which validates that required fields (host,password) are present. I test both valid and invalid parameter scenarios.runcalls integration helpers (get_query_activity/get_system_health) internally. I mock these at the tool module import path (e.g.,app.tools.ClickHouseQueryActivityTool.get_query_activity), NOT at the source moduleapp.integrations.clickhouse, because the tools import them directly.Key gotcha:
ClickHouseConfigis a dataclass with instance fields, not class attributes. Sopatch.object(ClickHouseConfig, "max_results", ...)won't work — instead I passmax_resultsas a parameter or mock the config creation.I considered using class-based BaseTool tests as the pattern, but the function-based pattern from
test_postgresql_server_status_tool.pywas a better match since both ClickHouse tools use@tooldecorators.Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.