@malloy-publisher/server 0.0.231 → 0.0.233
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 +135 -13
- package/dist/app/assets/{EnvironmentPage-wa_EPkwK.js → EnvironmentPage-DutP7T8h.js} +1 -1
- package/dist/app/assets/{HomePage-jnCrupQp.js → HomePage-BcxDrBfl.js} +1 -1
- package/dist/app/assets/{LightMode-DYbwNULZ.js → LightMode-BJukGxgz.js} +1 -1
- package/dist/app/assets/{MainPage-CuJLrPNI.js → MainPage-DXbwlMeF.js} +2 -2
- package/dist/app/assets/{MaterializationsPage-D_67x2ee.js → MaterializationsPage-BBQksmTU.js} +1 -1
- package/dist/app/assets/{ModelPage-D5JtAWqR.js → ModelPage-C6tK51uU.js} +1 -1
- package/dist/app/assets/{PackagePage-BRwtqUSG.js → PackagePage-Bo3cwwZE.js} +1 -1
- package/dist/app/assets/{RouteError-CBNNrnSD.js → RouteError-BufkcAKE.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-CTCeBneA.js → ThemeEditorPage-DICvvKpa.js} +1 -1
- package/dist/app/assets/{WorkbookPage-SN6f1RBm.js → WorkbookPage-Dkwt75Nj.js} +1 -1
- package/dist/app/assets/{core-Dp3q5Ieu.es-CD5FvM2s.js → core-C0nunIQT.es-DlMLKZBK.js} +1 -1
- package/dist/app/assets/{index-DU4r7GdU.js → index-BabP-V-S.js} +346 -321
- package/dist/app/assets/{index-BLCx1EdC.js → index-BusxL5Pt.js} +1 -1
- package/dist/app/assets/{index-C_tJstcx.js → index-CmEVVe-8.js} +15 -15
- package/dist/app/assets/{index-CfmBVB6M.js → index-Cs4WVm2z.js} +1 -1
- package/dist/app/assets/{index-B3Nn8Vm2.js → index-qnhU9CGo.js} +266 -265
- 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 +22627 -1260
- 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/controller/query.controller.ts +26 -21
- package/src/errors.ts +19 -0
- package/src/json_utils.spec.ts +51 -0
- package/src/json_utils.ts +33 -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/query_envelope.spec.ts +229 -0
- package/src/mcp/query_envelope.ts +230 -0
- package/src/mcp/server.protocol.spec.ts +128 -16
- package/src/mcp/skills/build_skills_bundle.ts +94 -4
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/mcp/skills/skills_bundle.spec.ts +113 -4
- package/src/mcp/tool_response.spec.ts +108 -0
- package/src/mcp/tool_response.ts +138 -0
- package/src/mcp/tools/compile_tool.spec.ts +112 -4
- package/src/mcp/tools/compile_tool.ts +61 -30
- package/src/mcp/tools/docs_search_tool.ts +6 -16
- package/src/mcp/tools/embedding_index.spec.ts +1236 -0
- package/src/mcp/tools/embedding_index.ts +808 -0
- package/src/mcp/tools/execute_query_tool.spec.ts +23 -3
- package/src/mcp/tools/execute_query_tool.ts +90 -151
- package/src/mcp/tools/get_context_eval.ts +194 -45
- package/src/mcp/tools/get_context_tool.spec.ts +358 -5
- package/src/mcp/tools/get_context_tool.ts +202 -56
- package/src/mcp/tools/reload_package_tool.ts +3 -29
- 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/compile_fragment_techniques.spec.ts +156 -0
- package/src/service/connection.spec.ts +371 -1
- package/src/service/connection.ts +339 -20
- package/src/service/connection_config.spec.ts +108 -0
- package/src/service/connection_config.ts +47 -8
- package/src/service/connection_federation.spec.ts +184 -0
- package/src/service/duckdb_instance_isolation.spec.ts +137 -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 +569 -59
- package/src/service/model_limits.spec.ts +28 -0
- package/src/service/model_limits.ts +21 -0
- 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_execute_query_tool.integration.spec.ts +37 -12
- package/tests/integration/mcp/mcp_get_context_semantic.integration.spec.ts +235 -0
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
afterAll,
|
|
3
|
+
afterEach,
|
|
4
|
+
beforeAll,
|
|
5
|
+
beforeEach,
|
|
6
|
+
describe,
|
|
7
|
+
expect,
|
|
8
|
+
it,
|
|
9
|
+
} from "bun:test";
|
|
10
|
+
import * as fs from "fs";
|
|
11
|
+
import * as os from "os";
|
|
12
|
+
import * as path from "path";
|
|
13
|
+
import {
|
|
14
|
+
docOnlyText,
|
|
15
|
+
docText,
|
|
16
|
+
sanitize,
|
|
17
|
+
registerGetContextTool,
|
|
18
|
+
} from "./get_context_tool";
|
|
19
|
+
import { embeddingText } from "./embedding_index";
|
|
3
20
|
import type { EnvironmentStore } from "../../service/environment_store";
|
|
21
|
+
import { PackageNotFoundError } from "../../errors";
|
|
22
|
+
import { DuckDBConnection } from "../../storage/duckdb/DuckDBConnection";
|
|
23
|
+
import { createEntityEmbeddingsTable } from "../../storage/duckdb/schema";
|
|
24
|
+
import {
|
|
25
|
+
EmbeddingProvider,
|
|
26
|
+
_clearEmbeddingProviderForTests,
|
|
27
|
+
_setEmbeddingProviderForTests,
|
|
28
|
+
} from "../../service/embedding_provider";
|
|
29
|
+
import { _resetEmbeddingIndexStateForTests } from "./embedding_index";
|
|
30
|
+
|
|
31
|
+
// Pin the baseline: every test in this file runs unconfigured (lexical)
|
|
32
|
+
// unless it sets a provider itself, regardless of ambient EMBEDDING_* env
|
|
33
|
+
// vars in the developer's shell.
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
_setEmbeddingProviderForTests(null);
|
|
36
|
+
_resetEmbeddingIndexStateForTests();
|
|
37
|
+
});
|
|
38
|
+
afterAll(() => {
|
|
39
|
+
_clearEmbeddingProviderForTests();
|
|
40
|
+
});
|
|
4
41
|
|
|
5
42
|
describe("get_context docText", () => {
|
|
6
43
|
it("extracts #(doc) text from annotation lines", () => {
|
|
@@ -31,6 +68,56 @@ describe("get_context docText", () => {
|
|
|
31
68
|
});
|
|
32
69
|
});
|
|
33
70
|
|
|
71
|
+
describe("get_context docOnlyText (embedding-input safety)", () => {
|
|
72
|
+
it("extracts #(doc) text like docText", () => {
|
|
73
|
+
expect(docOnlyText(["#(doc) Total revenue."])).toBe("Total revenue.");
|
|
74
|
+
expect(docOnlyText([{ value: "#(doc) Customer state." }])).toBe(
|
|
75
|
+
"Customer state.",
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("does NOT fall back to raw lines: no #(doc) yields empty", () => {
|
|
80
|
+
// The security-critical difference from docText: predicate-bearing
|
|
81
|
+
// annotations must never become embedding input.
|
|
82
|
+
expect(docOnlyText(["# bar_chart"])).toBe("");
|
|
83
|
+
expect(
|
|
84
|
+
docOnlyText([
|
|
85
|
+
"#(authorize) \"$ROLE = 'admin'\"",
|
|
86
|
+
"#(malloy) drillable",
|
|
87
|
+
]),
|
|
88
|
+
).toBe("");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("keeps only the #(doc) line when mixed with predicate annotations", () => {
|
|
92
|
+
expect(
|
|
93
|
+
docOnlyText([
|
|
94
|
+
"#(authorize) \"$TENANT = 'acme'\"",
|
|
95
|
+
"#(doc) Secured orders.",
|
|
96
|
+
]),
|
|
97
|
+
).toBe("Secured orders.");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("an #(authorize)-only entity produces no embedding text beyond its name", () => {
|
|
101
|
+
// End-to-end: what embeddingText actually sends for a governed,
|
|
102
|
+
// undocumented entity is the humanized name only, never the predicate.
|
|
103
|
+
const embedDoc = docOnlyText([
|
|
104
|
+
"#(authorize) \"$ROLE = 'admin'\"",
|
|
105
|
+
"#(authorize) \"$TENANT = 'acme' or $TENANT = 'globex'\"",
|
|
106
|
+
]);
|
|
107
|
+
const text = embeddingText({
|
|
108
|
+
kind: "source",
|
|
109
|
+
name: "orders_secured",
|
|
110
|
+
source: "orders_secured",
|
|
111
|
+
modelPath: "m.malloy",
|
|
112
|
+
embedDoc,
|
|
113
|
+
});
|
|
114
|
+
expect(text).toBe("orders secured");
|
|
115
|
+
expect(text).not.toContain("authorize");
|
|
116
|
+
expect(text).not.toContain("ROLE");
|
|
117
|
+
expect(text).not.toContain("acme");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
34
121
|
describe("get_context sanitize", () => {
|
|
35
122
|
it("strips lunr operator characters so a plain-English query never throws", () => {
|
|
36
123
|
const cleaned = sanitize('revenue: +top ~10 "exact" -minus ^boost *wild');
|
|
@@ -46,9 +133,15 @@ describe("get_context sanitize", () => {
|
|
|
46
133
|
|
|
47
134
|
// Capture the tool handler that registerGetContextTool passes to McpServer.tool,
|
|
48
135
|
// so each discovery tier can be exercised against a mocked EnvironmentStore.
|
|
136
|
+
type Content = Array<{
|
|
137
|
+
type?: string;
|
|
138
|
+
text?: string;
|
|
139
|
+
resource?: { text: string };
|
|
140
|
+
}>;
|
|
141
|
+
|
|
49
142
|
type Handler = (params: Record<string, unknown>) => Promise<{
|
|
50
143
|
isError?: boolean;
|
|
51
|
-
content:
|
|
144
|
+
content: Content;
|
|
52
145
|
}>;
|
|
53
146
|
|
|
54
147
|
function captureHandler(store: Partial<EnvironmentStore>): Handler {
|
|
@@ -63,8 +156,12 @@ function captureHandler(store: Partial<EnvironmentStore>): Handler {
|
|
|
63
156
|
return handler;
|
|
64
157
|
}
|
|
65
158
|
|
|
66
|
-
function parse(result: { content:
|
|
67
|
-
return JSON.parse(result.content[0].resource
|
|
159
|
+
function parse(result: { content: Content }) {
|
|
160
|
+
return JSON.parse(result.content[0].resource!.text);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function textBlock(result: { content: Content }) {
|
|
164
|
+
return result.content.find((b) => b.type === "text")?.text;
|
|
68
165
|
}
|
|
69
166
|
|
|
70
167
|
// A model with one source (order_items) carrying one dimension (state).
|
|
@@ -156,6 +253,53 @@ describe("get_context discovery tiers", () => {
|
|
|
156
253
|
const parsed = parse(result);
|
|
157
254
|
expect(parsed.results).toEqual([]);
|
|
158
255
|
expect(parsed.error).toContain("could not be resolved");
|
|
256
|
+
// Suggestions and a text block, same as this tool's three siblings. Both
|
|
257
|
+
// were absent before: the payload carried a bare message, and a
|
|
258
|
+
// text-only client saw nothing at all.
|
|
259
|
+
expect(parsed.suggestions.length).toBeGreaterThan(0);
|
|
260
|
+
expect(textBlock(result)).toContain("could not be resolved");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("reports an unknown package as not-found, not as an internal fault", async () => {
|
|
264
|
+
// Pins the classification, not just that an error came back. Before this
|
|
265
|
+
// routed through classifyToolError every failure arrived as the raw
|
|
266
|
+
// message with no remediation, so a typo'd package name gave the agent
|
|
267
|
+
// nothing to act on.
|
|
268
|
+
const handler = captureHandler({
|
|
269
|
+
getEnvironment: async () =>
|
|
270
|
+
({
|
|
271
|
+
getPackage: async () => {
|
|
272
|
+
throw new PackageNotFoundError("Package 'nope' not found");
|
|
273
|
+
},
|
|
274
|
+
}) as never,
|
|
275
|
+
});
|
|
276
|
+
const result = await handler({
|
|
277
|
+
environmentName: "malloy-samples",
|
|
278
|
+
packageName: "nope",
|
|
279
|
+
query: "state",
|
|
280
|
+
});
|
|
281
|
+
expect(result.isError).toBe(true);
|
|
282
|
+
const parsed = parse(result);
|
|
283
|
+
expect(parsed.results).toEqual([]);
|
|
284
|
+
expect(parsed.error).toContain("Resource not found");
|
|
285
|
+
expect(parsed.error).toContain("nope");
|
|
286
|
+
expect(textBlock(result)).toContain("Resource not found");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("reports a non-Error throwable without inventing 'Unknown error'", async () => {
|
|
290
|
+
// The old per-site `error instanceof Error ? error.message : "Unknown
|
|
291
|
+
// error"` turned a thrown string into exactly the unhelpful text this
|
|
292
|
+
// tool's callers reported. classifyToolError stringifies it instead.
|
|
293
|
+
const handler = captureHandler({
|
|
294
|
+
listEnvironments: async () => {
|
|
295
|
+
throw "the store exploded";
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
const result = await handler({});
|
|
299
|
+
const parsed = parse(result);
|
|
300
|
+
expect(parsed.error).toContain("the store exploded");
|
|
301
|
+
expect(parsed.error).not.toContain("Unknown error");
|
|
302
|
+
expect(textBlock(result)).toContain("the store exploded");
|
|
159
303
|
});
|
|
160
304
|
|
|
161
305
|
it("tier 3: package without a query lists only its sources", async () => {
|
|
@@ -213,6 +357,8 @@ describe("get_context discovery tiers", () => {
|
|
|
213
357
|
const parsed = parse(result);
|
|
214
358
|
expect(parsed.results).toEqual([]);
|
|
215
359
|
expect(parsed.error).toContain("not initialized");
|
|
360
|
+
expect(parsed.suggestions.length).toBeGreaterThan(0);
|
|
361
|
+
expect(textBlock(result)).toContain("not initialized");
|
|
216
362
|
});
|
|
217
363
|
|
|
218
364
|
it("tier 3: lists every source, not just the first 10", async () => {
|
|
@@ -236,4 +382,211 @@ describe("get_context discovery tiers", () => {
|
|
|
236
382
|
);
|
|
237
383
|
expect(results).toHaveLength(5);
|
|
238
384
|
});
|
|
385
|
+
|
|
386
|
+
it("tier 4: without a provider the payload has no retrieval marker or scores", async () => {
|
|
387
|
+
const handler = captureHandler({
|
|
388
|
+
getEnvironment: async () =>
|
|
389
|
+
({ getPackage: async () => mockPackage }) as never,
|
|
390
|
+
});
|
|
391
|
+
const payload = parse(
|
|
392
|
+
await handler({
|
|
393
|
+
environmentName: "malloy-samples",
|
|
394
|
+
packageName: "ecommerce",
|
|
395
|
+
query: "state",
|
|
396
|
+
}),
|
|
397
|
+
);
|
|
398
|
+
expect(payload.retrieval).toBeUndefined();
|
|
399
|
+
expect(Object.keys(payload)).toEqual(["results"]);
|
|
400
|
+
for (const r of payload.results) {
|
|
401
|
+
expect(r.score).toBeUndefined();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe("get_context semantic retrieval", () => {
|
|
407
|
+
let tempDir: string;
|
|
408
|
+
let db: DuckDBConnection;
|
|
409
|
+
|
|
410
|
+
beforeAll(async () => {
|
|
411
|
+
tempDir = fs.mkdtempSync(
|
|
412
|
+
path.join(os.tmpdir(), "get-context-semantic-spec-"),
|
|
413
|
+
);
|
|
414
|
+
db = new DuckDBConnection(path.join(tempDir, "test.db"));
|
|
415
|
+
await db.initialize();
|
|
416
|
+
await createEntityEmbeddingsTable(db);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
afterAll(async () => {
|
|
420
|
+
// Close before removing: Windows refuses to delete a directory
|
|
421
|
+
// holding DuckDB's open file handle.
|
|
422
|
+
await db.close();
|
|
423
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
afterEach(() => {
|
|
427
|
+
_setEmbeddingProviderForTests(null);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Entity texts are humanize(name) [+ doc]: "order items" and "state".
|
|
431
|
+
const VECTORS: Record<string, number[]> = {
|
|
432
|
+
"order items": [0, 1],
|
|
433
|
+
state: [1, 0],
|
|
434
|
+
"where do customers live": [1, 0],
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
function stubProvider(options: { fail?: boolean } = {}): EmbeddingProvider {
|
|
438
|
+
const fetchStub = (async (
|
|
439
|
+
_url: RequestInfo | URL,
|
|
440
|
+
init?: RequestInit,
|
|
441
|
+
) => {
|
|
442
|
+
if (options.fail) return new Response("down", { status: 500 });
|
|
443
|
+
const body = JSON.parse(String(init?.body)) as { input: string[] };
|
|
444
|
+
const data = body.input.map((text, index) => {
|
|
445
|
+
const embedding = VECTORS[text];
|
|
446
|
+
if (!embedding) throw new Error(`no stub vector for "${text}"`);
|
|
447
|
+
return { index, embedding };
|
|
448
|
+
});
|
|
449
|
+
return new Response(JSON.stringify({ data }), { status: 200 });
|
|
450
|
+
}) as typeof fetch;
|
|
451
|
+
return new EmbeddingProvider(
|
|
452
|
+
{
|
|
453
|
+
apiKey: "test",
|
|
454
|
+
model: "stub-model",
|
|
455
|
+
baseUrl: "https://stub.example.com/v1",
|
|
456
|
+
},
|
|
457
|
+
fetchStub,
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** A store whose package is a fresh instance, backed by the temp DB. */
|
|
462
|
+
function semanticStore(): Partial<EnvironmentStore> {
|
|
463
|
+
const pkg = {
|
|
464
|
+
listModels: async () => [{ path: "ecommerce.malloy" }],
|
|
465
|
+
getModel: () => mockModel,
|
|
466
|
+
};
|
|
467
|
+
return {
|
|
468
|
+
getEnvironment: async () => ({ getPackage: async () => pkg }) as never,
|
|
469
|
+
storageManager: {
|
|
470
|
+
getDuckDbConnection: () => db,
|
|
471
|
+
} as never,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async function callUntilSemantic(
|
|
476
|
+
handler: Handler,
|
|
477
|
+
params: Record<string, unknown>,
|
|
478
|
+
) {
|
|
479
|
+
for (let i = 0; i < 200; i++) {
|
|
480
|
+
const payload = parse(await handler(params));
|
|
481
|
+
if (payload.retrieval === "semantic") return payload;
|
|
482
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
483
|
+
}
|
|
484
|
+
throw new Error("retrieval never became semantic");
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
it("ranks semantically once the index syncs, with scores and a marker", async () => {
|
|
488
|
+
_setEmbeddingProviderForTests(stubProvider());
|
|
489
|
+
const handler = captureHandler(semanticStore());
|
|
490
|
+
const params = {
|
|
491
|
+
environmentName: "specs",
|
|
492
|
+
packageName: "semantic-pkg",
|
|
493
|
+
query: "where do customers live",
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// Cold start: the sync kicks off in the background and this call
|
|
497
|
+
// answers lexically, marked as such.
|
|
498
|
+
const first = parse(await handler(params));
|
|
499
|
+
expect(first.retrieval).toBe("lexical");
|
|
500
|
+
|
|
501
|
+
const payload = await callUntilSemantic(handler, params);
|
|
502
|
+
expect(payload.results[0].name).toBe("state");
|
|
503
|
+
expect(payload.results[0].kind).toBe("dimension");
|
|
504
|
+
expect(payload.results[0].score).toBeCloseTo(1.0, 3);
|
|
505
|
+
// "order items" is orthogonal to the query: below the similarity
|
|
506
|
+
// floor, so it must not pad the results.
|
|
507
|
+
expect(
|
|
508
|
+
payload.results.some(
|
|
509
|
+
(r: { name: string }) => r.name === "order_items",
|
|
510
|
+
),
|
|
511
|
+
).toBe(false);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it("falls back to lexical, marked, when the provider goes down after indexing", async () => {
|
|
515
|
+
// Index healthily first, so this pins the query-embed failure
|
|
516
|
+
// path, not just the cold start (which answers lexically anyway).
|
|
517
|
+
_setEmbeddingProviderForTests(stubProvider());
|
|
518
|
+
const handler = captureHandler(semanticStore());
|
|
519
|
+
const params = {
|
|
520
|
+
environmentName: "specs",
|
|
521
|
+
packageName: "failing-pkg",
|
|
522
|
+
query: "where do customers live",
|
|
523
|
+
};
|
|
524
|
+
await callUntilSemantic(handler, params);
|
|
525
|
+
|
|
526
|
+
// Same model and config, but the endpoint now returns 500s: the
|
|
527
|
+
// per-call query embed fails and the call degrades to marked
|
|
528
|
+
// lexical with no scores.
|
|
529
|
+
_setEmbeddingProviderForTests(stubProvider({ fail: true }));
|
|
530
|
+
const payload = parse(await handler({ ...params, query: "state" }));
|
|
531
|
+
expect(payload.retrieval).toBe("lexical");
|
|
532
|
+
expect(
|
|
533
|
+
payload.results.some((r: { name: string }) => r.name === "state"),
|
|
534
|
+
).toBe(true);
|
|
535
|
+
for (const r of payload.results) {
|
|
536
|
+
expect(r.score).toBeUndefined();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("degrades to lexical when the storage handle is unavailable", async () => {
|
|
541
|
+
_setEmbeddingProviderForTests(stubProvider());
|
|
542
|
+
const store = semanticStore();
|
|
543
|
+
delete (store as { storageManager?: unknown }).storageManager;
|
|
544
|
+
const handler = captureHandler(store);
|
|
545
|
+
const payload = parse(
|
|
546
|
+
await handler({
|
|
547
|
+
environmentName: "specs",
|
|
548
|
+
packageName: "no-storage-pkg",
|
|
549
|
+
query: "state",
|
|
550
|
+
}),
|
|
551
|
+
);
|
|
552
|
+
expect(payload.retrieval).toBe("lexical");
|
|
553
|
+
expect(
|
|
554
|
+
payload.results.some((r: { name: string }) => r.name === "state"),
|
|
555
|
+
).toBe(true);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("degrades to lexical (never throws) when the real config is malformed", async () => {
|
|
559
|
+
// Exercises the tool-path catch with REAL env parsing, not the
|
|
560
|
+
// _setEmbeddingProviderForTests override: a malformed base makes
|
|
561
|
+
// getEmbeddingProvider() throw, and tier 4 must swallow it and
|
|
562
|
+
// answer marked lexical (embeddingConfigured() is still true).
|
|
563
|
+
const saved = {
|
|
564
|
+
key: process.env.EMBEDDING_API_KEY,
|
|
565
|
+
base: process.env.EMBEDDING_API_BASE,
|
|
566
|
+
};
|
|
567
|
+
process.env.EMBEDDING_API_KEY = "k";
|
|
568
|
+
process.env.EMBEDDING_API_BASE = "not a url";
|
|
569
|
+
_clearEmbeddingProviderForTests();
|
|
570
|
+
try {
|
|
571
|
+
const handler = captureHandler(semanticStore());
|
|
572
|
+
const payload = parse(
|
|
573
|
+
await handler({
|
|
574
|
+
environmentName: "specs",
|
|
575
|
+
packageName: "malformed-cfg-pkg",
|
|
576
|
+
query: "state",
|
|
577
|
+
}),
|
|
578
|
+
);
|
|
579
|
+
expect(payload.retrieval).toBe("lexical");
|
|
580
|
+
expect(
|
|
581
|
+
payload.results.some((r: { name: string }) => r.name === "state"),
|
|
582
|
+
).toBe(true);
|
|
583
|
+
} finally {
|
|
584
|
+
if (saved.key === undefined) delete process.env.EMBEDDING_API_KEY;
|
|
585
|
+
else process.env.EMBEDDING_API_KEY = saved.key;
|
|
586
|
+
if (saved.base === undefined) delete process.env.EMBEDDING_API_BASE;
|
|
587
|
+
else process.env.EMBEDDING_API_BASE = saved.base;
|
|
588
|
+
_clearEmbeddingProviderForTests();
|
|
589
|
+
_setEmbeddingProviderForTests(null);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
239
592
|
});
|