@malloy-publisher/server 0.0.204 → 0.0.205

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 (55) hide show
  1. package/build.ts +10 -1
  2. package/dist/app/api-doc.yaml +133 -4
  3. package/dist/app/assets/{EnvironmentPage-CX06cjOF.js → EnvironmentPage-CAge6UHD.js} +1 -1
  4. package/dist/app/assets/HomePage-DhTe8qpa.js +1 -0
  5. package/dist/app/assets/{MainPage-nUJ9YatG.js → MainPage-CeTxxGex.js} +2 -2
  6. package/dist/app/assets/MaterializationsPage-CpDHB70t.js +1 -0
  7. package/dist/app/assets/ModelPage-D9sSMb75.js +1 -0
  8. package/dist/app/assets/{PackagePage-BaEVdEAG.js → PackagePage-LRqQWrFY.js} +1 -1
  9. package/dist/app/assets/{RouteError-BShQjZio.js → RouteError-xT6kuCNw.js} +1 -1
  10. package/dist/app/assets/{WorkbookPage-CBn6ZjJW.js → WorkbookPage-DsIh9svZ.js} +1 -1
  11. package/dist/app/assets/{core-DECXYL4E.es-OaRfXwuQ.js → core-C2sQrwVu.es-Bjem0hym.js} +1 -1
  12. package/dist/app/assets/{index-BLfPC1gy.js → index-BdOZDcce.js} +1 -1
  13. package/dist/app/assets/{index-Dy3YhAZQ.js → index-DHHAcY5o.js} +1 -1
  14. package/dist/app/assets/{index-DqiJ0bWp.js → index-RX3QOTde.js} +121 -121
  15. package/dist/app/assets/{index.umd-DAN9K8yC.js → index.umd-D2WH3D-f.js} +1 -1
  16. package/dist/app/index.html +1 -1
  17. package/dist/runtime/publisher.js +318 -0
  18. package/dist/server.mjs +567 -194
  19. package/package.json +5 -4
  20. package/scripts/bake-duckdb-extensions.js +104 -0
  21. package/src/controller/watch-mode.controller.ts +176 -46
  22. package/src/errors.spec.ts +21 -0
  23. package/src/mcp/error_messages.spec.ts +35 -0
  24. package/src/mcp/error_messages.ts +14 -1
  25. package/src/mcp/handler_utils.ts +12 -0
  26. package/src/runtime/publisher.js +318 -0
  27. package/src/server.ts +479 -2
  28. package/src/service/authorize_integration.spec.ts +96 -2
  29. package/src/service/compile_authorize.spec.ts +85 -0
  30. package/src/service/environment.ts +63 -5
  31. package/src/service/environment_store.ts +142 -11
  32. package/src/service/model.ts +44 -0
  33. package/src/service/package.ts +17 -6
  34. package/src/storage/duckdb/DuckDBConnection.ts +70 -124
  35. package/tests/fixtures/authorize-compile/model.malloy +9 -0
  36. package/tests/fixtures/authorize-compile/publisher.json +4 -0
  37. package/tests/fixtures/html-pages-nopublic/model.malloy +1 -0
  38. package/tests/fixtures/html-pages-nopublic/publisher.json +5 -0
  39. package/tests/fixtures/html-pages-test/data.csv +3 -0
  40. package/tests/fixtures/html-pages-test/public/assets/app.css +3 -0
  41. package/tests/fixtures/html-pages-test/public/data.json +1 -0
  42. package/tests/fixtures/html-pages-test/public/index.html +9 -0
  43. package/tests/fixtures/html-pages-test/public/sub/page2.html +9 -0
  44. package/tests/fixtures/html-pages-test/publisher.json +5 -0
  45. package/tests/fixtures/html-pages-test/report.malloy +1 -0
  46. package/tests/integration/authorize/compile_authorize_http.integration.spec.ts +92 -0
  47. package/tests/integration/duckdb_storage/duckdb_storage.integration.spec.ts +138 -0
  48. package/tests/integration/html_pages/html_pages.integration.spec.ts +378 -0
  49. package/tests/integration/watch-mode/watch_mode.integration.spec.ts +421 -0
  50. package/tests/unit/duckdb/attached_databases.test.ts +111 -0
  51. package/tests/unit/duckdb/duckdb_connection.test.ts +181 -0
  52. package/tests/unit/duckdb/repositories.test.ts +208 -0
  53. package/dist/app/assets/HomePage-CNFt_eUU.js +0 -1
  54. package/dist/app/assets/MaterializationsPage-B5goxVXW.js +0 -1
  55. package/dist/app/assets/ModelPage-Ba7Xh4lL.js +0 -1
