Files
Cibello-app/packages/memory-client/test/overview.test.ts
T
2026-08-11 02:41:39 +07:00

83 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { buildMemoryOverview } from "../src/index.js";
import type { MemoryItem } from "@app/shared-types";
function makeItem(overrides: Partial<MemoryItem> = {}): MemoryItem {
return {
id: "m1",
userId: "u1",
kind: "structured_fact",
key: "favorite_cuisine_swedish",
summarySv: "Gillar svensk mat",
value: { favoriteCuisine: "swedish" },
origin: "user_stated",
confidence: 1,
verifiedByUser: true,
paused: false,
createdAt: "2026-08-01T00:00:00.000Z",
updatedAt: "2026-08-01T00:00:00.000Z",
...overrides,
};
}
describe("buildMemoryOverview", () => {
it("grupperar minnen efter kind", () => {
const items: MemoryItem[] = [
makeItem({ id: "a", kind: "structured_fact", summarySv: "Fakta A" }),
makeItem({ id: "b", kind: "recipe_memory", summarySv: "Recept B" }),
makeItem({ id: "c", kind: "structured_fact", summarySv: "Fakta C" }),
];
const overview = buildMemoryOverview(items, "sv-SE");
const kinds = overview.sections.map((s) => s.kind);
expect(kinds).toContain("structured_fact");
expect(kinds).toContain("recipe_memory");
const factSection = overview.sections.find((s) => s.kind === "structured_fact")!;
expect(factSection.items).toHaveLength(2);
});
it("visar origin och confidence tydligt", () => {
const items: MemoryItem[] = [
makeItem({ origin: "observed", confidence: 0.75 }),
];
const overview = buildMemoryOverview(items, "sv-SE");
const item = overview.sections[0]!.items[0]!;
expect(item.originLabel).toBe("Vi har sett");
expect(item.confidencePercent).toBe(75);
});
it("markerar pausade poster synligt", () => {
const items: MemoryItem[] = [makeItem({ paused: true })];
const overview = buildMemoryOverview(items, "sv-SE");
const item = overview.sections[0]!.items[0]!;
expect(item.pausedLabel).toBe("Pausad");
expect(overview.pausedCount).toBe(1);
});
it("markerar ai_inferred som gissning", () => {
const items: MemoryItem[] = [makeItem({ origin: "ai_inferred", confidence: 0.5 })];
const overview = buildMemoryOverview(items, "sv-SE");
const item = overview.sections[0]!.items[0]!;
expect(item.originLabel).toBe("Gissning");
expect(item.guessLabel).toBe("Detta är en gissning bekräfta eller ändra om det stämmer.");
});
it("sorterar senast uppdaterade överst", () => {
const items: MemoryItem[] = [
makeItem({ id: "old", updatedAt: "2026-08-01T00:00:00.000Z" }),
makeItem({ id: "new", updatedAt: "2026-08-10T00:00:00.000Z" }),
];
const overview = buildMemoryOverview(items, "sv-SE");
expect(overview.sections[0]!.items[0]!.id).toBe("new");
expect(overview.sections[0]!.items[1]!.id).toBe("old");
});
it("stödjer engelska texter", () => {
const items: MemoryItem[] = [makeItem({ origin: "user_stated", paused: true })];
const overview = buildMemoryOverview(items, "en-US");
const item = overview.sections[0]!.items[0]!;
expect(item.originLabel).toBe("You said");
expect(item.pausedLabel).toBe("Paused");
expect(item.summary).toBe("Favorite cuisine: swedish");
});
});