70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
"""Unit regression tests for Issue #708: Connected-but-namespaces-missing detection and attachment safety."""
|
|
|
|
import mcp_namespace_health
|
|
|
|
|
|
def test_assess_connected_namespace_attachment_success():
|
|
connected = ["gitea-author", "gitea-reviewer", "gitea-merger"]
|
|
attached = ["gitea-author", "gitea-reviewer", "gitea-merger"]
|
|
res = mcp_namespace_health.assess_connected_namespace_attachment(
|
|
connected_servers=connected,
|
|
attached_session_namespaces=attached,
|
|
)
|
|
assert res["success"] is True
|
|
assert res["attachment_healthy"] is True
|
|
assert res["discovery_status"] == "namespaces_attached"
|
|
assert res["error_type"] is None
|
|
assert res["missing_namespaces"] == []
|
|
assert res["exact_next_action"] == "None; session tool namespaces attached."
|
|
|
|
|
|
def test_assess_connected_namespace_attachment_missing():
|
|
connected = ["gitea-author", "gitea-reviewer", "gitea-merger"]
|
|
attached = ["gitea-author"]
|
|
res = mcp_namespace_health.assess_connected_namespace_attachment(
|
|
connected_servers=connected,
|
|
attached_session_namespaces=attached,
|
|
)
|
|
assert res["success"] is False
|
|
assert res["attachment_healthy"] is False
|
|
assert res["discovery_status"] == "connected_but_namespaces_missing"
|
|
assert res["error_type"] == "mcp_connected_namespaces_missing"
|
|
assert "gitea-reviewer" in res["missing_namespaces"]
|
|
assert "gitea-merger" in res["missing_namespaces"]
|
|
assert "Reconnect the IDE/client MCP session" in res["exact_next_action"]
|
|
|
|
|
|
def test_assess_connected_namespace_attachment_disconnected():
|
|
res = mcp_namespace_health.assess_connected_namespace_attachment(
|
|
connected_servers=[],
|
|
attached_session_namespaces=[],
|
|
)
|
|
assert res["success"] is False
|
|
assert res["attachment_healthy"] is False
|
|
assert res["discovery_status"] == "disconnected"
|
|
|
|
|
|
def test_proof_of_connected_vs_attached_mapping():
|
|
connected = ["gitea-author", "gitea-reviewer"]
|
|
attached = ["gitea-author"]
|
|
res = mcp_namespace_health.assess_connected_namespace_attachment(
|
|
connected_servers=connected,
|
|
attached_session_namespaces=attached,
|
|
)
|
|
proof = res["proof_of_connected_vs_attached"]
|
|
assert proof["gitea-author"] == {"connected": True, "attached": True}
|
|
assert proof["gitea-reviewer"] == {"connected": True, "attached": False}
|
|
|
|
|
|
def test_unsafe_fallback_policy_enforcement():
|
|
res = mcp_namespace_health.assess_connected_namespace_attachment(
|
|
connected_servers=["gitea-author"],
|
|
attached_session_namespaces=[],
|
|
)
|
|
policy = res["unsafe_fallback_policy"]
|
|
assert "Workflow Safety Hard Stop (#708)" in policy
|
|
assert "direct imports" in policy
|
|
assert "API mutations" in policy
|
|
assert "profile hopping" in policy
|
|
assert "session-state overrides" in policy
|