mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:51:24 +00: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 path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
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 { createOpenAIEmbeddingProviderMock } from "./test-embeddings-mock.js";
|
||||||
|
import { createMemoryManagerOrThrow } from "./test-manager.js";
|
||||||
|
|
||||||
const embedBatch = vi.fn(async () => []);
|
const embedBatch = vi.fn(async () => []);
|
||||||
const embedQuery = vi.fn(async () => [0.2, 0.2, 0.2]);
|
const embedQuery = vi.fn(async () => [0.2, 0.2, 0.2]);
|
||||||
@@ -56,12 +57,7 @@ describe("memory search async sync", () => {
|
|||||||
},
|
},
|
||||||
} as OpenClawConfig;
|
} as OpenClawConfig;
|
||||||
|
|
||||||
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
manager = await createMemoryManagerOrThrow(cfg);
|
||||||
expect(result.manager).not.toBeNull();
|
|
||||||
if (!result.manager) {
|
|
||||||
throw new Error("manager missing");
|
|
||||||
}
|
|
||||||
manager = result.manager as unknown as MemoryIndexManager;
|
|
||||||
|
|
||||||
const pending = new Promise<void>(() => {});
|
const pending = new Promise<void>(() => {});
|
||||||
const syncMock = vi.fn(async () => pending);
|
const syncMock = vi.fn(async () => pending);
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
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 { buildFileEntry } from "./internal.js";
|
||||||
|
import { createMemoryManagerOrThrow } from "./test-manager.js";
|
||||||
|
|
||||||
vi.mock("./embeddings.js", () => {
|
vi.mock("./embeddings.js", () => {
|
||||||
return {
|
return {
|
||||||
@@ -57,12 +58,7 @@ describe("memory vector dedupe", () => {
|
|||||||
},
|
},
|
||||||
} as OpenClawConfig;
|
} as OpenClawConfig;
|
||||||
|
|
||||||
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
manager = await createMemoryManagerOrThrow(cfg);
|
||||||
expect(result.manager).not.toBeNull();
|
|
||||||
if (!result.manager) {
|
|
||||||
throw new Error("manager missing");
|
|
||||||
}
|
|
||||||
manager = result.manager as unknown as MemoryIndexManager;
|
|
||||||
|
|
||||||
const db = (
|
const db = (
|
||||||
manager as unknown as {
|
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