fix(chat): disable unusable history pagination (#676)

When the initial REST page returns empty messages, hasOlderMessages
was still set to true (offset > 0), causing an infinite loop of empty
load-more requests. Guard with && chatMessages.isNotEmpty().

Co-authored-by: M57 <Hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-07-22 12:09:29 +03:00
1 parent 0edb67338d
commit 56de3323f0
2 files changed
+50 -1

No files matched your search

@@ -1676,4 +1676,53 @@ class ChatViewModelTest {
assertNull(viewModel.uiState.value.errorMessage)
verify { HermesWsClient.disconnect() }
}
// ── History pagination guard (issue #674) ───────────────────────────────
/**
* When the initial REST page returns empty messages, hasOlderMessages
* must be false — otherwise the UI shows a load-more button that fetches
* the same empty page again, creating an infinite loop.
*/
@Test
fun testEmptyInitialRestPage_disablesOlderPagination() =
runTest {
val (viewModel, _) = createViewModelWithSession()
val mockApi = ApiClient.hermesApi
coEvery {
mockApi.getSessions(any(), any(), any())
} returns
retrofit2.Response.success(
com.m57.hermescontrol.data.model.SessionListResponse(
sessions =
listOf(
com.m57.hermescontrol.data.model.SessionInfo(
id = "session-456",
title = "Test",
message_count = 200,
),
),
total = 1,
),
)
coEvery {
mockApi.getSessionMessages("session-456", any(), any())
} returns
retrofit2.Response.success(
com.m57.hermescontrol.data.model.SessionMessagesResponse(
messages = emptyList(),
),
)
viewModel.switchSession("session-456")
advanceUntilIdle()
assertFalse(
"hasOlderMessages must be false when initial page is empty",
viewModel.uiState.value.hasOlderMessages,
)
assertTrue(viewModel.uiState.value.messages.isEmpty())
assertFalse(viewModel.uiState.value.isLoading)
}
}