fix(#1379): send only contract params in subagent.tail (#1383)

This commit is contained in:
m57 authored and GitHub committed 2026-09-29 17:04:10 +03:00
1 parent aac42032fb
commit 1dd8d2138d
4 files changed
+46 -15

No files matched your search

@@ -3,6 +3,14 @@ package com.m57.hermescontrol.data.ws
import com.m57.hermescontrol.data.model.SubagentListItem
import com.m57.hermescontrol.data.model.SubagentListResponse
import com.m57.hermescontrol.data.model.SubagentTailResponse
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.slot
import io.mockk.unmockkAll
import io.mockk.verify
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
@@ -11,6 +19,34 @@ import org.junit.Assert.assertTrue
import org.junit.Test
class SubagentRepositoryTest {
@After
fun tearDown() {
unmockkAll()
}
@Test
fun tailSubagentSendsExactlySessionIdAndSubagentId() {
// #1379: the contract forbids extra keys (max_bytes) and requires session_id.
val captured = slot<Map<String, Any>>()
mockkObject(HermesWsClient)
every { HermesWsClient.request(WsMethods.SUBAGENT_TAIL, capture(captured), any(), any()) } returns
CompletableDeferred<Any?>(mapOf("subagent_id" to "sub-1"))
runBlocking { SubagentRepository.tailSubagent("s1", "sub-1") }
assertEquals(mapOf<String, Any>("session_id" to "s1", "subagent_id" to "sub-1"), captured.captured)
}
@Test
fun tailSubagentSkipsTheCallWhenAnIdIsBlank() {
mockkObject(HermesWsClient)
runBlocking {
assertNull(SubagentRepository.tailSubagent("", "sub-1"))
assertNull(SubagentRepository.tailSubagent("s1", " "))
}
verify(exactly = 0) { HermesWsClient.request(any(), any(), any(), any()) }
}
@Test
fun testWsMethodsConstants() {
assertEquals("subagent.list", WsMethods.SUBAGENT_LIST)
@@ -448,7 +448,7 @@ class ChatSubagentsDelegateTest {
),
)
coEvery { mockRepository.tailSubagent("session-123", "sub-1", 16384) } returnsMany
coEvery { mockRepository.tailSubagent("session-123", "sub-1") } returnsMany
listOf(
SubagentTailResponse(subagentId = "sub-1", text = "Line 1\n", truncated = false),
SubagentTailResponse(subagentId = "sub-1", text = "Line 1\nLine 2\n", truncated = false),
@@ -485,7 +485,7 @@ class ChatSubagentsDelegateTest {
),
)
coEvery { mockRepository.tailSubagent("session-123", "sub-1", 16384) } returns
coEvery { mockRepository.tailSubagent("session-123", "sub-1") } returns
SubagentTailResponse(subagentId = "sub-1", text = "Finished output", truncated = false)
delegate.inspectSubagentTranscript("sub-1")
@@ -507,7 +507,7 @@ class ChatSubagentsDelegateTest {
advanceTimeBy(3000)
// Verify tailSubagent was called at most once or twice, not indefinitely
coVerify(atMost = 2) { mockRepository.tailSubagent("session-123", "sub-1", 16384) }
coVerify(atMost = 2) { mockRepository.tailSubagent("session-123", "sub-1") }
delegate.closeSubagentTranscript()
}
@@ -526,7 +526,7 @@ class ChatSubagentsDelegateTest {
),
)
coEvery { mockRepository.tailSubagent("session-123", "sub-1", 16384) } returns
coEvery { mockRepository.tailSubagent("session-123", "sub-1") } returns
SubagentTailResponse(subagentId = "sub-1", text = "Output")
delegate.inspectSubagentTranscript("sub-1")
@@ -553,7 +553,7 @@ class ChatSubagentsDelegateTest {
),
)
coEvery { mockRepository.tailSubagent("session-123", "sub-1", 16384) } throws
coEvery { mockRepository.tailSubagent("session-123", "sub-1") } throws
RuntimeException("Gateway connection error")
delegate.inspectSubagentTranscript("sub-1")
@@ -565,7 +565,7 @@ class ChatSubagentsDelegateTest {
assertFalse(transcript?.isLoading == true)
// Now recover on retry
coEvery { mockRepository.tailSubagent("session-123", "sub-1", 16384) } returns
coEvery { mockRepository.tailSubagent("session-123", "sub-1") } returns
SubagentTailResponse(subagentId = "sub-1", text = "Recovered logs")
delegate.retryTranscript()