@malloy-publisher/server 0.0.382-dev → 0.2.0
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/README.docker.md +145 -20
- package/README.md +65 -12
- package/dist/app/api-doc.html +5 -0
- package/dist/app/api-doc.yaml +3903 -583
- package/dist/app/assets/EnvironmentPage-DiUgLuCH.js +1 -0
- package/dist/app/assets/HomePage-MhhjhnFj.js +1 -0
- package/dist/app/assets/LightMode-BEyvNUzT.js +1 -0
- package/dist/app/assets/MainPage-D4Cfee9o.js +2 -0
- package/dist/app/assets/MaterializationsPage-nGgGqwSN.js +1 -0
- package/dist/app/assets/ModelPage-DLAcEw-F.js +1 -0
- package/dist/app/assets/PackagePage-Df0ikH7w.js +1 -0
- package/dist/app/assets/RouteError-BFQwtroH.js +1 -0
- package/dist/app/assets/ThemeEditorPage-OoskoQYN.js +1 -0
- package/dist/app/assets/WorkbookPage-CpFgvUDC.js +1 -0
- package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-lb28vQkR.es-BoVSOc75.js} +1 -1
- package/dist/app/assets/github-dark-DenFmJkN.es-DHJKELXO.js +1 -0
- package/dist/app/assets/index-5eLCcNmP.css +1 -0
- package/dist/app/assets/index-6ypuFH6g.js +1774 -0
- package/dist/app/assets/index-B8pnU_V_.js +615 -0
- package/dist/app/assets/index-BImcHmVP.js +1 -0
- package/dist/app/assets/index-DSoCUF-f.js +2725 -0
- package/dist/app/assets/index-DfqzSItA.js +2 -0
- package/dist/app/assets/index-w_0OQJgZ.js +23 -0
- package/dist/app/index.html +8 -4
- package/dist/cpufeatures-1yrn0vtw.node +0 -0
- package/dist/default-publisher.config.json +23 -0
- package/dist/{instrumentation.js → instrumentation.mjs} +10631 -10573
- package/dist/package_load_worker.mjs +15219 -0
- package/dist/runtime/publisher.js +331 -0
- package/dist/{server.js → server.mjs} +115548 -49590
- package/dist/sshcrypto-vd2k5hq9.node +0 -0
- package/package.json +41 -28
- package/publisher.config.example.bigquery.json +33 -0
- package/publisher.config.example.duckdb.json +23 -0
- package/.eslintrc.json +0 -44
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/build.ts +0 -38
- package/dist/app/assets/HomePage-Dn3E4CuB.js +0 -1
- package/dist/app/assets/MainPage-BzB3yoqi.js +0 -2
- package/dist/app/assets/ModelPage-C9O_sAXT.js +0 -1
- package/dist/app/assets/PackagePage-DcxKEjBX.js +0 -1
- package/dist/app/assets/ProjectPage-BDj307rF.js +0 -1
- package/dist/app/assets/RouteError-DAShbVCG.js +0 -1
- package/dist/app/assets/WorkbookPage-Cs_XYEaB.js +0 -1
- package/dist/app/assets/index-15BOvhp0.js +0 -456
- package/dist/app/assets/index-Bb2jqquW.js +0 -676
- package/dist/app/assets/index-CMlGQMcl.css +0 -1
- package/dist/app/assets/index-D68X76-7.js +0 -1276
- package/dist/app/assets/index.umd-DGBekgSu.js +0 -1145
- package/dxt/malloy_bridge.py +0 -354
- package/dxt/manifest.json +0 -22
- package/eslint.config.mjs +0 -76
- package/k6-tests/README.md +0 -144
- package/k6-tests/bun.lock +0 -797
- package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
- package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
- package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
- package/k6-tests/load-test/load-test-crud.ts +0 -142
- package/k6-tests/load-test/load-test.ts +0 -784
- package/k6-tests/package.json +0 -27
- package/k6-tests/scripts/run-with-otel.sh +0 -50
- package/k6-tests/smoke-test/smoke-test.ts +0 -158
- package/k6-tests/tsconfig.json +0 -29
- package/k6-tests/utils/client_factory.ts +0 -128
- package/k6-tests/utils/common.ts +0 -489
- package/k6-tests/utils/logger.ts +0 -62
- package/k6-tests/utils/types.d.ts +0 -35
- package/malloy_mcp.dxt +0 -0
- package/publisher.config.json +0 -33
- package/src/config.spec.ts +0 -850
- package/src/config.ts +0 -305
- package/src/constants.ts +0 -10
- package/src/controller/compile.controller.ts +0 -35
- package/src/controller/connection.controller.ts +0 -515
- package/src/controller/database.controller.ts +0 -21
- package/src/controller/manifest.controller.ts +0 -29
- package/src/controller/materialization.controller.ts +0 -125
- package/src/controller/model.controller.ts +0 -107
- package/src/controller/package.controller.ts +0 -182
- package/src/controller/query.controller.ts +0 -60
- package/src/controller/watch-mode.controller.ts +0 -98
- package/src/data_styles.ts +0 -71
- package/src/dto/connection.dto.spec.ts +0 -131
- package/src/dto/connection.dto.ts +0 -174
- package/src/dto/index.ts +0 -2
- package/src/dto/package.dto.spec.ts +0 -42
- package/src/dto/package.dto.ts +0 -12
- package/src/dto/validate.spec.ts +0 -76
- package/src/dto/validate.ts +0 -31
- package/src/errors.ts +0 -116
- package/src/health.ts +0 -189
- package/src/instrumentation.ts +0 -148
- package/src/logger.ts +0 -154
- package/src/mcp/error_messages.ts +0 -199
- package/src/mcp/handler_utils.ts +0 -239
- package/src/mcp/mcp_constants.ts +0 -22
- package/src/mcp/prompts/handlers.ts +0 -84
- package/src/mcp/prompts/index.ts +0 -11
- package/src/mcp/prompts/prompt_definitions.ts +0 -160
- package/src/mcp/prompts/prompt_service.ts +0 -67
- package/src/mcp/prompts/utils.ts +0 -62
- package/src/mcp/resource_metadata.ts +0 -47
- package/src/mcp/resources/model_resource.ts +0 -153
- package/src/mcp/resources/notebook_resource.ts +0 -137
- package/src/mcp/resources/package_resource.ts +0 -370
- package/src/mcp/resources/project_resource.ts +0 -184
- package/src/mcp/resources/query_resource.ts +0 -117
- package/src/mcp/resources/source_resource.ts +0 -141
- package/src/mcp/resources/view_resource.ts +0 -136
- package/src/mcp/server.ts +0 -62
- package/src/mcp/tools/discovery_tools.ts +0 -258
- package/src/mcp/tools/execute_query_tool.ts +0 -265
- package/src/server.ts +0 -1195
- package/src/service/connection.spec.ts +0 -1331
- package/src/service/connection.ts +0 -1511
- package/src/service/connection_service.spec.ts +0 -641
- package/src/service/connection_service.ts +0 -181
- package/src/service/db_utils.spec.ts +0 -714
- package/src/service/db_utils.ts +0 -1227
- package/src/service/filter.spec.ts +0 -447
- package/src/service/filter.ts +0 -337
- package/src/service/filter_integration.spec.ts +0 -825
- package/src/service/gcs_s3_utils.ts +0 -427
- package/src/service/manifest_service.spec.ts +0 -201
- package/src/service/manifest_service.ts +0 -106
- package/src/service/materialization_service.spec.ts +0 -648
- package/src/service/materialization_service.ts +0 -929
- package/src/service/materialized_table_gc.spec.ts +0 -383
- package/src/service/materialized_table_gc.ts +0 -279
- package/src/service/model.spec.ts +0 -257
- package/src/service/model.ts +0 -1069
- package/src/service/package.spec.ts +0 -236
- package/src/service/package.ts +0 -463
- package/src/service/project.ts +0 -681
- package/src/service/project_compile.spec.ts +0 -197
- package/src/service/project_store.spec.ts +0 -859
- package/src/service/project_store.ts +0 -1531
- package/src/service/quoting.ts +0 -41
- package/src/service/resolve_project.ts +0 -13
- package/src/storage/BaseRepository.ts +0 -31
- package/src/storage/DatabaseInterface.ts +0 -180
- package/src/storage/StorageManager.mock.ts +0 -59
- package/src/storage/StorageManager.ts +0 -210
- package/src/storage/duckdb/ConnectionRepository.ts +0 -141
- package/src/storage/duckdb/DuckDBConnection.ts +0 -177
- package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
- package/src/storage/duckdb/DuckDBRepository.ts +0 -224
- package/src/storage/duckdb/ManifestRepository.ts +0 -119
- package/src/storage/duckdb/MaterializationRepository.ts +0 -249
- package/src/storage/duckdb/PackageRepository.ts +0 -135
- package/src/storage/duckdb/ProjectRepository.ts +0 -148
- package/src/storage/duckdb/manifest_store.spec.ts +0 -133
- package/src/storage/duckdb/schema.ts +0 -147
- package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -146
- package/src/utils.ts +0 -13
- package/tests/fixtures/persist-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-test/persist_test.malloy +0 -11
- package/tests/fixtures/persist-test/publisher.json +0 -5
- package/tests/fixtures/publisher.config.json +0 -15
- package/tests/harness/e2e.ts +0 -96
- package/tests/harness/mcp_test_setup.ts +0 -344
- package/tests/harness/mocks.ts +0 -37
- package/tests/harness/rest_e2e.ts +0 -68
- package/tests/harness/uris.ts +0 -31
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -470
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -434
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -663
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -122
- package/tests/integration/mcp/setup.spec.ts +0 -5
- package/tests/unit/duckdb/attached_databases.test.ts +0 -1132
- package/tests/unit/ducklake/ducklake.test.ts +0 -950
- package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
- package/tests/unit/mcp/prompt_happy.test.ts +0 -51
- package/tsconfig.json +0 -32
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error Bun test types are not recognized by ESLint
|
|
2
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
-
import type {
|
|
5
|
-
Notification,
|
|
6
|
-
Request,
|
|
7
|
-
Result,
|
|
8
|
-
} from "@modelcontextprotocol/sdk/types.js"; // Keep these base types
|
|
9
|
-
import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
-
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
11
|
-
import { URL } from "url";
|
|
12
|
-
import { MCP_ERROR_MESSAGES } from "../../../src/mcp/mcp_constants"; // Keep for error message checks
|
|
13
|
-
|
|
14
|
-
// --- Import E2E Test Setup ---
|
|
15
|
-
import {
|
|
16
|
-
cleanupE2ETestEnvironment,
|
|
17
|
-
McpE2ETestEnvironment,
|
|
18
|
-
setupE2ETestEnvironment,
|
|
19
|
-
} from "../../harness/mcp_test_setup";
|
|
20
|
-
|
|
21
|
-
// --- Test Suite ---
|
|
22
|
-
describe("MCP Tool Handlers (E2E Integration)", () => {
|
|
23
|
-
let env: McpE2ETestEnvironment | null = null;
|
|
24
|
-
let mcpClient: Client;
|
|
25
|
-
|
|
26
|
-
const PROJECT_NAME = "malloy-samples";
|
|
27
|
-
const PACKAGE_NAME = "faa";
|
|
28
|
-
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
// Setup the E2E environment (starts server, connects client)
|
|
31
|
-
env = await setupE2ETestEnvironment();
|
|
32
|
-
mcpClient = env.mcpClient; // Assign client from setup
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
afterAll(async () => {
|
|
36
|
-
await cleanupE2ETestEnvironment(env);
|
|
37
|
-
env = null;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("malloy_executeQuery Tool", () => {
|
|
41
|
-
// Constants for test parameters
|
|
42
|
-
|
|
43
|
-
it(
|
|
44
|
-
"should execute a valid ad-hoc query successfully",
|
|
45
|
-
async () => {
|
|
46
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
47
|
-
const result = await mcpClient.callTool({
|
|
48
|
-
name: "malloy_executeQuery",
|
|
49
|
-
arguments: {
|
|
50
|
-
projectName: "malloy-samples",
|
|
51
|
-
packageName: PACKAGE_NAME,
|
|
52
|
-
modelPath: "flights.malloy",
|
|
53
|
-
query: "run: flights->{ aggregate: c is count() }",
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(result).toBeDefined();
|
|
58
|
-
expect(result.isError).not.toBe(true); // Should be success
|
|
59
|
-
expect(result.content).toBeDefined();
|
|
60
|
-
|
|
61
|
-
const content = result.content as Array<{
|
|
62
|
-
type: string;
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
}>;
|
|
66
|
-
expect(Array.isArray(content)).toBe(true);
|
|
67
|
-
// Expect 1 content block (result)
|
|
68
|
-
expect(content.length).toBe(1);
|
|
69
|
-
|
|
70
|
-
// Check structure of each block
|
|
71
|
-
for (const block of content) {
|
|
72
|
-
expect(block.type).toBe("resource");
|
|
73
|
-
expect(block.resource).toBeDefined();
|
|
74
|
-
expect(block.resource.type).toBe("application/json");
|
|
75
|
-
expect(block.resource.text).toBeDefined();
|
|
76
|
-
expect(typeof block.resource.text).toBe("string");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Basic check on the first block (result)
|
|
80
|
-
|
|
81
|
-
const queryResultBlock = content[0].resource;
|
|
82
|
-
expect(queryResultBlock.uri).toContain("#result");
|
|
83
|
-
const queryResultData = JSON.parse(queryResultBlock.text);
|
|
84
|
-
expect(queryResultData).toBeDefined();
|
|
85
|
-
// Check properties directly on the parsed Result object
|
|
86
|
-
expect(queryResultData.data).toBeDefined();
|
|
87
|
-
expect(Array.isArray(queryResultData.data.array_value)).toBe(true);
|
|
88
|
-
// Could add more specific checks on data if needed
|
|
89
|
-
},
|
|
90
|
-
{ timeout: 30000 },
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
it(
|
|
94
|
-
"should successfully execute a nested view using sourceName and queryName",
|
|
95
|
-
async () => {
|
|
96
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
97
|
-
const params = {
|
|
98
|
-
projectName: PROJECT_NAME,
|
|
99
|
-
packageName: PACKAGE_NAME,
|
|
100
|
-
modelPath: "flights.malloy",
|
|
101
|
-
sourceName: "flights", // Added sourceName
|
|
102
|
-
queryName: "top_carriers",
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// Expect RESOLUTION with success
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
const result: any = await mcpClient.callTool({
|
|
108
|
-
name: "malloy_executeQuery",
|
|
109
|
-
arguments: params,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(result).toBeDefined();
|
|
113
|
-
expect(result.isError).toBe(false); // Expecting success
|
|
114
|
-
expect(result.content).toBeDefined();
|
|
115
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
116
|
-
// Expect 1 content block (result)
|
|
117
|
-
expect(result.content.length).toBeGreaterThan(0);
|
|
118
|
-
|
|
119
|
-
// Check the structure of the first content block (result)
|
|
120
|
-
const queryResultBlock = result.content![0];
|
|
121
|
-
expect(queryResultBlock.type).toBe("resource");
|
|
122
|
-
expect(queryResultBlock.resource).toBeDefined();
|
|
123
|
-
expect(queryResultBlock.resource.type).toBe("application/json");
|
|
124
|
-
expect(queryResultBlock.resource.uri).toMatch(/result/); // Check URI contains queryResult
|
|
125
|
-
expect(queryResultBlock.resource.text).toBeDefined();
|
|
126
|
-
|
|
127
|
-
// Optionally, parse and check the actual data
|
|
128
|
-
const queryResultPayload = JSON.parse(
|
|
129
|
-
queryResultBlock.resource.text,
|
|
130
|
-
);
|
|
131
|
-
expect(queryResultPayload).toBeDefined();
|
|
132
|
-
// Add more specific data checks if needed, e.g., check for specific columns or row count > 0
|
|
133
|
-
// Example: expect(queryResultPayload._queryResult.data.rows.length).toBeGreaterThan(0);
|
|
134
|
-
},
|
|
135
|
-
{ timeout: 30000 },
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
it(
|
|
139
|
-
"should return application error for invalid Malloy query syntax",
|
|
140
|
-
async () => {
|
|
141
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
142
|
-
const params = {
|
|
143
|
-
projectName: PROJECT_NAME,
|
|
144
|
-
packageName: PACKAGE_NAME,
|
|
145
|
-
modelPath: "flights.malloy",
|
|
146
|
-
query: "run: flights->{BAD SYNTAX aggregate: flight_count is count()}",
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// Application Error (Malloy Compilation): Expect RESOLUTION with isError: true
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
-
const result: any = await mcpClient.callTool({
|
|
152
|
-
name: "malloy_executeQuery",
|
|
153
|
-
arguments: params,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
expect(result.isError).toBe(true);
|
|
157
|
-
expect(result.content).toBeDefined();
|
|
158
|
-
// Check the new structure: resource -> application/json
|
|
159
|
-
const errorBlockSyntax = result.content![0];
|
|
160
|
-
expect(errorBlockSyntax.type).toBe("resource");
|
|
161
|
-
expect(errorBlockSyntax.resource).toBeDefined();
|
|
162
|
-
expect(errorBlockSyntax.resource.type).toBe("application/json");
|
|
163
|
-
|
|
164
|
-
// Check for Malloy compilation error message from getMalloyErrorDetails
|
|
165
|
-
const errorJsonTextSyntax = errorBlockSyntax.resource
|
|
166
|
-
.text as string;
|
|
167
|
-
const errorPayloadSyntax = JSON.parse(errorJsonTextSyntax);
|
|
168
|
-
expect(errorPayloadSyntax.error).toMatch(
|
|
169
|
-
/syntax error|no viable alternative/i,
|
|
170
|
-
);
|
|
171
|
-
expect(Array.isArray(errorPayloadSyntax.suggestions)).toBe(true);
|
|
172
|
-
},
|
|
173
|
-
{ timeout: 30000 },
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
// --- Parameter Validation Error Tests ---
|
|
177
|
-
// These should RESOLVE with isError: true because the error is thrown
|
|
178
|
-
// inside the handler and caught by the transport bridge, which returns 200 OK + error payload.
|
|
179
|
-
it("should RESOLVE with InvalidParams for conflicting parameters (query and queryName)", async () => {
|
|
180
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
181
|
-
const params = {
|
|
182
|
-
projectName: PROJECT_NAME,
|
|
183
|
-
packageName: PACKAGE_NAME,
|
|
184
|
-
modelPath: "flights.malloy",
|
|
185
|
-
query: "run: flights->{aggregate: c is count()}",
|
|
186
|
-
queryName: "top_carriers",
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// Expect RESOLUTION because the error is thrown *inside* the handler
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
191
|
-
const result: any = await mcpClient.callTool({
|
|
192
|
-
name: "malloy_executeQuery",
|
|
193
|
-
arguments: params,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
expect(result.isError).toBe(true);
|
|
197
|
-
expect(result.content).toBeDefined();
|
|
198
|
-
// Revert to expecting type: "text" for McpError caught by SDK
|
|
199
|
-
expect(result.content?.[0]?.type).toBe("text");
|
|
200
|
-
// Check the error message in the content
|
|
201
|
-
expect(result.content?.[0]?.text).toBe(
|
|
202
|
-
// Match the message including the prefix added by the client/framework
|
|
203
|
-
`MCP error ${ErrorCode.InvalidParams}: ${MCP_ERROR_MESSAGES.MUTUALLY_EXCLUSIVE_PARAMS}`,
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("should RESOLVE with InvalidParams if required params are missing (e.g., query or queryName)", async () => {
|
|
208
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
209
|
-
const params = {
|
|
210
|
-
projectName: PROJECT_NAME,
|
|
211
|
-
packageName: PACKAGE_NAME,
|
|
212
|
-
modelPath: "flights.malloy",
|
|
213
|
-
// Missing query AND queryName
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// Expect RESOLUTION because the error is thrown *inside* the handler
|
|
217
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
218
|
-
const result: any = await mcpClient.callTool({
|
|
219
|
-
name: "malloy_executeQuery",
|
|
220
|
-
arguments: params,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
expect(result.isError).toBe(true);
|
|
224
|
-
expect(result.content).toBeDefined();
|
|
225
|
-
// Revert to expecting type: "text" for McpError caught by SDK
|
|
226
|
-
expect(result.content?.[0]?.type).toBe("text");
|
|
227
|
-
// Check the error message in the content
|
|
228
|
-
expect(result.content?.[0]?.text).toBe(
|
|
229
|
-
// Match the message including the prefix added by the client/framework
|
|
230
|
-
`MCP error ${ErrorCode.InvalidParams}: ${MCP_ERROR_MESSAGES.MISSING_REQUIRED_PARAMS}`,
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("should reject with InvalidParams if required top-level params are missing (e.g., modelPath)", async () => {
|
|
235
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
236
|
-
const params = {
|
|
237
|
-
// Missing modelPath
|
|
238
|
-
projectName: PROJECT_NAME,
|
|
239
|
-
packageName: PACKAGE_NAME,
|
|
240
|
-
query: "run: flights->{aggregate: flight_count is count()}",
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// Protocol Error (Caught by Zod/MCP): Expect REJECTION
|
|
244
|
-
await expect(
|
|
245
|
-
mcpClient.callTool({
|
|
246
|
-
name: "malloy_executeQuery",
|
|
247
|
-
arguments: params,
|
|
248
|
-
}),
|
|
249
|
-
).rejects.toMatchObject({
|
|
250
|
-
code: ErrorCode.InvalidParams,
|
|
251
|
-
// Zod error message will likely mention the missing field 'modelPath'
|
|
252
|
-
message: expect.stringContaining("modelPath"),
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
// --- End Parameter Validation Error Tests ---
|
|
256
|
-
|
|
257
|
-
it("should return application error if package not found", async () => {
|
|
258
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
259
|
-
const params = {
|
|
260
|
-
projectName: PROJECT_NAME,
|
|
261
|
-
packageName: "nonexistent_package", // Use a package that doesn't exist
|
|
262
|
-
modelPath: "flights.malloy",
|
|
263
|
-
query: "run: flights->{aggregate: c is count()}",
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// Application Error (Service Layer): Expect RESOLUTION with isError: true
|
|
267
|
-
// Cast to any
|
|
268
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
|
-
const result: any = await mcpClient.callTool({
|
|
270
|
-
name: "malloy_executeQuery",
|
|
271
|
-
arguments: params,
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
expect(result.isError).toBe(true);
|
|
275
|
-
expect(result.content).toBeDefined();
|
|
276
|
-
// Check the new structure: resource -> application/json
|
|
277
|
-
const errorBlockPkgNotFound = result.content![0];
|
|
278
|
-
expect(errorBlockPkgNotFound.type).toBe("resource");
|
|
279
|
-
expect(errorBlockPkgNotFound.resource).toBeDefined();
|
|
280
|
-
expect(errorBlockPkgNotFound.resource.type).toBe("application/json");
|
|
281
|
-
|
|
282
|
-
// Parse the JSON string from the resource text content
|
|
283
|
-
const errorJsonTextPkgNotFound = errorBlockPkgNotFound.resource
|
|
284
|
-
.text as string;
|
|
285
|
-
const errorPayloadPkgNotFound = JSON.parse(errorJsonTextPkgNotFound);
|
|
286
|
-
|
|
287
|
-
// Check the parsed error object
|
|
288
|
-
expect(errorPayloadPkgNotFound).toBeDefined();
|
|
289
|
-
expect(errorPayloadPkgNotFound.error).toBeDefined();
|
|
290
|
-
expect(errorPayloadPkgNotFound.suggestions).toBeDefined();
|
|
291
|
-
expect(Array.isArray(errorPayloadPkgNotFound.suggestions)).toBe(true);
|
|
292
|
-
expect(errorPayloadPkgNotFound.suggestions.length).toBeGreaterThan(0);
|
|
293
|
-
|
|
294
|
-
// Check the specific error message within the parsed object
|
|
295
|
-
const expectedErrorMessageNotFound = `Resource not found: package '${params.packageName}' in project '${params.projectName}'`;
|
|
296
|
-
expect(errorPayloadPkgNotFound.error).toEqual(
|
|
297
|
-
expectedErrorMessageNotFound,
|
|
298
|
-
);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("should return application error if model not found within package", async () => {
|
|
302
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
303
|
-
const params = {
|
|
304
|
-
projectName: PROJECT_NAME,
|
|
305
|
-
packageName: PACKAGE_NAME,
|
|
306
|
-
modelPath: "nonexistent_model.malloy", // Use a model that doesn't exist
|
|
307
|
-
query: "run: flights->{aggregate: c is count()}",
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// Application Error (Service Layer): Expect RESOLUTION with isError: true
|
|
311
|
-
// Cast to any
|
|
312
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
313
|
-
const result: any = await mcpClient.callTool({
|
|
314
|
-
name: "malloy_executeQuery",
|
|
315
|
-
arguments: params,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
expect(result.isError).toBe(true);
|
|
319
|
-
expect(result.content).toBeDefined();
|
|
320
|
-
// Check the new structure: resource -> application/json
|
|
321
|
-
const errorBlockModel = result.content![0];
|
|
322
|
-
expect(errorBlockModel.type).toBe("resource");
|
|
323
|
-
expect(errorBlockModel.resource).toBeDefined();
|
|
324
|
-
expect(errorBlockModel.resource.type).toBe("application/json");
|
|
325
|
-
|
|
326
|
-
// Parse the JSON string from the resource text content
|
|
327
|
-
const errorJsonTextModel = errorBlockModel.resource.text as string;
|
|
328
|
-
const errorPayloadModel = JSON.parse(errorJsonTextModel);
|
|
329
|
-
|
|
330
|
-
// Check the parsed error object
|
|
331
|
-
expect(errorPayloadModel).toBeDefined();
|
|
332
|
-
expect(errorPayloadModel.error).toBeDefined();
|
|
333
|
-
expect(errorPayloadModel.suggestions).toBeDefined();
|
|
334
|
-
expect(Array.isArray(errorPayloadModel.suggestions)).toBe(true);
|
|
335
|
-
expect(errorPayloadModel.suggestions.length).toBeGreaterThan(0);
|
|
336
|
-
|
|
337
|
-
// Check the specific error message within the parsed object
|
|
338
|
-
const expectedErrorMessageModel = `Resource not found: model '${params.modelPath}' in package '${params.packageName}' for project '${params.projectName}'`;
|
|
339
|
-
expect(errorPayloadModel.error).toEqual(expectedErrorMessageModel);
|
|
340
|
-
|
|
341
|
-
// Check for the specific model name and context in the message
|
|
342
|
-
expect(errorPayloadModel.error).toMatch(/Resource not found/i);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// Added from mcp_query_tool.spec.ts
|
|
346
|
-
it("should handle query cancellation via client close", async () => {
|
|
347
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
348
|
-
|
|
349
|
-
// Create a new client *specifically* for this test so we can close it
|
|
350
|
-
// without affecting other tests running concurrently (if any).
|
|
351
|
-
const cancelClient = new Client<Request, Notification, Result>({
|
|
352
|
-
name: "cancel-test-client",
|
|
353
|
-
version: "1.0",
|
|
354
|
-
});
|
|
355
|
-
// Corrected: Use StreamableHTTPClientTransport with the server URL + /mcp endpoint
|
|
356
|
-
const cancelTransport = new StreamableHTTPClientTransport(
|
|
357
|
-
new URL(env.serverUrl + "/mcp"),
|
|
358
|
-
);
|
|
359
|
-
await cancelClient.connect(cancelTransport);
|
|
360
|
-
|
|
361
|
-
expect.assertions(2); // Expecting two assertions: instanceof Error and message match
|
|
362
|
-
let toolPromise;
|
|
363
|
-
try {
|
|
364
|
-
toolPromise = cancelClient.callTool({
|
|
365
|
-
name: "malloy_executeQuery",
|
|
366
|
-
arguments: {
|
|
367
|
-
projectName: PROJECT_NAME,
|
|
368
|
-
packageName: PACKAGE_NAME,
|
|
369
|
-
modelPath: "flights.malloy",
|
|
370
|
-
// Use a query known to take a little time if possible, otherwise a simple one
|
|
371
|
-
query: "run: flights->{aggregate: c is count() for 100}",
|
|
372
|
-
},
|
|
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
|
-
}
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
// Test invalid usage - nested view called without sourceName
|
|
396
|
-
it("should return application error for nested view without sourceName", async () => {
|
|
397
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
398
|
-
const params = {
|
|
399
|
-
projectName: PROJECT_NAME,
|
|
400
|
-
packageName: PACKAGE_NAME,
|
|
401
|
-
modelPath: "flights.malloy",
|
|
402
|
-
queryName: "top_carriers", // Nested view, but sourceName is missing
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
// Expect RESOLUTION with error because it's invalid usage processed by the handler
|
|
406
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
407
|
-
const result: any = await mcpClient.callTool({
|
|
408
|
-
name: "malloy_executeQuery",
|
|
409
|
-
arguments: params,
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
expect(result).toBeDefined();
|
|
413
|
-
expect(result.isError).toBe(true); // Expecting error
|
|
414
|
-
expect(result.content).toBeDefined();
|
|
415
|
-
expect(Array.isArray(result.content)).toBe(true);
|
|
416
|
-
expect(result.content.length).toBeGreaterThan(0);
|
|
417
|
-
|
|
418
|
-
// Check the error structure: resource -> application/json
|
|
419
|
-
const errorBlock = result.content![0];
|
|
420
|
-
expect(errorBlock.type).toBe("resource");
|
|
421
|
-
expect(errorBlock.resource).toBeDefined();
|
|
422
|
-
expect(errorBlock.resource.type).toBe("application/json");
|
|
423
|
-
|
|
424
|
-
// Check for Malloy error indicating the query/view wasn't found at the top level
|
|
425
|
-
const errorJsonText = errorBlock.resource.text as string;
|
|
426
|
-
const errorPayload = JSON.parse(errorJsonText);
|
|
427
|
-
// Expect error about the query/view itself not found
|
|
428
|
-
expect(errorPayload.error).toMatch(
|
|
429
|
-
/Query 'top_carriers' not found|Reference to undefined object 'top_carriers'/i,
|
|
430
|
-
);
|
|
431
|
-
expect(Array.isArray(errorPayload.suggestions)).toBe(true);
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
});
|