recce-nightly 1.10.0.20250629__py3-none-any.whl → 1.25.0.20251112a2066__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- recce/VERSION +1 -1
- recce/__init__.py +5 -0
- recce/adapter/dbt_adapter/__init__.py +116 -74
- recce/artifact.py +76 -3
- recce/cli.py +665 -69
- recce/config.py +2 -2
- recce/connect_to_cloud.py +1 -1
- recce/core.py +3 -3
- recce/data/404.html +1 -22
- recce/data/__next.__PAGE__.txt +10 -0
- recce/data/__next._full.txt +23 -0
- recce/data/__next._index.txt +8 -0
- recce/data/__next._tree.txt +12 -0
- recce/data/_next/static/6LypcDXgyuSaiSCrsmUub/_buildManifest.js +11 -0
- recce/data/_next/static/6LypcDXgyuSaiSCrsmUub/_clientMiddlewareManifest.json +1 -0
- recce/data/_next/static/chunks/0a2b2dd4b57049c2.js +1 -0
- recce/data/_next/static/chunks/19c10d219a6a21ff.js +1 -0
- recce/data/_next/static/chunks/24fd885c7180a612.js +1 -0
- recce/data/_next/static/chunks/27e66b2eab4adc32.js +19 -0
- recce/data/_next/static/chunks/71f88fcc615bf282.js +1 -0
- recce/data/_next/static/chunks/917619ab62a32388.js +1 -0
- recce/data/_next/static/chunks/93ba5a62932b704f.js +4 -0
- recce/data/_next/static/chunks/a43a2a5e06d5a92b.js +1 -0
- recce/data/_next/static/chunks/a6c78b24bd8b84fc.js +1 -0
- recce/data/_next/static/chunks/b2610ba997ff8c4f.js +110 -0
- recce/data/_next/static/chunks/ba2d87265a68599d.css +2 -0
- recce/data/_next/static/chunks/c117fd1c1382dd83.js +11 -0
- recce/data/_next/static/chunks/c9425ca46eebdde9.js +1 -0
- recce/data/_next/static/chunks/cc8a9eadba012be0.css +6 -0
- recce/data/_next/static/chunks/e124bccf574a3361.css +1 -0
- recce/data/_next/static/chunks/e392ad92847c3e17.js +1 -0
- recce/data/_next/static/chunks/e4ce95efe88dae79.js +11 -0
- recce/data/_next/static/chunks/e69c777814fea6ed.js +2 -0
- recce/data/_next/static/chunks/turbopack-21cfd73037ff57ab.js +3 -0
- recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
- recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
- recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
- recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
- recce/data/_not-found/__next._full.txt +17 -0
- recce/data/_not-found/__next._index.txt +8 -0
- recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
- recce/data/_not-found/__next._not-found.txt +4 -0
- recce/data/_not-found/__next._tree.txt +10 -0
- recce/data/_not-found.html +1 -0
- recce/data/_not-found.txt +17 -0
- recce/data/auth_callback.html +1 -1
- recce/data/index.html +1 -27
- recce/data/index.txt +23 -8
- recce/event/__init__.py +9 -8
- recce/event/collector.py +6 -2
- recce/event/track.py +10 -0
- recce/github.py +1 -1
- recce/mcp_server.py +632 -0
- recce/models/types.py +23 -2
- recce/pull_request.py +1 -1
- recce/run.py +23 -16
- recce/server.py +165 -11
- recce/state/__init__.py +31 -0
- recce/state/cloud.py +632 -0
- recce/state/const.py +26 -0
- recce/state/local.py +56 -0
- recce/state/state.py +119 -0
- recce/state/state_loader.py +174 -0
- recce/summary.py +2 -1
- recce/tasks/dataframe.py +59 -2
- recce/tasks/rowcount.py +4 -1
- recce/tasks/schema.py +4 -1
- recce/tasks/valuediff.py +1 -1
- recce/util/api_token.py +11 -2
- recce/util/breaking.py +9 -0
- recce/util/cll.py +1 -2
- recce/util/io.py +2 -2
- recce/util/lineage.py +14 -18
- recce/util/perf_tracking.py +85 -0
- recce/util/recce_cloud.py +229 -5
- recce/yaml/__init__.py +2 -2
- recce_cloud/__init__.py +15 -0
- recce_cloud/api/__init__.py +17 -0
- recce_cloud/api/base.py +104 -0
- recce_cloud/api/client.py +150 -0
- recce_cloud/api/exceptions.py +26 -0
- recce_cloud/api/factory.py +63 -0
- recce_cloud/api/github.py +72 -0
- recce_cloud/api/gitlab.py +78 -0
- recce_cloud/artifact.py +57 -0
- recce_cloud/ci_providers/__init__.py +9 -0
- recce_cloud/ci_providers/base.py +82 -0
- recce_cloud/ci_providers/detector.py +147 -0
- recce_cloud/ci_providers/github_actions.py +136 -0
- recce_cloud/ci_providers/gitlab_ci.py +130 -0
- recce_cloud/cli.py +303 -0
- recce_cloud/upload.py +213 -0
- {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/METADATA +31 -27
- recce_nightly-1.25.0.20251112a2066.dist-info/RECORD +178 -0
- {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/top_level.txt +1 -0
- tests/adapter/dbt_adapter/test_dbt_cll.py +68 -17
- tests/recce_cloud/__init__.py +0 -0
- tests/recce_cloud/test_ci_providers.py +351 -0
- tests/recce_cloud/test_cli.py +372 -0
- tests/recce_cloud/test_client.py +273 -0
- tests/recce_cloud/test_platform_clients.py +279 -0
- tests/test_cli.py +106 -3
- tests/test_cli_mcp_optional.py +45 -0
- tests/test_cloud_listing_cli.py +324 -0
- tests/test_core.py +147 -0
- tests/test_mcp_server.py +332 -0
- tests/test_server.py +6 -6
- tests/test_summary.py +14 -6
- recce/data/_next/static/Mrb9CZ3toH6Q8xrzNzCrg/_buildManifest.js +0 -1
- recce/data/_next/static/chunks/181-acc61ddada3bc0ca.js +0 -43
- recce/data/_next/static/chunks/1bff33f1-1ef85cf5e658a751.js +0 -1
- recce/data/_next/static/chunks/217-879a84d70f7a907c.js +0 -2
- recce/data/_next/static/chunks/29e3cc0d-60045b2e47aa3916.js +0 -1
- recce/data/_next/static/chunks/36e1c10d-8e7be4a6c1f6ab2d.js +0 -1
- recce/data/_next/static/chunks/3998a672-03adacad07b346ac.js +0 -1
- recce/data/_next/static/chunks/3a92ee20-1081c360214f9602.js +0 -1
- recce/data/_next/static/chunks/41-f30276c289169376.js +0 -9
- recce/data/_next/static/chunks/450c323b-fd94e7ffaa4a5efa.js +0 -1
- recce/data/_next/static/chunks/47d8844f-929aed9b1c73a905.js +0 -1
- recce/data/_next/static/chunks/608-3b079b544e5d5f5e.js +0 -15
- recce/data/_next/static/chunks/6dc81886-adbfa45836061d79.js +0 -1
- recce/data/_next/static/chunks/7a8a3e83-edf6dc64b5d5f0a5.js +0 -1
- recce/data/_next/static/chunks/7f27ae6c-d5f0438edd5c2a5b.js +0 -1
- recce/data/_next/static/chunks/86730205-cfb14e3f051bab35.js +0 -1
- recce/data/_next/static/chunks/8d700b6a.8bb140898499c512.js +0 -1
- recce/data/_next/static/chunks/92-68460b15fe448f33.js +0 -1
- recce/data/_next/static/chunks/9746af58-a42b7d169cacadf0.js +0 -1
- recce/data/_next/static/chunks/a30376cd-de84559016d7e133.js +0 -1
- recce/data/_next/static/chunks/app/_not-found/page-01ed58b7f971d311.js +0 -1
- recce/data/_next/static/chunks/app/layout-292f035bb0d2a98e.js +0 -1
- recce/data/_next/static/chunks/app/page-598f8acc82179d01.js +0 -1
- recce/data/_next/static/chunks/b63b1b3f-4282bdcf459e075c.js +0 -1
- recce/data/_next/static/chunks/bbda5537-9ec25eb1dd62348a.js +0 -1
- recce/data/_next/static/chunks/c132bf7d-08cb668a789d6afd.js +0 -1
- recce/data/_next/static/chunks/ce84277d-2e5d1d46910cf052.js +0 -1
- recce/data/_next/static/chunks/febdd86e-c6b525341634b860.js +0 -54
- recce/data/_next/static/chunks/fee69bc6-2dbccaf9b90474e6.js +0 -1
- recce/data/_next/static/chunks/framework-ded83d71b51ce901.js +0 -1
- recce/data/_next/static/chunks/main-app-39061b0166c47f55.js +0 -1
- recce/data/_next/static/chunks/main-b5b3ae20a1405261.js +0 -1
- recce/data/_next/static/chunks/pages/_app-437c455677d62394.js +0 -1
- recce/data/_next/static/chunks/pages/_error-e7650df18ca04bde.js +0 -1
- recce/data/_next/static/chunks/webpack-7b49d5ba7e3a434d.js +0 -1
- recce/data/_next/static/css/17a96168e3a9db13.css +0 -1
- recce/data/_next/static/css/35c6679a098e1e34.css +0 -1
- recce/data/_next/static/css/951e2e0eea2d4a5b.css +0 -14
- recce/data/_next/static/css/a2b12b4ba4227f0a.css +0 -3
- recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
- recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
- recce/state.py +0 -786
- recce_nightly-1.10.0.20250629.dist-info/RECORD +0 -154
- tests/test_state.py +0 -134
- /recce/data/_next/static/{Mrb9CZ3toH6Q8xrzNzCrg → 6LypcDXgyuSaiSCrsmUub}/_ssgManifest.js +0 -0
- /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
- /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
- /recce/data/_next/static/media/{reload-image.79aabb7d.svg → reload-image.7aa931c7.svg} +0 -0
- {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/WHEEL +0 -0
- {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/entry_points.txt +0 -0
- {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/licenses/LICENSE +0 -0
tests/test_mcp_server.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
from unittest.mock import MagicMock, patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
# Skip all tests in this module if mcp is not available
|
|
6
|
+
pytest.importorskip("mcp")
|
|
7
|
+
|
|
8
|
+
from recce.core import RecceContext # noqa: E402
|
|
9
|
+
from recce.mcp_server import RecceMCPServer, run_mcp_server # noqa: E402
|
|
10
|
+
from recce.models.types import LineageDiff # noqa: E402
|
|
11
|
+
from recce.server import RecceServerMode # noqa: E402
|
|
12
|
+
from recce.tasks.profile import ProfileDiffTask # noqa: E402
|
|
13
|
+
from recce.tasks.query import QueryDiffTask, QueryTask # noqa: E402
|
|
14
|
+
from recce.tasks.rowcount import RowCountDiffTask # noqa: E402
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def mcp_server():
|
|
19
|
+
"""Fixture to create a RecceMCPServer instance for testing"""
|
|
20
|
+
mock_context = MagicMock(spec=RecceContext)
|
|
21
|
+
return RecceMCPServer(mock_context), mock_context
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestRecceMCPServer:
|
|
25
|
+
"""Test cases for the RecceMCPServer class"""
|
|
26
|
+
|
|
27
|
+
def test_server_initialization(self, mcp_server):
|
|
28
|
+
"""Test that the MCP server initializes correctly"""
|
|
29
|
+
server, mock_context = mcp_server
|
|
30
|
+
assert server.context == mock_context
|
|
31
|
+
assert server.server is not None
|
|
32
|
+
assert server.server.name == "recce"
|
|
33
|
+
|
|
34
|
+
@pytest.mark.asyncio
|
|
35
|
+
async def test_tool_lineage_diff(self, mcp_server):
|
|
36
|
+
"""Test the lineage_diff tool"""
|
|
37
|
+
server, mock_context = mcp_server
|
|
38
|
+
# Mock the lineage diff response
|
|
39
|
+
mock_lineage_diff = MagicMock(spec=LineageDiff)
|
|
40
|
+
mock_lineage_diff.model_dump.return_value = {
|
|
41
|
+
"base": {
|
|
42
|
+
"nodes": {
|
|
43
|
+
"model.project.model_a": {
|
|
44
|
+
"name": "model_a",
|
|
45
|
+
"resource_type": "model",
|
|
46
|
+
"config": {"materialized": "view"},
|
|
47
|
+
},
|
|
48
|
+
"model.project.model_b": {
|
|
49
|
+
"name": "model_b",
|
|
50
|
+
"resource_type": "model",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
"parent_map": {
|
|
54
|
+
"model.project.model_a": [],
|
|
55
|
+
"model.project.model_b": ["model.project.model_a"],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
"current": {
|
|
59
|
+
"nodes": {
|
|
60
|
+
"model.project.model_a": {
|
|
61
|
+
"name": "model_a",
|
|
62
|
+
"resource_type": "model",
|
|
63
|
+
"config": {"materialized": "view"},
|
|
64
|
+
},
|
|
65
|
+
"model.project.model_b": {
|
|
66
|
+
"name": "model_b",
|
|
67
|
+
"resource_type": "model",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
"parent_map": {
|
|
71
|
+
"model.project.model_a": [],
|
|
72
|
+
"model.project.model_b": ["model.project.model_a"],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
"diff": {
|
|
76
|
+
"model.project.model_a": {"change_status": "modified"},
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
mock_context.get_lineage_diff.return_value = mock_lineage_diff
|
|
80
|
+
mock_context.adapter.select_nodes.return_value = {
|
|
81
|
+
"model.project.model_a",
|
|
82
|
+
"model.project.model_b",
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# Execute the method
|
|
86
|
+
result = await server._tool_lineage_diff({})
|
|
87
|
+
|
|
88
|
+
# Verify the result structure
|
|
89
|
+
assert "nodes" in result
|
|
90
|
+
assert "parent_map" in result
|
|
91
|
+
|
|
92
|
+
# Verify nodes is a DataFrame dict with columns and data
|
|
93
|
+
nodes = result["nodes"]
|
|
94
|
+
assert "columns" in nodes
|
|
95
|
+
assert "data" in nodes
|
|
96
|
+
|
|
97
|
+
# Verify data is a list with 2 rows
|
|
98
|
+
assert isinstance(nodes["data"], list)
|
|
99
|
+
assert len(nodes["data"]) == 2
|
|
100
|
+
|
|
101
|
+
mock_context.get_lineage_diff.assert_called_once()
|
|
102
|
+
mock_context.adapter.select_nodes.assert_called()
|
|
103
|
+
|
|
104
|
+
@pytest.mark.asyncio
|
|
105
|
+
async def test_tool_schema_diff(self, mcp_server):
|
|
106
|
+
"""Test the schema_diff tool"""
|
|
107
|
+
server, mock_context = mcp_server
|
|
108
|
+
# Mock the lineage diff response with schema information
|
|
109
|
+
mock_lineage_diff = MagicMock(spec=LineageDiff)
|
|
110
|
+
mock_lineage_diff.model_dump.return_value = {
|
|
111
|
+
"base": {
|
|
112
|
+
"nodes": {
|
|
113
|
+
"model.project.model_a": {
|
|
114
|
+
"name": "model_a",
|
|
115
|
+
"resource_type": "model",
|
|
116
|
+
"columns": {
|
|
117
|
+
"id": {"name": "id", "type": "integer"},
|
|
118
|
+
"name": {"name": "name", "type": "text"},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
"current": {
|
|
124
|
+
"nodes": {
|
|
125
|
+
"model.project.model_a": {
|
|
126
|
+
"name": "model_a",
|
|
127
|
+
"resource_type": "model",
|
|
128
|
+
"columns": {
|
|
129
|
+
"id": {"name": "id", "type": "integer"},
|
|
130
|
+
"name": {"name": "name", "type": "text"},
|
|
131
|
+
"age": {"name": "age", "type": "integer"},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
mock_context.get_lineage_diff.return_value = mock_lineage_diff
|
|
138
|
+
mock_context.adapter.select_nodes.return_value = {"model.project.model_a"}
|
|
139
|
+
|
|
140
|
+
# Execute the method
|
|
141
|
+
result = await server._tool_schema_diff({})
|
|
142
|
+
|
|
143
|
+
# Verify the result is a DataFrame dict with columns and data
|
|
144
|
+
assert "columns" in result
|
|
145
|
+
assert "data" in result
|
|
146
|
+
assert "limit" in result
|
|
147
|
+
assert "more" in result
|
|
148
|
+
|
|
149
|
+
# Verify limit and more fields
|
|
150
|
+
assert result["limit"] == 100
|
|
151
|
+
assert isinstance(result["more"], bool)
|
|
152
|
+
assert isinstance(result["data"], list)
|
|
153
|
+
# Verify the data contains the added column
|
|
154
|
+
assert len(result["data"]) > 0
|
|
155
|
+
|
|
156
|
+
mock_context.get_lineage_diff.assert_called_once()
|
|
157
|
+
|
|
158
|
+
@pytest.mark.asyncio
|
|
159
|
+
async def test_tool_row_count_diff(self, mcp_server):
|
|
160
|
+
"""Test the row_count_diff tool"""
|
|
161
|
+
server, _ = mcp_server
|
|
162
|
+
# Mock the task execution
|
|
163
|
+
mock_result = {"results": [{"node_id": "model.project.my_model", "base": 100, "current": 105, "diff": 5}]}
|
|
164
|
+
|
|
165
|
+
with patch.object(RowCountDiffTask, "execute", return_value=mock_result):
|
|
166
|
+
result = await server._tool_row_count_diff({"node_names": ["my_model"]})
|
|
167
|
+
|
|
168
|
+
# Verify the result
|
|
169
|
+
assert result == mock_result
|
|
170
|
+
assert "results" in result
|
|
171
|
+
|
|
172
|
+
@pytest.mark.asyncio
|
|
173
|
+
async def test_tool_query(self, mcp_server):
|
|
174
|
+
"""Test the query tool"""
|
|
175
|
+
server, _ = mcp_server
|
|
176
|
+
# Mock the task execution
|
|
177
|
+
mock_result = MagicMock()
|
|
178
|
+
mock_result.model_dump.return_value = {
|
|
179
|
+
"columns": ["id", "name"],
|
|
180
|
+
"data": [[1, "Alice"], [2, "Bob"]],
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
with patch.object(QueryTask, "execute", return_value=mock_result):
|
|
184
|
+
result = await server._tool_query({"sql_template": "SELECT * FROM {{ ref('my_model') }}", "base": False})
|
|
185
|
+
|
|
186
|
+
# Verify the result
|
|
187
|
+
assert "columns" in result
|
|
188
|
+
assert "data" in result
|
|
189
|
+
mock_result.model_dump.assert_called_once_with(mode="json")
|
|
190
|
+
|
|
191
|
+
@pytest.mark.asyncio
|
|
192
|
+
async def test_tool_query_with_base_flag(self, mcp_server):
|
|
193
|
+
"""Test the query tool with base environment flag"""
|
|
194
|
+
server, _ = mcp_server
|
|
195
|
+
mock_result = {"columns": ["id"], "data": [[1]]}
|
|
196
|
+
|
|
197
|
+
with patch.object(QueryTask, "execute", return_value=mock_result) as mock_execute:
|
|
198
|
+
with patch.object(QueryTask, "__init__", return_value=None):
|
|
199
|
+
task = QueryTask(params={"sql_template": "SELECT 1"})
|
|
200
|
+
task.is_base = True
|
|
201
|
+
task.execute = mock_execute
|
|
202
|
+
|
|
203
|
+
result = await server._tool_query({"sql_template": "SELECT 1", "base": True})
|
|
204
|
+
|
|
205
|
+
# Verify base flag was set (would need to inspect task creation)
|
|
206
|
+
assert result == mock_result
|
|
207
|
+
|
|
208
|
+
@pytest.mark.asyncio
|
|
209
|
+
async def test_tool_query_diff(self, mcp_server):
|
|
210
|
+
"""Test the query_diff tool"""
|
|
211
|
+
server, _ = mcp_server
|
|
212
|
+
# Mock the task execution
|
|
213
|
+
mock_result = MagicMock()
|
|
214
|
+
mock_result.model_dump.return_value = {
|
|
215
|
+
"diff": {
|
|
216
|
+
"added": [[3, "Charlie"]],
|
|
217
|
+
"removed": [[1, "Alice"]],
|
|
218
|
+
"modified": [],
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
with patch.object(QueryDiffTask, "execute", return_value=mock_result):
|
|
223
|
+
result = await server._tool_query_diff(
|
|
224
|
+
{
|
|
225
|
+
"sql_template": "SELECT * FROM {{ ref('my_model') }}",
|
|
226
|
+
"primary_keys": ["id"],
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
# Verify the result
|
|
231
|
+
assert "diff" in result
|
|
232
|
+
mock_result.model_dump.assert_called_once_with(mode="json")
|
|
233
|
+
|
|
234
|
+
@pytest.mark.asyncio
|
|
235
|
+
async def test_tool_profile_diff(self, mcp_server):
|
|
236
|
+
"""Test the profile_diff tool"""
|
|
237
|
+
server, _ = mcp_server
|
|
238
|
+
# Mock the task execution
|
|
239
|
+
mock_result = MagicMock()
|
|
240
|
+
mock_result.model_dump.return_value = {
|
|
241
|
+
"columns": {
|
|
242
|
+
"id": {
|
|
243
|
+
"base": {"min": 1, "max": 100, "avg": 50.5},
|
|
244
|
+
"current": {"min": 1, "max": 105, "avg": 53.0},
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
with patch.object(ProfileDiffTask, "execute", return_value=mock_result):
|
|
250
|
+
result = await server._tool_profile_diff({"model": "my_model", "columns": ["id"]})
|
|
251
|
+
|
|
252
|
+
# Verify the result
|
|
253
|
+
assert "columns" in result
|
|
254
|
+
mock_result.model_dump.assert_called_once_with(mode="json")
|
|
255
|
+
|
|
256
|
+
@pytest.mark.asyncio
|
|
257
|
+
async def test_error_handling(self, mcp_server):
|
|
258
|
+
"""Test error handling in tool execution"""
|
|
259
|
+
server, mock_context = mcp_server
|
|
260
|
+
# Make get_lineage_diff raise an exception
|
|
261
|
+
mock_context.get_lineage_diff.side_effect = Exception("Test error")
|
|
262
|
+
|
|
263
|
+
# The method should raise the exception
|
|
264
|
+
with pytest.raises(Exception, match="Test error"):
|
|
265
|
+
await server._tool_lineage_diff({})
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class TestRunMCPServer:
|
|
269
|
+
"""Test cases for the run_mcp_server function"""
|
|
270
|
+
|
|
271
|
+
@pytest.mark.asyncio
|
|
272
|
+
@patch("recce.mcp_server.load_context")
|
|
273
|
+
@patch.object(RecceMCPServer, "run")
|
|
274
|
+
async def test_run_mcp_server(self, mock_run, mock_load_context):
|
|
275
|
+
"""Test the run_mcp_server entry point"""
|
|
276
|
+
# Mock the context
|
|
277
|
+
mock_context = MagicMock(spec=RecceContext)
|
|
278
|
+
mock_load_context.return_value = mock_context
|
|
279
|
+
|
|
280
|
+
# Mock the server run method
|
|
281
|
+
mock_run.return_value = None
|
|
282
|
+
|
|
283
|
+
# Run the server
|
|
284
|
+
await run_mcp_server(project_dir="/test/path")
|
|
285
|
+
|
|
286
|
+
# Verify context was loaded with correct kwargs
|
|
287
|
+
mock_load_context.assert_called_once_with(project_dir="/test/path")
|
|
288
|
+
|
|
289
|
+
# Verify server was run
|
|
290
|
+
mock_run.assert_called_once()
|
|
291
|
+
|
|
292
|
+
@pytest.mark.asyncio
|
|
293
|
+
@patch("recce.mcp_server.load_context")
|
|
294
|
+
async def test_run_mcp_server_context_error(self, mock_load_context):
|
|
295
|
+
"""Test run_mcp_server handles context loading errors"""
|
|
296
|
+
# Make load_context raise an exception
|
|
297
|
+
mock_load_context.side_effect = FileNotFoundError("manifest.json not found")
|
|
298
|
+
|
|
299
|
+
# The function should raise the exception
|
|
300
|
+
with pytest.raises(FileNotFoundError):
|
|
301
|
+
await run_mcp_server()
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_mcp_cli_command_exists():
|
|
305
|
+
"""Test that the mcp-server CLI command is registered"""
|
|
306
|
+
from recce.cli import cli
|
|
307
|
+
|
|
308
|
+
# Check that mcp_server is in the CLI commands
|
|
309
|
+
commands = [cmd.name for cmd in cli.commands.values()]
|
|
310
|
+
assert "mcp_server" in commands or "mcp-server" in commands
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
class TestMCPServerModes:
|
|
314
|
+
"""Test cases for MCP server mode functionality"""
|
|
315
|
+
|
|
316
|
+
def test_server_mode_default(self):
|
|
317
|
+
"""Test that server mode is the default when not specified"""
|
|
318
|
+
mock_context = MagicMock(spec=RecceContext)
|
|
319
|
+
server = RecceMCPServer(mock_context)
|
|
320
|
+
|
|
321
|
+
# Default mode should be server
|
|
322
|
+
assert server.mode == RecceServerMode.server
|
|
323
|
+
|
|
324
|
+
def test_non_server_mode_restricts_tools(self):
|
|
325
|
+
"""Test that non-server mode (preview, read-only) restricts diff tools"""
|
|
326
|
+
mock_context = MagicMock(spec=RecceContext)
|
|
327
|
+
server = RecceMCPServer(mock_context, mode=RecceServerMode.preview)
|
|
328
|
+
|
|
329
|
+
# Verify mode is set correctly
|
|
330
|
+
assert server.mode == RecceServerMode.preview
|
|
331
|
+
# Verify it's not server mode
|
|
332
|
+
assert server.mode != RecceServerMode.server
|
tests/test_server.py
CHANGED
|
@@ -31,9 +31,9 @@ def test_health():
|
|
|
31
31
|
|
|
32
32
|
def test_stateless(dbt_test_helper):
|
|
33
33
|
context = default_context()
|
|
34
|
-
from recce.state import
|
|
34
|
+
from recce.state import FileStateLoader
|
|
35
35
|
|
|
36
|
-
context.state_loader =
|
|
36
|
+
context.state_loader = FileStateLoader()
|
|
37
37
|
client = TestClient(app)
|
|
38
38
|
response = client.get("/api/info")
|
|
39
39
|
assert response.status_code == 200
|
|
@@ -44,9 +44,9 @@ def test_stateless(dbt_test_helper):
|
|
|
44
44
|
|
|
45
45
|
def test_file_mode(dbt_test_helper):
|
|
46
46
|
context = default_context()
|
|
47
|
-
from recce.state import
|
|
47
|
+
from recce.state import FileStateLoader
|
|
48
48
|
|
|
49
|
-
context.state_loader =
|
|
49
|
+
context.state_loader = FileStateLoader(state_file="/tmp/recce_state.json")
|
|
50
50
|
client = TestClient(app)
|
|
51
51
|
response = client.get("/api/info")
|
|
52
52
|
assert response.status_code == 200
|
|
@@ -63,9 +63,9 @@ def test_saveas_and_rename(dbt_test_helper, temp_folder):
|
|
|
63
63
|
state_file3 = os.path.join(temp_folder, "recce_state3.json")
|
|
64
64
|
os.makedirs(os.path.join(temp_folder, "dir.json"))
|
|
65
65
|
|
|
66
|
-
from recce.state import
|
|
66
|
+
from recce.state import FileStateLoader
|
|
67
67
|
|
|
68
|
-
context.state_loader =
|
|
68
|
+
context.state_loader = FileStateLoader(state_file=state_file)
|
|
69
69
|
client = TestClient(app)
|
|
70
70
|
|
|
71
71
|
response = client.post("/api/save", json={"filename": "recce_state2.json"})
|
tests/test_summary.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
3
4
|
|
|
4
5
|
from recce.adapter.dbt_adapter import DbtAdapter, DbtVersion, load_manifest
|
|
5
6
|
from recce.core import RecceContext, set_default_context
|
|
@@ -13,11 +14,12 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
13
14
|
base_manifest_dir = os.path.join(current_dir, "data", "manifest", "base")
|
|
14
15
|
pr2_manifest_dir = os.path.join(current_dir, "data", "manifest", "pr2") # Pull Request 2l
|
|
15
16
|
|
|
16
|
-
dbt_version = DbtVersion()
|
|
17
|
-
|
|
18
17
|
|
|
19
|
-
@unittest.skipIf(dbt_version < "1.8.1", "Dbt version is less than 1.8.1")
|
|
20
18
|
def test_generate_summary_metadata():
|
|
19
|
+
dbt_version = DbtVersion()
|
|
20
|
+
if dbt_version < "1.8.1":
|
|
21
|
+
pytest.skip("Dbt version is less than 1.8.1")
|
|
22
|
+
|
|
21
23
|
manifest = load_manifest(path=os.path.join(current_dir, "manifest.json"))
|
|
22
24
|
assert manifest is not None
|
|
23
25
|
dbt_adapter = DbtAdapter(curr_manifest=manifest)
|
|
@@ -35,8 +37,11 @@ def test_generate_summary_metadata():
|
|
|
35
37
|
generate_summary_metadata(curr_lineage, base_lineage)
|
|
36
38
|
|
|
37
39
|
|
|
38
|
-
@unittest.skipIf(dbt_version < "v1.8.1", "Dbt version is less than 1.8.1")
|
|
39
40
|
def test_build_lineage_graph():
|
|
41
|
+
dbt_version = DbtVersion()
|
|
42
|
+
if dbt_version < "1.8.1":
|
|
43
|
+
pytest.skip("Dbt version is less than 1.8.1")
|
|
44
|
+
|
|
40
45
|
base_manifest = load_manifest(path=os.path.join(base_manifest_dir, "manifest.json"))
|
|
41
46
|
curr_manifest = load_manifest(path=os.path.join(pr2_manifest_dir, "manifest.json"))
|
|
42
47
|
dbt_adapter = DbtAdapter(curr_manifest=curr_manifest, base_manifest=base_manifest)
|
|
@@ -51,8 +56,11 @@ def test_build_lineage_graph():
|
|
|
51
56
|
assert len(lineage_graph.modified_set) == 3
|
|
52
57
|
|
|
53
58
|
|
|
54
|
-
@unittest.skipIf(dbt_version < "v1.8.1", "Dbt version is less than 1.8.1")
|
|
55
59
|
def test_generate_mermaid_lineage_graph():
|
|
60
|
+
dbt_version = DbtVersion()
|
|
61
|
+
if dbt_version < "1.8.1":
|
|
62
|
+
pytest.skip("Dbt version is less than 1.8.1")
|
|
63
|
+
|
|
56
64
|
set_default_context(RecceContext())
|
|
57
65
|
base_manifest = load_manifest(path=os.path.join(base_manifest_dir, "manifest.json"))
|
|
58
66
|
curr_manifest = load_manifest(path=os.path.join(pr2_manifest_dir, "manifest.json"))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
self.__BUILD_MANIFEST={__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/_error":["static/chunks/pages/_error-e7650df18ca04bde.js"],sortedPages:["/_app","/_error"]},self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
|