@malloy-publisher/server 0.0.382-dev → 0.2.1
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 +3929 -534
- package/dist/app/assets/EnvironmentPage-CHq5BF4l.js +1 -0
- package/dist/app/assets/HomePage-CIp-pJCa.js +1 -0
- package/dist/app/assets/LightMode-mHHPjEeA.js +1 -0
- package/dist/app/assets/MainPage-CylxO5Yu.js +2 -0
- package/dist/app/assets/MaterializationsPage-a0vjqxib.js +1 -0
- package/dist/app/assets/ModelPage-Cz-MrSZQ.js +1 -0
- package/dist/app/assets/PackagePage-Cdg5D7AN.js +1 -0
- package/dist/app/assets/RouteError-B5SIyn6G.js +1 -0
- package/dist/app/assets/ThemeEditorPage-B62rRc-y.js +1 -0
- package/dist/app/assets/WorkbookPage-45cG1Gx6.js +1 -0
- package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-DyU47reh.es-DY9b3WjS.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-C5ClsnS7.js +1774 -0
- package/dist/app/assets/index-DF9tVqwN.js +1 -0
- package/dist/app/assets/index-DSoCUF-f.js +2725 -0
- package/dist/app/assets/index-DgVRz2wm.js +2 -0
- package/dist/app/assets/index-P-pF8nU5.js +632 -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} +141276 -74705
- 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,1132 +0,0 @@
|
|
|
1
|
-
import { DuckDBConnection } from "@malloydata/db-duckdb";
|
|
2
|
-
import {
|
|
3
|
-
afterAll,
|
|
4
|
-
afterEach,
|
|
5
|
-
beforeAll,
|
|
6
|
-
beforeEach,
|
|
7
|
-
describe,
|
|
8
|
-
expect,
|
|
9
|
-
it,
|
|
10
|
-
} from "bun:test";
|
|
11
|
-
import fs from "fs/promises";
|
|
12
|
-
import os from "os";
|
|
13
|
-
import path from "path";
|
|
14
|
-
import type { components } from "../../../src/api";
|
|
15
|
-
import { createProjectConnections } from "../../../src/service/connection";
|
|
16
|
-
|
|
17
|
-
type ApiConnection = components["schemas"]["Connection"];
|
|
18
|
-
|
|
19
|
-
const TEST_DB_DIR = path.join(os.tmpdir(), "duckdb-attached-db-tests");
|
|
20
|
-
const TEST_DB_PATH = path.join(TEST_DB_DIR, "test.duckdb");
|
|
21
|
-
|
|
22
|
-
describe("DuckDB Attached Databases", () => {
|
|
23
|
-
let connection: DuckDBConnection;
|
|
24
|
-
|
|
25
|
-
beforeAll(async () => {
|
|
26
|
-
await fs.mkdir(TEST_DB_DIR, { recursive: true });
|
|
27
|
-
connection = new DuckDBConnection("test", TEST_DB_PATH, TEST_DB_DIR);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterAll(async () => {
|
|
31
|
-
try {
|
|
32
|
-
await connection.close();
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
34
|
-
await fs.rm(TEST_DB_DIR, { recursive: true, force: true });
|
|
35
|
-
} catch {
|
|
36
|
-
// Ignore cleanup errors
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("Extension Availability Tests", () => {
|
|
41
|
-
it("should verify community extension install capability", async () => {
|
|
42
|
-
const result = await connection.runSQL("INSTALL json;");
|
|
43
|
-
expect(result).toBeDefined();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should report clear error when extension is not found", async () => {
|
|
47
|
-
try {
|
|
48
|
-
await connection.runSQL(
|
|
49
|
-
"INSTALL 'nonexistent_extension_xyz' FROM community;",
|
|
50
|
-
);
|
|
51
|
-
expect(true).toBe(false);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
expect(error).toBeInstanceOf(Error);
|
|
54
|
-
const message = (error as Error).message.toLowerCase();
|
|
55
|
-
expect(
|
|
56
|
-
message.includes("extension") || message.includes("not found"),
|
|
57
|
-
).toBe(true);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should load httpfs extension for cloud storage", async () => {
|
|
62
|
-
await connection.runSQL("INSTALL httpfs;");
|
|
63
|
-
await connection.runSQL("LOAD httpfs;");
|
|
64
|
-
const result = await connection.runSQL(
|
|
65
|
-
"SELECT * FROM duckdb_extensions() WHERE extension_name = 'httpfs';",
|
|
66
|
-
);
|
|
67
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should load postgres extension", async () => {
|
|
71
|
-
await connection.runSQL("INSTALL postgres;");
|
|
72
|
-
await connection.runSQL("LOAD postgres;");
|
|
73
|
-
// Extension is named 'postgres' but registered as 'postgres_scanner'
|
|
74
|
-
const result = await connection.runSQL(
|
|
75
|
-
"SELECT * FROM duckdb_extensions() WHERE extension_name = 'postgres_scanner';",
|
|
76
|
-
);
|
|
77
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should load bigquery extension from community", async () => {
|
|
81
|
-
try {
|
|
82
|
-
await connection.runSQL("INSTALL 'bigquery' FROM community;");
|
|
83
|
-
await connection.runSQL("LOAD bigquery;");
|
|
84
|
-
const result = await connection.runSQL(
|
|
85
|
-
"SELECT * FROM duckdb_extensions() WHERE extension_name = 'bigquery';",
|
|
86
|
-
);
|
|
87
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
const message = (error as Error).message;
|
|
90
|
-
if (
|
|
91
|
-
message.includes("not found") ||
|
|
92
|
-
message.includes("Extension")
|
|
93
|
-
) {
|
|
94
|
-
console.error(
|
|
95
|
-
`\nBigQuery extension not available for this DuckDB version/platform.`,
|
|
96
|
-
);
|
|
97
|
-
console.error(`Error: ${message}\n`);
|
|
98
|
-
}
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("should load snowflake extension from community", async () => {
|
|
104
|
-
try {
|
|
105
|
-
await connection.runSQL("INSTALL 'snowflake' FROM community;");
|
|
106
|
-
await connection.runSQL("LOAD snowflake;");
|
|
107
|
-
const result = await connection.runSQL(
|
|
108
|
-
"SELECT * FROM duckdb_extensions() WHERE extension_name = 'snowflake';",
|
|
109
|
-
);
|
|
110
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
const message = (error as Error).message;
|
|
113
|
-
if (
|
|
114
|
-
message.includes("not found") ||
|
|
115
|
-
message.includes("Extension")
|
|
116
|
-
) {
|
|
117
|
-
console.error(
|
|
118
|
-
`\nSnowflake extension not available for this DuckDB version/platform.`,
|
|
119
|
-
);
|
|
120
|
-
console.error(`Error: ${message}\n`);
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should load ducklake extension", async () => {
|
|
127
|
-
try {
|
|
128
|
-
await connection.runSQL("INSTALL ducklake;");
|
|
129
|
-
await connection.runSQL("LOAD ducklake;");
|
|
130
|
-
const result = await connection.runSQL(
|
|
131
|
-
"SELECT * FROM duckdb_extensions() WHERE extension_name = 'ducklake';",
|
|
132
|
-
);
|
|
133
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
const message = (error as Error).message;
|
|
136
|
-
if (
|
|
137
|
-
message.includes("not found") ||
|
|
138
|
-
message.includes("Extension")
|
|
139
|
-
) {
|
|
140
|
-
console.error(
|
|
141
|
-
`\nDuckLake extension not available for this DuckDB version/platform.`,
|
|
142
|
-
);
|
|
143
|
-
console.error(`Error: ${message}\n`);
|
|
144
|
-
}
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe("Configuration Validation - Negative Tests", () => {
|
|
151
|
-
it("should reject BigQuery config without service account key", async () => {
|
|
152
|
-
const invalidConfig = {
|
|
153
|
-
name: "test_bq",
|
|
154
|
-
type: "bigquery",
|
|
155
|
-
bigqueryConnection: {
|
|
156
|
-
defaultProjectId: "test-project",
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
expect(
|
|
161
|
-
invalidConfig.bigqueryConnection.defaultProjectId,
|
|
162
|
-
).toBeDefined();
|
|
163
|
-
expect(
|
|
164
|
-
(invalidConfig.bigqueryConnection as Record<string, unknown>)
|
|
165
|
-
.serviceAccountKeyJson,
|
|
166
|
-
).toBeUndefined();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("should reject invalid service account JSON", async () => {
|
|
170
|
-
const invalidJson = '{"type": "wrong_type"}';
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
const keyData = JSON.parse(invalidJson);
|
|
174
|
-
if (keyData.type !== "service_account") {
|
|
175
|
-
throw new Error(
|
|
176
|
-
'Invalid service account key: incorrect "type" field',
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
expect(true).toBe(false);
|
|
180
|
-
} catch (error) {
|
|
181
|
-
expect((error as Error).message).toContain("type");
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("should reject service account JSON missing required fields", async () => {
|
|
186
|
-
const incompleteJson = JSON.stringify({
|
|
187
|
-
type: "service_account",
|
|
188
|
-
project_id: "test-project",
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const requiredFields = [
|
|
192
|
-
"type",
|
|
193
|
-
"project_id",
|
|
194
|
-
"private_key",
|
|
195
|
-
"client_email",
|
|
196
|
-
];
|
|
197
|
-
const keyData = JSON.parse(incompleteJson);
|
|
198
|
-
|
|
199
|
-
const missingFields = requiredFields.filter(
|
|
200
|
-
(field) => !keyData[field],
|
|
201
|
-
);
|
|
202
|
-
expect(missingFields).toContain("private_key");
|
|
203
|
-
expect(missingFields).toContain("client_email");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("should reject Snowflake config without required credentials", async () => {
|
|
207
|
-
const invalidConfig = {
|
|
208
|
-
name: "test_sf",
|
|
209
|
-
type: "snowflake",
|
|
210
|
-
snowflakeConnection: {
|
|
211
|
-
account: "test-account",
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const requiredFields = {
|
|
216
|
-
account:
|
|
217
|
-
(invalidConfig.snowflakeConnection as Record<string, unknown>)
|
|
218
|
-
.account || null,
|
|
219
|
-
username:
|
|
220
|
-
(invalidConfig.snowflakeConnection as Record<string, unknown>)
|
|
221
|
-
.username || null,
|
|
222
|
-
password:
|
|
223
|
-
(invalidConfig.snowflakeConnection as Record<string, unknown>)
|
|
224
|
-
.password || null,
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const missingFields = Object.entries(requiredFields)
|
|
228
|
-
.filter(([, value]) => !value)
|
|
229
|
-
.map(([key]) => key);
|
|
230
|
-
|
|
231
|
-
expect(missingFields).toContain("username");
|
|
232
|
-
expect(missingFields).toContain("password");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("should reject GCS config without keyId and secret", async () => {
|
|
236
|
-
const invalidConfig = {
|
|
237
|
-
name: "test_gcs",
|
|
238
|
-
type: "gcs",
|
|
239
|
-
gcsConnection: {},
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
expect(
|
|
243
|
-
(invalidConfig.gcsConnection as Record<string, unknown>).keyId,
|
|
244
|
-
).toBeUndefined();
|
|
245
|
-
expect(
|
|
246
|
-
(invalidConfig.gcsConnection as Record<string, unknown>).secret,
|
|
247
|
-
).toBeUndefined();
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("should reject S3 config without credentials", async () => {
|
|
251
|
-
const invalidConfig = {
|
|
252
|
-
name: "test_s3",
|
|
253
|
-
type: "s3",
|
|
254
|
-
s3Connection: {},
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
expect(
|
|
258
|
-
(invalidConfig.s3Connection as Record<string, unknown>).accessKeyId,
|
|
259
|
-
).toBeUndefined();
|
|
260
|
-
expect(
|
|
261
|
-
(invalidConfig.s3Connection as Record<string, unknown>)
|
|
262
|
-
.secretAccessKey,
|
|
263
|
-
).toBeUndefined();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("should reject unsupported database type", async () => {
|
|
267
|
-
const unsupportedType = "mongodb";
|
|
268
|
-
const supportedTypes = [
|
|
269
|
-
"bigquery",
|
|
270
|
-
"snowflake",
|
|
271
|
-
"postgres",
|
|
272
|
-
"gcs",
|
|
273
|
-
"s3",
|
|
274
|
-
];
|
|
275
|
-
|
|
276
|
-
expect(supportedTypes).not.toContain(unsupportedType);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
describe("DuckDB Connection - Positive Tests", () => {
|
|
281
|
-
it("should create and query in-memory database", async () => {
|
|
282
|
-
const memConnection = new DuckDBConnection(
|
|
283
|
-
"mem_test",
|
|
284
|
-
":memory:",
|
|
285
|
-
TEST_DB_DIR,
|
|
286
|
-
);
|
|
287
|
-
const result = await memConnection.runSQL("SELECT 1 as value;");
|
|
288
|
-
expect(result.rows[0]).toEqual({ value: 1 });
|
|
289
|
-
await memConnection.close();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it("should show databases including memory", async () => {
|
|
293
|
-
const result = await connection.runSQL("SHOW DATABASES;");
|
|
294
|
-
expect(result.rows).toBeDefined();
|
|
295
|
-
expect(Array.isArray(result.rows)).toBe(true);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it("should handle SQL escaping correctly", async () => {
|
|
299
|
-
const testValue = "test'with\"special;chars";
|
|
300
|
-
const escaped = testValue.replace(/'/g, "''");
|
|
301
|
-
const result = await connection.runSQL(
|
|
302
|
-
`SELECT '${escaped}' as escaped_value;`,
|
|
303
|
-
);
|
|
304
|
-
expect(result.rows[0].escaped_value).toBe(testValue);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("should create and use secrets", async () => {
|
|
308
|
-
await connection.runSQL(`
|
|
309
|
-
CREATE OR REPLACE SECRET test_secret (
|
|
310
|
-
TYPE S3,
|
|
311
|
-
KEY_ID 'test_key',
|
|
312
|
-
SECRET 'test_secret_value',
|
|
313
|
-
REGION 'us-east-1'
|
|
314
|
-
);
|
|
315
|
-
`);
|
|
316
|
-
|
|
317
|
-
const secrets = await connection.runSQL(
|
|
318
|
-
"SELECT * FROM duckdb_secrets();",
|
|
319
|
-
);
|
|
320
|
-
expect(secrets.rows.length).toBeGreaterThan(0);
|
|
321
|
-
|
|
322
|
-
await connection.runSQL("DROP SECRET IF EXISTS test_secret;");
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
describe("Version Compatibility Check", () => {
|
|
327
|
-
it("should report DuckDB version for diagnostics", async () => {
|
|
328
|
-
const result = await connection.runSQL("SELECT version() as version;");
|
|
329
|
-
const version = result.rows[0].version as string;
|
|
330
|
-
|
|
331
|
-
console.log(`\n📊 DuckDB Version: ${version}`);
|
|
332
|
-
|
|
333
|
-
expect(version).toBeDefined();
|
|
334
|
-
expect(typeof version).toBe("string");
|
|
335
|
-
expect(version).toMatch(/v?\d+\.\d+\.\d+/);
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it("should list available extensions for diagnostics", async () => {
|
|
339
|
-
const result = await connection.runSQL(
|
|
340
|
-
"SELECT extension_name, loaded, installed FROM duckdb_extensions() WHERE installed = true ORDER BY extension_name;",
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
console.log(`\n📦 Installed Extensions:`);
|
|
344
|
-
for (const row of result.rows) {
|
|
345
|
-
const r = row as {
|
|
346
|
-
extension_name: string;
|
|
347
|
-
loaded: boolean;
|
|
348
|
-
installed: boolean;
|
|
349
|
-
};
|
|
350
|
-
console.log(` - ${r.extension_name} (loaded: ${r.loaded})`);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
expect(result.rows).toBeDefined();
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
describe("createProjectConnections - DuckDB", () => {
|
|
359
|
-
const PROJECT_TEST_DIR = path.join(os.tmpdir(), "duckdb-project-tests");
|
|
360
|
-
let createdConnections: Map<string, unknown> = new Map();
|
|
361
|
-
|
|
362
|
-
beforeEach(async () => {
|
|
363
|
-
await fs.mkdir(PROJECT_TEST_DIR, { recursive: true });
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
afterEach(async () => {
|
|
367
|
-
for (const conn of createdConnections.values()) {
|
|
368
|
-
try {
|
|
369
|
-
await (conn as DuckDBConnection).close();
|
|
370
|
-
} catch {
|
|
371
|
-
// Ignore
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
createdConnections.clear();
|
|
375
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
376
|
-
try {
|
|
377
|
-
await fs.rm(PROJECT_TEST_DIR, { recursive: true, force: true });
|
|
378
|
-
} catch {
|
|
379
|
-
// Ignore
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
describe("Positive Tests", () => {
|
|
384
|
-
it("should create a named duckdb connection", async () => {
|
|
385
|
-
const connections: ApiConnection[] = [
|
|
386
|
-
{
|
|
387
|
-
name: "my_duckdb_conn",
|
|
388
|
-
type: "duckdb",
|
|
389
|
-
duckdbConnection: {
|
|
390
|
-
attachedDatabases: [
|
|
391
|
-
{
|
|
392
|
-
name: "test_gcs",
|
|
393
|
-
type: "gcs",
|
|
394
|
-
gcsConnection: {
|
|
395
|
-
keyId: "test-key-id",
|
|
396
|
-
secret: "test-secret",
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
],
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
];
|
|
403
|
-
|
|
404
|
-
const { malloyConnections, apiConnections } =
|
|
405
|
-
await createProjectConnections(connections, PROJECT_TEST_DIR);
|
|
406
|
-
|
|
407
|
-
createdConnections = malloyConnections;
|
|
408
|
-
|
|
409
|
-
expect(malloyConnections.has("my_duckdb_conn")).toBe(true);
|
|
410
|
-
expect(apiConnections.length).toBe(1);
|
|
411
|
-
expect(apiConnections[0].name).toBe("my_duckdb_conn");
|
|
412
|
-
expect(apiConnections[0].type).toBe("duckdb");
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it("should create named DuckDB connection", async () => {
|
|
416
|
-
const connections: ApiConnection[] = [
|
|
417
|
-
{
|
|
418
|
-
name: "my_duckdb",
|
|
419
|
-
type: "duckdb",
|
|
420
|
-
duckdbConnection: {
|
|
421
|
-
attachedDatabases: [
|
|
422
|
-
{
|
|
423
|
-
name: "test_gcs",
|
|
424
|
-
type: "gcs",
|
|
425
|
-
gcsConnection: {
|
|
426
|
-
keyId: "test-key-id",
|
|
427
|
-
secret: "test-secret",
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
],
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
];
|
|
434
|
-
|
|
435
|
-
const { malloyConnections, apiConnections } =
|
|
436
|
-
await createProjectConnections(connections, PROJECT_TEST_DIR);
|
|
437
|
-
|
|
438
|
-
createdConnections = malloyConnections;
|
|
439
|
-
|
|
440
|
-
expect(malloyConnections.has("my_duckdb")).toBe(true);
|
|
441
|
-
expect(apiConnections.length).toBe(1);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it("should set connection attributes correctly", async () => {
|
|
445
|
-
const connections: ApiConnection[] = [
|
|
446
|
-
{
|
|
447
|
-
name: "attr_test",
|
|
448
|
-
type: "duckdb",
|
|
449
|
-
duckdbConnection: {
|
|
450
|
-
attachedDatabases: [
|
|
451
|
-
{
|
|
452
|
-
name: "test_gcs",
|
|
453
|
-
type: "gcs",
|
|
454
|
-
gcsConnection: {
|
|
455
|
-
keyId: "test-key-id",
|
|
456
|
-
secret: "test-secret",
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
],
|
|
460
|
-
},
|
|
461
|
-
},
|
|
462
|
-
];
|
|
463
|
-
|
|
464
|
-
const { malloyConnections, apiConnections } =
|
|
465
|
-
await createProjectConnections(connections, PROJECT_TEST_DIR);
|
|
466
|
-
|
|
467
|
-
createdConnections = malloyConnections;
|
|
468
|
-
|
|
469
|
-
const conn = apiConnections.find((c) => c.name === "attr_test");
|
|
470
|
-
expect(conn?.attributes).toBeDefined();
|
|
471
|
-
expect(conn?.attributes?.dialectName).toBe("duckdb");
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
it("should handle multiple connection types", async () => {
|
|
475
|
-
const connections: ApiConnection[] = [
|
|
476
|
-
{
|
|
477
|
-
name: "postgres_conn",
|
|
478
|
-
type: "postgres",
|
|
479
|
-
postgresConnection: {
|
|
480
|
-
host: "localhost",
|
|
481
|
-
port: 5432,
|
|
482
|
-
userName: "test",
|
|
483
|
-
password: "test",
|
|
484
|
-
databaseName: "test",
|
|
485
|
-
},
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
name: "my_duck",
|
|
489
|
-
type: "duckdb",
|
|
490
|
-
duckdbConnection: {
|
|
491
|
-
attachedDatabases: [
|
|
492
|
-
{
|
|
493
|
-
name: "test_gcs",
|
|
494
|
-
type: "gcs",
|
|
495
|
-
gcsConnection: {
|
|
496
|
-
keyId: "test-key-id",
|
|
497
|
-
secret: "test-secret",
|
|
498
|
-
},
|
|
499
|
-
},
|
|
500
|
-
],
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
];
|
|
504
|
-
|
|
505
|
-
const { malloyConnections } = await createProjectConnections(
|
|
506
|
-
connections,
|
|
507
|
-
PROJECT_TEST_DIR,
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
createdConnections = malloyConnections;
|
|
511
|
-
|
|
512
|
-
expect(malloyConnections.has("postgres_conn")).toBe(true);
|
|
513
|
-
expect(malloyConnections.has("my_duck")).toBe(true);
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
it("should create database file at project path", async () => {
|
|
517
|
-
const connections: ApiConnection[] = [
|
|
518
|
-
{
|
|
519
|
-
name: "file_test",
|
|
520
|
-
type: "duckdb",
|
|
521
|
-
duckdbConnection: {
|
|
522
|
-
attachedDatabases: [
|
|
523
|
-
{
|
|
524
|
-
name: "test_gcs",
|
|
525
|
-
type: "gcs",
|
|
526
|
-
gcsConnection: {
|
|
527
|
-
keyId: "test-key-id",
|
|
528
|
-
secret: "test-secret",
|
|
529
|
-
},
|
|
530
|
-
},
|
|
531
|
-
],
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
];
|
|
535
|
-
|
|
536
|
-
const { malloyConnections } = await createProjectConnections(
|
|
537
|
-
connections,
|
|
538
|
-
PROJECT_TEST_DIR,
|
|
539
|
-
);
|
|
540
|
-
|
|
541
|
-
createdConnections = malloyConnections;
|
|
542
|
-
|
|
543
|
-
const conn = malloyConnections.get(
|
|
544
|
-
"file_test",
|
|
545
|
-
) as unknown as DuckDBConnection;
|
|
546
|
-
await conn.runSQL("CREATE TABLE test_table (id INT);");
|
|
547
|
-
|
|
548
|
-
const dbPath = path.join(PROJECT_TEST_DIR, "file_test.duckdb");
|
|
549
|
-
const exists = await fs
|
|
550
|
-
.access(dbPath)
|
|
551
|
-
.then(() => true)
|
|
552
|
-
.catch(() => false);
|
|
553
|
-
expect(exists).toBe(true);
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
describe("Negative Tests", () => {
|
|
558
|
-
it("should handle duplicate connection names by using the last one", async () => {
|
|
559
|
-
const connections: ApiConnection[] = [
|
|
560
|
-
{
|
|
561
|
-
name: "duplicate",
|
|
562
|
-
type: "duckdb",
|
|
563
|
-
duckdbConnection: {
|
|
564
|
-
attachedDatabases: [
|
|
565
|
-
{
|
|
566
|
-
name: "test_gcs",
|
|
567
|
-
type: "gcs",
|
|
568
|
-
gcsConnection: {
|
|
569
|
-
keyId: "test-key-id",
|
|
570
|
-
secret: "test-secret",
|
|
571
|
-
},
|
|
572
|
-
},
|
|
573
|
-
],
|
|
574
|
-
},
|
|
575
|
-
},
|
|
576
|
-
{
|
|
577
|
-
name: "duplicate",
|
|
578
|
-
type: "duckdb",
|
|
579
|
-
duckdbConnection: {
|
|
580
|
-
attachedDatabases: [
|
|
581
|
-
{
|
|
582
|
-
name: "test_gcs2",
|
|
583
|
-
type: "gcs",
|
|
584
|
-
gcsConnection: {
|
|
585
|
-
keyId: "test-key-id",
|
|
586
|
-
secret: "test-secret",
|
|
587
|
-
},
|
|
588
|
-
},
|
|
589
|
-
],
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
];
|
|
593
|
-
|
|
594
|
-
const { malloyConnections } = await createProjectConnections(
|
|
595
|
-
connections,
|
|
596
|
-
PROJECT_TEST_DIR,
|
|
597
|
-
);
|
|
598
|
-
|
|
599
|
-
createdConnections = malloyConnections;
|
|
600
|
-
|
|
601
|
-
// Should only have one connection with that name
|
|
602
|
-
expect(malloyConnections.has("duplicate")).toBe(true);
|
|
603
|
-
expect(malloyConnections.size).toBe(1);
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
it("should throw on missing connection name", async () => {
|
|
607
|
-
const connections: ApiConnection[] = [
|
|
608
|
-
{
|
|
609
|
-
name: "",
|
|
610
|
-
type: "duckdb",
|
|
611
|
-
duckdbConnection: {
|
|
612
|
-
attachedDatabases: [
|
|
613
|
-
{
|
|
614
|
-
name: "test_gcs",
|
|
615
|
-
type: "gcs",
|
|
616
|
-
gcsConnection: {
|
|
617
|
-
keyId: "test-key-id",
|
|
618
|
-
secret: "test-secret",
|
|
619
|
-
},
|
|
620
|
-
},
|
|
621
|
-
],
|
|
622
|
-
},
|
|
623
|
-
},
|
|
624
|
-
];
|
|
625
|
-
|
|
626
|
-
await expect(
|
|
627
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
628
|
-
).rejects.toThrow();
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
it("should throw on missing duckdbConnection config", async () => {
|
|
632
|
-
const connections = [
|
|
633
|
-
{
|
|
634
|
-
name: "no_config",
|
|
635
|
-
type: "duckdb",
|
|
636
|
-
},
|
|
637
|
-
] as ApiConnection[];
|
|
638
|
-
|
|
639
|
-
await expect(
|
|
640
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
641
|
-
).rejects.toThrow("DuckDB connection configuration is missing");
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
it("should throw on unsupported attached database type", async () => {
|
|
645
|
-
const connections: ApiConnection[] = [
|
|
646
|
-
{
|
|
647
|
-
name: "bad_attach",
|
|
648
|
-
type: "duckdb",
|
|
649
|
-
duckdbConnection: {
|
|
650
|
-
attachedDatabases: [
|
|
651
|
-
{
|
|
652
|
-
name: "unsupported_db",
|
|
653
|
-
type: "mongodb" as "bigquery",
|
|
654
|
-
},
|
|
655
|
-
],
|
|
656
|
-
},
|
|
657
|
-
},
|
|
658
|
-
];
|
|
659
|
-
|
|
660
|
-
await expect(
|
|
661
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
662
|
-
).rejects.toThrow("Unsupported database type");
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
it("should throw on BigQuery attach without service account", async () => {
|
|
666
|
-
const connections: ApiConnection[] = [
|
|
667
|
-
{
|
|
668
|
-
name: "bq_no_creds",
|
|
669
|
-
type: "duckdb",
|
|
670
|
-
duckdbConnection: {
|
|
671
|
-
attachedDatabases: [
|
|
672
|
-
{
|
|
673
|
-
name: "bq_test",
|
|
674
|
-
type: "bigquery",
|
|
675
|
-
bigqueryConnection: {
|
|
676
|
-
defaultProjectId: "test-project",
|
|
677
|
-
},
|
|
678
|
-
},
|
|
679
|
-
],
|
|
680
|
-
},
|
|
681
|
-
},
|
|
682
|
-
];
|
|
683
|
-
|
|
684
|
-
await expect(
|
|
685
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
686
|
-
).rejects.toThrow("service account key required");
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
it("should throw on GCS attach without credentials", async () => {
|
|
690
|
-
const connections = [
|
|
691
|
-
{
|
|
692
|
-
name: "gcs_no_creds",
|
|
693
|
-
type: "duckdb",
|
|
694
|
-
duckdbConnection: {
|
|
695
|
-
attachedDatabases: [
|
|
696
|
-
{
|
|
697
|
-
name: "gcs_test",
|
|
698
|
-
type: "gcs",
|
|
699
|
-
gcsConnection: {},
|
|
700
|
-
},
|
|
701
|
-
],
|
|
702
|
-
},
|
|
703
|
-
},
|
|
704
|
-
] as ApiConnection[];
|
|
705
|
-
|
|
706
|
-
await expect(
|
|
707
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
708
|
-
).rejects.toThrow("keyId and secret are required");
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
it("should throw on S3 attach without credentials", async () => {
|
|
712
|
-
const connections = [
|
|
713
|
-
{
|
|
714
|
-
name: "s3_no_creds",
|
|
715
|
-
type: "duckdb",
|
|
716
|
-
duckdbConnection: {
|
|
717
|
-
attachedDatabases: [
|
|
718
|
-
{
|
|
719
|
-
name: "s3_test",
|
|
720
|
-
type: "s3",
|
|
721
|
-
s3Connection: {},
|
|
722
|
-
},
|
|
723
|
-
],
|
|
724
|
-
},
|
|
725
|
-
},
|
|
726
|
-
] as ApiConnection[];
|
|
727
|
-
|
|
728
|
-
await expect(
|
|
729
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
730
|
-
).rejects.toThrow("accessKeyId and secretAccessKey are required");
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
it("should throw on DuckLake without catalog connection", async () => {
|
|
734
|
-
const connections = [
|
|
735
|
-
{
|
|
736
|
-
name: "ducklake_no_catalog",
|
|
737
|
-
type: "ducklake",
|
|
738
|
-
ducklakeConnection: {
|
|
739
|
-
storage: {
|
|
740
|
-
bucketUrl: "s3://test-bucket",
|
|
741
|
-
s3Connection: {
|
|
742
|
-
accessKeyId: "test",
|
|
743
|
-
secretAccessKey: "test",
|
|
744
|
-
},
|
|
745
|
-
},
|
|
746
|
-
},
|
|
747
|
-
},
|
|
748
|
-
] as ApiConnection[];
|
|
749
|
-
|
|
750
|
-
await expect(
|
|
751
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
752
|
-
).rejects.toThrow("PostgreSQL connection configuration is required");
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
it("should throw on DuckLake without connection config", async () => {
|
|
756
|
-
const connections = [
|
|
757
|
-
{
|
|
758
|
-
name: "ducklake_no_config",
|
|
759
|
-
type: "ducklake",
|
|
760
|
-
},
|
|
761
|
-
] as ApiConnection[];
|
|
762
|
-
|
|
763
|
-
await expect(
|
|
764
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
765
|
-
).rejects.toThrow("DuckLake connection configuration is missing");
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
it("should throw on Snowflake attach without credentials", async () => {
|
|
769
|
-
const connections: ApiConnection[] = [
|
|
770
|
-
{
|
|
771
|
-
name: "sf_no_creds",
|
|
772
|
-
type: "duckdb",
|
|
773
|
-
duckdbConnection: {
|
|
774
|
-
attachedDatabases: [
|
|
775
|
-
{
|
|
776
|
-
name: "sf_test",
|
|
777
|
-
type: "snowflake",
|
|
778
|
-
snowflakeConnection: {
|
|
779
|
-
account: "test-account",
|
|
780
|
-
},
|
|
781
|
-
},
|
|
782
|
-
],
|
|
783
|
-
},
|
|
784
|
-
},
|
|
785
|
-
];
|
|
786
|
-
|
|
787
|
-
await expect(
|
|
788
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
789
|
-
).rejects.toThrow("username is required");
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it("should throw on Postgres attach without connection config", async () => {
|
|
793
|
-
const connections: ApiConnection[] = [
|
|
794
|
-
{
|
|
795
|
-
name: "pg_no_config",
|
|
796
|
-
type: "duckdb",
|
|
797
|
-
duckdbConnection: {
|
|
798
|
-
attachedDatabases: [
|
|
799
|
-
{
|
|
800
|
-
name: "pg_test",
|
|
801
|
-
type: "postgres",
|
|
802
|
-
},
|
|
803
|
-
],
|
|
804
|
-
},
|
|
805
|
-
},
|
|
806
|
-
];
|
|
807
|
-
|
|
808
|
-
await expect(
|
|
809
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
810
|
-
).rejects.toThrow("PostgreSQL connection configuration missing");
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
it("should throw when attached database name conflicts with connection name", async () => {
|
|
814
|
-
const connections: ApiConnection[] = [
|
|
815
|
-
{
|
|
816
|
-
name: "my_duckdb",
|
|
817
|
-
type: "duckdb",
|
|
818
|
-
duckdbConnection: {
|
|
819
|
-
attachedDatabases: [
|
|
820
|
-
{
|
|
821
|
-
name: "my_duckdb",
|
|
822
|
-
type: "bigquery",
|
|
823
|
-
bigqueryConnection: {
|
|
824
|
-
defaultProjectId: "test-project",
|
|
825
|
-
serviceAccountKeyJson: JSON.stringify({
|
|
826
|
-
type: "service_account",
|
|
827
|
-
project_id: "test-project",
|
|
828
|
-
private_key: "test-key",
|
|
829
|
-
client_email: "test@test.com",
|
|
830
|
-
}),
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
],
|
|
834
|
-
},
|
|
835
|
-
},
|
|
836
|
-
];
|
|
837
|
-
|
|
838
|
-
await expect(
|
|
839
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
840
|
-
).rejects.toThrow(
|
|
841
|
-
"DuckDB attached databases names cannot conflict with connection name",
|
|
842
|
-
);
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
it("should throw when DuckDB connection name is 'duckdb'", async () => {
|
|
846
|
-
const connections: ApiConnection[] = [
|
|
847
|
-
{
|
|
848
|
-
name: "duckdb",
|
|
849
|
-
type: "duckdb",
|
|
850
|
-
duckdbConnection: {
|
|
851
|
-
attachedDatabases: [],
|
|
852
|
-
},
|
|
853
|
-
},
|
|
854
|
-
];
|
|
855
|
-
|
|
856
|
-
await expect(
|
|
857
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
858
|
-
).rejects.toThrow("DuckDB connection name cannot be 'duckdb'");
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
it("should throw when DuckDB connection name is 'duckdb' with attached databases", async () => {
|
|
862
|
-
const connections: ApiConnection[] = [
|
|
863
|
-
{
|
|
864
|
-
name: "duckdb",
|
|
865
|
-
type: "duckdb",
|
|
866
|
-
duckdbConnection: {
|
|
867
|
-
attachedDatabases: [
|
|
868
|
-
{
|
|
869
|
-
name: "my_bigquery",
|
|
870
|
-
type: "bigquery",
|
|
871
|
-
bigqueryConnection: {
|
|
872
|
-
defaultProjectId: "test-project",
|
|
873
|
-
serviceAccountKeyJson: JSON.stringify({
|
|
874
|
-
type: "service_account",
|
|
875
|
-
project_id: "test-project",
|
|
876
|
-
private_key: "test-key",
|
|
877
|
-
client_email: "test@test.com",
|
|
878
|
-
}),
|
|
879
|
-
},
|
|
880
|
-
},
|
|
881
|
-
],
|
|
882
|
-
},
|
|
883
|
-
},
|
|
884
|
-
];
|
|
885
|
-
|
|
886
|
-
await expect(
|
|
887
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
888
|
-
).rejects.toThrow("DuckDB connection name cannot be 'duckdb'");
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
it("should throw when DuckDB connection has no attached databases", async () => {
|
|
892
|
-
const connections: ApiConnection[] = [
|
|
893
|
-
{
|
|
894
|
-
name: "no_attached_db",
|
|
895
|
-
type: "duckdb",
|
|
896
|
-
duckdbConnection: {
|
|
897
|
-
attachedDatabases: [],
|
|
898
|
-
},
|
|
899
|
-
},
|
|
900
|
-
];
|
|
901
|
-
|
|
902
|
-
await expect(
|
|
903
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
904
|
-
).rejects.toThrow(
|
|
905
|
-
"DuckDB connection must have at least one attached database",
|
|
906
|
-
);
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it("should throw on unsupported connection type", async () => {
|
|
910
|
-
const connections = [
|
|
911
|
-
{
|
|
912
|
-
name: "unsupported",
|
|
913
|
-
type: "redis" as "duckdb",
|
|
914
|
-
},
|
|
915
|
-
] as ApiConnection[];
|
|
916
|
-
|
|
917
|
-
await expect(
|
|
918
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
919
|
-
).rejects.toThrow("Unsupported connection type");
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
it("should throw when connection name is missing", async () => {
|
|
923
|
-
const connections = [
|
|
924
|
-
{
|
|
925
|
-
type: "duckdb",
|
|
926
|
-
duckdbConnection: {
|
|
927
|
-
attachedDatabases: [
|
|
928
|
-
{
|
|
929
|
-
name: "test_gcs",
|
|
930
|
-
type: "gcs",
|
|
931
|
-
gcsConnection: {
|
|
932
|
-
keyId: "test-key-id",
|
|
933
|
-
secret: "test-secret",
|
|
934
|
-
},
|
|
935
|
-
},
|
|
936
|
-
],
|
|
937
|
-
},
|
|
938
|
-
},
|
|
939
|
-
] as ApiConnection[];
|
|
940
|
-
|
|
941
|
-
await expect(
|
|
942
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
943
|
-
).rejects.toThrow();
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
describe("createProjectConnections - Other Connection Types", () => {
|
|
949
|
-
const PROJECT_TEST_DIR = path.join(
|
|
950
|
-
os.tmpdir(),
|
|
951
|
-
"connection-validation-tests",
|
|
952
|
-
);
|
|
953
|
-
const createdConnections: Map<string, unknown> = new Map();
|
|
954
|
-
|
|
955
|
-
beforeEach(async () => {
|
|
956
|
-
await fs.mkdir(PROJECT_TEST_DIR, { recursive: true });
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
afterEach(async () => {
|
|
960
|
-
for (const conn of createdConnections.values()) {
|
|
961
|
-
try {
|
|
962
|
-
if (
|
|
963
|
-
typeof (conn as { close?: () => Promise<void> }).close ===
|
|
964
|
-
"function"
|
|
965
|
-
) {
|
|
966
|
-
await (conn as { close: () => Promise<void> }).close();
|
|
967
|
-
}
|
|
968
|
-
} catch {
|
|
969
|
-
// Ignore
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
createdConnections.clear();
|
|
973
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
974
|
-
try {
|
|
975
|
-
await fs.rm(PROJECT_TEST_DIR, { recursive: true, force: true });
|
|
976
|
-
} catch {
|
|
977
|
-
// Ignore
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
describe("Snowflake Connection Validation", () => {
|
|
982
|
-
it("should throw when Snowflake config is missing", async () => {
|
|
983
|
-
const connections = [
|
|
984
|
-
{
|
|
985
|
-
name: "sf_test",
|
|
986
|
-
type: "snowflake",
|
|
987
|
-
},
|
|
988
|
-
] as ApiConnection[];
|
|
989
|
-
|
|
990
|
-
await expect(
|
|
991
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
992
|
-
).rejects.toThrow("Snowflake connection configuration is missing");
|
|
993
|
-
});
|
|
994
|
-
|
|
995
|
-
it("should throw when Snowflake account is missing", async () => {
|
|
996
|
-
const connections: ApiConnection[] = [
|
|
997
|
-
{
|
|
998
|
-
name: "sf_test",
|
|
999
|
-
type: "snowflake",
|
|
1000
|
-
snowflakeConnection: {
|
|
1001
|
-
username: "test",
|
|
1002
|
-
password: "test",
|
|
1003
|
-
warehouse: "test",
|
|
1004
|
-
},
|
|
1005
|
-
},
|
|
1006
|
-
];
|
|
1007
|
-
|
|
1008
|
-
await expect(
|
|
1009
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1010
|
-
).rejects.toThrow("Snowflake account is required");
|
|
1011
|
-
});
|
|
1012
|
-
|
|
1013
|
-
it("should throw when Snowflake username is missing", async () => {
|
|
1014
|
-
const connections: ApiConnection[] = [
|
|
1015
|
-
{
|
|
1016
|
-
name: "sf_test",
|
|
1017
|
-
type: "snowflake",
|
|
1018
|
-
snowflakeConnection: {
|
|
1019
|
-
account: "test-account",
|
|
1020
|
-
password: "test",
|
|
1021
|
-
warehouse: "test",
|
|
1022
|
-
},
|
|
1023
|
-
},
|
|
1024
|
-
];
|
|
1025
|
-
|
|
1026
|
-
await expect(
|
|
1027
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1028
|
-
).rejects.toThrow("Snowflake username is required");
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
it("should throw when Snowflake password and private key are both missing", async () => {
|
|
1032
|
-
const connections: ApiConnection[] = [
|
|
1033
|
-
{
|
|
1034
|
-
name: "sf_test",
|
|
1035
|
-
type: "snowflake",
|
|
1036
|
-
snowflakeConnection: {
|
|
1037
|
-
account: "test-account",
|
|
1038
|
-
username: "test",
|
|
1039
|
-
warehouse: "test",
|
|
1040
|
-
},
|
|
1041
|
-
},
|
|
1042
|
-
];
|
|
1043
|
-
|
|
1044
|
-
await expect(
|
|
1045
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1046
|
-
).rejects.toThrow(
|
|
1047
|
-
"Snowflake password or private key or private key path is required",
|
|
1048
|
-
);
|
|
1049
|
-
});
|
|
1050
|
-
|
|
1051
|
-
it("should throw when Snowflake warehouse is missing", async () => {
|
|
1052
|
-
const connections: ApiConnection[] = [
|
|
1053
|
-
{
|
|
1054
|
-
name: "sf_test",
|
|
1055
|
-
type: "snowflake",
|
|
1056
|
-
snowflakeConnection: {
|
|
1057
|
-
account: "test-account",
|
|
1058
|
-
username: "test",
|
|
1059
|
-
password: "test",
|
|
1060
|
-
},
|
|
1061
|
-
},
|
|
1062
|
-
];
|
|
1063
|
-
|
|
1064
|
-
await expect(
|
|
1065
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1066
|
-
).rejects.toThrow("Snowflake warehouse is required");
|
|
1067
|
-
});
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
describe("Trino Connection Validation", () => {
|
|
1071
|
-
it("should throw when Trino config is missing", async () => {
|
|
1072
|
-
const connections = [
|
|
1073
|
-
{
|
|
1074
|
-
name: "trino_test",
|
|
1075
|
-
type: "trino",
|
|
1076
|
-
},
|
|
1077
|
-
] as ApiConnection[];
|
|
1078
|
-
|
|
1079
|
-
await expect(
|
|
1080
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1081
|
-
).rejects.toThrow("Trino connection configuration is missing");
|
|
1082
|
-
});
|
|
1083
|
-
|
|
1084
|
-
it("should throw when Trino server URL is invalid (no protocol)", async () => {
|
|
1085
|
-
const connections: ApiConnection[] = [
|
|
1086
|
-
{
|
|
1087
|
-
name: "trino_test",
|
|
1088
|
-
type: "trino",
|
|
1089
|
-
trinoConnection: {
|
|
1090
|
-
server: "localhost:8080",
|
|
1091
|
-
port: 8080,
|
|
1092
|
-
},
|
|
1093
|
-
},
|
|
1094
|
-
];
|
|
1095
|
-
|
|
1096
|
-
await expect(
|
|
1097
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1098
|
-
).rejects.toThrow(
|
|
1099
|
-
'Invalid Trino connection: expected "http://server:port" or "https://server:port"',
|
|
1100
|
-
);
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
|
-
describe("MotherDuck Connection Validation", () => {
|
|
1105
|
-
it("should throw when MotherDuck config is missing", async () => {
|
|
1106
|
-
const connections = [
|
|
1107
|
-
{
|
|
1108
|
-
name: "md_test",
|
|
1109
|
-
type: "motherduck",
|
|
1110
|
-
},
|
|
1111
|
-
] as ApiConnection[];
|
|
1112
|
-
|
|
1113
|
-
await expect(
|
|
1114
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1115
|
-
).rejects.toThrow("MotherDuck connection configuration is missing");
|
|
1116
|
-
});
|
|
1117
|
-
|
|
1118
|
-
it("should throw when MotherDuck access token is missing", async () => {
|
|
1119
|
-
const connections: ApiConnection[] = [
|
|
1120
|
-
{
|
|
1121
|
-
name: "md_test",
|
|
1122
|
-
type: "motherduck",
|
|
1123
|
-
motherduckConnection: {},
|
|
1124
|
-
},
|
|
1125
|
-
];
|
|
1126
|
-
|
|
1127
|
-
await expect(
|
|
1128
|
-
createProjectConnections(connections, PROJECT_TEST_DIR),
|
|
1129
|
-
).rejects.toThrow("MotherDuck access token is required");
|
|
1130
|
-
});
|
|
1131
|
-
});
|
|
1132
|
-
});
|