test: share memory lancedb temp config harness
This commit is contained in:
parent
1ea5bba848
commit
4d1fcc1df2
@ -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 liveEnabled = HAS_OPENAI_KEY && process.env.OPENCLAW_LIVE_TEST === "1";
|
||||||
const describeLive = liveEnabled ? describe : describe.skip;
|
const describeLive = liveEnabled ? describe : describe.skip;
|
||||||
|
|
||||||
describe("memory plugin e2e", () => {
|
function installTmpDirHarness(params: { prefix: string }) {
|
||||||
let tmpDir: string;
|
let tmpDir = "";
|
||||||
let dbPath: string;
|
let dbPath = "";
|
||||||
|
|
||||||
beforeEach(async () => {
|
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");
|
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 () => {
|
test("memory plugin registers and initializes correctly", async () => {
|
||||||
// Dynamic import to avoid loading LanceDB when not testing
|
// Dynamic import to avoid loading LanceDB when not testing
|
||||||
const { default: memoryPlugin } = await import("./index.js");
|
const { default: memoryPlugin } = await import("./index.js");
|
||||||
@ -46,21 +67,14 @@ describe("memory plugin e2e", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("config schema parses valid config", async () => {
|
test("config schema parses valid config", async () => {
|
||||||
const { default: memoryPlugin } = await import("./index.js");
|
const config = await parseConfig({
|
||||||
|
|
||||||
const config = memoryPlugin.configSchema?.parse?.({
|
|
||||||
embedding: {
|
|
||||||
apiKey: OPENAI_API_KEY,
|
|
||||||
model: "text-embedding-3-small",
|
|
||||||
},
|
|
||||||
dbPath,
|
|
||||||
autoCapture: true,
|
autoCapture: true,
|
||||||
autoRecall: true,
|
autoRecall: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(config).toBeDefined();
|
expect(config).toBeDefined();
|
||||||
expect(config?.embedding?.apiKey).toBe(OPENAI_API_KEY);
|
expect(config?.embedding?.apiKey).toBe(OPENAI_API_KEY);
|
||||||
expect(config?.dbPath).toBe(dbPath);
|
expect(config?.dbPath).toBe(getDbPath());
|
||||||
expect(config?.captureMaxChars).toBe(500);
|
expect(config?.captureMaxChars).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,7 +88,7 @@ describe("memory plugin e2e", () => {
|
|||||||
embedding: {
|
embedding: {
|
||||||
apiKey: "${TEST_MEMORY_API_KEY}",
|
apiKey: "${TEST_MEMORY_API_KEY}",
|
||||||
},
|
},
|
||||||
dbPath,
|
dbPath: getDbPath(),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(config?.embedding?.apiKey).toBe("test-key-123");
|
expect(config?.embedding?.apiKey).toBe("test-key-123");
|
||||||
@ -88,7 +102,7 @@ describe("memory plugin e2e", () => {
|
|||||||
expect(() => {
|
expect(() => {
|
||||||
memoryPlugin.configSchema?.parse?.({
|
memoryPlugin.configSchema?.parse?.({
|
||||||
embedding: {},
|
embedding: {},
|
||||||
dbPath,
|
dbPath: getDbPath(),
|
||||||
});
|
});
|
||||||
}).toThrow("embedding.apiKey is required");
|
}).toThrow("embedding.apiKey is required");
|
||||||
});
|
});
|
||||||
@ -99,21 +113,14 @@ describe("memory plugin e2e", () => {
|
|||||||
expect(() => {
|
expect(() => {
|
||||||
memoryPlugin.configSchema?.parse?.({
|
memoryPlugin.configSchema?.parse?.({
|
||||||
embedding: { apiKey: OPENAI_API_KEY },
|
embedding: { apiKey: OPENAI_API_KEY },
|
||||||
dbPath,
|
dbPath: getDbPath(),
|
||||||
captureMaxChars: 99,
|
captureMaxChars: 99,
|
||||||
});
|
});
|
||||||
}).toThrow("captureMaxChars must be between 100 and 10000");
|
}).toThrow("captureMaxChars must be between 100 and 10000");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("config schema accepts captureMaxChars override", async () => {
|
test("config schema accepts captureMaxChars override", async () => {
|
||||||
const { default: memoryPlugin } = await import("./index.js");
|
const config = await parseConfig({
|
||||||
|
|
||||||
const config = memoryPlugin.configSchema?.parse?.({
|
|
||||||
embedding: {
|
|
||||||
apiKey: OPENAI_API_KEY,
|
|
||||||
model: "text-embedding-3-small",
|
|
||||||
},
|
|
||||||
dbPath,
|
|
||||||
captureMaxChars: 1800,
|
captureMaxChars: 1800,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,15 +128,7 @@ describe("memory plugin e2e", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("config schema keeps autoCapture disabled by default", async () => {
|
test("config schema keeps autoCapture disabled by default", async () => {
|
||||||
const { default: memoryPlugin } = await import("./index.js");
|
const config = await parseConfig();
|
||||||
|
|
||||||
const config = memoryPlugin.configSchema?.parse?.({
|
|
||||||
embedding: {
|
|
||||||
apiKey: OPENAI_API_KEY,
|
|
||||||
model: "text-embedding-3-small",
|
|
||||||
},
|
|
||||||
dbPath,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(config?.autoCapture).toBe(false);
|
expect(config?.autoCapture).toBe(false);
|
||||||
expect(config?.autoRecall).toBe(true);
|
expect(config?.autoRecall).toBe(true);
|
||||||
@ -176,7 +175,7 @@ describe("memory plugin e2e", () => {
|
|||||||
model: "text-embedding-3-small",
|
model: "text-embedding-3-small",
|
||||||
dimensions: 1024,
|
dimensions: 1024,
|
||||||
},
|
},
|
||||||
dbPath,
|
dbPath: getDbPath(),
|
||||||
autoCapture: false,
|
autoCapture: false,
|
||||||
autoRecall: false,
|
autoRecall: false,
|
||||||
},
|
},
|
||||||
@ -279,19 +278,7 @@ describe("memory plugin e2e", () => {
|
|||||||
|
|
||||||
// Live tests that require OpenAI API key and actually use LanceDB
|
// Live tests that require OpenAI API key and actually use LanceDB
|
||||||
describeLive("memory plugin live tests", () => {
|
describeLive("memory plugin live tests", () => {
|
||||||
let tmpDir: string;
|
const { getDbPath } = installTmpDirHarness({ prefix: "openclaw-memory-live-" });
|
||||||
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 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("memory tools work end-to-end", async () => {
|
test("memory tools work end-to-end", async () => {
|
||||||
const { default: memoryPlugin } = await import("./index.js");
|
const { default: memoryPlugin } = await import("./index.js");
|
||||||
@ -318,7 +305,7 @@ describeLive("memory plugin live tests", () => {
|
|||||||
apiKey: liveApiKey,
|
apiKey: liveApiKey,
|
||||||
model: "text-embedding-3-small",
|
model: "text-embedding-3-small",
|
||||||
},
|
},
|
||||||
dbPath,
|
dbPath: getDbPath(),
|
||||||
autoCapture: false,
|
autoCapture: false,
|
||||||
autoRecall: false,
|
autoRecall: false,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user