fix(#686): implement robust history pagination (#687)

* fix(#686): implement robust history pagination

Honor server-returned offset, degrade gracefully on older servers, and parse JSON tool results.

* fix(ci): repair unit-test compilation and pagination test mocks

- Remove trailing blank line in SessionMessagesResponse.kt (ktlint)
- Replace unresolved io.mockk.eq/coAnswers usage in ChatViewModelTest with
  an ordered-call counter inside coAnswers, which compiles and runs on
  MockK 1.14.11 (eq is a matcher-scope member, not a top-level import)
- Align HermesApiServiceMockWebServerTest with the PR's JsonElement content
  model (contentText) and the new include_compacted=true default query param

All unit tests pass locally with the ByteBuddy agent preload.

---------

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-07-23 00:30:48 +03:00
1 parent 34ba93901b
commit def122ab58
5 files changed
+294 -16

No files matched your search

@@ -247,11 +247,11 @@ class HermesApiServiceMockWebServerTest {
assertEquals(3, messages.size)
assertEquals("user", messages[0].role)
assertEquals("Hello Hermes", messages[0].content)
assertEquals("Hello Hermes", messages[0].contentText)
assertEquals("1718000000", messages[0].timestampText)
assertEquals("assistant", messages[1].role)
assertEquals("Hi! How can I help?", messages[1].content)
assertEquals("Hi! How can I help?", messages[1].contentText)
assertEquals("tool", messages[2].role)
assertEquals("tool_execution", messages[2].type)
@@ -270,11 +270,68 @@ class HermesApiServiceMockWebServerTest {
assertTrue(response.isSuccessful)
assertEquals(
"/api/sessions/desktop/session/messages?limit=150&offset=300",
"/api/sessions/desktop/session/messages?limit=150&offset=300&include_compacted=true",
mockServer.takeRequest().path,
)
}
@Test
fun getSessionMessages_withJsonObjectToolResult_deserializesSuccessfully() =
runBlocking {
mockServer.enqueue(
MockResponse()
.setResponseCode(200)
.setBody(
"""
{
"messages": [
{
"role": "tool",
"content": {"status": "ok", "items": [1, 2]},
"type": "tool_result"
}
]
}
""".trimIndent(),
),
)
val response = api.getSessionMessages("test-session-id")
assertTrue(response.isSuccessful)
val body = response.body()
assertNotNull(body)
assertEquals(1, body!!.messages.size)
assertEquals("tool", body.messages[0].role)
assertEquals("{\"status\":\"ok\",\"items\":[1,2]}", body.messages[0].contentText)
}
@Test
fun getSessionMessages_withOffsetAndTotal_deserializesPaginationFields() =
runBlocking {
mockServer.enqueue(
MockResponse()
.setResponseCode(200)
.setBody(
"""
{
"messages": [],
"offset": 45,
"total": 120
}
""".trimIndent(),
),
)
val response = api.getSessionMessages("test-session-id")
assertTrue(response.isSuccessful)
val body = response.body()
assertNotNull(body)
assertEquals(45, body!!.offset)
assertEquals(120, body.total)
}
@Test
fun getSessionMessages_withNullRole_doesNotCrash() =
runBlocking {
@@ -303,7 +360,7 @@ class HermesApiServiceMockWebServerTest {
assertNotNull(body)
assertEquals(1, body!!.messages.size)
assertNull(body.messages[0].role)
assertEquals("Plain content", body.messages[0].content)
assertEquals("Plain content", body.messages[0].contentText)
assertNull(body.messages[0].timestamp)
}
@@ -383,7 +440,7 @@ class HermesApiServiceMockWebServerTest {
val request = mockServer.takeRequest()
assertEquals(
"path should contain the session ID with slashes preserved",
"/api/sessions/session/with/slashes/messages?offset=0",
"/api/sessions/session/with/slashes/messages?offset=0&include_compacted=true",
request.path,
)
}