@malloy-publisher/server 0.0.230 → 0.0.232
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 +4 -0
- package/dist/app/api-doc.yaml +74 -3
- package/dist/app/assets/{EnvironmentPage-wa_EPkwK.js → EnvironmentPage-DXEaZIPx.js} +1 -1
- package/dist/app/assets/{HomePage-jnCrupQp.js → HomePage-kofsqpZt.js} +1 -1
- package/dist/app/assets/{LightMode-DYbwNULZ.js → LightMode-CNhIlIlJ.js} +1 -1
- package/dist/app/assets/{MainPage-CuJLrPNI.js → MainPage-Bgqo8jCy.js} +1 -1
- package/dist/app/assets/{MaterializationsPage-D_67x2ee.js → MaterializationsPage-CgBlgGz2.js} +1 -1
- package/dist/app/assets/{ModelPage-D5JtAWqR.js → ModelPage-B0TjoDtf.js} +1 -1
- package/dist/app/assets/{PackagePage-BRwtqUSG.js → PackagePage-BL8vnFj1.js} +1 -1
- package/dist/app/assets/{RouteError-CBNNrnSD.js → RouteError-BzPby0X2.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-CTCeBneA.js → ThemeEditorPage-CTEP_9r3.js} +1 -1
- package/dist/app/assets/{WorkbookPage-SN6f1RBm.js → WorkbookPage-BwM3BmKw.js} +1 -1
- package/dist/app/assets/{core-Dp3q5Ieu.es-CD5FvM2s.js → core-CK68iv6w.es-CpRxXBt7.js} +1 -1
- package/dist/app/assets/{index-C_tJstcx.js → index-B33zGctF.js} +15 -15
- package/dist/app/assets/{index-DU4r7GdU.js → index-BabP-V-S.js} +346 -321
- package/dist/app/assets/{index-B3Nn8Vm2.js → index-BkiWKaAF.js} +266 -265
- package/dist/app/assets/{index-BLCx1EdC.js → index-CmkW1MiE.js} +1 -1
- package/dist/app/assets/{index-CfmBVB6M.js → index-tXJXwdyj.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/instrumentation.mjs +2 -0
- package/dist/package_load_worker.mjs +11 -1
- package/dist/server.mjs +3186 -433
- package/package.json +12 -12
- package/scripts/bake-duckdb-extensions.js +4 -1
- package/src/config.spec.ts +39 -0
- package/src/config.ts +135 -0
- package/src/controller/materialization.controller.spec.ts +62 -0
- package/src/controller/materialization.controller.ts +15 -0
- package/src/controller/package.controller.spec.ts +6 -0
- package/src/controller/package.controller.ts +7 -2
- package/src/errors.ts +19 -0
- package/src/logger.spec.ts +18 -1
- package/src/logger.ts +3 -1
- package/src/materialization_metrics.spec.ts +89 -4
- package/src/materialization_metrics.ts +155 -5
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/mcp/tools/embedding_index.spec.ts +1236 -0
- package/src/mcp/tools/embedding_index.ts +808 -0
- package/src/mcp/tools/get_context_eval.ts +194 -45
- package/src/mcp/tools/get_context_tool.spec.ts +295 -2
- package/src/mcp/tools/get_context_tool.ts +159 -10
- package/src/pg_helpers.spec.ts +201 -0
- package/src/pg_helpers.ts +44 -5
- package/src/server.ts +24 -0
- package/src/service/build_plan.spec.ts +128 -2
- package/src/service/build_plan.ts +239 -17
- package/src/service/connection.ts +263 -7
- package/src/service/connection_config.spec.ts +48 -0
- package/src/service/connection_config.ts +21 -8
- package/src/service/connection_federation.spec.ts +184 -0
- package/src/service/embedding_provider.spec.ts +329 -0
- package/src/service/embedding_provider.ts +236 -0
- package/src/service/environment.ts +274 -12
- package/src/service/environment_store.spec.ts +678 -3
- package/src/service/environment_store.ts +449 -33
- package/src/service/environment_store_clone.spec.ts +350 -0
- package/src/service/manifest_loader.spec.ts +68 -13
- package/src/service/manifest_loader.ts +67 -19
- package/src/service/materialization_build_session.spec.ts +435 -0
- package/src/service/materialization_build_session.ts +681 -0
- package/src/service/materialization_eligibility.spec.ts +158 -0
- package/src/service/materialization_eligibility.ts +305 -0
- package/src/service/materialization_serve_transform.spec.ts +1003 -0
- package/src/service/materialization_serve_transform.ts +779 -0
- package/src/service/materialization_service.spec.ts +774 -7
- package/src/service/materialization_service.ts +1107 -42
- package/src/service/materialization_test_fixtures.ts +7 -0
- package/src/service/model.spec.ts +207 -0
- package/src/service/model.ts +540 -52
- package/src/service/model_storage_serve.spec.ts +193 -0
- package/src/service/model_storage_serve_joins.spec.ts +193 -0
- package/src/service/package.spec.ts +196 -0
- package/src/service/package.ts +385 -17
- package/src/service/persistence_policy.spec.ts +109 -0
- package/src/storage/duckdb/schema.ts +37 -0
- package/tests/fixtures/xlsx/database.xlsx +0 -0
- package/tests/integration/first_boot/readiness_line.integration.spec.ts +177 -0
- package/tests/integration/materialization/manifest_binding.integration.spec.ts +104 -0
- package/tests/integration/mcp/mcp_get_context_semantic.integration.spec.ts +235 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterEach,
|
|
3
|
+
beforeEach,
|
|
4
|
+
describe,
|
|
5
|
+
expect,
|
|
6
|
+
it,
|
|
7
|
+
mock,
|
|
8
|
+
spyOn,
|
|
9
|
+
} from "bun:test";
|
|
10
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import { TEMP_DIR_PATH } from "../constants";
|
|
13
|
+
import { logger } from "../logger";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Wiring coverage for the package git clone: the shallow-clone options must
|
|
17
|
+
* actually reach `simple-git`'s clone call, the factory must carry a progress
|
|
18
|
+
* handler whose output lands on stderr with the right label, and the readiness
|
|
19
|
+
* line must not print when boot fails. The pure helpers (options content,
|
|
20
|
+
* throttling, label text) are covered in environment_store.spec.ts; this file
|
|
21
|
+
* proves the plumbing.
|
|
22
|
+
*
|
|
23
|
+
* simple-git is module-mocked BEFORE the store is imported (the anchoring
|
|
24
|
+
* spec's ordering idiom). The mock leaks forward in bun's shared module cache,
|
|
25
|
+
* which is safe here: environment_store.ts is the only importer, and the only
|
|
26
|
+
* spec that performs a real clone (connection.spec.ts) is credential-gated and
|
|
27
|
+
* runs in its own workflow process.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const serverRootPath = path.join(TEMP_DIR_PATH, "clone-spec-server-root");
|
|
31
|
+
|
|
32
|
+
const ENV_NAME = "clone-env";
|
|
33
|
+
const PKG_NAME = "pkg-a";
|
|
34
|
+
|
|
35
|
+
interface RecordedClone {
|
|
36
|
+
repoUrl: string;
|
|
37
|
+
dir: string;
|
|
38
|
+
opts: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let recordedClones: RecordedClone[] = [];
|
|
42
|
+
let lastFactoryOpts: {
|
|
43
|
+
progress?: (event: {
|
|
44
|
+
method: string;
|
|
45
|
+
stage: string;
|
|
46
|
+
progress: number;
|
|
47
|
+
processed: number;
|
|
48
|
+
total: number;
|
|
49
|
+
}) => void;
|
|
50
|
+
} | null = null;
|
|
51
|
+
let storageInitFails = false;
|
|
52
|
+
let storageInitMessage = "storage init failed (test)";
|
|
53
|
+
let cloneFailure: Error | null = null;
|
|
54
|
+
|
|
55
|
+
mock.module("simple-git", () => ({
|
|
56
|
+
default: (factoryOpts?: typeof lastFactoryOpts) => {
|
|
57
|
+
lastFactoryOpts = factoryOpts ?? null;
|
|
58
|
+
return {
|
|
59
|
+
clone: (
|
|
60
|
+
repoUrl: string,
|
|
61
|
+
dir: string,
|
|
62
|
+
opts: Record<string, unknown>,
|
|
63
|
+
cb: (err: Error | null) => void,
|
|
64
|
+
) => {
|
|
65
|
+
recordedClones.push({ repoUrl, dir, opts });
|
|
66
|
+
if (cloneFailure) {
|
|
67
|
+
cb(cloneFailure);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Materialize the fixture the extraction step expects: the repo
|
|
71
|
+
// contains a subdirectory per package (pkg-a plus a sibling used
|
|
72
|
+
// by the shared-clone counter test). Extraction only copies the
|
|
73
|
+
// named subdir, so an unused one is harmless to single-package
|
|
74
|
+
// tests.
|
|
75
|
+
for (const name of [PKG_NAME, "pkg-b"]) {
|
|
76
|
+
const pkgDir = path.join(dir, name);
|
|
77
|
+
mkdirSync(pkgDir, { recursive: true });
|
|
78
|
+
writeFileSync(
|
|
79
|
+
path.join(pkgDir, "publisher.json"),
|
|
80
|
+
JSON.stringify({ name }),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
// Drive the progress handler the way the real plugin would.
|
|
84
|
+
lastFactoryOpts?.progress?.({
|
|
85
|
+
method: "clone",
|
|
86
|
+
stage: "receiving",
|
|
87
|
+
progress: 50,
|
|
88
|
+
processed: 1,
|
|
89
|
+
total: 2,
|
|
90
|
+
});
|
|
91
|
+
cb(null);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
mock.module("../storage/StorageManager", () => ({
|
|
98
|
+
StorageManager: class MockStorageManager {
|
|
99
|
+
async initialize(): Promise<void> {
|
|
100
|
+
if (storageInitFails) {
|
|
101
|
+
throw new Error(storageInitMessage);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getRepository() {
|
|
105
|
+
return {
|
|
106
|
+
listEnvironments: async () => [],
|
|
107
|
+
getEnvironmentByName: async () => null,
|
|
108
|
+
createEnvironment: async (data: Record<string, unknown>) => ({
|
|
109
|
+
id: "env-id",
|
|
110
|
+
name: data.name,
|
|
111
|
+
path: data.path,
|
|
112
|
+
}),
|
|
113
|
+
listPackages: async () => [],
|
|
114
|
+
getPackageByName: async () => null,
|
|
115
|
+
createPackage: async (data: Record<string, unknown>) => ({
|
|
116
|
+
id: "pkg-id",
|
|
117
|
+
name: data.name,
|
|
118
|
+
}),
|
|
119
|
+
listConnections: async () => [],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
StorageConfig: {} as Record<string, unknown>,
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
const { EnvironmentStore, GIT_CLONE_OPTIONS } = await import(
|
|
127
|
+
"./environment_store"
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
describe("git clone wiring", () => {
|
|
131
|
+
let stderrWrites: string[];
|
|
132
|
+
let stderrSpy: ReturnType<typeof spyOn>;
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
rmSync(serverRootPath, { recursive: true, force: true });
|
|
136
|
+
mkdirSync(serverRootPath, { recursive: true });
|
|
137
|
+
recordedClones = [];
|
|
138
|
+
lastFactoryOpts = null;
|
|
139
|
+
storageInitFails = false;
|
|
140
|
+
storageInitMessage = "storage init failed (test)";
|
|
141
|
+
cloneFailure = null;
|
|
142
|
+
stderrWrites = [];
|
|
143
|
+
stderrSpy = spyOn(process.stderr, "write").mockImplementation(
|
|
144
|
+
(chunk: string | Uint8Array) => {
|
|
145
|
+
stderrWrites.push(String(chunk));
|
|
146
|
+
return true;
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
afterEach(() => {
|
|
152
|
+
stderrSpy.mockRestore();
|
|
153
|
+
rmSync(serverRootPath, { recursive: true, force: true });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("boot clones shallow, streams labeled progress, and mounts the package", async () => {
|
|
157
|
+
writeFileSync(
|
|
158
|
+
path.join(serverRootPath, "publisher.config.json"),
|
|
159
|
+
JSON.stringify({
|
|
160
|
+
frozenConfig: false,
|
|
161
|
+
environments: [
|
|
162
|
+
{
|
|
163
|
+
name: ENV_NAME,
|
|
164
|
+
packages: [
|
|
165
|
+
{
|
|
166
|
+
name: PKG_NAME,
|
|
167
|
+
location: `https://github.com/example/repo/tree/main/${PKG_NAME}`,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
connections: [],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const infoSpy = spyOn(logger, "info");
|
|
177
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
178
|
+
await store.finishedInitialization;
|
|
179
|
+
|
|
180
|
+
// The options object reaches .clone verbatim.
|
|
181
|
+
expect(recordedClones).toHaveLength(1);
|
|
182
|
+
expect(recordedClones[0].repoUrl).toBe("https://github.com/example/repo");
|
|
183
|
+
expect(recordedClones[0].opts).toEqual(GIT_CLONE_OPTIONS);
|
|
184
|
+
|
|
185
|
+
// The extraction log carries the mounted-of-total counter.
|
|
186
|
+
const infoMessages = infoSpy.mock.calls.map((c) => String(c[0]));
|
|
187
|
+
infoSpy.mockRestore();
|
|
188
|
+
expect(
|
|
189
|
+
infoMessages.some(
|
|
190
|
+
(m) =>
|
|
191
|
+
m.includes('Extracted package "pkg-a"') && m.includes("(1/1)"),
|
|
192
|
+
),
|
|
193
|
+
).toBe(true);
|
|
194
|
+
|
|
195
|
+
// The progress event surfaced on stderr, labeled with env and package.
|
|
196
|
+
const output = stderrWrites.join("");
|
|
197
|
+
expect(output).toContain(
|
|
198
|
+
`[${ENV_NAME}] cloning example/repo (${PKG_NAME}): receiving 50% (1/2)`,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// The package extracted from the (fake) clone and mounted.
|
|
202
|
+
expect(
|
|
203
|
+
existsSync(
|
|
204
|
+
path.join(
|
|
205
|
+
serverRootPath,
|
|
206
|
+
"publisher_data",
|
|
207
|
+
ENV_NAME,
|
|
208
|
+
PKG_NAME,
|
|
209
|
+
"publisher.json",
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
).toBe(true);
|
|
213
|
+
|
|
214
|
+
// And the boot announced itself exactly once.
|
|
215
|
+
const readyLines = output
|
|
216
|
+
.split("\n")
|
|
217
|
+
.filter((line) => line.startsWith("PUBLISHER_READY"));
|
|
218
|
+
expect(readyLines).toHaveLength(1);
|
|
219
|
+
expect(readyLines[0]).toContain("environments=1");
|
|
220
|
+
expect(readyLines[0]).toContain("packages=1");
|
|
221
|
+
expect(readyLines[0]).toContain("load_errors=0");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("the mounted-of-total counter accumulates across packages in a shared clone", async () => {
|
|
225
|
+
// Two packages share one repo clone; the counter is one variable across
|
|
226
|
+
// every mount branch, so a single (1/2)->(2/2) run pins that it advances
|
|
227
|
+
// rather than reporting a constant.
|
|
228
|
+
writeFileSync(
|
|
229
|
+
path.join(serverRootPath, "publisher.config.json"),
|
|
230
|
+
JSON.stringify({
|
|
231
|
+
frozenConfig: false,
|
|
232
|
+
environments: [
|
|
233
|
+
{
|
|
234
|
+
name: ENV_NAME,
|
|
235
|
+
packages: [
|
|
236
|
+
{
|
|
237
|
+
name: PKG_NAME,
|
|
238
|
+
location: `https://github.com/example/repo/tree/main/${PKG_NAME}`,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "pkg-b",
|
|
242
|
+
location: `https://github.com/example/repo/tree/main/pkg-b`,
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
connections: [],
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const infoSpy = spyOn(logger, "info");
|
|
252
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
253
|
+
await store.finishedInitialization;
|
|
254
|
+
const infoMessages = infoSpy.mock.calls.map((c) => String(c[0]));
|
|
255
|
+
infoSpy.mockRestore();
|
|
256
|
+
|
|
257
|
+
// One clone serves both, and the counter runs 1/2 then 2/2.
|
|
258
|
+
expect(recordedClones).toHaveLength(1);
|
|
259
|
+
const counters = infoMessages
|
|
260
|
+
.filter((m) => m.startsWith("Extracted package"))
|
|
261
|
+
.map((m) => m.slice(m.lastIndexOf("(")));
|
|
262
|
+
expect(counters).toEqual(["(1/2)", "(2/2)"]);
|
|
263
|
+
expect(stderrWrites.join("")).toContain("packages=2");
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("direct download extracts the subdirectory and labels by repo alone", async () => {
|
|
267
|
+
// The controller add-package path: downloadGitHubDirectory is called
|
|
268
|
+
// with the raw /tree/... location and no progress context.
|
|
269
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
270
|
+
await store.finishedInitialization;
|
|
271
|
+
|
|
272
|
+
const target = path.join(serverRootPath, "publisher_data", "direct");
|
|
273
|
+
await store.downloadGitHubDirectory(
|
|
274
|
+
`https://github.com/example/repo/tree/main/${PKG_NAME}`,
|
|
275
|
+
target,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
expect(recordedClones).toHaveLength(1);
|
|
279
|
+
expect(recordedClones[0].opts).toEqual(GIT_CLONE_OPTIONS);
|
|
280
|
+
// Subdirectory contents were hoisted to the target root.
|
|
281
|
+
expect(existsSync(path.join(target, "publisher.json"))).toBe(true);
|
|
282
|
+
expect(existsSync(path.join(target, PKG_NAME))).toBe(false);
|
|
283
|
+
// No environment context on this path, so the label is the repo alone.
|
|
284
|
+
expect(stderrWrites.join("")).toContain(
|
|
285
|
+
"cloning example/repo: receiving 50% (1/2)",
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("a failed clone rejects with the progress noise stripped", async () => {
|
|
290
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
291
|
+
await store.finishedInitialization;
|
|
292
|
+
cloneFailure = new Error(
|
|
293
|
+
"Cloning into '/x'...\nReceiving objects: 50% (5/10)\nfatal: early EOF",
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const target = path.join(serverRootPath, "publisher_data", "direct");
|
|
297
|
+
let caught: Error | undefined;
|
|
298
|
+
try {
|
|
299
|
+
await store.downloadGitHubDirectory(
|
|
300
|
+
"https://github.com/example/repo",
|
|
301
|
+
target,
|
|
302
|
+
);
|
|
303
|
+
} catch (e) {
|
|
304
|
+
caught = e as Error;
|
|
305
|
+
}
|
|
306
|
+
expect(caught).toBeDefined();
|
|
307
|
+
// The message keeps what went wrong and drops the --progress spew;
|
|
308
|
+
// the stack (which V8 seeds with the message, prefixed "Error: ") is
|
|
309
|
+
// stripped too, including the prefixed "Cloning into" first line.
|
|
310
|
+
expect(caught!.message).toBe("fatal: early EOF");
|
|
311
|
+
expect(caught!.stack ?? "").not.toContain("Receiving objects");
|
|
312
|
+
expect(caught!.stack ?? "").not.toContain("Cloning into");
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("prints the failure token instead of the readiness line when boot fails", async () => {
|
|
316
|
+
storageInitFails = true;
|
|
317
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
318
|
+
// initialize() swallows the failure by design; the promise resolves.
|
|
319
|
+
await store.finishedInitialization;
|
|
320
|
+
const output = stderrWrites.join("");
|
|
321
|
+
expect(output.includes("PUBLISHER_READY")).toBe(false);
|
|
322
|
+
// A script waiting on the ready token fails fast instead of hanging.
|
|
323
|
+
const failLines = output
|
|
324
|
+
.split("\n")
|
|
325
|
+
.filter((line) => line.startsWith("PUBLISHER_INIT_FAILED"));
|
|
326
|
+
expect(failLines).toHaveLength(1);
|
|
327
|
+
expect(failLines[0]).toContain("storage init failed (test)");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("redacts a pg password in the failure token", async () => {
|
|
331
|
+
// The init error can carry a connection string; the INIT_FAILED token
|
|
332
|
+
// must redact the keyword-form password before it reaches stderr.
|
|
333
|
+
// (The adjacent winston init-error log shares the raw-message gap with
|
|
334
|
+
// every other extractErrorDataFromError site; redacting those centrally
|
|
335
|
+
// is a separate security follow-up, tracked in npx-fast-first-boot.md.)
|
|
336
|
+
storageInitFails = true;
|
|
337
|
+
storageInitMessage =
|
|
338
|
+
"attach failed: host=db port=5432 password=supersecret dbname=x";
|
|
339
|
+
const store = new EnvironmentStore(serverRootPath);
|
|
340
|
+
await store.finishedInitialization;
|
|
341
|
+
|
|
342
|
+
const failLine = stderrWrites
|
|
343
|
+
.join("")
|
|
344
|
+
.split("\n")
|
|
345
|
+
.find((line) => line.startsWith("PUBLISHER_INIT_FAILED"));
|
|
346
|
+
expect(failLine).toBeDefined();
|
|
347
|
+
expect(failLine).toContain("password=***");
|
|
348
|
+
expect(failLine).not.toContain("supersecret");
|
|
349
|
+
});
|
|
350
|
+
});
|
|
@@ -24,7 +24,7 @@ describe("fetchManifestEntries", () => {
|
|
|
24
24
|
return file;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
it("maps physicalTableName to the Malloy runtime tableName", async () => {
|
|
27
|
+
it("maps physicalTableName to the Malloy runtime tableName (colocated entries)", async () => {
|
|
28
28
|
const file = await writeManifest({
|
|
29
29
|
builtAt: new Date().toISOString(),
|
|
30
30
|
strict: false,
|
|
@@ -38,17 +38,64 @@ describe("fetchManifestEntries", () => {
|
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const { tableNameManifest, storageEntries } =
|
|
42
|
+
await fetchManifestEntries(file);
|
|
42
43
|
|
|
43
|
-
expect(
|
|
44
|
+
expect(tableNameManifest).toEqual({
|
|
44
45
|
b1: { tableName: "schema.orders_mz" },
|
|
45
46
|
// connectionName is carried through so the bind step can quote the
|
|
46
47
|
// table path for that connection's dialect (Package.quoteBoundTableNames).
|
|
47
48
|
b2: { tableName: "schema.daily_mz", connectionName: "bq" },
|
|
48
49
|
});
|
|
50
|
+
expect(storageEntries).toEqual({});
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
it("
|
|
53
|
+
it("routes storage= entries (with storageConnectionName) to storageEntries, not the tableName manifest", async () => {
|
|
54
|
+
const schema = [
|
|
55
|
+
{ name: "d", type: "DATE" },
|
|
56
|
+
{ name: "n", type: "BIGINT" },
|
|
57
|
+
];
|
|
58
|
+
const file = await writeManifest({
|
|
59
|
+
entries: {
|
|
60
|
+
// colocated: in-warehouse substitution
|
|
61
|
+
wh: {
|
|
62
|
+
sourceEntityId: "wh",
|
|
63
|
+
physicalTableName: "orders_v1",
|
|
64
|
+
connectionName: "bq",
|
|
65
|
+
},
|
|
66
|
+
// storage tier: cross-connection serve binding (full entry retained)
|
|
67
|
+
lake: {
|
|
68
|
+
sourceEntityId: "lake",
|
|
69
|
+
sourceName: "daily_orders",
|
|
70
|
+
physicalTableName: "daily_orders",
|
|
71
|
+
connectionName: "bq",
|
|
72
|
+
storageConnectionName: "lake",
|
|
73
|
+
schema,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const { tableNameManifest, storageEntries } =
|
|
79
|
+
await fetchManifestEntries(file);
|
|
80
|
+
|
|
81
|
+
// The storage entry must NOT enter the same-connection tableName manifest.
|
|
82
|
+
expect(tableNameManifest).toEqual({
|
|
83
|
+
wh: { tableName: "orders_v1", connectionName: "bq" },
|
|
84
|
+
});
|
|
85
|
+
// …and is preserved as a full entry (schema + sourceName + destination).
|
|
86
|
+
expect(storageEntries).toEqual({
|
|
87
|
+
lake: {
|
|
88
|
+
sourceEntityId: "lake",
|
|
89
|
+
sourceName: "daily_orders",
|
|
90
|
+
physicalTableName: "daily_orders",
|
|
91
|
+
connectionName: "bq",
|
|
92
|
+
storageConnectionName: "lake",
|
|
93
|
+
schema,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("carries the host-supplied freshness fields verbatim (colocated)", async () => {
|
|
52
99
|
const dataAsOf = "2026-07-07T00:00:00.000Z";
|
|
53
100
|
const file = await writeManifest({
|
|
54
101
|
entries: {
|
|
@@ -66,11 +113,11 @@ describe("fetchManifestEntries", () => {
|
|
|
66
113
|
},
|
|
67
114
|
});
|
|
68
115
|
|
|
69
|
-
const
|
|
116
|
+
const { tableNameManifest } = await fetchManifestEntries(file);
|
|
70
117
|
|
|
71
118
|
// Filter-free: freshness fields are retained for the serve-path gate; a
|
|
72
119
|
// window-less entry is left un-gated.
|
|
73
|
-
expect(
|
|
120
|
+
expect(tableNameManifest).toEqual({
|
|
74
121
|
gated: {
|
|
75
122
|
tableName: "schema.gated_mz",
|
|
76
123
|
dataAsOf,
|
|
@@ -86,9 +133,11 @@ describe("fetchManifestEntries", () => {
|
|
|
86
133
|
entries: { b1: { sourceEntityId: "b1", physicalTableName: "t1" } },
|
|
87
134
|
});
|
|
88
135
|
|
|
89
|
-
const
|
|
136
|
+
const { tableNameManifest } = await fetchManifestEntries(
|
|
137
|
+
pathToFileURL(file).href,
|
|
138
|
+
);
|
|
90
139
|
|
|
91
|
-
expect(
|
|
140
|
+
expect(tableNameManifest).toEqual({ b1: { tableName: "t1" } });
|
|
92
141
|
});
|
|
93
142
|
|
|
94
143
|
it("skips entries without a physicalTableName", async () => {
|
|
@@ -99,17 +148,23 @@ describe("fetchManifestEntries", () => {
|
|
|
99
148
|
},
|
|
100
149
|
});
|
|
101
150
|
|
|
102
|
-
const
|
|
151
|
+
const { tableNameManifest } = await fetchManifestEntries(file);
|
|
103
152
|
|
|
104
|
-
expect(
|
|
153
|
+
expect(tableNameManifest).toEqual({ good: { tableName: "t1" } });
|
|
105
154
|
});
|
|
106
155
|
|
|
107
|
-
it("returns
|
|
156
|
+
it("returns empty maps when there are no entries", async () => {
|
|
108
157
|
const file = await writeManifest({ entries: {} });
|
|
109
|
-
expect(await fetchManifestEntries(file)).toEqual({
|
|
158
|
+
expect(await fetchManifestEntries(file)).toEqual({
|
|
159
|
+
tableNameManifest: {},
|
|
160
|
+
storageEntries: {},
|
|
161
|
+
});
|
|
110
162
|
|
|
111
163
|
const file2 = await writeManifest({});
|
|
112
|
-
expect(await fetchManifestEntries(file2)).toEqual({
|
|
164
|
+
expect(await fetchManifestEntries(file2)).toEqual({
|
|
165
|
+
tableNameManifest: {},
|
|
166
|
+
storageEntries: {},
|
|
167
|
+
});
|
|
113
168
|
});
|
|
114
169
|
|
|
115
170
|
it("throws on malformed JSON", async () => {
|
|
@@ -4,10 +4,29 @@ import * as fs from "fs/promises";
|
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { components } from "../api";
|
|
6
6
|
import { logger } from "../logger";
|
|
7
|
-
import { FreshnessManifest } from "../storage/DatabaseInterface";
|
|
7
|
+
import { FreshnessManifest, ManifestEntry } from "../storage/DatabaseInterface";
|
|
8
8
|
|
|
9
9
|
type WireBuildManifest = components["schemas"]["BuildManifest"];
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A fetched build manifest, split by tier. A storage-materialized entry (one
|
|
13
|
+
* that carries `storageConnectionName`) is served cross-connection via the
|
|
14
|
+
* virtual-source transform, so it becomes a serve BINDING — it must never enter
|
|
15
|
+
* the same-connection `tableName` substitution. Everything else is an
|
|
16
|
+
* colocated entry the Malloy runtime resolves by substituting its
|
|
17
|
+
* `tableName` at compile time.
|
|
18
|
+
*/
|
|
19
|
+
export interface FetchedManifest {
|
|
20
|
+
/** colocated entries: same-connection `tableName` substitution. */
|
|
21
|
+
tableNameManifest: FreshnessManifest;
|
|
22
|
+
/**
|
|
23
|
+
* `storage=` entries keyed by sourceEntityId, carried as full
|
|
24
|
+
* {@link ManifestEntry}s (with `storageConnectionName` + captured `schema` +
|
|
25
|
+
* `sourceName`) so the bind step can derive cross-connection serve bindings.
|
|
26
|
+
*/
|
|
27
|
+
storageEntries: Record<string, ManifestEntry>;
|
|
28
|
+
}
|
|
29
|
+
|
|
11
30
|
// Lazily-created clients reused across fetches. Both use the ambient credential
|
|
12
31
|
// chain (ADC for GCS; the default provider chain for S3) — the same auth the
|
|
13
32
|
// package downloader already relies on.
|
|
@@ -57,22 +76,26 @@ async function readManifestBytes(uri: string): Promise<string> {
|
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
/**
|
|
60
|
-
* Fetch and parse the
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* `
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
79
|
+
* Fetch and parse the host-computed build manifest at `uri`, split by
|
|
80
|
+
* tier into {@link FetchedManifest}. The wire manifest keys physical tables
|
|
81
|
+
* under `physicalTableName`; for an colocated entry the Malloy
|
|
82
|
+
* runtime consumes `tableName`, so that field is translated here and the entry
|
|
83
|
+
* lands in `tableNameManifest`, carrying the freshness fields verbatim (so the
|
|
84
|
+
* serve path can gate `age vs window` per query) and `connectionName` (so the
|
|
85
|
+
* bind step can quote the path for that connection's dialect — see
|
|
86
|
+
* Package.quoteBoundTableNames).
|
|
87
|
+
*
|
|
88
|
+
* A `storage=`-materialized entry (one carrying `storageConnectionName`) is
|
|
89
|
+
* routed instead to `storageEntries` as its full {@link ManifestEntry}: it lives
|
|
90
|
+
* on a DIFFERENT connection and is served through the virtual-source transform
|
|
91
|
+
* from its captured `schema`, so it must never become a same-connection
|
|
92
|
+
* `tableName` substitution. Entries missing a physical table are skipped. This
|
|
93
|
+
* is a pure fetch + parse: it does **not** filter on freshness (that happens per
|
|
94
|
+
* query on the serve path). Throws if the URI can't be read or parsed.
|
|
72
95
|
*/
|
|
73
96
|
export async function fetchManifestEntries(
|
|
74
97
|
uri: string,
|
|
75
|
-
): Promise<
|
|
98
|
+
): Promise<FetchedManifest> {
|
|
76
99
|
const raw = await readManifestBytes(uri);
|
|
77
100
|
|
|
78
101
|
let parsed: WireBuildManifest;
|
|
@@ -86,17 +109,42 @@ export async function fetchManifestEntries(
|
|
|
86
109
|
);
|
|
87
110
|
}
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
return splitManifestEntries(parsed.entries ?? {}, uri);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Split an already-in-hand manifest entry map by tier into
|
|
117
|
+
* {@link FetchedManifest}, applying the same wire→runtime translation as
|
|
118
|
+
* {@link fetchManifestEntries} (physicalTableName → colocated `tableName`
|
|
119
|
+
* substitution carrying freshness + connectionName; a `storageConnectionName`
|
|
120
|
+
* entry stays a full {@link ManifestEntry} for the virtual-source transform).
|
|
121
|
+
* Pure: no I/O, no freshness filtering. Shared by the URI-fetch path (host
|
|
122
|
+
* manifest) and the local-store rebind (a package's own latest persisted
|
|
123
|
+
* materialization, re-applied on load). `source` is a label for the skip log.
|
|
124
|
+
*/
|
|
125
|
+
export function splitManifestEntries(
|
|
126
|
+
entries: Record<string, ManifestEntry>,
|
|
127
|
+
source: string,
|
|
128
|
+
): FetchedManifest {
|
|
129
|
+
const tableNameManifest: FreshnessManifest = {};
|
|
130
|
+
const storageEntries: Record<string, ManifestEntry> = {};
|
|
131
|
+
for (const [sourceEntityId, entry] of Object.entries(entries)) {
|
|
91
132
|
const physicalTableName = entry?.physicalTableName;
|
|
92
133
|
if (!physicalTableName) {
|
|
93
134
|
logger.warn("Manifest entry has no physicalTableName; skipping", {
|
|
94
|
-
|
|
135
|
+
source,
|
|
95
136
|
sourceEntityId,
|
|
96
137
|
});
|
|
97
138
|
continue;
|
|
98
139
|
}
|
|
99
|
-
|
|
140
|
+
if (entry.storageConnectionName) {
|
|
141
|
+
// Cross-connection storage tier: keep the full entry (schema +
|
|
142
|
+
// sourceName + storageConnectionName) for the serve-binding derivation;
|
|
143
|
+
// never enter the same-connection tableName manifest.
|
|
144
|
+
storageEntries[sourceEntityId] = entry;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
tableNameManifest[sourceEntityId] = {
|
|
100
148
|
tableName: physicalTableName,
|
|
101
149
|
connectionName: entry.connectionName,
|
|
102
150
|
dataAsOf: entry.dataAsOf,
|
|
@@ -104,5 +152,5 @@ export async function fetchManifestEntries(
|
|
|
104
152
|
freshnessFallback: entry.freshnessFallback,
|
|
105
153
|
};
|
|
106
154
|
}
|
|
107
|
-
return
|
|
155
|
+
return { tableNameManifest, storageEntries };
|
|
108
156
|
}
|