From ba7bad929b4d5ff61edf251883f07219d05612bc Mon Sep 17 00:00:00 2001 From: codeasier Date: Sat, 8 Aug 2026 22:16:13 +0800 Subject: [PATCH] fix(query): drop unused device_id parameter from leak_detection template The leak_detection template advertised a device_id parameter, but the SQL body only references min_size and the executor-injected device_block_table. QueryService and QueryExecutor resolve the target device from explicit --device, focus, or the first discovered device before rendering, so any params.device_id was a no-op leaked through CLI, Python API, and MCP template metadata. - Remove parameters.device_id from leak_detection.yaml. - Sync the en/zh querying.md parameter lists. - Add regression assertions that the template exposes only min_size and that CLI/MCP template-info agree on that surface. Fixes #90 --- .../templates/business/leak_detection.yaml | 5 ---- tests/query/test_registry.py | 10 +++++++ tests/test_contract_cli_mcp.py | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/pt_snap_cli/query/templates/business/leak_detection.yaml b/src/pt_snap_cli/query/templates/business/leak_detection.yaml index bb33987..89f6e3e 100644 --- a/src/pt_snap_cli/query/templates/business/leak_detection.yaml +++ b/src/pt_snap_cli/query/templates/business/leak_detection.yaml @@ -12,11 +12,6 @@ queries: default: 0 required: false description: Minimum leak size in bytes - device_id: - type: int - default: null - required: false - description: Device ID to query query: | SELECT id, address, size, allocEventId FROM {{ device_block_table }} diff --git a/tests/query/test_registry.py b/tests/query/test_registry.py index c5e2df3..0d42a96 100644 --- a/tests/query/test_registry.py +++ b/tests/query/test_registry.py @@ -209,6 +209,16 @@ def test_list_by_category_business(self): assert "test_biz" in result assert "leak_detection" in result + def test_leak_detection_template_exposes_only_min_size(self): + """Regression for issue #90: ``leak_detection`` must not advertise + ``device_id`` as a parameter because device selection is owned by the + top-level ``--device`` flag, Python ``device_id`` argument, and focus. + """ + info = get_template_info("leak_detection") + assert info is not None + assert "min_size" in info["parameters"] + assert "device_id" not in info["parameters"] + def test_list_by_category_with_details(self): register_query( QueryTemplate( diff --git a/tests/test_contract_cli_mcp.py b/tests/test_contract_cli_mcp.py index 1e2b5da..c01c8a3 100644 --- a/tests/test_contract_cli_mcp.py +++ b/tests/test_contract_cli_mcp.py @@ -262,6 +262,32 @@ def test_template_info_contract_matches_cli_and_mcp_semantics( assert cli_info == mcp_info +def test_leak_detection_template_does_not_advertise_device_id( + contract_db: Path, mcp_server: ModuleType +) -> None: + """Regression for issue #90: ``device_id`` is resolved from focus / --device, + not from template parameters, so the template metadata must not expose it. + """ + cli_result = runner.invoke( + app, + ["query", str(contract_db), "--template-info", "leak_detection"], + ) + assert cli_result.exit_code == 0 + + server = _set_mcp_focus(mcp_server, contract_db) + cli_info = _normalize_cli_template_info(cli_result.stdout) + mcp_info = server.get_template_info("leak_detection") + + for info in (cli_info, mcp_info): + assert info is not None + assert "parameters" in info + assert "device_id" not in info["parameters"], ( + "leak_detection must not advertise device_id; use --device / " + "API device_id / focus selection instead." + ) + assert "min_size" in info["parameters"] + + def test_query_execution_contract_matches_cli_and_mcp_semantics( contract_db: Path, mcp_server: ModuleType ) -> None: