4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
"""Tests for MySQLCurrentProcessesTool (function-based, @tool decorated)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
from unittest.mock import patch
|
|
|
|
from integrations.mysql.tools.mysql_current_processes_tool import get_mysql_current_processes
|
|
from tests.tools.conftest import BaseToolContract
|
|
|
|
|
|
class TestMySQLCurrentProcessesToolContract(BaseToolContract):
|
|
def get_tool_under_test(self) -> Any:
|
|
return get_mysql_current_processes.__opensre_registered_tool__
|
|
|
|
|
|
def test_metadata() -> None:
|
|
rt = get_mysql_current_processes.__opensre_registered_tool__
|
|
assert rt.name == "get_mysql_current_processes"
|
|
assert rt.source == "mysql"
|
|
|
|
|
|
def test_run_happy_path() -> None:
|
|
fake_result = {
|
|
"source": "mysql",
|
|
"available": True,
|
|
"threshold_seconds": 2,
|
|
"total_processes": 2,
|
|
"processes": [
|
|
{
|
|
"id": 42,
|
|
"user": "app_user",
|
|
"host": "192.168.1.100:54321",
|
|
"db": "application_db",
|
|
"command": "Query",
|
|
"time": 15,
|
|
"state": "Sending data",
|
|
"info": "SELECT * FROM large_table WHERE status = 'pending'",
|
|
},
|
|
{
|
|
"id": 43,
|
|
"user": "analytics",
|
|
"host": "10.0.0.5:11223",
|
|
"db": "application_db",
|
|
"command": "Query",
|
|
"time": 30,
|
|
"state": "Sorting result",
|
|
"info": "SELECT COUNT(*) FROM events GROUP BY user_id",
|
|
},
|
|
],
|
|
}
|
|
with patch(
|
|
"integrations.mysql.tools.mysql_current_processes_tool.get_current_processes",
|
|
return_value=fake_result,
|
|
):
|
|
result = get_mysql_current_processes(
|
|
host="localhost", database="testdb", threshold_seconds=2
|
|
)
|
|
assert result["threshold_seconds"] == 2
|
|
assert result["total_processes"] == 2
|
|
assert len(result["processes"]) == 2
|
|
assert result["processes"][0]["time"] == 15
|
|
|
|
|
|
def test_run_error_propagated() -> None:
|
|
with patch(
|
|
"integrations.mysql.tools.mysql_current_processes_tool.get_current_processes",
|
|
return_value={"source": "mysql", "available": False, "error": "access denied"},
|
|
):
|
|
result = get_mysql_current_processes(host="invalid", database="testdb")
|
|
assert "error" in result
|
|
assert result["available"] is False
|
|
|
|
|
|
def test_default_db_warning_present_when_database_omitted() -> None:
|
|
with patch(
|
|
"integrations.mysql.tools.mysql_current_processes_tool.get_current_processes",
|
|
return_value={"source": "mysql", "available": True, "processes": []},
|
|
):
|
|
result = get_mysql_current_processes(host="localhost")
|
|
assert "default_db_warning" in result
|
|
assert "mysql" in result["default_db_warning"]
|
|
|
|
|
|
def test_no_default_db_warning_when_database_provided() -> None:
|
|
with patch(
|
|
"integrations.mysql.tools.mysql_current_processes_tool.get_current_processes",
|
|
return_value={"source": "mysql", "available": True, "processes": []},
|
|
):
|
|
result = get_mysql_current_processes(host="localhost", database="mydb")
|
|
assert "default_db_warning" not in result
|