@@ -0,0 +1,421 @@
1
+ /// <reference types="bun-types" />
2
+
3
+ import { afterAll, beforeAll, describe, expect, it } from "bun:test";
4
+ import { type ChildProcess, spawn } from "child_process";
5
+ import fs from "fs";
6
+ import net from "net";
7
+ import os from "os";
8
+ import path from "path";
9
+ import { fileURLToPath } from "url";
10
+
11
+ /**
12
+ * End-to-end coverage for watch mode's source-edit live reload, plus the
13
+ * copy-mode gate it depends on.
14
+ *
15
+ * Watch mode only recompiles source edits when the server is started with
16
+ * `--watch-env` (i.e. `PUBLISHER_WATCH=<env>`): that flag mounts local-dir
17
+ * packages as in-place symlinks instead of copies, so an edit to the source
18
+ * directory is visible to the chokidar watcher, which recompiles just that
19
+ * package via `Environment.getPackage(name, reload=true)`. Without the flag
20
+ * packages stay copies and source edits do not propagate, even if a watcher is
21
+ * started over REST: production keeps the decoupled copy semantics.
22
+ *
23
+ * That mount decision is made in the `EnvironmentStore` constructor, before any
24
+ * package loads, and `POST /watch-mode/start` resolves the env from the on-disk
25
+ * `publisher.config.json`. Neither can be driven through the shared in-process
26
+ * REST harness (one cached server + store for the whole file), so this suite
27
+ * boots dedicated server subprocesses from source, each with its own
28
+ * `SERVER_ROOT`, optional `PUBLISHER_WATCH`, and a seeded config pointing at a
29
+ * writable temp source package that the tests then edit.
30
+ */
31
+
32
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
33
+ // tests/integration/watch-mode -> packages/server
34
+ const SERVER_DIR = path.resolve(__dirname, "../../..");
35
+
36
+ const ENV_NAME = "watch-it-env";
37
+ const PKG_NAME = "watch-it-pkg";
38
+
39
+ interface TestServer {
40
+ baseUrl: string;
41
+ /** publisher_data/<env>/<pkg>: a symlink under watch mode, a real dir otherwise. */
42
+ mountedPkgPath: string;
43
+ /** Writable source package dir the tests mutate to simulate source edits. */
44
+ srcDir: string;
45
+ stop(): Promise<void>;
46
+ }
47
+
48
+ /** Allocate an OS-assigned free TCP port (avoids fixed-port collisions). */
49
+ async function getFreePort(): Promise<number> {
50
+ return new Promise<number>((resolve, reject) => {
51
+ const srv = net.createServer();
52
+ srv.on("error", reject);
53
+ srv.listen(0, "127.0.0.1", () => {
54
+ const addr = srv.address();
55
+ const found = typeof addr === "object" && addr ? addr.port : 0;
56
+ srv.close(() =>
57
+ found ? resolve(found) : reject(new Error("no free port")),
58
+ );
59
+ });
60
+ });
61
+ }
62
+
63
+ /** Returns true once `predicate` does, or false if `timeoutMs` elapses first. */
64
+ async function poll(
65
+ predicate: () => Promise<boolean>,
66
+ timeoutMs: number,
67
+ intervalMs = 300,
68
+ ): Promise<boolean> {
69
+ const deadline = Date.now() + timeoutMs;
70
+ while (Date.now() < deadline) {
71
+ if (await predicate()) return true;
72
+ await new Promise((r) => setTimeout(r, intervalMs));
73
+ }
74
+ return false;
75
+ }
76
+
77
+ const apiUrl = (baseUrl: string, sub: string) =>
78
+ `${baseUrl}/api/v0/environments/${ENV_NAME}/packages/${PKG_NAME}${sub}`;
79
+
80
+ const modelsText = async (baseUrl: string): Promise<string> => {
81
+ const res = await fetch(apiUrl(baseUrl, "/models"));
82
+ return res.ok ? await res.text() : "";
83
+ };
84
+
85
+ /**
86
+ * Boot a dedicated Publisher server subprocess from source against a seeded
87
+ * config. With `watch: true` the env is passed via `PUBLISHER_WATCH`, enabling
88
+ * the in-place symlink mount and auto-starting the watcher after env load.
89
+ */
90
+ async function startServer(opts: { watch: boolean }): Promise<TestServer> {
91
+ const srcDir = fs.mkdtempSync(path.join(os.tmpdir(), "wm-src-"));
92
+ fs.writeFileSync(
93
+ path.join(srcDir, "publisher.json"),
94
+ JSON.stringify({ name: PKG_NAME, version: "1.0.0" }),
95
+ );
96
+ fs.writeFileSync(
97
+ path.join(srcDir, "first.malloy"),
98
+ 'source: first_source is duckdb.sql("SELECT 1 as n")\n',
99
+ );
100
+
101
+ const serverRoot = fs.mkdtempSync(path.join(os.tmpdir(), "wm-root-"));
102
+ fs.writeFileSync(
103
+ path.join(serverRoot, "publisher.config.json"),
104
+ JSON.stringify({
105
+ frozenConfig: false,
106
+ environments: [
107
+ {
108
+ name: ENV_NAME,
109
+ packages: [{ name: PKG_NAME, location: srcDir }],
110
+ connections: [],
111
+ },
112
+ ],
113
+ }),
114
+ );
115
+
116
+ const port = await getFreePort();
117
+ let mcpPort = await getFreePort();
118
+ while (mcpPort === port) mcpPort = await getFreePort();
119
+ const baseUrl = `http://127.0.0.1:${port}`;
120
+
121
+ const env: NodeJS.ProcessEnv = {
122
+ ...process.env,
123
+ SERVER_ROOT: serverRoot,
124
+ PUBLISHER_HOST: "127.0.0.1",
125
+ PUBLISHER_PORT: String(port),
126
+ MCP_PORT: String(mcpPort),
127
+ };
128
+ if (opts.watch) env.PUBLISHER_WATCH = ENV_NAME;
129
+
130
+ // No `--watch` on bun, so there is no stray file watcher to clean up beyond
131
+ // the server itself.
132
+ const proc: ChildProcess = spawn("bun", ["src/server.ts"], {
133
+ cwd: SERVER_DIR,
134
+ env,
135
+ stdio: ["ignore", "pipe", "pipe"],
136
+ });
137
+ let exited = false;
138
+ let serverLog = "";
139
+ const capture = (d: Buffer) => {
140
+ serverLog = (serverLog + d.toString()).slice(-4000);
141
+ };
142
+ proc.stdout?.on("data", capture);
143
+ proc.stderr?.on("data", capture);
144
+ proc.on("exit", () => {
145
+ exited = true;
146
+ });
147
+
148
+ const cleanup = () => {
149
+ for (const dir of [srcDir, serverRoot]) {
150
+ try {
151
+ fs.rmSync(dir, { recursive: true, force: true });
152
+ } catch {
153
+ // best-effort cleanup
154
+ }
155
+ }
156
+ };
157
+
158
+ try {
159
+ const ready = await poll(async () => {
160
+ if (exited) throw new Error("server exited before becoming ready");
161
+ try {
162
+ return (await fetch(apiUrl(baseUrl, "/models"))).ok;
163
+ } catch {
164
+ return false;
165
+ }
166
+ }, 120_000);
167
+ if (!ready) throw new Error("server did not become ready within 120s");
168
+ } catch (err) {
169
+ proc.kill("SIGKILL");
170
+ cleanup();
171
+ const reason = err instanceof Error ? err.message : String(err);
172
+ throw new Error(`${reason}\n--- server log tail ---\n${serverLog}`);
173
+ }
174
+
175
+ const stop = async (): Promise<void> => {
176
+ if (!exited) {
177
+ await new Promise<void>((resolve) => {
178
+ // Backstop in case SIGTERM is ignored; cleared once the process exits.
179
+ const backstop = setTimeout(() => proc.kill("SIGKILL"), 5_000);
180
+ proc.on("exit", () => {
181
+ clearTimeout(backstop);
182
+ resolve();
183
+ });
184
+ proc.kill("SIGTERM");
185
+ });
186
+ }
187
+ cleanup();
188
+ };
189
+
190
+ return {
191
+ baseUrl,
192
+ mountedPkgPath: path.join(
193
+ serverRoot,
194
+ "publisher_data",
195
+ ENV_NAME,
196
+ PKG_NAME,
197
+ ),
198
+ srcDir,
199
+ stop,
200
+ };
201
+ }
202
+
203
+ describe("Watch-mode source-edit live reload via --watch-env (E2E)", () => {
204
+ let server: TestServer | null = null;
205
+ let baseUrl = "";
206
+
207
+ beforeAll(async () => {
208
+ server = await startServer({ watch: true });
209
+ baseUrl = server.baseUrl;
210
+ });
211
+
212
+ afterAll(async () => {
213
+ await server?.stop();
214
+ server = null;
215
+ });
216
+
217
+ // ── in-place mount ────────────────────────────────────────────────
218
+
219
+ it("mounts a local-dir package in place (resolving to the source)", () => {
220
+ // A copy would resolve to a distinct path under publisher_data; an
221
+ // in-place mount resolves back to the source dir. realpath covers both a
222
+ // POSIX symlink and a Windows directory junction.
223
+ expect(fs.realpathSync(server!.mountedPkgPath)).toBe(
224
+ fs.realpathSync(server!.srcDir),
225
+ );
226
+ if (process.platform !== "win32") {
227
+ expect(fs.lstatSync(server!.mountedPkgPath).isSymbolicLink()).toBe(
228
+ true,
229
+ );
230
+ }
231
+ });
232
+
233
+ // ── status lifecycle / validation ─────────────────────────────────
234
+
235
+ it("auto-starts watching the configured env and reports enabled", async () => {
236
+ const res = await fetch(`${baseUrl}/api/v0/watch-mode/status`);
237
+ expect(res.status).toBe(200);
238
+ const status = (await res.json()) as {
239
+ enabled: boolean;
240
+ environmentName: string;
241
+ watchingPath: string;
242
+ };
243
+ expect(status.enabled).toBe(true);
244
+ expect(status.environmentName).toBe(ENV_NAME);
245
+ expect(status.watchingPath).toBe(path.dirname(server!.mountedPkgPath));
246
+ });
247
+
248
+ it("accepts an explicit start for the already-watched env and stays enabled", async () => {
249
+ const res = await fetch(`${baseUrl}/api/v0/watch-mode/start`, {
250
+ method: "POST",
251
+ headers: { "Content-Type": "application/json" },
252
+ body: JSON.stringify({ environmentName: ENV_NAME }),
253
+ });
254
+ expect(res.status).toBe(200);
255
+ // ensureWatching is idempotent; confirm the watcher is still live for our env.
256
+ const status = (await (
257
+ await fetch(`${baseUrl}/api/v0/watch-mode/status`)
258
+ ).json()) as { enabled: boolean; environmentName: string };
259
+ expect(status.enabled).toBe(true);
260
+ expect(status.environmentName).toBe(ENV_NAME);
261
+ });
262
+
263
+ it("rejects start for an unknown environment with 404", async () => {
264
+ const res = await fetch(`${baseUrl}/api/v0/watch-mode/start`, {
265
+ method: "POST",
266
+ headers: { "Content-Type": "application/json" },
267
+ body: JSON.stringify({ environmentName: "does-not-exist" }),
268
+ });
269
+ expect(res.status).toBe(404);
270
+ });
271
+
272
+ it("rejects start for an unsafe environment name with 400", async () => {
273
+ const res = await fetch(`${baseUrl}/api/v0/watch-mode/start`, {
274
+ method: "POST",
275
+ headers: { "Content-Type": "application/json" },
276
+ body: JSON.stringify({ environmentName: "../etc" }),
277
+ });
278
+ expect(res.status).toBe(400);
279
+ });
280
+
281
+ // ── recompile propagation (the actual fix) ────────────────────────
282
+
283
+ it("serves a newly added model after a source edit (reload)", async () => {
284
+ const before = await modelsText(baseUrl);
285
+ expect(before).toContain("first.malloy");
286
+ expect(before).not.toContain("second.malloy");
287
+
288
+ fs.writeFileSync(
289
+ path.join(server!.srcDir, "second.malloy"),
290
+ 'source: second_source is duckdb.sql("SELECT 2 as n")\n',
291
+ );
292
+
293
+ const appeared = await poll(
294
+ async () => (await modelsText(baseUrl)).includes("second.malloy"),
295
+ 25_000,
296
+ );
297
+ expect(appeared).toBe(true);
298
+ });
299
+
300
+ it("reflects an edit to an existing model's contents (recompile)", async () => {
301
+ // Rename the source inside first.malloy; the compiled model detail must
302
+ // pick up the new name, proving the package recompiled (not just a
303
+ // directory re-scan).
304
+ fs.writeFileSync(
305
+ path.join(server!.srcDir, "first.malloy"),
306
+ 'source: renamed_source is duckdb.sql("SELECT 1 as n")\n',
307
+ );
308
+
309
+ const recompiled = await poll(async () => {
310
+ const res = await fetch(apiUrl(baseUrl, "/models/first.malloy"));
311
+ if (!res.ok) return false;
312
+ // `sources` is the parsed source list ({ name, views }); `sourceInfos`
313
+ // is a sibling array of JSON-encoded strings, the wrong shape to read
314
+ // `.name` off of.
315
+ const model = (await res.json()) as {
316
+ sources?: Array<{ name?: string }>;
317
+ };
318
+ return (model.sources ?? []).some((s) => s.name === "renamed_source");
319
+ }, 25_000);
320
+ expect(recompiled).toBe(true);
321
+ });
322
+
323
+ it("survives a transient compile error during reload and recovers", async () => {
324
+ // The most common watch action is saving a model mid-edit with a
325
+ // transient syntax error. That must not destroy the in-place mount: a
326
+ // failed-load cleanup that rm'd the mount symlink would brick the package
327
+ // until a restart. Write an invalid model, confirm the mount survives,
328
+ // then fix it and confirm the package recompiles and serves the new source.
329
+ const badPath = path.join(server!.srcDir, "broken.malloy");
330
+ fs.writeFileSync(badPath, "source: broken is duckdb.sql(\n"); // parse error
331
+
332
+ // Over a window long enough for the watcher to fire and fail the reload,
333
+ // the mounted package path must never disappear.
334
+ const mountGone = await poll(
335
+ async () => !fs.existsSync(server!.mountedPkgPath),
336
+ 8_000,
337
+ );
338
+ expect(mountGone).toBe(false);
339
+
340
+ // Fix the model; the package must recompile (proving the mount, hence the
341
+ // live source, is still reachable) and serve the recovered source.
342
+ fs.writeFileSync(
343
+ badPath,
344
+ 'source: recovered_source is duckdb.sql("SELECT 1 as n")\n',
345
+ );
346
+ const recovered = await poll(async () => {
347
+ const res = await fetch(apiUrl(baseUrl, "/models/broken.malloy"));
348
+ if (!res.ok) return false;
349
+ const model = (await res.json()) as {
350
+ sources?: Array<{ name?: string }>;
351
+ };
352
+ return (model.sources ?? []).some(
353
+ (s) => s.name === "recovered_source",
354
+ );
355
+ }, 25_000);
356
+ expect(recovered).toBe(true);
357
+ });
358
+
359
+ // ── stop ──────────────────────────────────────────────────────────
360
+
361
+ it("stops watching and reports disabled", async () => {
362
+ const stop = await fetch(`${baseUrl}/api/v0/watch-mode/stop`, {
363
+ method: "POST",
364
+ });
365
+ expect(stop.status).toBe(200);
366
+
367
+ const status = (await (
368
+ await fetch(`${baseUrl}/api/v0/watch-mode/status`)
369
+ ).json()) as { enabled: boolean; watchingPath: string };
370
+ expect(status.enabled).toBe(false);
371
+ expect(status.watchingPath).toBe("");
372
+ });
373
+ });
374
+
375
+ describe("Watch-mode copy semantics without --watch-env (E2E)", () => {
376
+ let server: TestServer | null = null;
377
+ let baseUrl = "";
378
+
379
+ beforeAll(async () => {
380
+ server = await startServer({ watch: false });
381
+ baseUrl = server.baseUrl;
382
+ });
383
+
384
+ afterAll(async () => {
385
+ await server?.stop();
386
+ server = null;
387
+ });
388
+
389
+ it("mounts a local-dir package as a copy (decoupled from the source)", () => {
390
+ // No --watch-env: the package is copied into publisher_data, so it is a
391
+ // real directory and does not resolve back to the source.
392
+ expect(fs.lstatSync(server!.mountedPkgPath).isSymbolicLink()).toBe(false);
393
+ expect(fs.realpathSync(server!.mountedPkgPath)).not.toBe(
394
+ fs.realpathSync(server!.srcDir),
395
+ );
396
+ });
397
+
398
+ it("does not propagate a source edit even with a watcher started", async () => {
399
+ // Starting the watcher succeeds (the env is in the config), but it watches
400
+ // the copy, so editing the source never reaches what the server serves.
401
+ const start = await fetch(`${baseUrl}/api/v0/watch-mode/start`, {
402
+ method: "POST",
403
+ headers: { "Content-Type": "application/json" },
404
+ body: JSON.stringify({ environmentName: ENV_NAME }),
405
+ });
406
+ expect(start.status).toBe(200);
407
+
408
+ fs.writeFileSync(
409
+ path.join(server!.srcDir, "second.malloy"),
410
+ 'source: second_source is duckdb.sql("SELECT 2 as n")\n',
411
+ );
412
+
413
+ // Copy mode never propagates, so this should time out without appearing.
414
+ const appeared = await poll(
415
+ async () => (await modelsText(baseUrl)).includes("second.malloy"),
416
+ 6_000,
417
+ );
418
+ expect(appeared).toBe(false);
419
+ expect(await modelsText(baseUrl)).toContain("first.malloy");
420
+ });
421
+ });
@@ -67,6 +67,15 @@ describe("DuckDB Attached Databases", () => {
67
67
  expect(result.rows.length).toBeGreaterThan(0);
68
68
  });
