Skip to content

The agent that grows with you

test(sidebar): pins inside the recency window still report more sessions on disk

kshitijk4poor31ca48512be2
diff --git a/apps/desktop/src/hermes.test.ts b/apps/desktop/src/hermes.test.ts
index 30c70e8e123..e1c801b1fbc 100644
--- a/apps/desktop/src/hermes.test.ts
+++ b/apps/desktop/src/hermes.test.ts
@@ -245,6 +245,41 @@ describe('Hermes REST helpers', () => {
expect(result.messaging.sessions).toEqual([])
})
+ it('counts pinned rows toward a full legacy page so older sessions stay reachable', async () => {
+ // #81484: pins inside the window take LIMIT slots. 3 pinned + 17 unpinned
+ // against a cap of 20 IS a full page; discounting the pins read 17 < 20
+ // and the load-more row never mounted.
+ const row = (id: string, pinned: boolean) => ({ id, title: id, profile: 'default', pinned })
+
+ const recents = [
+ ...Array.from({ length: 3 }, (_, i) => row(`pinned-${i}`, true)),
+ ...Array.from({ length: 17 }, (_, i) => row(`recent-${i}`, false))
+ ]
+
+ api.mockImplementation(({ path }: { path: string }) => {
+ if (path.startsWith('/api/profiles/sessions/sidebar')) {
+ return Promise.reject(new Error('404: {"detail":"No such API endpoint: /api/profiles/sessions/sidebar"}'))
+ }
+
+ if (path.includes('source=cron') || path.includes('exclude_sources=')) {
+ return Promise.resolve({ ...emptySessionsResponse, sessions: [], total: 0 })
+ }
+
+ return Promise.resolve({ ...emptySessionsResponse, sessions: recents, total: recents.length })
+ })
+
+ const result = await listSidebarSessions({
+ recentsProfile: 'default',
+ recentsLimit: 20,
+ recentsExclude: [],
+ cronLimit: 50,
+ messagingLimit: 100,
+ messagingExclude: []
+ })
+
+ expect(result.recents.profiles_truncated).toEqual({ default: true })
+ })
+
it('falls back to the per-slice endpoint when the batched route 404s on an older backend', async () => {
const row = (id: string) => ({ id, title: id, profile: 'default' })
diff --git a/tests/hermes_cli/test_profiles_sidebar_scope.py b/tests/hermes_cli/test_profiles_sidebar_scope.py
index 5b5f4f6aab6..4bf1b95a53a 100644
--- a/tests/hermes_cli/test_profiles_sidebar_scope.py
+++ b/tests/hermes_cli/test_profiles_sidebar_scope.py
@@ -256,3 +256,39 @@ class TestCrossProfileProjectTree:
# The healthy profile's tree still lands; only the broken one drops out.
assert "Healthy" in [project["label"] for project in payload["projects"]]
assert [project["sessionCount"] for project in payload["projects"] if project["isNoProject"]] == [1]
+
+
+class TestSidebarTruncation:
+
+ def test_pinned_rows_inside_the_window_still_report_more_on_disk(self, client, profiles_on_disk):
+ # Regression for #81484: the window is a LIMIT page by recency, so a
+ # pin among the newest rows takes a slot. Discounting pins reported 18
+ # < 20 and the sidebar never offered "Load more" for the older rows.
+ from hermes_state import SessionDB
+
+ home = profiles_on_disk["default"]
+ params = {"recents_profile": "default", "recents_limit": 4}
+
+ def truncated():
+ payload = client.get("/api/profiles/sessions/sidebar", params=params).json()
+ return len(payload["recents"]["sessions"]), payload["recents"]["profiles_truncated"]
+
+ for index in range(3):
+ _seed_session(home, f"s-{index}", source="desktop")
+ db = SessionDB(db_path=home / "state.db")
+ try:
+ assert db.set_session_pinned("s-2", True)
+ finally:
+ db.close()
+ # Short list: the pin is already on the page, nothing to back-fill, no "more".
+ assert truncated() == (3, {"default": False})
+
+ for index in range(3, 6):
+ _seed_session(home, f"s-{index}", source="desktop")
+ db = SessionDB(db_path=home / "state.db")
+ try:
+ assert db.set_session_pinned("s-5", True)
+ finally:
+ db.close()
+ # Six on disk, two pins among the newest four: a full window, more below it.
+ assert truncated() == (4, {"default": True})