Files
rohitg00--agentmemory/test/viewer-memories-sort.test.ts
wehub-resource-sync 979fb22d7c
CI / test (20, macos-latest) (push) Waiting to run
CI / test (20, ubuntu-latest) (push) Waiting to run
CI / test (22, macos-latest) (push) Waiting to run
CI / test (22, ubuntu-latest) (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:01:18 +08:00

33 lines
1.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { readFileSync } from "node:fs";
// Viewer Memories tab used to render in KV-insertion order, hiding new
// entries at the bottom of long lists (#674). loadMemories() now sorts
// the response newest-first on `createdAt` (fallback `updatedAt`) before
// renderMemories sees it. Matches the pattern already used by Sessions
// and Metrics tabs which sort on `startedAt` desc via localeCompare.
describe("viewer Memories tab sorts newest first (#674)", () => {
const viewer = readFileSync("src/viewer/index.html", "utf-8");
it("loadMemories sorts items by createdAt desc before storing in state", () => {
expect(viewer).toMatch(
/loadMemories[\s\S]*?items\.sort\(function\(a,\s*b\)\s*\{[\s\S]*?bc\.localeCompare\(ac\)/,
);
});
it("sort falls back to updatedAt when createdAt is missing", () => {
expect(viewer).toMatch(
/\(a && a\.createdAt\) \|\| \(a && a\.updatedAt\)/,
);
expect(viewer).toMatch(
/\(b && b\.createdAt\) \|\| \(b && b\.updatedAt\)/,
);
});
it("Memories sort mirrors the Sessions/Metrics localeCompare descending pattern", () => {
expect(viewer).toMatch(
/sessions\.sort\(function\(a, b\) \{ return \(b\.startedAt \|\| ''\)\.localeCompare\(a\.startedAt \|\| ''\); \}\)/,
);
});
});