69
69
 
70
+ it("should load aws extension for cloud storage", async () => {
71
+ await connection.runSQL("INSTALL aws;");
72
+ await connection.runSQL("LOAD aws;");
73
+ const result = await connection.runSQL(
74
+ "SELECT * FROM duckdb_extensions() WHERE extension_name = 'aws';",
75
+ );
76
+ expect(result.rows.length).toBeGreaterThan(0);
77
+ });
78
+
70
79
  it("should load postgres extension", async () => {
71
80
  await connection.runSQL("INSTALL postgres;");
72
81
  await connection.runSQL("LOAD postgres;");
@@ -145,6 +154,108 @@ describe("DuckDB Attached Databases", () => {
145
154
  throw error;
146
155
  }
147
156
  });
157
+
158
+ // The connection/storage layers INSTALL/LOAD these at runtime (cloud
159
+ // attach, the per-package sandbox, the materialization catalog). This
160
+ // asserts the DuckDB engine we resolve -- Malloy's @duckdb/node-api or
161
+ // our own npm pin, whichever this connection uses -- can install AND load
162
+ // every one of them, so a version bump that drops support for any is
163
+ // caught here rather than at runtime.
164
+ it("loads every core runtime DuckDB extension (httpfs, aws, azure, postgres, ducklake)", async () => {
165
+ // INSTALL name -> the name it registers as in duckdb_extensions().
166
+ const required: Array<{ install: string; registered: string }> = [
167
+ { install: "httpfs", registered: "httpfs" },
168
+ { install: "aws", registered: "aws" },
169
+ { install: "azure", registered: "azure" },
170
+ { install: "postgres", registered: "postgres_scanner" },
171
+ { install: "ducklake", registered: "ducklake" },
172
+ ];
173
+
174
+ for (const { install, registered } of required) {
175
+ await connection.runSQL(`INSTALL ${install};`);
176
+ await connection.runSQL(`LOAD ${install};`);
177
+
178
+ const result = await connection.runSQL(
179
+ `SELECT loaded, installed FROM duckdb_extensions() WHERE extension_name = '${registered}';`,
180
+ );
181
+ const row = result.rows[0] as
182
+ | { loaded: boolean; installed: boolean }
183
+ | undefined;
184
+
185
+ expect(
186
+ row,
187
+ `extension '${install}' (registered '${registered}') not present after INSTALL/LOAD`,
188
+ ).toBeDefined();
189
+ expect(
190
+ row?.installed,
191
+ `extension '${install}' is not installed`,
192
+ ).toBe(true);
193
+ expect(
194
+ row?.loaded,
195
+ `extension '${install}' is installed but not loaded`,
196
+ ).toBe(true);
197
+ }
198
+ });
199
+
200
+ it("loads every community runtime DuckDB extension (bigquery, snowflake) where the platform supports it", async () => {
201
+ // bigquery and snowflake come from the DuckDB community repository.
202
+ // Unlike the core extensions they are platform-dependent: snowflake in
203
+ // particular relies on a native ADBC driver not available on every
204
+ // OS/arch (e.g. the Windows runner). When one can't load on this
205
+ // platform, log it and continue rather than failing -- the goal is to
206
+ // confirm that *where supported*, the resolved DuckDB engine loads it.
207
+ //
208
+ // The earlier per-extension tests already INSTALL these, so here we
209
+ // only LOAD. We deliberately avoid `FORCE INSTALL`: re-installing an
210
+ // extension that's already in the shared on-disk cache makes DuckDB
211
+ // move/overwrite the file, which races and fails on Windows
212
+ // ("Could not move file: Access is denied.").
213
+ const community = ["bigquery", "snowflake"];
214
+
215
+ for (const ext of community) {
216
+ try {
217
+ await connection.runSQL(`INSTALL '${ext}' FROM community;`);
218
+ await connection.runSQL(`LOAD ${ext};`);
219
+ } catch (error) {
220
+ const message =
221
+ error instanceof Error ? error.message : String(error);
222
+ console.warn(
223
+ `community extension '${ext}' not available on this platform; skipping: ${message}`,
224
+ );
225
+ continue;
226
+ }
227
+
228
+ const result = await connection.runSQL(
229
+ `SELECT loaded, installed FROM duckdb_extensions() WHERE extension_name = '${ext}';`,
230
+ );
231
+ const row = result.rows[0] as
232
+ | { loaded: boolean; installed: boolean }
233
+ | undefined;
234
+
235
+ // INSTALL/LOAD reported success above, so the extension should now
236
+ // report loaded. If the engine reports otherwise on this platform,
237
+ // log it rather than failing -- community extensions are best-effort
238
+ // and the connection layer tolerates the same.
239
+ if (!row?.loaded) {
240
+ console.warn(
241
+ `community extension '${ext}' reported success but is not loaded on this platform; skipping assertion`,
242
+ );
243
+ }
244
+ }
245
+
246
+ // The suite still asserts something concrete: at least one community
247
+ // extension loads on every supported platform (bigquery is broadly
248
+ // available; snowflake depends on a native driver). This catches a
249
+ // total community-repo breakage without being brittle per-platform.
250
+ const loaded = await connection.runSQL(
251
+ "SELECT count(*) AS n FROM duckdb_extensions() WHERE loaded AND extension_name IN ('bigquery', 'snowflake');",
252
+ );
253
+ const n = Number((loaded.rows[0] as { n: number | bigint }).n);
254
+ expect(
255
+ n,
256
+ "expected at least one community extension (bigquery/snowflake) to load",
257
+ ).toBeGreaterThan(0);
258
+ });
148
259
  });
149
260
 
150
261
  describe("Configuration Validation - Negative Tests", () => {