refactor: canonicalize mcp source id helpers
This commit is contained in:
@@ -247,8 +247,19 @@ def test_wf_mcp_broker_discovery_keeps_specs_adapter() -> None:
|
||||
assert broker_specs.__name__ == "specs_from_discovered_tools"
|
||||
|
||||
|
||||
def test_wf_mcp_broker_service_adapter_shim_reexports_wf_sources_mcp_adapter_helper() -> None:
|
||||
def test_wf_mcp_broker_service_adapter_shim_reexports_wf_sources_mcp_adapter_helper() -> (
|
||||
None
|
||||
):
|
||||
from wf_mcp.broker.service.adapters import require_adapter as compat_require_adapter
|
||||
from wf_sources_mcp.adapters import require_adapter
|
||||
|
||||
assert compat_require_adapter is require_adapter
|
||||
|
||||
|
||||
def test_wf_mcp_connection_id_helpers_reexport_wf_sources_mcp_ids() -> None:
|
||||
from wf_mcp.connections import parse_connection_id as compat_parse_connection_id
|
||||
from wf_mcp.shared.names import RESERVED_CONNECTION_IDS as compat_reserved_ids
|
||||
from wf_sources_mcp.ids import RESERVED_CONNECTION_IDS, parse_connection_id
|
||||
|
||||
assert compat_parse_connection_id is parse_connection_id
|
||||
assert compat_reserved_ids is RESERVED_CONNECTION_IDS
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from wf_sources_mcp.ids import (
|
||||
CONNECTION_ID_PATTERN,
|
||||
RESERVED_CONNECTION_IDS,
|
||||
parse_connection_id,
|
||||
validate_connection_id,
|
||||
)
|
||||
|
||||
|
||||
def test_validate_connection_id_returns_valid_id() -> None:
|
||||
assert validate_connection_id("github.work") == "github.work"
|
||||
assert validate_connection_id("my_source.default") == "my_source.default"
|
||||
|
||||
|
||||
def test_parse_connection_id_splits_provider_and_account() -> None:
|
||||
assert parse_connection_id("github.work") == ("github", "work")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source_id",
|
||||
["", "github", ".github.work", "github.", "github/work", "github work", "../bad"],
|
||||
)
|
||||
def test_validate_connection_id_rejects_unsafe_or_unqualified_ids(
|
||||
source_id: str,
|
||||
) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
validate_connection_id(source_id)
|
||||
|
||||
|
||||
def test_reserved_connection_ids_are_canonical_source_constants() -> None:
|
||||
assert "wf.admin" in RESERVED_CONNECTION_IDS
|
||||
assert "wf.mcp" in RESERVED_CONNECTION_IDS
|
||||
assert CONNECTION_ID_PATTERN.startswith("^")
|
||||
@@ -92,11 +92,15 @@ def test_wf_sources_mcp_does_not_import_old_sdk_protocol_modules() -> None:
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp SDK/runtime protocol modules:\n"
|
||||
@@ -117,11 +121,15 @@ def test_wf_sources_mcp_does_not_import_old_sdk_converter_module() -> None:
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp SDK converter module:\n"
|
||||
@@ -140,11 +148,15 @@ def test_wf_sources_mcp_does_not_import_old_broker_discovery_module() -> None:
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp broker discovery module:\n"
|
||||
@@ -163,11 +175,15 @@ def test_wf_sources_mcp_does_not_import_old_workflow_wrapper_module() -> None:
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp workflow wrapper module:\n"
|
||||
@@ -186,11 +202,15 @@ def test_wf_sources_mcp_does_not_import_old_broker_event_modules() -> None:
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp broker event modules:\n"
|
||||
@@ -209,13 +229,44 @@ def test_wf_sources_mcp_does_not_import_old_broker_service_adapter_module() -> N
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp broker service adapter module:\n"
|
||||
+ "\n".join(f" {violation}" for violation in violations)
|
||||
)
|
||||
|
||||
|
||||
def test_wf_sources_mcp_does_not_import_old_wf_mcp_id_modules() -> None:
|
||||
root = Path(__file__).resolve().parents[2] / "src" / "wf_sources_mcp"
|
||||
forbidden = {"wf_mcp.connections", "wf_mcp.shared.names"}
|
||||
violations: list[str] = []
|
||||
|
||||
for py_file in sorted(root.rglob("*.py")):
|
||||
rel = py_file.relative_to(root.parent)
|
||||
module = str(rel.with_suffix("")).replace("/", ".").replace("\\", ".")
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: from {node.module} import ..."
|
||||
)
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(
|
||||
f"{module}:{node.lineno}: import {alias.name}"
|
||||
)
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp source ID modules:\n"
|
||||
+ "\n".join(f" {violation}" for violation in violations)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user