Files
openclaw/extensions/memory-wiki/src/tool.test.ts
2026-05-09 03:02:03 +01:00

32 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { ResolvedMemoryWikiConfig } from "./config.js";
import { createWikiApplyTool } from "./tool.js";
function asSchemaObject(value: unknown): Record<string, unknown> {
expect(typeof value).toBe("object");
expect(value).not.toBeNull();
expect(Array.isArray(value)).toBe(false);
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new Error("Expected JSON schema object");
}
return value as Record<string, unknown>;
}
describe("memory-wiki tools", () => {
it("allows provenance metadata in wiki_apply claim evidence", () => {
const tool = createWikiApplyTool({} as ResolvedMemoryWikiConfig);
const applyProperties = asSchemaObject(asSchemaObject(tool.parameters).properties);
const claimsSchema = asSchemaObject(applyProperties.claims);
const claimSchema = asSchemaObject(claimsSchema.items);
const claimProperties = asSchemaObject(claimSchema.properties);
const evidenceSchema = asSchemaObject(claimProperties.evidence);
const evidenceArraySchema = asSchemaObject(evidenceSchema.items);
const evidenceProperties = asSchemaObject(evidenceArraySchema.properties);
expect(Object.keys(evidenceProperties)).toEqual(
expect.arrayContaining(["kind", "confidence", "privacyTier"]),
);
expect(evidenceProperties.confidence).toMatchObject({ minimum: 0, maximum: 1 });
});
});