hermes-agent/web/src/lib/session-refresh.test.ts
Alex Yates dc5cb0a440 fix(dashboard): refresh Sessions list in real time when new sessions are created
The dashboard's FastAPI server and a terminal CLI are separate processes
sharing one SQLite session DB; there is no inter-process push channel.
The Sessions page polled the 50 newest sessions every 5s for the
"overview" card but only re-fetched the paginated sessions list on page
change or delete, so a session started in a terminal never appeared in
the list until the user navigated.

Reuse the existing 5s overview poll as a change signal: when the head
session id changes, silently reload the current page (no loading
spinner flicker, no scroll/reset of expanded rows or bulk selection,
which are keyed by id). The detection logic is extracted into a pure
shouldRefreshSessions() helper with unit tests. Adds a minimal vitest
setup for web/ (test script + config).
2026-06-19 17:26:11 +05:30

21 lines
762 B
TypeScript

import { describe, it, expect } from "vitest";
import { shouldRefreshSessions } from "./session-refresh";
describe("shouldRefreshSessions", () => {
it("returns false on the first poll (no baseline yet)", () => {
expect(shouldRefreshSessions(null, "s2")).toBe(false);
});
it("returns false when the current response has no sessions", () => {
expect(shouldRefreshSessions("s1", null)).toBe(false);
expect(shouldRefreshSessions(null, null)).toBe(false);
});
it("returns false when the newest session id is unchanged", () => {
expect(shouldRefreshSessions("s1", "s1")).toBe(false);
});
it("returns true when a new session appears at the head of the list", () => {
expect(shouldRefreshSessions("s1", "s2")).toBe(true);
});
});