Skip to content

Commit cf782a2

Browse files
rwmjhbHeng Xia
andauthored
test: restore master baseline CI coverage (#667)
Co-authored-by: Heng Xia <pope@Hengs-Mac-mini.local>
1 parent faa847c commit cf782a2

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

scripts/verify-ci-test-manifest.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const EXPECTED_BASELINE = [
4848
{ group: "core-regression", runner: "node", file: "test/store-serialization.test.mjs" },
4949
{ group: "core-regression", runner: "node", file: "test/access-tracker-retry.test.mjs" },
5050
{ group: "core-regression", runner: "node", file: "test/embedder-cache.test.mjs" },
51+
// Issue #629 batch embedding fix
52+
{ group: "llm-clients-and-auth", runner: "node", file: "test/embedder-ollama-batch-routing.test.mjs" },
5153
];
5254

5355
function fail(message) {

test/embedder-ollama-batch-routing.test.mjs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ function readJson(req) {
4141

4242
function makeOllamaMock(handler) {
4343
return http.createServer((req, res) => {
44-
if (req.method === "POST" && req.url === "/api/embeddings") {
44+
const requestPath = (req.url || "").replace(/^\/ollama\b/, "");
45+
46+
if (req.method === "POST" && requestPath === "/api/embeddings") {
4547
handler(req, res, "api");
4648
return;
4749
}
48-
if (req.method === "POST" && req.url === "/v1/embeddings") {
50+
if (req.method === "POST" && requestPath === "/v1/embeddings") {
4951
handler(req, res, "v1");
5052
return;
5153
}
@@ -76,6 +78,12 @@ async function startMockServer(server) {
7678
});
7779
}
7880

81+
function makeOllamaBaseURL(port) {
82+
// Use a path marker instead of the default Ollama port so the test still
83+
// exercises isOllamaProvider() without colliding with a real local server.
84+
return `http://127.0.0.1:${port}/ollama/v1`;
85+
}
86+
7987
test("single requests use /api/embeddings with prompt field", async () => {
8088
let capturedBody = null;
8189

@@ -86,7 +94,7 @@ test("single requests use /api/embeddings with prompt field", async () => {
8694
});
8795

8896
const port = await startMockServer(server);
89-
const baseURL = `http://127.0.0.1:${port}/v1`;
97+
const baseURL = makeOllamaBaseURL(port);
9098

9199
try {
92100
const embedder = new Embedder({
@@ -97,6 +105,7 @@ test("single requests use /api/embeddings with prompt field", async () => {
97105
dimensions: DIMS,
98106
});
99107

108+
assert.equal(embedder.isOllamaProvider(), true, "expected /ollama baseURL to use native fetch");
100109
const result = await embedder.embedPassage("hello world");
101110

102111
assert.equal(capturedBody?.model, "mxbai-embed-large");
@@ -122,7 +131,7 @@ test("batch requests use /v1/embeddings with input array", async () => {
122131
});
123132

124133
const port = await startMockServer(server);
125-
const baseURL = `http://127.0.0.1:${port}/v1`;
134+
const baseURL = makeOllamaBaseURL(port);
126135

127136
try {
128137
const embedder = new Embedder({
@@ -164,7 +173,7 @@ test("batch rejects response with wrong number of embeddings", async () => {
164173
});
165174

166175
const port = await startMockServer(server);
167-
const baseURL = `http://127.0.0.1:${port}/v1`;
176+
const baseURL = makeOllamaBaseURL(port);
168177

169178
try {
170179
const embedder = new Embedder({
@@ -209,7 +218,7 @@ test("batch rejects response with empty embedding array", async () => {
209218
});
210219

211220
const port = await startMockServer(server);
212-
const baseURL = `http://127.0.0.1:${port}/v1`;
221+
const baseURL = makeOllamaBaseURL(port);
213222

214223
try {
215224
const embedder = new Embedder({
@@ -246,7 +255,7 @@ test("single-element batch still routes to /v1/embeddings", async () => {
246255
});
247256

248257
const port = await startMockServer(server);
249-
const baseURL = `http://127.0.0.1:${port}/v1`;
258+
const baseURL = makeOllamaBaseURL(port);
250259

251260
try {
252261
const embedder = new Embedder({
@@ -266,4 +275,4 @@ test("single-element batch still routes to /v1/embeddings", async () => {
266275
} finally {
267276
await new Promise((resolve) => server.close(resolve));
268277
}
269-
});
278+
});

test/recall-text-cleanup.test.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const origCreateEmbedder = embedderModuleForMock.createEmbedder;
2525

2626
const pluginModule = jiti("../index.ts");
2727
const memoryLanceDBProPlugin = pluginModule.default || pluginModule;
28+
const resetRegistration = pluginModule.resetRegistration ?? (() => {});
2829
const { registerMemoryRecallTool, registerMemoryStoreTool } = jiti("../src/tools.ts");
2930
const { MemoryRetriever } = jiti("../src/retriever.js");
3031
const { buildSmartMetadata, stringifySmartMetadata } = jiti("../src/smart-metadata.ts");
@@ -329,13 +330,15 @@ describe("recall text cleanup", () => {
329330
beforeEach(() => {
330331
workspaceDir = mkdtempSync(path.join(tmpdir(), "recall-text-cleanup-test-"));
331332
originalRetrieve = MemoryRetriever.prototype.retrieve;
333+
resetRegistration();
332334
});
333335

334336
afterEach(() => {
335337
MemoryRetriever.prototype.retrieve = originalRetrieve;
336338
// Restore factory functions on the .js module (same cache as index.ts uses)
337339
retrieverModuleForMock.createRetriever = origCreateRetriever;
338340
embedderModuleForMock.createEmbedder = origCreateEmbedder;
341+
resetRegistration();
339342
rmSync(workspaceDir, { recursive: true, force: true });
340343
});
341344

@@ -1096,4 +1099,3 @@ describe("recall text cleanup", () => {
10961099
}
10971100
});
10981101
});
1099-

test/smart-extractor-branches.mjs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Module._initPaths();
1616

1717
const jiti = jitiFactory(import.meta.url, { interopDefault: true });
1818
const plugin = jiti("../index.ts");
19+
const resetRegistration = plugin.resetRegistration ?? (() => {});
1920
const { MemoryStore } = jiti("../src/store.ts");
2021
const { createEmbedder } = jiti("../src/embedder.ts");
2122
const { buildSmartMetadata, stringifySmartMetadata } = jiti("../src/smart-metadata.ts");
@@ -151,6 +152,11 @@ async function runAgentEndHook(api, event, ctx) {
151152
}
152153
}
153154

155+
function registerFreshPlugin(api) {
156+
resetRegistration();
157+
plugin.register(api);
158+
}
159+
154160
async function seedPreference(dbPath) {
155161
const store = new MemoryStore({ dbPath, vectorDim: EMBEDDING_DIMENSIONS });
156162
const embedder = createEmbedder({
@@ -268,7 +274,7 @@ async function runScenario(mode) {
268274
`http://127.0.0.1:${port}`,
269275
logs,
270276
);
271-
plugin.register(api);
277+
registerFreshPlugin(api);
272278
await seedPreference(dbPath);
273279

274280
await runAgentEndHook(
@@ -450,7 +456,7 @@ async function runMultiRoundScenario() {
450456
`http://127.0.0.1:${port}`,
451457
logs,
452458
);
453-
plugin.register(api);
459+
registerFreshPlugin(api);
454460

455461
const rounds = [
456462
["最近我在调整饮品偏好。", "我喜欢乌龙茶。", "这条偏好以后都有效。", "请记住。"],
@@ -549,7 +555,7 @@ async function runInjectedRecallScenario() {
549555
`http://127.0.0.1:${port}`,
550556
logs,
551557
);
552-
plugin.register(api);
558+
registerFreshPlugin(api);
553559

554560
await runAgentEndHook(
555561
api,
@@ -643,7 +649,7 @@ async function runPrependedRecallWithUserTextScenario() {
643649
`http://127.0.0.1:${port}`,
644650
logs,
645651
);
646-
plugin.register(api);
652+
registerFreshPlugin(api);
647653

648654
await runAgentEndHook(
649655
api,
@@ -735,7 +741,7 @@ async function runInboundMetadataWrappedScenario() {
735741
`http://127.0.0.1:${port}`,
736742
logs,
737743
);
738-
plugin.register(api);
744+
registerFreshPlugin(api);
739745

740746
await runAgentEndHook(
741747
api,
@@ -791,7 +797,7 @@ async function runSessionDeltaScenario() {
791797
"http://127.0.0.1:9",
792798
logs,
793799
);
794-
plugin.register(api);
800+
registerFreshPlugin(api);
795801

796802
await runAgentEndHook(
797803
api,
@@ -855,7 +861,7 @@ async function runPendingIngressScenario() {
855861
"http://127.0.0.1:9",
856862
logs,
857863
);
858-
plugin.register(api);
864+
registerFreshPlugin(api);
859865

860866
await api.hooks.message_received(
861867
{ from: "discord:channel:1", content: "@jige_claw_bot 我的饮品偏好是乌龙茶" },
@@ -911,7 +917,7 @@ async function runRememberCommandContextScenario() {
911917
"http://127.0.0.1:9",
912918
logs,
913919
);
914-
plugin.register(api);
920+
registerFreshPlugin(api);
915921

916922
await api.hooks.message_received(
917923
{ from: "discord:channel:1", content: "@jige_claw_bot 我的饮品偏好是乌龙茶" },
@@ -1036,7 +1042,7 @@ async function runUserMdExclusiveProfileScenario() {
10361042
enabled: true,
10371043
},
10381044
};
1039-
plugin.register(api);
1045+
registerFreshPlugin(api);
10401046

10411047
await runAgentEndHook(
10421048
api,
@@ -1134,7 +1140,7 @@ async function runBoundarySkipKeepsRegexFallbackScenario() {
11341140
enabled: true,
11351141
},
11361142
};
1137-
plugin.register(api);
1143+
registerFreshPlugin(api);
11381144

11391145
await runAgentEndHook(
11401146
api,
@@ -1236,7 +1242,7 @@ async function runInboundMetadataCleanupScenario() {
12361242
`http://127.0.0.1:${port}`,
12371243
logs,
12381244
);
1239-
plugin.register(api);
1245+
registerFreshPlugin(api);
12401246

12411247
await runAgentEndHook(
12421248
api,

0 commit comments

Comments
 (0)