mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: share memory manager bootstrap helper
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
13
src/memory/test-manager.ts
Normal file
13
src/memory/test-manager.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user