Files
wehub-resource-sync 555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:45 +08:00

48 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { formatAge, formatMemoryCompact, formatMemoryList } from "../src/memory/formatting.ts";
describe("formatAge", () => {
it("formats minutes", () => {
expect(formatAge(new Date(Date.now() - 30 * 60_000))).toBe("30m ago");
});
it("formats hours", () => {
expect(formatAge(new Date(Date.now() - 3 * 3_600_000))).toBe("3h ago");
});
it("formats days", () => {
expect(formatAge(new Date(Date.now() - 5 * 86_400_000))).toBe("5d ago");
});
});
describe("formatMemoryCompact", () => {
it("formats a memory as a single line", () => {
const mem = {
id: "abc-123-def-456",
memory: "User prefers dark mode",
categories: ["preference"],
createdAt: new Date(),
};
const line = formatMemoryCompact(mem);
expect(line).toContain("[preference]");
expect(line).toContain("User prefers dark mode");
expect(line).toContain("[mem0:abc-123-def-456]");
});
});
describe("formatMemoryList", () => {
it("formats multiple memories with numbering", () => {
const memories = [
{ id: "id-1", memory: "Fact one", categories: ["insight"], createdAt: new Date() },
{ id: "id-2", memory: "Fact two", categories: ["convention"], createdAt: new Date() },
];
const output = formatMemoryList(memories);
expect(output).toContain("1.");
expect(output).toContain("2.");
});
it("returns empty message for no memories", () => {
expect(formatMemoryList([])).toBe("No memories found.");
});
});