mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 19:40:40 +00:00
test: share memory lancedb temp config harness
This commit is contained in:
@@ -18,12 +18,12 @@ const HAS_OPENAI_KEY = Boolean(process.env.OPENAI_API_KEY);
|
||||
const liveEnabled = HAS_OPENAI_KEY && process.env.OPENCLAW_LIVE_TEST === "1";
|
||||
const describeLive = liveEnabled ? describe : describe.skip;
|
||||
|
||||
describe("memory plugin e2e", () => {
|
||||
let tmpDir: string;
|
||||
let dbPath: string;
|
||||
function installTmpDirHarness(params: { prefix: string }) {
|
||||
let tmpDir = "";
|
||||
let dbPath = "";
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-memory-test-"));
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), params.prefix));
|
||||
dbPath = path.join(tmpDir, "lancedb");
|
||||
});
|
||||
|
||||
@@ -33,6 +33,27 @@ describe("memory plugin e2e", () => {
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getTmpDir: () => tmpDir,
|
||||
getDbPath: () => dbPath,
|
||||
};
|
||||
}
|
||||
|
||||
describe("memory plugin e2e", () => {
|
||||
const { getDbPath } = installTmpDirHarness({ prefix: "openclaw-memory-test-" });
|
||||
|
||||
async function parseConfig(overrides: Record<string, unknown> = {}) {
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
return memoryPlugin.configSchema?.parse?.({
|
||||
embedding: {
|
||||
apiKey: OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
},
|
||||
dbPath: getDbPath(),
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
test("memory plugin registers and initializes correctly", async () => {
|
||||
// Dynamic import to avoid loading LanceDB when not testing
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
@@ -46,21 +67,14 @@ describe("memory plugin e2e", () => {
|
||||
});
|
||||
|
||||
test("config schema parses valid config", async () => {
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
|
||||
const config = memoryPlugin.configSchema?.parse?.({
|
||||
embedding: {
|
||||
apiKey: OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
},
|
||||
dbPath,
|
||||
const config = await parseConfig({
|
||||
autoCapture: true,
|
||||
autoRecall: true,
|
||||
});
|
||||
|
||||
expect(config).toBeDefined();
|
||||
expect(config?.embedding?.apiKey).toBe(OPENAI_API_KEY);
|
||||
expect(config?.dbPath).toBe(dbPath);
|
||||
expect(config?.dbPath).toBe(getDbPath());
|
||||
expect(config?.captureMaxChars).toBe(500);
|
||||
});
|
||||
|
||||
@@ -74,7 +88,7 @@ describe("memory plugin e2e", () => {
|
||||
embedding: {
|
||||
apiKey: "${TEST_MEMORY_API_KEY}",
|
||||
},
|
||||
dbPath,
|
||||
dbPath: getDbPath(),
|
||||
});
|
||||
|
||||
expect(config?.embedding?.apiKey).toBe("test-key-123");
|
||||
@@ -88,7 +102,7 @@ describe("memory plugin e2e", () => {
|
||||
expect(() => {
|
||||
memoryPlugin.configSchema?.parse?.({
|
||||
embedding: {},
|
||||
dbPath,
|
||||
dbPath: getDbPath(),
|
||||
});
|
||||
}).toThrow("embedding.apiKey is required");
|
||||
});
|
||||
@@ -99,21 +113,14 @@ describe("memory plugin e2e", () => {
|
||||
expect(() => {
|
||||
memoryPlugin.configSchema?.parse?.({
|
||||
embedding: { apiKey: OPENAI_API_KEY },
|
||||
dbPath,
|
||||
dbPath: getDbPath(),
|
||||
captureMaxChars: 99,
|
||||
});
|
||||
}).toThrow("captureMaxChars must be between 100 and 10000");
|
||||
});
|
||||
|
||||
test("config schema accepts captureMaxChars override", async () => {
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
|
||||
const config = memoryPlugin.configSchema?.parse?.({
|
||||
embedding: {
|
||||
apiKey: OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
},
|
||||
dbPath,
|
||||
const config = await parseConfig({
|
||||
captureMaxChars: 1800,
|
||||
});
|
||||
|
||||
@@ -121,15 +128,7 @@ describe("memory plugin e2e", () => {
|
||||
});
|
||||
|
||||
test("config schema keeps autoCapture disabled by default", async () => {
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
|
||||
const config = memoryPlugin.configSchema?.parse?.({
|
||||
embedding: {
|
||||
apiKey: OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
},
|
||||
dbPath,
|
||||
});
|
||||
const config = await parseConfig();
|
||||
|
||||
expect(config?.autoCapture).toBe(false);
|
||||
expect(config?.autoRecall).toBe(true);
|
||||
@@ -176,7 +175,7 @@ describe("memory plugin e2e", () => {
|
||||
model: "text-embedding-3-small",
|
||||
dimensions: 1024,
|
||||
},
|
||||
dbPath,
|
||||
dbPath: getDbPath(),
|
||||
autoCapture: false,
|
||||
autoRecall: false,
|
||||
},
|
||||
@@ -279,19 +278,7 @@ describe("memory plugin e2e", () => {
|
||||
|
||||
// Live tests that require OpenAI API key and actually use LanceDB
|
||||
describeLive("memory plugin live tests", () => {
|
||||
let tmpDir: string;
|
||||
let dbPath: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-memory-live-"));
|
||||
dbPath = path.join(tmpDir, "lancedb");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (tmpDir) {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
const { getDbPath } = installTmpDirHarness({ prefix: "openclaw-memory-live-" });
|
||||
|
||||
test("memory tools work end-to-end", async () => {
|
||||
const { default: memoryPlugin } = await import("./index.js");
|
||||
@@ -318,7 +305,7 @@ describeLive("memory plugin live tests", () => {
|
||||
apiKey: liveApiKey,
|
||||
model: "text-embedding-3-small",
|
||||
},
|
||||
dbPath,
|
||||
dbPath: getDbPath(),
|
||||
autoCapture: false,
|
||||
autoRecall: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user