@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,344 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
-
import {
|
|
4
|
-
Notification,
|
|
5
|
-
Request,
|
|
6
|
-
Result,
|
|
7
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
import http from "http";
|
|
9
|
-
import { AddressInfo } from "net";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
12
|
-
import { URL } from "url";
|
|
13
|
-
|
|
14
|
-
// --- Real Server Import ---
|
|
15
|
-
// Import the actual configured Express app instance
|
|
16
|
-
|
|
17
|
-
// --- E2E Test Environment Setup ---
|
|
18
|
-
|
|
19
|
-
export interface McpE2ETestEnvironment {
|
|
20
|
-
httpServer: http.Server;
|
|
21
|
-
serverUrl: string;
|
|
22
|
-
mcpClient: Client<Request, Notification, Result>;
|
|
23
|
-
originalServerRoot: string | undefined;
|
|
24
|
-
originalInitializeStorage: string | undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Counter for unique port assignment per test suite
|
|
28
|
-
let portCounter = 0;
|
|
29
|
-
|
|
30
|
-
// Mutex to prevent concurrent initialization (since all tests share the same database)
|
|
31
|
-
let initializationLock: Promise<void> | null = null;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Starts the real application server and connects a real MCP client.
|
|
35
|
-
*/
|
|
36
|
-
export async function setupE2ETestEnvironment(): Promise<McpE2ETestEnvironment> {
|
|
37
|
-
// Wait for any ongoing initialization to complete (prevents concurrent DB initialization)
|
|
38
|
-
if (initializationLock) {
|
|
39
|
-
console.log(
|
|
40
|
-
"[E2E Test Setup] Waiting for previous initialization to complete...",
|
|
41
|
-
);
|
|
42
|
-
await initializationLock;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Create a new lock for this initialization
|
|
46
|
-
let resolveLock: () => void;
|
|
47
|
-
initializationLock = new Promise((resolve) => {
|
|
48
|
-
resolveLock = resolve;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
return await setupE2ETestEnvironmentInternal();
|
|
53
|
-
} finally {
|
|
54
|
-
// Release the lock
|
|
55
|
-
resolveLock!();
|
|
56
|
-
initializationLock = null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function setupE2ETestEnvironmentInternal(): Promise<McpE2ETestEnvironment> {
|
|
61
|
-
// --- Store and Set SERVER_ROOT Env Var ---
|
|
62
|
-
// The ProjectStore relies on SERVER_ROOT to find publisher.config.json.
|
|
63
|
-
const originalServerRoot = process.env.SERVER_ROOT; // Store original value
|
|
64
|
-
// Resolve the path to 'packages/server' based on the location of this file
|
|
65
|
-
// Use import.meta.url for cross-platform compatibility (works on Windows)
|
|
66
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
67
|
-
const __dirname = path.dirname(__filename);
|
|
68
|
-
const serverPackageDir = path.resolve(__dirname, "../../"); // Go up two levels from .../packages/server/tests/harness
|
|
69
|
-
process.env.SERVER_ROOT = serverPackageDir;
|
|
70
|
-
console.log(
|
|
71
|
-
`[E2E Test Setup] Temporarily set SERVER_ROOT=${process.env.SERVER_ROOT}`,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
// --- Set INITIALIZE_STORAGE to ensure packages are downloaded ---
|
|
75
|
-
// This ensures packages from GitHub are cloned/downloaded during initialization
|
|
76
|
-
const originalInitializeStorage = process.env.INITIALIZE_STORAGE; // Store original value
|
|
77
|
-
process.env.INITIALIZE_STORAGE = "true";
|
|
78
|
-
console.log(
|
|
79
|
-
`[E2E Test Setup] Temporarily set INITIALIZE_STORAGE=${process.env.INITIALIZE_STORAGE}`,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// --- IMPORTANT: Import server *after* setting env var ---
|
|
83
|
-
// Dynamically import the actual app instance
|
|
84
|
-
const { mcpApp } = await import("../../src/server");
|
|
85
|
-
|
|
86
|
-
let serverInstance: http.Server;
|
|
87
|
-
let serverUrl: string;
|
|
88
|
-
|
|
89
|
-
// Use unique port per test suite to avoid conflicts when running in parallel
|
|
90
|
-
// Increment port counter and use it to create unique ports: 4042, 4043, 4044, etc.
|
|
91
|
-
const portOffset = portCounter++;
|
|
92
|
-
const TEST_MCP_PORT = Number(process.env.MCP_PORT || 4040) + 2 + portOffset;
|
|
93
|
-
|
|
94
|
-
await new Promise<void>((resolve, reject) => {
|
|
95
|
-
const server = http
|
|
96
|
-
.createServer(mcpApp)
|
|
97
|
-
.listen(TEST_MCP_PORT, "127.0.0.1", () => {
|
|
98
|
-
// Use explicit TEST_MCP_PORT
|
|
99
|
-
try {
|
|
100
|
-
const address = server.address() as AddressInfo;
|
|
101
|
-
if (!address)
|
|
102
|
-
throw new Error("Server address is null after listen");
|
|
103
|
-
serverInstance = server;
|
|
104
|
-
serverUrl = `http://127.0.0.1:${TEST_MCP_PORT}`;
|
|
105
|
-
console.log(
|
|
106
|
-
`[E2E Test Setup] Real server (using mcpApp) listening on ${serverUrl} (Port: ${TEST_MCP_PORT})`,
|
|
107
|
-
);
|
|
108
|
-
resolve();
|
|
109
|
-
} catch (err) {
|
|
110
|
-
reject(err);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
server.on("error", (err: NodeJS.ErrnoException) => {
|
|
114
|
-
// Provide more specific error info if available (like EADDRINUSE)
|
|
115
|
-
console.error(
|
|
116
|
-
`[E2E Test Setup] Server failed to start on port ${TEST_MCP_PORT}: ${err.code} - ${err.message}`,
|
|
117
|
-
);
|
|
118
|
-
reject(err);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Ensure serverInstance and serverUrl are assigned
|
|
123
|
-
const listeningServerInstance = serverInstance!;
|
|
124
|
-
const listeningServerUrl = serverUrl!;
|
|
125
|
-
|
|
126
|
-
// --- Wait a moment for server to start accepting connections ---
|
|
127
|
-
console.log("[E2E Test Setup] Waiting for server to accept connections...");
|
|
128
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
129
|
-
|
|
130
|
-
// --- Wait for server to be ready (packages downloaded) ---
|
|
131
|
-
// Poll the readiness endpoint to ensure initialization completes before tests run
|
|
132
|
-
// Note: Reduced timeout to 90s to be under the 100s test timeout
|
|
133
|
-
console.log("[E2E Test Setup] Waiting for server to be ready...");
|
|
134
|
-
const maxWaitTime = 90000; // 90 seconds max wait (under 100s test timeout)
|
|
135
|
-
const pollInterval = 1000; // Check every second
|
|
136
|
-
const startTime = Date.now();
|
|
137
|
-
let isReady = false;
|
|
138
|
-
|
|
139
|
-
while (!isReady && Date.now() - startTime < maxWaitTime) {
|
|
140
|
-
try {
|
|
141
|
-
// Use Promise.race to add timeout to fetch
|
|
142
|
-
const fetchPromise = fetch(`${listeningServerUrl}/health/readiness`);
|
|
143
|
-
const timeoutPromise = new Promise<never>((_, reject) =>
|
|
144
|
-
setTimeout(() => reject(new Error("Fetch timeout")), 5000),
|
|
145
|
-
);
|
|
146
|
-
const response = await Promise.race([fetchPromise, timeoutPromise]);
|
|
147
|
-
|
|
148
|
-
if (response.ok) {
|
|
149
|
-
const data = await response.json();
|
|
150
|
-
if (data.status === "UP") {
|
|
151
|
-
isReady = true;
|
|
152
|
-
console.log("[E2E Test Setup] Server is ready.");
|
|
153
|
-
break;
|
|
154
|
-
} else {
|
|
155
|
-
console.log(
|
|
156
|
-
`[E2E Test Setup] Server not ready yet (status: ${data.status}), waiting... (${Math.round((Date.now() - startTime) / 1000)}s)`,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
console.log(
|
|
161
|
-
`[E2E Test Setup] Readiness check returned ${response.status}, waiting... (${Math.round((Date.now() - startTime) / 1000)}s)`,
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
} catch (error) {
|
|
165
|
-
// Server might not be ready yet, continue polling
|
|
166
|
-
const errorMsg =
|
|
167
|
-
error instanceof Error ? error.message : String(error);
|
|
168
|
-
// Only log every 5 seconds to reduce noise
|
|
169
|
-
const elapsed = Math.round((Date.now() - startTime) / 1000);
|
|
170
|
-
if (elapsed % 5 === 0) {
|
|
171
|
-
console.log(
|
|
172
|
-
`[E2E Test Setup] Readiness check failed (${errorMsg}), waiting... (${elapsed}s)`,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (!isReady) {
|
|
180
|
-
// Cleanup before throwing
|
|
181
|
-
if (listeningServerInstance?.listening) {
|
|
182
|
-
listeningServerInstance.closeAllConnections?.();
|
|
183
|
-
await new Promise<void>((res) =>
|
|
184
|
-
listeningServerInstance.close(() => res()),
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Server did not become ready within ${maxWaitTime / 1000} seconds. Package downloads may have failed.`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// --- Client Setup ---
|
|
193
|
-
const mcpClient = new Client<Request, Notification, Result>({
|
|
194
|
-
name: "mcp-e2e-test-client",
|
|
195
|
-
version: "1.0",
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// Use StreamableHTTPClientTransport, connecting to the base URL + /mcp endpoint
|
|
199
|
-
const mcpEndpointPath = "/mcp"; // Matches the endpoint used in server.ts
|
|
200
|
-
const clientTransport = new StreamableHTTPClientTransport(
|
|
201
|
-
new URL(`${listeningServerUrl}${mcpEndpointPath}`),
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
// Connect client (with timeout)
|
|
205
|
-
console.log(
|
|
206
|
-
`[E2E Test Setup] Connecting MCP client to ${listeningServerUrl}${mcpEndpointPath} ...`,
|
|
207
|
-
);
|
|
208
|
-
let connectTimeout: NodeJS.Timeout | null = null;
|
|
209
|
-
try {
|
|
210
|
-
const connectPromise = mcpClient.connect(clientTransport);
|
|
211
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
212
|
-
connectTimeout = setTimeout(() => {
|
|
213
|
-
reject(
|
|
214
|
-
new Error("[E2E Test Setup] Client connection timeout (5s)"),
|
|
215
|
-
);
|
|
216
|
-
}, 5000);
|
|
217
|
-
});
|
|
218
|
-
await Promise.race([connectPromise, timeoutPromise]);
|
|
219
|
-
console.log("[E2E Test Setup] MCP client connected.");
|
|
220
|
-
} catch (error) {
|
|
221
|
-
console.error("[E2E Test Setup] MCP Client connection failed:", error);
|
|
222
|
-
// Attempt cleanup even if connection failed
|
|
223
|
-
await mcpClient
|
|
224
|
-
?.close()
|
|
225
|
-
.catch(() =>
|
|
226
|
-
console.error("[E2E Test Setup] Error closing failed client:"),
|
|
227
|
-
);
|
|
228
|
-
if (listeningServerInstance?.listening) {
|
|
229
|
-
listeningServerInstance.closeAllConnections?.(); // Force close connections
|
|
230
|
-
await new Promise<void>((res) =>
|
|
231
|
-
listeningServerInstance.close(() => res()),
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
throw error;
|
|
235
|
-
} finally {
|
|
236
|
-
if (connectTimeout) clearTimeout(connectTimeout);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// --- Return Environment ---
|
|
240
|
-
return {
|
|
241
|
-
httpServer: listeningServerInstance,
|
|
242
|
-
serverUrl: listeningServerUrl,
|
|
243
|
-
mcpClient,
|
|
244
|
-
originalServerRoot,
|
|
245
|
-
originalInitializeStorage,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Cleans up the E2E test environment by closing the client and server.
|
|
251
|
-
*/
|
|
252
|
-
export async function cleanupE2ETestEnvironment(
|
|
253
|
-
env: McpE2ETestEnvironment | null,
|
|
254
|
-
): Promise<void> {
|
|
255
|
-
if (!env) {
|
|
256
|
-
// Attempt cleanup even if env is null (e.g., setup failed after config creation)
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// --- Restore Original SERVER_ROOT and INITIALIZE_STORAGE ---
|
|
261
|
-
// Restore the original SERVER_ROOT value after tests are complete.
|
|
262
|
-
const { originalServerRoot, originalInitializeStorage } = env;
|
|
263
|
-
if (originalServerRoot === undefined) {
|
|
264
|
-
delete process.env.SERVER_ROOT;
|
|
265
|
-
console.log("[E2E Test Cleanup] Restored SERVER_ROOT (deleted)");
|
|
266
|
-
} else {
|
|
267
|
-
process.env.SERVER_ROOT = originalServerRoot;
|
|
268
|
-
console.log(
|
|
269
|
-
`[E2E Test Cleanup] Restored SERVER_ROOT=${process.env.SERVER_ROOT}`,
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Restore the original INITIALIZE_STORAGE value after tests are complete.
|
|
274
|
-
if (originalInitializeStorage === undefined) {
|
|
275
|
-
delete process.env.INITIALIZE_STORAGE;
|
|
276
|
-
console.log("[E2E Test Cleanup] Restored INITIALIZE_STORAGE (deleted)");
|
|
277
|
-
} else {
|
|
278
|
-
process.env.INITIALIZE_STORAGE = originalInitializeStorage;
|
|
279
|
-
console.log(
|
|
280
|
-
`[E2E Test Cleanup] Restored INITIALIZE_STORAGE=${process.env.INITIALIZE_STORAGE}`,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const { mcpClient, httpServer } = env;
|
|
285
|
-
|
|
286
|
-
// 1. Close client first (with timeout)
|
|
287
|
-
if (mcpClient) {
|
|
288
|
-
try {
|
|
289
|
-
const closePromise = mcpClient.close();
|
|
290
|
-
const timeoutPromise = new Promise<void>((_, reject) => {
|
|
291
|
-
setTimeout(() => reject(new Error("Client close timeout")), 5000);
|
|
292
|
-
});
|
|
293
|
-
await Promise.race([closePromise, timeoutPromise]);
|
|
294
|
-
} catch (error) {
|
|
295
|
-
// Ignore client close errors during cleanup potentially
|
|
296
|
-
console.warn(
|
|
297
|
-
"[E2E Test Cleanup] Error closing MCP client (ignoring):",
|
|
298
|
-
error instanceof Error ? error.message : String(error),
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// 2. Close HTTP server connections and then the server itself (with timeout)
|
|
304
|
-
if (httpServer) {
|
|
305
|
-
// Force close any remaining connections immediately
|
|
306
|
-
httpServer.closeAllConnections?.();
|
|
307
|
-
|
|
308
|
-
if (httpServer.listening) {
|
|
309
|
-
try {
|
|
310
|
-
const closePromise = new Promise<void>((resolve, reject) => {
|
|
311
|
-
const timeout = setTimeout(() => {
|
|
312
|
-
reject(new Error("Server close timeout"));
|
|
313
|
-
}, 5000);
|
|
314
|
-
httpServer.close((err: NodeJS.ErrnoException | undefined) => {
|
|
315
|
-
clearTimeout(timeout);
|
|
316
|
-
if (err && err.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
317
|
-
console.error(
|
|
318
|
-
"[E2E Test Cleanup] Error closing HTTP server (after closing connections):",
|
|
319
|
-
err,
|
|
320
|
-
);
|
|
321
|
-
} else if (!err) {
|
|
322
|
-
console.log("[E2E Test Cleanup] HTTP server closed.");
|
|
323
|
-
}
|
|
324
|
-
resolve();
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
await closePromise;
|
|
328
|
-
} catch (error) {
|
|
329
|
-
console.warn(
|
|
330
|
-
"[E2E Test Cleanup] Server close timeout or error (forcing close):",
|
|
331
|
-
error instanceof Error ? error.message : String(error),
|
|
332
|
-
);
|
|
333
|
-
// Force destroy if close times out
|
|
334
|
-
if (httpServer.listening) {
|
|
335
|
-
httpServer.closeAllConnections?.();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
} else {
|
|
339
|
-
console.log(
|
|
340
|
-
"[E2E Test Cleanup] HTTP server was not listening or already closed.",
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
package/tests/harness/mocks.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import sinon from "sinon";
|
|
2
|
-
import { ProjectStore } from "../../src/service/project_store";
|
|
3
|
-
|
|
4
|
-
/** Return a stubbed ProjectStore where every lookup throws or returns minimal objects. */
|
|
5
|
-
export function fakeProjectStore(): sinon.SinonStubbedInstance<ProjectStore> {
|
|
6
|
-
const ps = sinon.createStubInstance(ProjectStore);
|
|
7
|
-
// For now just have getProject reject; suites can stub more.
|
|
8
|
-
ps.getProject.rejects(new Error("fakeProjectStore: getProject not stubbed"));
|
|
9
|
-
return ps;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// The runtime implementation of `McpServer` lives in the MCP SDK package, which
|
|
13
|
-
// is **not** required for unit/integration tests that only need a stubbed
|
|
14
|
-
// instance. Importing it at runtime would fail when the dependency is not
|
|
15
|
-
// present in the local workspace. Instead we define a minimal dummy class that
|
|
16
|
-
// satisfies Sinon while keeping the public type surface the same for tests.
|
|
17
|
-
//
|
|
18
|
-
// NOTE: If we later add the real SDK as a dependency we can simply replace this
|
|
19
|
-
// dummy class with:
|
|
20
|
-
// import { McpServer } from "@modelcontextprotocol/sdk";
|
|
21
|
-
class DummyMcpServer {}
|
|
22
|
-
|
|
23
|
-
// Re-export the symbol so downstream test files can continue to refer to the
|
|
24
|
-
// name `McpServer` without changes.
|
|
25
|
-
export type McpServer = DummyMcpServer;
|
|
26
|
-
|
|
27
|
-
/** Convenience helper mimicking the old mocks used in integration specs. */
|
|
28
|
-
export function createMalloyServiceMocks() {
|
|
29
|
-
return {
|
|
30
|
-
projectStore: fakeProjectStore(),
|
|
31
|
-
} as const;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Create a Sinon spy wrapper around a new DummyMcpServer instance. */
|
|
35
|
-
export function spyMcpServer(): sinon.SinonStubbedInstance<DummyMcpServer> {
|
|
36
|
-
return sinon.createStubInstance(DummyMcpServer);
|
|
37
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import http from "http";
|
|
2
|
-
|
|
3
|
-
export interface RestE2EEnv {
|
|
4
|
-
httpServer: http.Server;
|
|
5
|
-
baseUrl: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Spin up an HTTP server wrapping the real Express REST app.
|
|
10
|
-
*
|
|
11
|
-
* Works regardless of which test file first imported server.ts —
|
|
12
|
-
* reuses the cached Express app and binds on an OS-assigned port
|
|
13
|
-
* to avoid collisions.
|
|
14
|
-
*
|
|
15
|
-
* Callers are responsible for creating any test-specific projects
|
|
16
|
-
* via the REST API (POST /api/v0/projects) and cleaning them up.
|
|
17
|
-
*/
|
|
18
|
-
export async function startRestE2E(): Promise<
|
|
19
|
-
RestE2EEnv & { stop(): Promise<void> }
|
|
20
|
-
> {
|
|
21
|
-
const { app } = await import("../../src/server");
|
|
22
|
-
|
|
23
|
-
const httpServer: http.Server = await new Promise<http.Server>(
|
|
24
|
-
(resolve, reject) => {
|
|
25
|
-
const srv = http
|
|
26
|
-
.createServer(app)
|
|
27
|
-
.listen(0, "127.0.0.1", () => resolve(srv));
|
|
28
|
-
srv.on("error", (err: NodeJS.ErrnoException) => {
|
|
29
|
-
console.error("[REST E2E] server listen error", err);
|
|
30
|
-
reject(err);
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const addr = httpServer.address() as { port: number };
|
|
36
|
-
const baseUrl = `http://127.0.0.1:${addr.port}`;
|
|
37
|
-
|
|
38
|
-
const maxWait = 180_000;
|
|
39
|
-
const start = Date.now();
|
|
40
|
-
let ready = false;
|
|
41
|
-
while (!ready && Date.now() - start < maxWait) {
|
|
42
|
-
try {
|
|
43
|
-
const res = await fetch(`${baseUrl}/health/readiness`);
|
|
44
|
-
if (res.ok) {
|
|
45
|
-
const data = (await res.json()) as { status: string };
|
|
46
|
-
if (data.status === "UP") {
|
|
47
|
-
ready = true;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
52
|
-
// server not ready yet
|
|
53
|
-
}
|
|
54
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
55
|
-
}
|
|
56
|
-
if (!ready) {
|
|
57
|
-
httpServer.closeAllConnections?.();
|
|
58
|
-
await new Promise<void>((r) => httpServer.close(() => r()));
|
|
59
|
-
throw new Error("REST E2E server did not become ready in time");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const stop = async (): Promise<void> => {
|
|
63
|
-
httpServer.closeAllConnections?.();
|
|
64
|
-
await new Promise<void>((r) => httpServer.close(() => r()));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return { httpServer, baseUrl, stop };
|
|
68
|
-
}
|
package/tests/harness/uris.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface FixtureUris {
|
|
2
|
-
project: string;
|
|
3
|
-
package: string;
|
|
4
|
-
flightsModel: string;
|
|
5
|
-
source: string;
|
|
6
|
-
view: string;
|
|
7
|
-
query: string;
|
|
8
|
-
notebook: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Return canonical URIs used across integration tests, parametrised by project
|
|
13
|
-
* and package. Most suites will call this with defaults.
|
|
14
|
-
*/
|
|
15
|
-
export function malloyUris(
|
|
16
|
-
project = "malloy-samples",
|
|
17
|
-
pkg = "faa",
|
|
18
|
-
): FixtureUris {
|
|
19
|
-
const base = `malloy://project/${project}`;
|
|
20
|
-
const pkgUri = `${base}/package/${pkg}`;
|
|
21
|
-
const model = `${pkgUri}/models/flights.malloy`;
|
|
22
|
-
return {
|
|
23
|
-
project: base,
|
|
24
|
-
package: pkgUri,
|
|
25
|
-
flightsModel: model,
|
|
26
|
-
source: `${model}/sources/flights`,
|
|
27
|
-
view: `${model}/sources/flights/views/flights_by_month`,
|
|
28
|
-
query: `${model}/queries/flights_by_carrier`,
|
|
29
|
-
notebook: `${pkgUri}/notebooks/overview.malloynb`,
|
|
30
|
-
};
|
|
31
|
-
}
|