Skip to content

Add unit tests for ClickHouse tools (QueryActivity, SystemHealth) #995

@yashksaini-coder

Description

@yashksaini-coder

Summary

ClickHouseQueryActivityTool and ClickHouseSystemHealthTool have no unit tests. An integration test at tests/integrations/test_clickhouse.py covers config validation, but tool-level behaviour is untested.

Context

Both tools delegate to app/integrations/clickhouse.py (get_query_activity, get_system_health) and use a shared config model ClickHouseConfig plus clickhouse_is_available and clickhouse_extract_params helpers. The ClickHouse client (clickhouse_connect) is imported lazily — no live instance needed in tests.

What to implement

Create two files:

  • tests/tools/test_clickhouse_query_activity_tool.py
  • tests/tools/test_clickhouse_system_health_tool.py

Each should cover:

  1. Contract test — inherit BaseToolContract from tests/tools/conftest.py
  2. is_availableTrue when sources["clickhouse"] has host and connection_verified: True; False otherwise
  3. extract_params — assert host, port, database, username, limit are mapped correctly from sources
  4. run happy path — patch app.integrations.clickhouse.get_query_activity (or get_system_health) with a MagicMock and assert the tool returns available: True with the expected structure
  5. run error path — patch to raise an exception (e.g., Exception("connection refused")) and verify a graceful error dict is returned

Acceptance criteria

  • Two test files under tests/tools/
  • Covers all scenarios above
  • make test-cov passes
  • make lint passes

References

  • Pattern: tests/tools/test_elasticsearch_logs_tool.py (closest analogue — similar structure)
  • Tool sources: app/tools/ClickHouseQueryActivityTool/, app/tools/ClickHouseSystemHealthTool/
  • Integration helpers: app/integrations/clickhouse.py
  • Existing integration test: tests/integrations/test_clickhouse.py

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomerstestsTest coverage and test organization

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions