@malloy-publisher/server 0.0.165 → 0.0.168

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.
Files changed (41) hide show
  1. package/.eslintrc.json +9 -1
  2. package/dist/app/api-doc.yaml +143 -1
  3. package/dist/app/assets/HomePage-D2tUw_9U.js +1 -0
  4. package/dist/app/assets/{MainPage-DAyUfYba.js → MainPage-DBQW76L7.js} +2 -2
  5. package/dist/app/assets/{ModelPage-CrMryV1s.js → ModelPage-BnfOKuhQ.js} +1 -1
  6. package/dist/app/assets/PackagePage-zPhE-rDg.js +1 -0
  7. package/dist/app/assets/ProjectPage-BpSTvuW6.js +1 -0
  8. package/dist/app/assets/RouteError-Cp9-yCK5.js +1 -0
  9. package/dist/app/assets/{WorkbookPage-DZEVYGW3.js → WorkbookPage-FD_gmxeE.js} +1 -1
  10. package/dist/app/assets/{index-BvVmB5sv.js → index-D5QBYuLK.js} +150 -150
  11. package/dist/app/assets/{index-CsC07BYd.js → index-DNCvL_5f.js} +1 -1
  12. package/dist/app/assets/{index-DWhjtyBB.js → index-x9S1fsYn.js} +1 -1
  13. package/dist/app/assets/{index.umd-DvM-lTQa.js → index.umd-CTYdFEHH.js} +1 -1
  14. package/dist/app/index.html +1 -1
  15. package/dist/instrumentation.js +85955 -88560
  16. package/dist/server.js +197441 -106276
  17. package/package.json +2 -1
  18. package/src/controller/compile.controller.ts +35 -0
  19. package/src/controller/connection.controller.ts +22 -2
  20. package/src/controller/model.controller.ts +20 -9
  21. package/src/health.ts +8 -0
  22. package/src/instrumentation.ts +123 -34
  23. package/src/server.ts +49 -3
  24. package/src/service/connection.spec.ts +1331 -0
  25. package/src/service/connection.ts +407 -29
  26. package/src/service/db_utils.ts +104 -45
  27. package/src/service/gcs_s3_utils.ts +115 -40
  28. package/src/service/model.ts +5 -5
  29. package/src/service/project.ts +140 -4
  30. package/src/service/project_compile.spec.ts +197 -0
  31. package/src/service/project_store.ts +49 -21
  32. package/src/storage/StorageManager.ts +4 -3
  33. package/src/storage/duckdb/schema.ts +6 -5
  34. package/tests/harness/e2e.ts +4 -0
  35. package/tests/harness/mcp_test_setup.ts +172 -28
  36. package/tests/unit/duckdb/attached_databases.test.ts +61 -3
  37. package/tests/unit/ducklake/ducklake.test.ts +950 -0
  38. package/dist/app/assets/HomePage-QekMXs8r.js +0 -1
  39. package/dist/app/assets/PackagePage-DDaABD2A.js +0 -1
  40. package/dist/app/assets/ProjectPage-FAYUFGhL.js +0 -1
  41. package/dist/app/assets/RouteError-BKYctANX.js +0 -1
@@ -1,3 +1,5 @@
1
+ import type { LogMessage } from "@malloydata/malloy";
2
+ import { FixedConnectionMap, MalloyError, Runtime } from "@malloydata/malloy";
1
3
  import { BaseConnection } from "@malloydata/malloy/connection";
2
4
  import { Mutex } from "async-mutex";
3
5
  import * as fs from "fs";
@@ -10,7 +12,12 @@ import {
10
12
  ProjectNotFoundError,
11
13
  } from "../errors";
12
14
  import { logger } from "../logger";
13
- import { createProjectConnections, InternalConnection } from "./connection";
15
+ import { URL_READER } from "../utils";
16
+ import {
17
+ createProjectConnections,
18
+ deleteDuckLakeConnectionFile,
19
+ InternalConnection,
20
+ } from "./connection";
14
21
  import { ApiConnection } from "./model";
15
22
  import { Package } from "./package";
