mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:50:43 +00:00
test: share lancedb temp fixtures
This commit is contained in:
@@ -8,10 +8,7 @@
|
||||
* - Auto-capture filtering
|
||||
*/
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, test, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import { describe, test, expect, vi } from "vitest";
|
||||
import memoryPlugin, {
|
||||
detectCategory,
|
||||
formatRelevantMemoriesContext,
|
||||
@@ -19,6 +16,7 @@ import memoryPlugin, {
|
||||
shouldCapture,
|
||||
} from "./index.js";
|
||||
import { createLanceDbRuntimeLoader, type LanceDbRuntimeLogger } from "./lancedb-runtime.js";
|
||||
import { installTmpDirHarness } from "./test-helpers.js";
|
||||
|
||||
const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "test-key";
|
||||
type MemoryPluginTestConfig = {
|
||||
@@ -51,27 +49,6 @@ type RuntimeManifest = {
|
||||
dependencies: Record<string, string>;
|
||||
};
|
||||
|
||||
function installTmpDirHarness(params: { prefix: string }) {
|
||||
let tmpDir = "";
|
||||
let dbPath = "";
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), params.prefix));
|
||||
dbPath = path.join(tmpDir, "lancedb");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (tmpDir) {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getTmpDir: () => tmpDir,
|
||||
getDbPath: () => dbPath,
|
||||
};
|
||||
}
|
||||
|
||||
function createMockModule(): LanceDbModule {
|
||||
return {
|
||||
connect: vi.fn(),
|
||||
|
||||
@@ -1,34 +1,11 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { installTmpDirHarness } from "./test-helpers.js";
|
||||
|
||||
const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "";
|
||||
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;
|
||||
|
||||
function installTmpDirHarness(params: { prefix: string }) {
|
||||
let tmpDir = "";
|
||||
let dbPath = "";
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), params.prefix));
|
||||
dbPath = path.join(tmpDir, "lancedb");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (tmpDir) {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getTmpDir: () => tmpDir,
|
||||
getDbPath: () => dbPath,
|
||||
};
|
||||
}
|
||||
|
||||
// Live tests that require OpenAI API key and actually use LanceDB
|
||||
describeLive("memory plugin live tests", () => {
|
||||
const { getDbPath } = installTmpDirHarness({ prefix: "openclaw-memory-live-" });
|
||||
|
||||
25
extensions/memory-lancedb/test-helpers.ts
Normal file
25
extensions/memory-lancedb/test-helpers.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
|
||||
export function installTmpDirHarness(params: { prefix: string }) {
|
||||
let tmpDir = "";
|
||||
let dbPath = "";
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), params.prefix));
|
||||
dbPath = path.join(tmpDir, "lancedb");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (tmpDir) {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getTmpDir: () => tmpDir,
|
||||
getDbPath: () => dbPath,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user