






















@@ -18,7 +18,7 @@ import memoryPlugin, {
1818normalizeRecallQuery,
1919shouldCapture,
2020} from "./index.js";
21-import { createLanceDbRuntimeLoader, type LanceDbRuntimeLogger } from "./lancedb-runtime.js";
21+import { createLanceDbRuntimeLoader } from "./lancedb-runtime.js";
2222import { installTmpDirHarness } from "./test-helpers.js";
23232424const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "test-key";
@@ -38,22 +38,7 @@ type MemoryPluginTestConfig = {
3838storageOptions?: Record<string, string>;
3939};
404041-const TEST_RUNTIME_MANIFEST = {
42-name: "openclaw-memory-lancedb-runtime",
43-private: true as const,
44-type: "module" as const,
45-dependencies: {
46-"@lancedb/lancedb": "^0.27.1",
47-},
48-};
49-5041type LanceDbModule = typeof import("@lancedb/lancedb");
51-type RuntimeManifest = {
52-name: string;
53-private: true;
54-type: "module";
55-dependencies: Record<string, string>;
56-};
57425843function createMockModule(): LanceDbModule {
5944return {
@@ -67,40 +52,19 @@ function invokeEmbeddingCreate(mock: ReturnType<typeof vi.fn>, body: unknown) {
67526853function createRuntimeLoader(
6954overrides: {
70-env?: NodeJS.ProcessEnv;
7155importBundled?: () => Promise<LanceDbModule>;
72-importResolved?: (resolvedPath: string) => Promise<LanceDbModule>;
7356platform?: NodeJS.Platform;
7457arch?: NodeJS.Architecture;
75-resolveRuntimeEntry?: (params: {
76-runtimeDir: string;
77-manifest: RuntimeManifest;
78-}) => string | null;
79-installRuntime?: (params: {
80-runtimeDir: string;
81-manifest: RuntimeManifest;
82-env: NodeJS.ProcessEnv;
83-logger?: LanceDbRuntimeLogger;
84-}) => Promise<string>;
8558} = {},
8659) {
8760return createLanceDbRuntimeLoader({
88-env: overrides.env ?? ({} as NodeJS.ProcessEnv),
8961platform: overrides.platform,
9062arch: overrides.arch,
91-resolveStateDir: () => "/tmp/openclaw-state",
92-runtimeManifest: TEST_RUNTIME_MANIFEST,
9363importBundled:
9464overrides.importBundled ??
9565(async () => {
9666throw new Error("Cannot find package '@lancedb/lancedb'");
9767}),
98-importResolved: overrides.importResolved ?? (async () => createMockModule()),
99-resolveRuntimeEntry: overrides.resolveRuntimeEntry ?? (() => null),
100-installRuntime:
101-overrides.installRuntime ??
102-(async ({ runtimeDir }: { runtimeDir: string }) =>
103-`${runtimeDir}/node_modules/@lancedb/lancedb/index.js`),
10468});
10569}
10670@@ -2261,131 +2225,47 @@ describe("lancedb runtime loader", () => {
22612225test("uses the bundled module when it is already available", async () => {
22622226const bundledModule = createMockModule();
22632227const importBundled = vi.fn(async () => bundledModule);
2264-const importResolved = vi.fn(async () => createMockModule());
2265-const resolveRuntimeEntry = vi.fn(() => null);
2266-const installRuntime = vi.fn(async () => "/tmp/openclaw-state/plugin-runtimes/lancedb.js");
22672228const loader = createRuntimeLoader({
22682229 importBundled,
2269- importResolved,
2270- resolveRuntimeEntry,
2271- installRuntime,
22722230});
2273223122742232await expect(loader.load()).resolves.toBe(bundledModule);
227522332276-expect(resolveRuntimeEntry).not.toHaveBeenCalled();
2277-expect(installRuntime).not.toHaveBeenCalled();
2278-expect(importResolved).not.toHaveBeenCalled();
2234+expect(importBundled).toHaveBeenCalledTimes(1);
22792235});
228022362281-test("reuses an existing user runtime install before attempting a reinstall", async () => {
2282-const runtimeModule = createMockModule();
2283-const importResolved = vi.fn(async () => runtimeModule);
2284-const resolveRuntimeEntry = vi.fn(
2285-() => "/tmp/openclaw-state/plugin-runtimes/memory-lancedb/runtime-entry.js",
2286-);
2287-const installRuntime = vi.fn(
2288-async () => "/tmp/openclaw-state/plugin-runtimes/memory-lancedb/runtime-entry.js",
2289-);
2290-const loader = createRuntimeLoader({
2291- importResolved,
2292- resolveRuntimeEntry,
2293- installRuntime,
2294-});
2295-2296-await expect(loader.load()).resolves.toBe(runtimeModule);
2297-2298-expect(resolveRuntimeEntry).toHaveBeenCalledWith(
2299-expect.objectContaining({
2300-runtimeDir: "/tmp/openclaw-state/plugin-runtimes/memory-lancedb/lancedb",
2301-}),
2302-);
2303-expect(installRuntime).not.toHaveBeenCalled();
2304-});
2305-2306-test("installs LanceDB into user state when the bundled runtime is unavailable", async () => {
2307-const runtimeModule = createMockModule();
2308-const logger: LanceDbRuntimeLogger = {
2309-warn: vi.fn(),
2310-info: vi.fn(),
2311-};
2312-const importResolved = vi.fn(async () => runtimeModule);
2313-const resolveRuntimeEntry = vi.fn(() => null);
2314-const installRuntime = vi.fn(
2315-async ({ runtimeDir }: { runtimeDir: string }) =>
2316-`${runtimeDir}/node_modules/@lancedb/lancedb/index.js`,
2317-);
2318-const loader = createRuntimeLoader({
2319- importResolved,
2320- resolveRuntimeEntry,
2321- installRuntime,
2322-});
2323-2324-await expect(loader.load(logger)).resolves.toBe(runtimeModule);
2325-2326-expect(installRuntime).toHaveBeenCalledWith(
2327-expect.objectContaining({
2328-runtimeDir: "/tmp/openclaw-state/plugin-runtimes/memory-lancedb/lancedb",
2329-manifest: TEST_RUNTIME_MANIFEST,
2330-}),
2331-);
2332-expect(logger.warn).toHaveBeenCalledWith(
2333-expect.stringContaining(
2334-"installing runtime deps under /tmp/openclaw-state/plugin-runtimes/memory-lancedb/lancedb",
2335-),
2336-);
2337-});
2338-2339-test("fails fast in nix mode instead of attempting auto-install", async () => {
2340-const installRuntime = vi.fn(
2341-async ({ runtimeDir }: { runtimeDir: string }) =>
2342-`${runtimeDir}/node_modules/@lancedb/lancedb/index.js`,
2343-);
2237+test("fails clearly on Intel macOS instead of attempting an unsupported native install", async () => {
23442238const loader = createRuntimeLoader({
2345-env: { OPENCLAW_NIX_MODE: "1" } as NodeJS.ProcessEnv,
2346-installRuntime,
2239+platform: "darwin",
2240+arch: "x64",
23472241});
2348224223492243await expect(loader.load()).rejects.toThrow(
2350-"memory-lancedb: failed to load LanceDB and Nix mode disables auto-install.",
2244+"memory-lancedb: LanceDB runtime is unavailable on darwin-x64.",
23512245);
2352-expect(installRuntime).not.toHaveBeenCalled();
23532246});
235422472355-test("fails clearly on Intel macOS instead of attempting an unsupported native install", async () => {
2356-const installRuntime = vi.fn(
2357-async ({ runtimeDir }: { runtimeDir: string }) =>
2358-`${runtimeDir}/node_modules/@lancedb/lancedb/index.js`,
2359-);
2360-const loader = createRuntimeLoader({
2361-platform: "darwin",
2362-arch: "x64",
2363- installRuntime,
2364-});
2248+test("fails fast when package dependencies are missing", async () => {
2249+const loader = createRuntimeLoader();
2365225023662251await expect(loader.load()).rejects.toThrow(
2367-"memory-lancedb: LanceDB runtime is unavailable on darwin-x64.",
2252+"memory-lancedb: bundled @lancedb/lancedb dependency is unavailable.",
23682253);
2369-expect(installRuntime).not.toHaveBeenCalled();
23702254});
237122552372-test("clears the cached failure so later calls can retry the install", async () => {
2256+test("clears the cached failure so later calls can retry the package import", async () => {
23732257const runtimeModule = createMockModule();
2374-const installRuntime = vi
2258+const importBundled = vi
23752259.fn()
23762260.mockRejectedValueOnce(new Error("network down"))
2377-.mockResolvedValueOnce(
2378-"/tmp/openclaw-state/plugin-runtimes/memory-lancedb/lancedb/node_modules/@lancedb/lancedb/index.js",
2379-);
2380-const importResolved = vi.fn(async () => runtimeModule);
2261+.mockResolvedValueOnce(runtimeModule);
23812262const loader = createRuntimeLoader({
2382- installRuntime,
2383- importResolved,
2263+ importBundled,
23842264});
2385226523862266await expect(loader.load()).rejects.toThrow("network down");
23872267await expect(loader.load()).resolves.toBe(runtimeModule);
238822682389-expect(installRuntime).toHaveBeenCalledTimes(2);
2269+expect(importBundled).toHaveBeenCalledTimes(2);
23902270});
23912271});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。