Files
openclaw/extensions/memory-lancedb/config.test.ts
Peter Steinberger 1507a9701b refactor: centralize inbound supplemental context
* refactor: centralize inbound supplemental context

* refactor: trim supplemental finalizer typing

* docs: clarify supplemental context projection

* refactor: move inbound finalization into core

* refactor: simplify channel inbound facts

* refactor: fold supplemental media into inbound finalizer

* refactor: migrate channel inbound callers to builder

* docs: mark inbound finalizer compat types deprecated

* refactor: wire runtime turn context builder

* refactor: replace channel turn runtime API

* fix: respect discord quote visibility

* fix: avoid deprecated line dispatch helper

* refactor: deprecate channel message SDK seams

* docs: trim channel outbound SDK page

* test: migrate irc inbound assertion

* refactor: deprecate outbound SDK facades

* refactor: deprecate channel helper SDK facades

* refactor: deprecate channel streaming SDK facade

* refactor: move direct dm helpers into inbound SDK

* chore: mark legacy test-utils SDK alias deprecated

* refactor: remove unused allow-from read helper

* refactor: route remaining channel dispatch through core

* refactor: enforce modern extension SDK imports

* test: give slow image root tests more time

* ci: support node fallback on windows

* fix: add transcripts tool display metadata

* refactor: trim legacy channel test seams

* fix: preserve channel compat after rebase

* fix: keep deprecated channel inbound aliases

* fix: preserve discord thread context visibility

* fix: clean final rebase conflicts

* fix: preserve channel message dispatch aliases

* fix: sync channel refactor after rebase

* fix: sync channel refactor after latest main

* fix: dedupe memory-core subagent mock

* test: align clickclack inbound dispatch assertions

* fix: sync plugin sdk api hash after rebase

* fix: sync channel refactor after latest main

* fix: sync plugin sdk api hash after rebase

* fix: sync plugin sdk api hash after latest main

* test: remove stale inbound context awaits
2026-05-27 09:26:06 +01:00

182 lines
4.8 KiB
TypeScript

import fs from "node:fs";
import {
type JsonSchemaObject,
validateJsonSchemaValue,
} from "openclaw/plugin-sdk/json-schema-runtime";
import { describe, expect, it } from "vitest";
import { memoryConfigSchema } from "./config.js";
const manifest = JSON.parse(
fs.readFileSync(new URL("./openclaw.plugin.json", import.meta.url), "utf-8"),
) as { configSchema: JsonSchemaObject };
describe("memory-lancedb config", () => {
it("accepts dreaming in the manifest schema and preserves it in runtime parsing", () => {
const manifestResult = validateJsonSchemaValue({
schema: manifest.configSchema,
cacheKey: "memory-lancedb.manifest.dreaming",
value: {
embedding: {
apiKey: "sk-test",
},
dreaming: {
enabled: true,
},
},
});
const parsed = memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
dreaming: {
enabled: true,
},
});
expect(manifestResult.ok).toBe(true);
expect(parsed.dreaming).toEqual({
enabled: true,
});
});
it("accepts provider-backed embedding config without a plugin apiKey", () => {
const manifestResult = validateJsonSchemaValue({
schema: manifest.configSchema,
cacheKey: "memory-lancedb.manifest.provider-auth",
value: {
embedding: {
provider: "openai",
model: "text-embedding-3-small",
},
},
});
const parsed = memoryConfigSchema.parse({
embedding: {
provider: "openai",
model: "text-embedding-3-small",
},
});
expect(manifestResult.ok).toBe(true);
expect(parsed.embedding.apiKey).toBeUndefined();
expect(parsed.embedding.provider).toBe("openai");
});
it("rejects empty embedding config in the manifest schema and runtime parser", () => {
const manifestResult = validateJsonSchemaValue({
schema: manifest.configSchema,
cacheKey: "memory-lancedb.manifest.empty-embedding",
value: {
embedding: {},
},
});
expect(manifestResult.ok).toBe(false);
if (!manifestResult.ok) {
expect(manifestResult.errors.map((error) => error.text)).toContain(
"embedding: must not have fewer than 1 properties",
);
}
expect(() => {
memoryConfigSchema.parse({
embedding: {},
});
}).toThrow("embedding config must include at least one setting");
});
it("allows missing embedding config in the manifest so setup can discover fields", () => {
const manifestResult = validateJsonSchemaValue({
schema: manifest.configSchema,
cacheKey: "memory-lancedb.manifest.missing-embedding",
value: {},
});
expect(manifestResult.ok).toBe(true);
expect(() => {
memoryConfigSchema.parse({});
}).toThrow("embedding config required");
});
it("rejects empty embedding providers", () => {
expect(() => {
memoryConfigSchema.parse({
embedding: {
provider: "",
model: "text-embedding-3-small",
},
});
}).toThrow("embedding.provider must not be empty");
});
it("still rejects unrelated unknown top-level config keys", () => {
expect(() => {
memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
dreaming: {
enabled: true,
},
unexpected: true,
});
}).toThrow("memory config has unknown keys: unexpected");
});
it("accepts custom trigger literals in the manifest schema and runtime parser", () => {
const manifestResult = validateJsonSchemaValue({
schema: manifest.configSchema,
cacheKey: "memory-lancedb.manifest.custom-triggers",
value: {
embedding: {
apiKey: "sk-test",
},
customTriggers: ["记住", "important project"],
},
});
const parsed = memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
customTriggers: [" 记住 ", "important project"],
});
expect(manifestResult.ok).toBe(true);
expect(parsed.customTriggers).toEqual(["记住", "important project"]);
});
it("rejects unsafe custom trigger config values", () => {
expect(() => {
memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
customTriggers: ["记住", ""],
});
}).toThrow("customTriggers.1 must not be empty");
expect(() => {
memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
customTriggers: ["x".repeat(101)],
});
}).toThrow("customTriggers.0 must be at most 100 characters");
});
it("rejects non-object dreaming values in runtime parsing", () => {
expect(() => {
memoryConfigSchema.parse({
embedding: {
apiKey: "sk-test",
},
dreaming: true,
});
}).toThrow("dreaming config must be an object");
});
});