@malloy-publisher/server 0.0.195 → 0.0.196
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.
- package/dist/app/api-doc.yaml +213 -214
- package/dist/app/assets/EnvironmentPage-1j6QDWAy.js +1 -0
- package/dist/app/assets/HomePage-DMop21VG.js +1 -0
- package/dist/app/assets/MainPage-BbE8ETz1.js +2 -0
- package/dist/app/assets/ModelPage-D2jvfe3t.js +1 -0
- package/dist/app/assets/PackagePage-BbnhGoD3.js +1 -0
- package/dist/app/assets/{RouteError-DefbDO7F.js → RouteError-D3LGEZ3i.js} +1 -1
- package/dist/app/assets/WorkbookPage-DttVIj4u.js +1 -0
- package/dist/app/assets/{core-BrfQApxh.es-DnvCX4oH.js → core-w79IMXAG.es-Bd0UlzOL.js} +1 -1
- package/dist/app/assets/{index-Bu0ub036.js → index-5K9YjIxF.js} +117 -117
- package/dist/app/assets/{index-CkzK3JIl.js → index-C513UodQ.js} +1 -1
- package/dist/app/assets/{index-CoA6HIGS.js → index-DIgzgp69.js} +1 -1
- package/dist/app/assets/{index.umd-B6Ms2PpL.js → index.umd-BMeMPq_9.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/server.mjs +1976 -1322
- package/package.json +2 -2
- package/publisher.config.json +2 -2
- package/src/config.spec.ts +181 -66
- package/src/config.ts +68 -47
- package/src/controller/compile.controller.ts +10 -7
- package/src/controller/connection.controller.ts +79 -58
- package/src/controller/database.controller.ts +10 -7
- package/src/controller/manifest.controller.ts +23 -14
- package/src/controller/materialization.controller.ts +14 -14
- package/src/controller/model.controller.ts +35 -20
- package/src/controller/package.controller.ts +83 -49
- package/src/controller/query.controller.ts +11 -8
- package/src/controller/watch-mode.controller.ts +35 -29
- package/src/errors.ts +2 -2
- package/src/mcp/error_messages.ts +2 -2
- package/src/mcp/handler_utils.ts +23 -20
- package/src/mcp/mcp_constants.ts +1 -1
- package/src/mcp/prompts/handlers.ts +3 -3
- package/src/mcp/prompts/prompt_service.ts +5 -5
- package/src/mcp/prompts/utils.ts +12 -12
- package/src/mcp/resource_metadata.ts +3 -3
- package/src/mcp/resources/environment_resource.ts +187 -0
- package/src/mcp/resources/model_resource.ts +19 -17
- package/src/mcp/resources/notebook_resource.ts +13 -13
- package/src/mcp/resources/package_resource.ts +30 -27
- package/src/mcp/resources/query_resource.ts +15 -10
- package/src/mcp/resources/source_resource.ts +10 -10
- package/src/mcp/resources/view_resource.ts +11 -11
- package/src/mcp/server.ts +16 -14
- package/src/mcp/tools/discovery_tools.ts +67 -49
- package/src/mcp/tools/execute_query_tool.ts +14 -14
- package/src/server-old.ts +1119 -0
- package/src/server.ts +191 -159
- package/src/service/connection.spec.ts +158 -133
- package/src/service/connection.ts +42 -39
- package/src/service/connection_config.spec.ts +13 -11
- package/src/service/connection_config.ts +28 -19
- package/src/service/connection_service.spec.ts +63 -43
- package/src/service/connection_service.ts +106 -89
- package/src/service/{project.ts → environment.ts} +92 -77
- package/src/service/{project_compile.spec.ts → environment_compile.spec.ts} +1 -1
- package/src/service/{project_store.spec.ts → environment_store.spec.ts} +99 -83
- package/src/service/{project_store.ts → environment_store.ts} +373 -327
- package/src/service/manifest_service.spec.ts +15 -15
- package/src/service/manifest_service.ts +26 -21
- package/src/service/materialization_service.spec.ts +93 -59
- package/src/service/materialization_service.ts +71 -62
- package/src/service/materialized_table_gc.spec.ts +15 -15
- package/src/service/materialized_table_gc.ts +3 -3
- package/src/service/model.ts +4 -4
- package/src/service/package.spec.ts +2 -2
- package/src/service/package.ts +23 -21
- package/src/service/resolve_environment.ts +15 -0
- package/src/storage/DatabaseInterface.ts +34 -25
- package/src/storage/StorageManager.mock.ts +3 -3
- package/src/storage/StorageManager.ts +64 -28
- package/src/storage/duckdb/ConnectionRepository.ts +13 -11
- package/src/storage/duckdb/DuckDBConnection.ts +1 -1
- package/src/storage/duckdb/DuckDBManifestStore.ts +6 -6
- package/src/storage/duckdb/DuckDBRepository.ts +47 -47
- package/src/storage/duckdb/{ProjectRepository.ts → EnvironmentRepository.ts} +35 -35
- package/src/storage/duckdb/ManifestRepository.ts +21 -20
- package/src/storage/duckdb/MaterializationRepository.ts +31 -28
- package/src/storage/duckdb/PackageRepository.ts +11 -11
- package/src/storage/duckdb/manifest_store.spec.ts +2 -2
- package/src/storage/duckdb/schema.ts +61 -20
- package/src/storage/ducklake/DuckLakeManifestStore.ts +20 -11
- package/tests/fixtures/publisher.config.json +1 -1
- package/tests/harness/e2e.ts +1 -1
- package/tests/harness/mcp_test_setup.ts +12 -24
- package/tests/harness/mocks.ts +10 -8
- package/tests/harness/rest_e2e.ts +2 -2
- package/tests/integration/legacy_routes/legacy_routes.integration.spec.ts +259 -0
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +4 -4
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +28 -49
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +39 -47
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +1 -1
- package/tests/unit/duckdb/attached_databases.test.ts +51 -33
- package/tests/unit/duckdb/legacy_schema_migration.test.ts +194 -0
- package/tests/unit/ducklake/ducklake.test.ts +24 -22
- package/tests/unit/mcp/prompt_happy.test.ts +8 -8
- package/dist/app/assets/HomePage-DbZS0N7G.js +0 -1
- package/dist/app/assets/MainPage-CBuWkbmr.js +0 -2
- package/dist/app/assets/ModelPage-Bt37smot.js +0 -1
- package/dist/app/assets/PackagePage-DLZe50WG.js +0 -1
- package/dist/app/assets/ProjectPage-FQTEPXP4.js +0 -1
- package/dist/app/assets/WorkbookPage-CkAo16ar.js +0 -1
- package/src/mcp/resources/project_resource.ts +0 -184
- package/src/service/resolve_project.ts +0 -13
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
|
|
3
|
+
// TODO: Remove this during projects cleanup
|
|
4
|
+
/**
|
|
5
|
+
* Smoke tests for the legacy `/api/v0/projects/...` REST surface registered
|
|
6
|
+
* by `server-old.ts`. These routes exist purely to keep pre-rename SDK
|
|
7
|
+
* clients (e.g. `@malloydata/db-publisher`) working after the
|
|
8
|
+
* projects→environments rename.
|
|
9
|
+
*
|
|
10
|
+
* One test per route group: projects CRUD, packages, connections, models,
|
|
11
|
+
* notebooks, databases, queries, materializations, manifest. The
|
|
12
|
+
* materialization test additionally asserts the response field rename
|
|
13
|
+
* (`projectId` not `environmentId`). `/status` is no longer in the legacy
|
|
14
|
+
* surface — both old and new clients hit the single `/api/v0/status`
|
|
15
|
+
* handler in server.ts, which returns `environments`.
|
|
16
|
+
*
|
|
17
|
+
* This file is intentionally separate from the regular integration suite so
|
|
18
|
+
* it can be deleted in one motion when legacy support is dropped.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
22
|
+
import path from "path";
|
|
23
|
+
import { fileURLToPath } from "url";
|
|
24
|
+
import { RestE2EEnv, startRestE2E } from "../../harness/rest_e2e";
|
|
25
|
+
|
|
26
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = path.dirname(__filename);
|
|
28
|
+
|
|
29
|
+
// Use a distinct project name so this suite doesn't collide with the
|
|
30
|
+
// materialization integration suite (which also uses "test-project") if
|
|
31
|
+
// they ever run in the same DB instance.
|
|
32
|
+
const PROJECT_NAME = "legacy-routes-test-project";
|
|
33
|
+
const PACKAGE_NAME = "persist-test";
|
|
34
|
+
|
|
35
|
+
describe("Legacy /api/v0/projects/* REST routes (E2E)", () => {
|
|
36
|
+
let env: (RestE2EEnv & { stop(): Promise<void> }) | null = null;
|
|
37
|
+
let baseUrl: string;
|
|
38
|
+
|
|
39
|
+
beforeAll(async () => {
|
|
40
|
+
env = await startRestE2E();
|
|
41
|
+
baseUrl = env.baseUrl;
|
|
42
|
+
|
|
43
|
+
// Create the test environment via the LEGACY route — proves POST
|
|
44
|
+
// /projects works end-to-end.
|
|
45
|
+
const fixtureDir = path.resolve(__dirname, "../../fixtures/persist-test");
|
|
46
|
+
const createRes = await fetch(`${baseUrl}/api/v0/projects`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
name: PROJECT_NAME,
|
|
51
|
+
packages: [{ name: PACKAGE_NAME, location: fixtureDir }],
|
|
52
|
+
connections: [],
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
if (!createRes.ok) {
|
|
56
|
+
const body = await createRes.text();
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Failed to create test project via legacy route (${createRes.status}): ${body}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Wait for the package to finish loading via the legacy GET path.
|
|
63
|
+
const deadline = Date.now() + 30_000;
|
|
64
|
+
let pkgReady = false;
|
|
65
|
+
while (!pkgReady && Date.now() < deadline) {
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(
|
|
68
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}`,
|
|
69
|
+
);
|
|
70
|
+
if (res.ok) {
|
|
71
|
+
pkgReady = true;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// not ready yet
|
|
76
|
+
}
|
|
77
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
78
|
+
}
|
|
79
|
+
if (!pkgReady) {
|
|
80
|
+
throw new Error("Test package did not become available in time");
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
afterAll(async () => {
|
|
85
|
+
if (baseUrl) {
|
|
86
|
+
try {
|
|
87
|
+
// Clean up via the legacy DELETE route.
|
|
88
|
+
await fetch(`${baseUrl}/api/v0/projects/${PROJECT_NAME}`, {
|
|
89
|
+
method: "DELETE",
|
|
90
|
+
});
|
|
91
|
+
} catch {
|
|
92
|
+
// best-effort cleanup
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
await env?.stop();
|
|
96
|
+
env = null;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("projects CRUD", () => {
|
|
100
|
+
it("GET /projects lists environments under the legacy URL", async () => {
|
|
101
|
+
const res = await fetch(`${baseUrl}/api/v0/projects`);
|
|
102
|
+
expect(res.status).toBe(200);
|
|
103
|
+
const body = (await res.json()) as Array<{ name?: string }>;
|
|
104
|
+
expect(Array.isArray(body)).toBe(true);
|
|
105
|
+
expect(body.some((e) => e.name === PROJECT_NAME)).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("GET /projects/:projectName returns the project", async () => {
|
|
109
|
+
const res = await fetch(`${baseUrl}/api/v0/projects/${PROJECT_NAME}`);
|
|
110
|
+
expect(res.status).toBe(200);
|
|
111
|
+
const body = (await res.json()) as { name?: string };
|
|
112
|
+
expect(body.name).toBe(PROJECT_NAME);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("packages", () => {
|
|
117
|
+
it("GET /projects/:projectName/packages returns the package list", async () => {
|
|
118
|
+
const res = await fetch(
|
|
119
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages`,
|
|
120
|
+
);
|
|
121
|
+
expect(res.status).toBe(200);
|
|
122
|
+
const body = (await res.json()) as Array<{ name?: string }>;
|
|
123
|
+
expect(Array.isArray(body)).toBe(true);
|
|
124
|
+
expect(body.some((p) => p.name === PACKAGE_NAME)).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("GET /projects/:projectName/packages/:packageName returns the package", async () => {
|
|
128
|
+
const res = await fetch(
|
|
129
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}`,
|
|
130
|
+
);
|
|
131
|
+
expect(res.status).toBe(200);
|
|
132
|
+
const body = (await res.json()) as { name?: string };
|
|
133
|
+
expect(body.name).toBe(PACKAGE_NAME);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("connections", () => {
|
|
138
|
+
it("GET /projects/:projectName/connections returns 200 (may be empty)", async () => {
|
|
139
|
+
const res = await fetch(
|
|
140
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/connections`,
|
|
141
|
+
);
|
|
142
|
+
expect(res.status).toBe(200);
|
|
143
|
+
const body = await res.json();
|
|
144
|
+
expect(Array.isArray(body)).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("models", () => {
|
|
149
|
+
it("GET /projects/:projectName/packages/:packageName/models returns the model list", async () => {
|
|
150
|
+
const res = await fetch(
|
|
151
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/models`,
|
|
152
|
+
);
|
|
153
|
+
expect(res.status).toBe(200);
|
|
154
|
+
const body = await res.json();
|
|
155
|
+
expect(Array.isArray(body)).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("notebooks", () => {
|
|
160
|
+
it("GET /projects/:projectName/packages/:packageName/notebooks returns 200", async () => {
|
|
161
|
+
const res = await fetch(
|
|
162
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/notebooks`,
|
|
163
|
+
);
|
|
164
|
+
expect(res.status).toBe(200);
|
|
165
|
+
const body = await res.json();
|
|
166
|
+
expect(Array.isArray(body)).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("databases", () => {
|
|
171
|
+
it("GET /projects/:projectName/packages/:packageName/databases returns 200", async () => {
|
|
172
|
+
const res = await fetch(
|
|
173
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/databases`,
|
|
174
|
+
);
|
|
175
|
+
expect(res.status).toBe(200);
|
|
176
|
+
const body = await res.json();
|
|
177
|
+
expect(Array.isArray(body)).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("queries", () => {
|
|
182
|
+
it("POST /projects/:projectName/packages/:packageName/models/.../query reaches the handler", async () => {
|
|
183
|
+
// Hit the route with a bogus model name. We only need to prove the
|
|
184
|
+
// legacy URL is wired up to the controller — a structured JSON
|
|
185
|
+
// error (not Express's HTML fall-through 404) is sufficient signal.
|
|
186
|
+
const res = await fetch(
|
|
187
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/models/does-not-exist.malloy/query`,
|
|
188
|
+
{
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: { "Content-Type": "application/json" },
|
|
191
|
+
body: JSON.stringify({ query: "run: nothing" }),
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
expect(res.status).toBeGreaterThanOrEqual(400);
|
|
195
|
+
expect(res.status).toBeLessThan(600);
|
|
196
|
+
// Controller errors come back as JSON with a `message` field.
|
|
197
|
+
// An unhandled Express 404 returns HTML — that would fail here.
|
|
198
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
199
|
+
expect(typeof body.message).toBe("string");
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("materializations", () => {
|
|
204
|
+
it("GET list and POST create return 'projectId' (not 'environmentId') under the legacy URL", async () => {
|
|
205
|
+
const listRes = await fetch(
|
|
206
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/materializations`,
|
|
207
|
+
);
|
|
208
|
+
expect(listRes.status).toBe(200);
|
|
209
|
+
const list = (await listRes.json()) as unknown;
|
|
210
|
+
expect(Array.isArray(list)).toBe(true);
|
|
211
|
+
|
|
212
|
+
// Create one so we can assert the field rename on a populated payload.
|
|
213
|
+
const createRes = await fetch(
|
|
214
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/materializations`,
|
|
215
|
+
{
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: { "Content-Type": "application/json" },
|
|
218
|
+
body: JSON.stringify({ autoLoadManifest: true }),
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
expect(createRes.status).toBe(201);
|
|
222
|
+
const created = (await createRes.json()) as Record<string, unknown>;
|
|
223
|
+
|
|
224
|
+
// Legacy contract: materialization payloads expose `projectId`, not
|
|
225
|
+
// `environmentId`. This is the response remapper in server-old.ts.
|
|
226
|
+
expect(created).toHaveProperty("projectId");
|
|
227
|
+
expect(created).not.toHaveProperty("environmentId");
|
|
228
|
+
|
|
229
|
+
const id = created.id as string;
|
|
230
|
+
// Best-effort cleanup so we don't leak a PENDING materialization
|
|
231
|
+
// into other tests. We don't poll-to-terminal; the suite teardown
|
|
232
|
+
// of the project will mop up.
|
|
233
|
+
try {
|
|
234
|
+
await fetch(
|
|
235
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/materializations/${id}?action=stop`,
|
|
236
|
+
{ method: "POST" },
|
|
237
|
+
);
|
|
238
|
+
await fetch(
|
|
239
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/materializations/${id}`,
|
|
240
|
+
{ method: "DELETE" },
|
|
241
|
+
);
|
|
242
|
+
} catch {
|
|
243
|
+
// ignore
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe("manifest", () => {
|
|
249
|
+
it("GET /projects/:projectName/packages/:packageName/manifest returns 200 or a structured 4xx", async () => {
|
|
250
|
+
const res = await fetch(
|
|
251
|
+
`${baseUrl}/api/v0/projects/${PROJECT_NAME}/packages/${PACKAGE_NAME}/manifest`,
|
|
252
|
+
);
|
|
253
|
+
// Without a built materialization the manifest may be empty/404 —
|
|
254
|
+
// we only assert the legacy URL reaches the handler, not 404 from
|
|
255
|
+
// Express's catch-all.
|
|
256
|
+
expect([200, 400, 404]).toContain(res.status);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -10,7 +10,7 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
|
|
11
11
|
const PROJECT_NAME = "test-project";
|
|
12
12
|
const PACKAGE_NAME = "persist-test";
|
|
13
|
-
const API = `/api/v0/
|
|
13
|
+
const API = `/api/v0/environments/${PROJECT_NAME}/packages/${PACKAGE_NAME}`;
|
|
14
14
|
|
|
15
15
|
describe("Materialization & Manifest REST API (E2E)", () => {
|
|
16
16
|
let env: (RestE2EEnv & { stop(): Promise<void> }) | null = null;
|
|
@@ -23,7 +23,7 @@ describe("Materialization & Manifest REST API (E2E)", () => {
|
|
|
23
23
|
// Create the test project via the REST API using an absolute
|
|
24
24
|
// path to the fixture so it works regardless of SERVER_ROOT.
|
|
25
25
|
const fixtureDir = path.resolve(__dirname, "../../fixtures/persist-test");
|
|
26
|
-
const createRes = await fetch(`${baseUrl}/api/v0/
|
|
26
|
+
const createRes = await fetch(`${baseUrl}/api/v0/environments`, {
|
|
27
27
|
method: "POST",
|
|
28
28
|
headers: { "Content-Type": "application/json" },
|
|
29
29
|
body: JSON.stringify({
|
|
@@ -45,7 +45,7 @@ describe("Materialization & Manifest REST API (E2E)", () => {
|
|
|
45
45
|
while (!pkgReady && Date.now() < deadline) {
|
|
46
46
|
try {
|
|
47
47
|
const res = await fetch(
|
|
48
|
-
`${baseUrl}/api/v0/
|
|
48
|
+
`${baseUrl}/api/v0/environments/${PROJECT_NAME}/packages/${PACKAGE_NAME}`,
|
|
49
49
|
);
|
|
50
50
|
if (res.ok) {
|
|
51
51
|
pkgReady = true;
|
|
@@ -65,7 +65,7 @@ describe("Materialization & Manifest REST API (E2E)", () => {
|
|
|
65
65
|
// Tear down the test project, then the HTTP server.
|
|
66
66
|
if (baseUrl) {
|
|
67
67
|
try {
|
|
68
|
-
await fetch(`${baseUrl}/api/v0/
|
|
68
|
+
await fetch(`${baseUrl}/api/v0/environments/${PROJECT_NAME}`, {
|
|
69
69
|
method: "DELETE",
|
|
70
70
|
});
|
|
71
71
|
} catch {
|
|
@@ -19,11 +19,11 @@ import {
|
|
|
19
19
|
} from "../../harness/mcp_test_setup";
|
|
20
20
|
|
|
21
21
|
// --- Test Suite ---
|
|
22
|
-
describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
22
|
+
describe.serial("MCP Tool Handlers (E2E Integration)", () => {
|
|
23
23
|
let env: McpE2ETestEnvironment | null = null;
|
|
24
24
|
let mcpClient: Client;
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const ENVIRONMENT_NAME = "malloy-samples";
|
|
27
27
|
const PACKAGE_NAME = "faa";
|
|
28
28
|
|
|
29
29
|
beforeAll(async () => {
|
|
@@ -47,7 +47,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
47
47
|
const result = await mcpClient.callTool({
|
|
48
48
|
name: "malloy_executeQuery",
|
|
49
49
|
arguments: {
|
|
50
|
-
|
|
50
|
+
environmentName: ENVIRONMENT_NAME,
|
|
51
51
|
packageName: PACKAGE_NAME,
|
|
52
52
|
modelPath: "flights.malloy",
|
|
53
53
|
query: "run: flights->{ aggregate: c is count() }",
|
|
@@ -95,7 +95,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
95
95
|
async () => {
|
|
96
96
|
if (!env) throw new Error("Test environment not initialized");
|
|
97
97
|
const params = {
|
|
98
|
-
|
|
98
|
+
environmentName: ENVIRONMENT_NAME,
|
|
99
99
|
packageName: PACKAGE_NAME,
|
|
100
100
|
modelPath: "flights.malloy",
|
|
101
101
|
sourceName: "flights", // Added sourceName
|
|
@@ -140,7 +140,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
140
140
|
async () => {
|
|
141
141
|
if (!env) throw new Error("Test environment not initialized");
|
|
142
142
|
const params = {
|
|
143
|
-
|
|
143
|
+
environmentName: ENVIRONMENT_NAME,
|
|
144
144
|
packageName: PACKAGE_NAME,
|
|
145
145
|
modelPath: "flights.malloy",
|
|
146
146
|
query: "run: flights->{BAD SYNTAX aggregate: flight_count is count()}",
|
|
@@ -179,7 +179,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
179
179
|
it("should RESOLVE with InvalidParams for conflicting parameters (query and queryName)", async () => {
|
|
180
180
|
if (!env) throw new Error("Test environment not initialized");
|
|
181
181
|
const params = {
|
|
182
|
-
|
|
182
|
+
environmentName: ENVIRONMENT_NAME,
|
|
183
183
|
packageName: PACKAGE_NAME,
|
|
184
184
|
modelPath: "flights.malloy",
|
|
185
185
|
query: "run: flights->{aggregate: c is count()}",
|
|
@@ -207,7 +207,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
207
207
|
it("should RESOLVE with InvalidParams if required params are missing (e.g., query or queryName)", async () => {
|
|
208
208
|
if (!env) throw new Error("Test environment not initialized");
|
|
209
209
|
const params = {
|
|
210
|
-
|
|
210
|
+
environmentName: ENVIRONMENT_NAME,
|
|
211
211
|
packageName: PACKAGE_NAME,
|
|
212
212
|
modelPath: "flights.malloy",
|
|
213
213
|
// Missing query AND queryName
|
|
@@ -235,7 +235,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
235
235
|
if (!env) throw new Error("Test environment not initialized");
|
|
236
236
|
const params = {
|
|
237
237
|
// Missing modelPath
|
|
238
|
-
|
|
238
|
+
environmentName: ENVIRONMENT_NAME,
|
|
239
239
|
packageName: PACKAGE_NAME,
|
|
240
240
|
query: "run: flights->{aggregate: flight_count is count()}",
|
|
241
241
|
};
|
|
@@ -257,7 +257,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
257
257
|
it("should return application error if package not found", async () => {
|
|
258
258
|
if (!env) throw new Error("Test environment not initialized");
|
|
259
259
|
const params = {
|
|
260
|
-
|
|
260
|
+
environmentName: ENVIRONMENT_NAME,
|
|
261
261
|
packageName: "nonexistent_package", // Use a package that doesn't exist
|
|
262
262
|
modelPath: "flights.malloy",
|
|
263
263
|
query: "run: flights->{aggregate: c is count()}",
|
|
@@ -292,7 +292,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
292
292
|
expect(errorPayloadPkgNotFound.suggestions.length).toBeGreaterThan(0);
|
|
293
293
|
|
|
294
294
|
// Check the specific error message within the parsed object
|
|
295
|
-
const expectedErrorMessageNotFound = `Resource not found: package '${params.packageName}' in
|
|
295
|
+
const expectedErrorMessageNotFound = `Resource not found: package '${params.packageName}' in environment '${params.environmentName}'`;
|
|
296
296
|
expect(errorPayloadPkgNotFound.error).toEqual(
|
|
297
297
|
expectedErrorMessageNotFound,
|
|
298
298
|
);
|
|
@@ -301,7 +301,7 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
301
301
|
it("should return application error if model not found within package", async () => {
|
|
302
302
|
if (!env) throw new Error("Test environment not initialized");
|
|
303
303
|
const params = {
|
|
304
|
-
|
|
304
|
+
environmentName: ENVIRONMENT_NAME,
|
|
305
305
|
packageName: PACKAGE_NAME,
|
|
306
306
|
modelPath: "nonexistent_model.malloy", // Use a model that doesn't exist
|
|
307
307
|
query: "run: flights->{aggregate: c is count()}",
|
|
@@ -335,68 +335,47 @@ describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
|
335
335
|
expect(errorPayloadModel.suggestions.length).toBeGreaterThan(0);
|
|
336
336
|
|
|
337
337
|
// Check the specific error message within the parsed object
|
|
338
|
-
const expectedErrorMessageModel = `Resource not found: model '${params.modelPath}' in package '${params.packageName}' for
|
|
338
|
+
const expectedErrorMessageModel = `Resource not found: model '${params.modelPath}' in package '${params.packageName}' for environment '${params.environmentName}'`;
|
|
339
339
|
expect(errorPayloadModel.error).toEqual(expectedErrorMessageModel);
|
|
340
340
|
|
|
341
341
|
// Check for the specific model name and context in the message
|
|
342
342
|
expect(errorPayloadModel.error).toMatch(/Resource not found/i);
|
|
343
343
|
});
|
|
344
344
|
|
|
345
|
-
//
|
|
346
|
-
|
|
345
|
+
// Stateless HTTP + fast queries make true in-flight cancellation flaky
|
|
346
|
+
// (the response often completes before close wins the race). Assert the
|
|
347
|
+
// transport contract instead: a closed client cannot issue further tools.
|
|
348
|
+
it("should reject malloy_executeQuery after the MCP client is closed", async () => {
|
|
347
349
|
if (!env) throw new Error("Test environment not initialized");
|
|
348
350
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const cancelClient = new Client<Request, Notification, Result>({
|
|
352
|
-
name: "cancel-test-client",
|
|
351
|
+
const closedClient = new Client<Request, Notification, Result>({
|
|
352
|
+
name: "closed-client-test",
|
|
353
353
|
version: "1.0",
|
|
354
354
|
});
|
|
355
|
-
|
|
356
|
-
const cancelTransport = new StreamableHTTPClientTransport(
|
|
355
|
+
const transport = new StreamableHTTPClientTransport(
|
|
357
356
|
new URL(env.serverUrl + "/mcp"),
|
|
358
357
|
);
|
|
359
|
-
await
|
|
358
|
+
await closedClient.connect(transport);
|
|
359
|
+
await closedClient.close();
|
|
360
360
|
|
|
361
|
-
expect
|
|
362
|
-
|
|
363
|
-
try {
|
|
364
|
-
toolPromise = cancelClient.callTool({
|
|
361
|
+
await expect(
|
|
362
|
+
closedClient.callTool({
|
|
365
363
|
name: "malloy_executeQuery",
|
|
366
364
|
arguments: {
|
|
367
|
-
|
|
365
|
+
environmentName: ENVIRONMENT_NAME,
|
|
368
366
|
packageName: PACKAGE_NAME,
|
|
369
367
|
modelPath: "flights.malloy",
|
|
370
|
-
|
|
371
|
-
query: "run: flights->{aggregate: c is count() for 100}",
|
|
368
|
+
query: "run: flights->{aggregate: c is count()}",
|
|
372
369
|
},
|
|
373
|
-
})
|
|
374
|
-
|
|
375
|
-
// Give the request a moment to start on the server
|
|
376
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
377
|
-
|
|
378
|
-
// Close the client to trigger cancellation
|
|
379
|
-
await cancelClient.close();
|
|
380
|
-
|
|
381
|
-
// Await the promise - it should reject due to the closure
|
|
382
|
-
await toolPromise;
|
|
383
|
-
|
|
384
|
-
throw new Error("Promise should have rejected due to cancellation");
|
|
385
|
-
} catch (error) {
|
|
386
|
-
// Check that the error is an Error instance and the message indicates closure/cancellation
|
|
387
|
-
expect(error).toBeInstanceOf(Error);
|
|
388
|
-
expect((error as Error).message).toMatch(/cancel|closed/i);
|
|
389
|
-
} finally {
|
|
390
|
-
// Ensure the temporary client is closed even if the test failed unexpectedly
|
|
391
|
-
await cancelClient.close().catch(() => {}); // Ignore errors on final cleanup
|
|
392
|
-
}
|
|
370
|
+
}),
|
|
371
|
+
).rejects.toThrow();
|
|
393
372
|
});
|
|
394
373
|
|
|
395
374
|
// Test invalid usage - nested view called without sourceName
|
|
396
375
|
it("should return application error for nested view without sourceName", async () => {
|
|
397
376
|
if (!env) throw new Error("Test environment not initialized");
|
|
398
377
|
const params = {
|
|
399
|
-
|
|
378
|
+
environmentName: ENVIRONMENT_NAME,
|
|
400
379
|
packageName: PACKAGE_NAME,
|
|
401
380
|
modelPath: "flights.malloy",
|
|
402
381
|
queryName: "top_carriers", // Nested view, but sourceName is missing
|