test: share memory manager bootstrap helper

This commit is contained in:
Peter Steinberger
2026-02-19 14:25:08 +00:00
parent 2581b67cdb
commit eb9861b20a
3 changed files with 19 additions and 14 deletions

View File

@@ -3,8 +3,9 @@ import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
import type { MemoryIndexManager } from "./index.js";
import { createOpenAIEmbeddingProviderMock } from "./test-embeddings-mock.js";
import { createMemoryManagerOrThrow } from "./test-manager.js";
const embedBatch = vi.fn(async () => []);
const embedQuery = vi.fn(async () => [0.2, 0.2, 0.2]);
@@ -56,12 +57,7 @@ describe("memory search async sync", () => {
},
} as OpenClawConfig;
const result = await getMemorySearchManager({ cfg, agentId: "main" });
expect(result.manager).not.toBeNull();
if (!result.manager) {
throw new Error("manager missing");
}
manager = result.manager as unknown as MemoryIndexManager;
manager = await createMemoryManagerOrThrow(cfg);
const pending = new Promise<void>(() => {});
const syncMock = vi.fn(async () => pending);

View File

@@ -3,8 +3,9 @@ import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
import type { MemoryIndexManager } from "./index.js";
import { buildFileEntry } from "./internal.js";
import { createMemoryManagerOrThrow } from "./test-manager.js";
vi.mock("./embeddings.js", () => {
return {
@@ -57,12 +58,7 @@ describe("memory vector dedupe", () => {
},
} as OpenClawConfig;
const result = await getMemorySearchManager({ cfg, agentId: "main" });
expect(result.manager).not.toBeNull();
if (!result.manager) {
throw new Error("manager missing");
}
manager = result.manager as unknown as MemoryIndexManager;
manager = await createMemoryManagerOrThrow(cfg);
const db = (
manager as unknown as {

View File

@@ -0,0 +1,13 @@
import type { OpenClawConfig } from "../config/config.js";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
export async function createMemoryManagerOrThrow(
cfg: OpenClawConfig,
agentId = "main",
): Promise<MemoryIndexManager> {
const result = await getMemorySearchManager({ cfg, agentId });
if (!result.manager) {
throw new Error("manager missing");
}
return result.manager as unknown as MemoryIndexManager;
}