16
23
 
@@ -83,12 +90,13 @@ export class Project {
83
90
  logger.info(
84
91
  `Updating ${payload.connections.length} connections for project ${this.projectName}`,
85
92
  );
86
-
93
+ const isUpdateConnectionRequest = true;
87
94
  // Reload connections with full config
88
95
  const { malloyConnections, apiConnections } =
89
96
  await createProjectConnections(
90
97
  payload.connections,
91
98
  this.projectPath,
99
+ isUpdateConnectionRequest,
92
100
  );
93
101
 
94
102
  // Update the project's connection maps
@@ -159,6 +167,71 @@ export class Project {
159
167
  return this.metadata;
160
168
  }
161
169
 
170
+ public async compileSource(
171
+ packageName: string,
172
+ modelName: string,
173
+ source: string,
174
+ includeSql: boolean = false,
175
+ ): Promise<{ problems: LogMessage[]; sql?: string }> {
176
+ // Place the virtual file in the model's directory so relative imports resolve correctly.
177
+ const modelDir = path.dirname(
178
+ path.join(this.projectPath, packageName, modelName),
179
+ );
180
+ const virtualUri = `file://${path.join(modelDir, "__compile_check.malloy")}`;
181
+ const virtualUrl = new URL(virtualUri);
182
+
183
+ // Read the model file and extract its preamble (pragmas + imports) so that
184
+ // the user's query inherits the model's import context.
185
+ const modelPath = path.join(this.projectPath, packageName, modelName);
186
+ const preamble = await extractPreamble(modelPath);
187
+ const fullSource = preamble ? `${preamble}\n${source}` : source;
188
+
189
+ // Create a URL Reader that serves the source string for the virtual file,
190
+ // but falls back to the disk for everything else (imports).
191
+ const interceptingReader = {
192
+ readURL: async (url: URL) => {
193
+ if (url.toString() === virtualUri) {
194
+ return fullSource;
195
+ }
196
+ return URL_READER.readURL(url);
197
+ },
198
+ };
199
+
200
+ // Initialize Runtime with the project's active connections
201
+ const runtime = new Runtime({
202
+ urlReader: interceptingReader,
203
+ connections: new FixedConnectionMap(this.malloyConnections, "duckdb"),
204
+ });
205
+
206
+ // Attempt to compile
207
+ try {
208
+ const modelMaterializer = runtime.loadModel(virtualUrl);
209
+ const model = await modelMaterializer.getModel();
210
+
211
+ // If includeSql is requested and compilation succeeded, attempt to extract SQL
212
+ let sql: string | undefined;
213
+ if (includeSql) {
214
+ try {
215
+ const queryMaterializer = modelMaterializer.loadFinalQuery();
216
+ sql = await queryMaterializer.getSQL();
217
+ } catch {
218
+ // Source may not contain a runnable query (e.g. only source definitions),
219
+ // in which case we simply omit the sql field.
220
+ }
221
+ }
222
+
223
+ // If successful, return any non-fatal warnings
224
+ return { problems: model.problems, sql };
225
+ } catch (error) {
226
+ // If parsing/compilation fails, return the errors
227
+ if (error instanceof MalloyError) {
228
+ return { problems: error.problems };
229
+ }
230
+ // If it's a system error (e.g. file not found), throw it up
231
+ throw error;
232
+ }
233
+ }
234
+
162
235
  public listApiConnections(): ApiConnection[] {
163
236
  return this.apiConnections;
164
237
  }
@@ -244,11 +317,18 @@ export class Project {
244
317
  // package multiple times.
245
318
  let packageMutex = this.packageMutexes.get(packageName);
246
319
  if (packageMutex?.isLocked()) {
320
+ logger.debug(
321
+ `Package ${packageName} is being loaded, waiting for unlock...`,
322
+ );
247
323
  await packageMutex.waitForUnlock();
324
+ logger.debug(`Package ${packageName} unlocked`);
248
325
  const existingPackage = this.packages.get(packageName);
249
326
  if (existingPackage) {
327
+ logger.debug(`Package ${packageName} loaded by another request`);
250
328
  return existingPackage;
251
329
  }
330
+ // If package still doesn't exist after unlock, it might have failed to load
331
+ // Continue to try loading it ourselves
252
332
  }
253
333
  packageMutex = new Mutex();
254
334
  this.packageMutexes.set(packageName, packageMutex);
@@ -264,19 +344,23 @@ export class Project {
264
344
  this.setPackageStatus(packageName, PackageStatus.LOADING);
265
345
 
266
346
  try {
347
+ logger.debug(`Loading package ${packageName}...`);
348
+ const packagePath = path.join(this.projectPath, packageName);
267
349
  const _package = await Package.create(
268
350
  this.projectName,
269
351
  packageName,
270
- path.join(this.projectPath, packageName),
352
+ packagePath,
271
353
  this.malloyConnections,
272
354
  );
273
355
  this.packages.set(packageName, _package);
274
356
 
275
357
  // Set package status to serving
276
358
  this.setPackageStatus(packageName, PackageStatus.SERVING);
359
+ logger.debug(`Successfully loaded package ${packageName}`);
277
360
 
278
361
  return _package;
279
362
  } catch (error) {
363
+ logger.error(`Failed to load package ${packageName}`, { error });
280
364
  // Clean up on error - mutex will be automatically released by runExclusive
281
365
  this.packages.delete(packageName);
282
366
  this.packageStatuses.delete(packageName);
@@ -457,8 +541,11 @@ export class Project {
457
541
  (conn) => conn.name === connectionName,
458
542
  );
459
543
 
460
- if (this.apiConnections[index]?.type === "duckdb") {
544
+ const connectionType = this.apiConnections[index]?.type;
545
+ if (connectionType === "duckdb") {
461
546
  await this.deleteDuckDBConnection(connectionName);
547
+ } else if (connectionType === "ducklake") {
548
+ await this.deleteDuckLakeConnection(connectionName);
462
549
  }
463
550
 
464
551
  if (index !== -1) {
@@ -536,4 +623,53 @@ export class Project {
536
623
  );
537
624
  });
538
625
  }
626
+
627
+ public async deleteDuckLakeConnection(
628
+ connectionName: string,
629
+ ): Promise<void> {
630
+ await deleteDuckLakeConnectionFile(connectionName, this.projectPath);
631
+ logger.info(
632
+ `Removed DuckLake connection ${connectionName} from project ${this.projectName}`,
633
+ );
634
+ }
635
+ }
636
+
637
+ /**
638
+ * Extracts the preamble from a Malloy model file — the leading block of
639
+ * `##!` pragmas, `import` statements, blank lines, and comments that appear
640
+ * before any `source:`, `query:`, or `run:` definition. This allows a
641
+ * submitted query to inherit the model's import context.
642
+ */
643
+ export async function extractPreamble(modelPath: string): Promise<string> {
644
+ try {
645
+ const content = await fs.promises.readFile(modelPath, "utf8");
646
+ return extractPreambleFromSource(content);
647
+ } catch {
648
+ // If the model file can't be read, return empty preamble
649
+ // and let the compilation surface any import errors naturally.
650
+ return "";
651
+ }
652
+ }
653
+
654
+ /**
655
+ * Extracts the preamble from Malloy source text. Exported for testing.
656
+ */
657
+ export function extractPreambleFromSource(content: string): string {
658
+ const lines = content.split("\n");
659
+ const preambleLines: string[] = [];
660
+
661
+ for (const line of lines) {
662
+ const trimmed = line.trim();
663
+ // Stop at the first source/query/run definition
664
+ if (
665
+ trimmed.startsWith("source:") ||
666
+ trimmed.startsWith("query:") ||
667
+ trimmed.startsWith("run:")
668
+ ) {
669
+ break;
670
+ }
671
+ preambleLines.push(line);
672
+ }
673
+
674
+ return preambleLines.join("\n").trimEnd();
539
675
  }
@@ -0,0 +1,197 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { extractPreamble, extractPreambleFromSource } from "./project";
5
+
6
+ describe("extractPreambleFromSource", () => {
7
+ it("should extract pragmas and imports before a source definition", () => {
8
+ const content = [
9
+ "##! experimental.parameters",
10
+ 'import "utils.malloy"',
11
+ 'import { revenue } from "metrics.malloy"',
12
+ "",
13
+ 'source: my_source is duckdb.table("data.parquet")',
14
+ ' dimension: name is "test"',
15
+ ].join("\n");
16
+
17
+ const result = extractPreambleFromSource(content);
18
+ expect(result).toBe(
19
+ [
20
+ "##! experimental.parameters",
21
+ 'import "utils.malloy"',
22
+ 'import { revenue } from "metrics.malloy"',
23
+ ].join("\n"),
24
+ );
25
+ });
26
+
27
+ it("should extract pragmas and imports before a run statement", () => {
28
+ const content = [
29
+ 'import { my_source } from "model.malloy"',
30
+ "",
31
+ "run: my_source -> { aggregate: count() }",
32
+ ].join("\n");
33
+
34
+ const result = extractPreambleFromSource(content);
35
+ expect(result).toBe('import { my_source } from "model.malloy"');
36
+ });
37
+
38
+ it("should extract pragmas and imports before a query definition", () => {
39
+ const content = [
40
+ 'import { my_source } from "model.malloy"',
41
+ "",
42
+ "query: top_items is my_source -> { limit: 10 }",
43
+ ].join("\n");
44
+
45
+ const result = extractPreambleFromSource(content);
46
+ expect(result).toBe('import { my_source } from "model.malloy"');
47
+ });
48
+
49
+ it("should return empty string when file starts with source:", () => {
50
+ const content = 'source: my_source is duckdb.table("data.parquet")';
51
+
52
+ const result = extractPreambleFromSource(content);
53
+ expect(result).toBe("");
54
+ });
55
+
56
+ it("should return empty string when file starts with run:", () => {
57
+ const content = 'run: duckdb.sql("SELECT 1")';
58
+
59
+ const result = extractPreambleFromSource(content);
60
+ expect(result).toBe("");
61
+ });
62
+
63
+ it("should return empty string when file starts with query:", () => {
64
+ const content = 'query: q is duckdb.sql("SELECT 1")';
65
+
66
+ const result = extractPreambleFromSource(content);
67
+ expect(result).toBe("");
68
+ });
69
+
70
+ it("should preserve comments in the preamble", () => {
71
+ const content = [
72
+ "##! experimental.parameters",
73
+ "// This model defines revenue metrics",
74
+ 'import { revenue } from "metrics.malloy"',
75
+ "// Main source below",
76
+ 'source: my_source is duckdb.table("data.parquet")',
77
+ ].join("\n");
78
+
79
+ const result = extractPreambleFromSource(content);
80
+ expect(result).toBe(
81
+ [
82
+ "##! experimental.parameters",
83
+ "// This model defines revenue metrics",
84
+ 'import { revenue } from "metrics.malloy"',
85
+ "// Main source below",
86
+ ].join("\n"),
87
+ );
88
+ });
89
+
90
+ it("should handle multiple import blocks", () => {
91
+ const content = [
92
+ 'import { a } from "file_a.malloy"',
93
+ 'import { b } from "file_b.malloy"',
94
+ 'import { c, d } from "file_c.malloy"',
95
+ "",
96
+ "source: combined is a {",
97
+ " join_one: b on b.id = a.b_id",
98
+ "}",
99
+ ].join("\n");
100
+
101
+ const result = extractPreambleFromSource(content);
102
+ expect(result).toBe(
103
+ [
104
+ 'import { a } from "file_a.malloy"',
105
+ 'import { b } from "file_b.malloy"',
106
+ 'import { c, d } from "file_c.malloy"',
107
+ ].join("\n"),
108
+ );
109
+ });
110
+
111
+ it("should return all content when there are no source/query/run definitions", () => {
112
+ const content = [
113
+ "##! experimental.parameters",
114
+ 'import { revenue } from "metrics.malloy"',
115
+ "",
116
+ "// no definitions yet",
117
+ ].join("\n");
118
+
119
+ const result = extractPreambleFromSource(content);
120
+ expect(result).toBe(
121
+ [
122
+ "##! experimental.parameters",
123
+ 'import { revenue } from "metrics.malloy"',
124
+ "",
125
+ "// no definitions yet",
126
+ ].join("\n"),
127
+ );
128
+ });
129
+
130
+ it("should return empty string for empty input", () => {
131
+ expect(extractPreambleFromSource("")).toBe("");
132
+ });
133
+
134
+ it("should handle indented source/query/run definitions", () => {
135
+ const content = [
136
+ 'import "model.malloy"',
137
+ "",
138
+ ' source: indented is duckdb.table("data.parquet")',
139
+ ].join("\n");
140
+
141
+ // Indented definitions should still be detected (trimmed before check)
142
+ const result = extractPreambleFromSource(content);
143
+ expect(result).toBe('import "model.malloy"');
144
+ });
145
+
146
+ it("should not stop on 'source' appearing in comments or strings", () => {
147
+ const content = [
148
+ "// This file defines the source of truth",
149
+ 'import "model.malloy"',
150
+ 'source: my_source is duckdb.table("data.parquet")',
151
+ ].join("\n");
152
+
153
+ const result = extractPreambleFromSource(content);
154
+ expect(result).toBe(
155
+ [
156
+ "// This file defines the source of truth",
157
+ 'import "model.malloy"',
158
+ ].join("\n"),
159
+ );
160
+ });
161
+ });
162
+
163
+ describe("extractPreamble (file-based)", () => {
164
+ const testDir = path.join(process.cwd(), "test-temp-preamble");
165
+ const testModelPath = path.join(testDir, "test_model.malloy");
166
+
167
+ beforeEach(() => {
168
+ if (!fs.existsSync(testDir)) {
169
+ fs.mkdirSync(testDir, { recursive: true });
170
+ }
171
+ });
172
+
173
+ afterEach(() => {
174
+ if (fs.existsSync(testDir)) {
175
+ fs.rmSync(testDir, { recursive: true, force: true });
176
+ }
177
+ });
178
+
179
+ it("should read and extract preamble from a file", async () => {
180
+ const content = [
181
+ 'import { revenue } from "metrics.malloy"',
182
+ "",
183
+ 'source: my_source is duckdb.table("data.parquet")',
184
+ ].join("\n");
185
+ fs.writeFileSync(testModelPath, content);
186
+
187
+ const result = await extractPreamble(testModelPath);
188
+ expect(result).toBe('import { revenue } from "metrics.malloy"');
189
+ });
190
+
191
+ it("should return empty string when file does not exist", async () => {
192
+ const result = await extractPreamble(
193
+ path.join(testDir, "nonexistent.malloy"),
194
+ );
195
+ expect(result).toBe("");
196
+ });
197
+ });
@@ -196,7 +196,8 @@ export class ProjectStore {
196
196
  );
197
197
  } catch (error) {
198
198
  markNotReady();
199
- logger.error("Error initializing project store", { error });
199
+ const errorData = this.extractErrorDataFromError(error);
200
+ logger.error("Error initializing project store", errorData);
200
201
  process.exit(1);
201
202
  }
202
203
  }
@@ -533,7 +534,7 @@ export class ProjectStore {
533
534
  PUBLISHER_DATA_DIR,
534
535
  );
535
536
  logger.info(
536
- `Re init: Cleaning up upload documents path ${uploadDocsPath}`,
537
+ `Reinitialization mode: Cleaning up upload documents path ${uploadDocsPath}`,
537
538
  );
538
539
  try {
539
540
  await fs.promises.rm(uploadDocsPath, {
@@ -1025,11 +1026,10 @@ export class ProjectStore {
1025
1026
  }
1026
1027
  }
1027
1028
  } catch (error) {
1029
+ const errorData = this.extractErrorDataFromError(error);
1028
1030
  logger.error(
1029
1031
  `Failed to download or mount location "${groupedLocation}"`,
1030
- {
1031
- error,
1032
- },
1032
+ errorData,
1033
1033
  );
1034
1034
  throw new PackageNotFoundError(
1035
1035
  `Failed to download or mount location: ${groupedLocation}`,
@@ -1075,9 +1075,11 @@ export class ProjectStore {
1075
1075
  );
1076
1076
  return;
1077
1077
  } catch (error) {
1078
- logger.error(`Failed to download GCS directory "${location}"`, {
1079
- error,
1080
- });
1078
+ const errorData = this.extractErrorDataFromError(error);
1079
+ logger.error(
1080
+ `Failed to download GCS directory "${location}"`,
1081
+ errorData,
1082
+ );
1081
1083
  throw new PackageNotFoundError(
1082
1084
  `Failed to download GCS directory: ${location}`,
1083
1085
  );
@@ -1093,9 +1095,11 @@ export class ProjectStore {
1093
1095
  await this.downloadGitHubDirectory(location, targetPath);
1094
1096
  return;
1095
1097
  } catch (error) {
1096
- logger.error(`Failed to clone GitHub repository "${location}"`, {
1097
- error,
1098
- });
1098
+ const errorData = this.extractErrorDataFromError(error);
1099
+ logger.error(
1100
+ `Failed to clone GitHub repository "${location}"`,
1101
+ errorData,
1102
+ );
1099
1103
  throw new PackageNotFoundError(
1100
1104
  `Failed to clone GitHub repository: ${location}`,
1101
1105
  );
@@ -1111,9 +1115,11 @@ export class ProjectStore {
1111
1115
  await this.downloadS3Directory(location, projectName, targetPath);
1112
1116
  return;
1113
1117
  } catch (error) {
1114
- logger.error(`Failed to download S3 directory "${location}"`, {
1115
- error,
1116
- });
1118
+ const errorData = this.extractErrorDataFromError(error);
1119
+ logger.error(
1120
+ `Failed to download S3 directory "${location}"`,
1121
+ errorData,
1122
+ );
1117
1123
  throw new PackageNotFoundError(
1118
1124
  `Failed to download S3 directory: ${location}`,
1119
1125
  );
@@ -1137,9 +1143,11 @@ export class ProjectStore {
1137
1143
  );
1138
1144
  return;
1139
1145
  } catch (error) {
1140
- logger.error(`Failed to mount local directory "${packagePath}"`, {
1141
- error,
1142
- });
1146
+ const errorData = this.extractErrorDataFromError(error);
1147
+ logger.error(
1148
+ `Failed to mount local directory "${packagePath}"`,
1149
+ errorData,
1150
+ );
1143
1151
  throw new PackageNotFoundError(
1144
1152
  `Failed to mount local directory: ${packagePath}`,
1145
1153
  );
@@ -1332,10 +1340,11 @@ export class ProjectStore {
1332
1340
  await new Promise<void>((resolve, reject) => {
1333
1341
  simpleGit().clone(repoUrl, absoluteDirPath, {}, (err) => {
1334
1342
  if (err) {
1335
- console.error(err);
1336
- logger.error(`Failed to clone GitHub repository "${repoUrl}"`, {
1337
- error: err,
1338
- });
1343
+ const errorData = this.extractErrorDataFromError(err);
1344
+ logger.error(
1345
+ `Failed to clone GitHub repository "${repoUrl}"`,
1346
+ errorData,
1347
+ );
1339
1348
  reject(err);
1340
1349
  }
1341
1350
  resolve();
@@ -1396,4 +1405,23 @@ export class ProjectStore {
1396
1405
 
1397
1406
  // https://github.com/credibledata/malloy-samples/imdb/publisher.json -> ${absoluteDirPath}/publisher.json
1398
1407
  }
1408
+
1409
+ private extractErrorDataFromError(error: unknown): {
1410
+ error: string;
1411
+ stack?: string;
1412
+ task?: unknown;
1413
+ } {
1414
+ const errorMessage =
1415
+ error instanceof Error ? error.message : String(error);
1416
+ const errorData: { error: string; stack?: string; task?: unknown } = {
1417
+ error: errorMessage,
1418
+ };
1419
+ if (error instanceof Error && logger.level === "debug") {
1420
+ errorData.stack = error.stack;
1421
+ }
1422
+ if (error && typeof error === "object" && "task" in error) {
1423
+ errorData.task = (error as { task?: unknown }).task;
1424
+ }
1425
+ return errorData;
1426
+ }
1399
1427
  }
@@ -1,3 +1,4 @@
1
+ import { logger } from "../logger";
1
2
  import { DatabaseConnection, ResourceRepository } from "./DatabaseInterface";
2
3
  import { DuckDBConnection } from "./duckdb/DuckDBConnection";
3
4
  import { DuckDBRepository } from "./duckdb/DuckDBRepository";
@@ -37,11 +38,11 @@ export class StorageManager {
37
38
 
38
39
  async initialize(reinit: boolean = false): Promise<void> {
39
40
  if (reinit) {
40
- console.log(
41
- "RE-INITIALIZATION MODE: Database will be dropped and recreated",
41
+ logger.info(
42
+ "Reinitialization mode: Database will be dropped and recreated",
42
43
  );
43
44
  } else {
44
- console.log("NORMAL MODE: Loading from existing database");
45
+ logger.info("Normal mode: Loading from existing database");
45
46
  }
46
47
 
47
48
  switch (this.config.type) {
@@ -1,3 +1,4 @@
1
+ import { logger } from "../../logger";
1
2
  import { DuckDBConnection } from "./DuckDBConnection";
2
3
 
3
4
  export async function initializeSchema(
@@ -11,12 +12,12 @@ export async function initializeSchema(
11
12
  }
12
13
 
13
14
  if (force) {
14
- console.log(
15
+ logger.info(
15
16
  "Reinitializing database schema dropping and recreating all tables",
16
17
  );
17
18
  await dropAllTables(db);
18
19
  } else {
19
- console.log("Creating database schema for the first time...");
20
+ logger.info("Creating database schema for the first time...");
20
21
  }
21
22
 
22
23
  // Projects table
@@ -75,14 +76,14 @@ export async function initializeSchema(
75
76
  async function dropAllTables(db: DuckDBConnection): Promise<void> {
76
77
  const tables = ["packages", "connections", "projects"];
77
78
 
78
- console.log("Dropping tables:", tables.join(", "));
79
+ logger.info("Dropping tables:", tables.join(", "));
79
80
 
80
81
  for (const table of tables) {
81
82
  try {
82
83
  await db.run(`DROP TABLE IF EXISTS ${table} `);
83
- console.log(`Dropped table: ${table}`);
84
+ logger.info(`Dropped table: ${table}`);
84
85
  } catch (err) {
85
- console.warn(` Warning: Could not drop table ${table}:`, err);
86
+ logger.warn(` Warning: Could not drop table ${table}:`, err);
86
87
  }
87
88
  }
88
89
  }
@@ -7,6 +7,7 @@ import type {
7
7
  } from "@modelcontextprotocol/sdk/types.js";
8
8
  import http from "http";
9
9
  import path from "path";
10
+ import { fileURLToPath } from "url";
10
11
  import { URL } from "url";
11
12
 
12
13
  /**
@@ -30,6 +31,9 @@ export async function startE2E(): Promise<E2EEnv & { stop(): Promise<void> }> {
30
31
  // 1. Set SERVER_ROOT so ProjectStore loader finds publisher.config.json
31
32
  //--------------------------------------------------------------------------
32
33
  originalServerRoot = process.env.SERVER_ROOT;
34
+ // Use import.meta.url for cross-platform compatibility (works on Windows)
35
+ const __filename = fileURLToPath(import.meta.url);
36
+ const __dirname = path.dirname(__filename);
33
37
  const serverPackageDir = path.resolve(__dirname, "../../../"); // packages/server
34
38
  process.env.SERVER_ROOT = serverPackageDir;
35
39