Merge branch 'main' into chat-hide-notice-timeout

This commit is contained in:
2026-10-18 23:29:59 +01:00
69 changed files with 2662 additions and 1098 deletions
@@ -13,6 +13,8 @@ import net.awan.pipelines.data.protocol.ChatPromptRequest
import net.awan.pipelines.data.protocol.ChatProtocol
import net.awan.pipelines.data.protocol.ChatQuery
import net.awan.pipelines.data.protocol.ChatSession
import net.awan.pipelines.data.protocol.ChatShellOutputPage
import net.awan.pipelines.data.protocol.ChatShell
import net.awan.pipelines.data.protocol.Message
import net.awan.pipelines.data.protocol.Graph
import net.awan.pipelines.data.protocol.PipelineDetail
@@ -312,6 +314,22 @@ class PipelinesRepository(
return response.chatHistory ?: ChatHistoryPage(messages = response.chatMessages ?: emptyList())
}
/** Reads one bounded page from a verified, currently observable shell. */
suspend fun chatShellOutput(sessionId: String, shellId: String, cursor: Long = 0, limit: Int = ChatProtocol.SHELL_OUTPUT_LIMIT): ChatShellOutputPage {
if (sessionId.isBlank() || shellId.isBlank()) throw ProtocolException("Select a shell first.")
if (cursor < 0 || limit <= 0 || limit > ChatProtocol.SHELL_OUTPUT_LIMIT) {
throw ProtocolException("Shell output bounds are invalid.")
}
return client.call(ChatProtocol.shellOutputRequest(sessionId, shellId, cursor, limit)).chatShellOutput
?: throw ProtocolException("The server returned no shell output page.")
}
/** Lists currently observed shells owned by this operator chat session. */
suspend fun chatShells(sessionId: String): List<ChatShell> {
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
return client.call(ChatProtocol.shellsRequest(sessionId)).chatShells ?: emptyList()
}
/**
* Attaches this connection to [sessionId]'s shared live stream, so it sees
* every frame any client's turn produces — the other devices' prompts and the
@@ -2,6 +2,8 @@ package net.awan.pipelines.data.protocol
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
@@ -201,6 +203,27 @@ data class ChatShell(
val exit: Int? = null,
)
@Serializable
@OptIn(ExperimentalSerializationApi::class)
data class ChatShellOutputQuery(
@SerialName("session_id") val sessionId: String = "",
@SerialName("shell_id") val shellId: String = "",
@EncodeDefault(EncodeDefault.Mode.ALWAYS)
val cursor: Long = 0,
@EncodeDefault(EncodeDefault.Mode.ALWAYS)
val limit: Int = ChatProtocol.SHELL_OUTPUT_LIMIT,
)
@Serializable
data class ChatShellOutputPage(
val shell: ChatShell = ChatShell(),
val output: String = "",
val cursor: Long = 0,
val size: Long = 0,
val truncated: Boolean = false,
val unavailable: Boolean = false,
)
@Serializable
data class ChatStep(
val status: String = "",
@@ -282,6 +305,7 @@ object ChatProtocol {
const val SHELL_RUNNING = "running"
const val SHELL_EXITED = "exited"
const val SHELL_OUTPUT_LIMIT = 64 * 1024
/**
* A prompt another client sent, echoed live to this client so it appears in
@@ -359,6 +383,15 @@ object ChatProtocol {
fun interruptRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId))
fun shellOutputRequest(sessionId: String, shellId: String, cursor: Long = 0, limit: Int = SHELL_OUTPUT_LIMIT): Message =
Message(
type = Protocol.CHAT_SHELL_OUTPUT,
chatShellOutputQuery = ChatShellOutputQuery(sessionId, shellId, cursor, limit),
)
fun shellsRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_SHELLS, chatQuery = ChatQuery(sessionId = sessionId))
/**
* The `chat_close` frame that finishes [sessionId]: the server stops any
* running turn (through the same interrupt) and records the session closed on
@@ -79,6 +79,8 @@ object Protocol {
// The operator's directory choices for a new chat (home first, then the
// directories of previous operator sessions, most recently used first).
const val CHAT_DIRECTORIES = "chat_directories"
const val CHAT_SHELLS = "chat_shells"
const val CHAT_SHELL_OUTPUT = "chat_shell_output"
// Server-pushed frames with no matching request.
const val CHAT_EVENT = "chat_event"
const val CHAT_PERMISSION = "chat_permission"
@@ -712,4 +714,7 @@ data class Message(
// close/reopen requests themselves ride on chat_query like chat_interrupt.
@SerialName("chat_close") val chatClose: ChatCloseResult? = null,
@SerialName("chat_directories") val chatDirectories: List<String>? = null,
@SerialName("chat_shell_output_query") val chatShellOutputQuery: ChatShellOutputQuery? = null,
@SerialName("chat_shells") val chatShells: List<ChatShell>? = null,
@SerialName("chat_shell_output") val chatShellOutput: ChatShellOutputPage? = null,
)
@@ -34,7 +34,6 @@ import net.awan.pipelines.data.protocol.Protocol
import net.awan.pipelines.data.protocol.RunDetail
import net.awan.pipelines.data.protocol.RunEventFrame
import net.awan.pipelines.data.protocol.SearchResponse
import net.awan.pipelines.data.protocol.SessionEvidence
import net.awan.pipelines.data.protocol.Template
import net.awan.pipelines.data.transport.ConnectionState
import net.awan.pipelines.data.transport.ServerUrl
@@ -119,9 +118,6 @@ class AppViewModel(
private val _runDetail = MutableStateFlow(LoadState<RunDetail>())
val runDetail: StateFlow<LoadState<RunDetail>> = _runDetail.asStateFlow()
private val _evidence = MutableStateFlow(LoadState<List<SessionEvidence>>())
val evidence: StateFlow<LoadState<List<SessionEvidence>>> = _evidence.asStateFlow()
/**
* Whether the live run stream is delivering pushes. Shown as the small
* "live"/"reconnecting" badge in the runs list and the run detail so a view
@@ -794,8 +790,6 @@ class AppViewModel(
}
}
fun loadEvidence(id: Long) = load(_evidence) { repository.getRunEvidence(id) }
/** Fetches an artifact's bytes for an inline image preview; null on failure. */
suspend fun fetchArtifactBytes(url: String): ByteArray? =
runCatching { repository.fetchArtifactBytes(url) }.getOrNull()
@@ -865,14 +859,6 @@ class AppViewModel(
}
}
/**
* Drops any previously loaded evidence so a different run never shows the
* previous run's records. Evidence is then fetched on demand, never polled.
*/
fun resetEvidence() {
_evidence.value = LoadState()
}
/**
* Loads a run on demand (opening it, or after a manual cancel/retry).
* [silent] keeps the current content without a loading flash while it is
@@ -304,7 +304,9 @@ fun searchTarget(hit: SearchResult): SearchTarget? = when {
fun searchFieldSection(field: String): Int = when (field) {
"input" -> 2
"output" -> 3
"evidence", "transcript" -> 4
// Evidence was a retired run-detail tab. Keep old search hits safe by
// opening Summary rather than accidentally selecting Timeline.
"evidence", "transcript" -> 0
else -> 0
}
@@ -20,8 +20,9 @@ const val MAX_PANE_DEPTH = 3
/**
* The saved pane-stack selection: which pane is rightmost, which item (0 = none),
* its pipeline/run version, which detail section (page) is showing, which
* stage/visit the stage pane is on and, when a stage section is open, its key.
* its pipeline/run version, which detail section (page) is showing and its
* stable tab key, which stage/visit the stage pane is on and, when a stage
* section is open, its key.
* Every field is a primitive, so the state round-trips through a Bundle cheaply
* and survives rotation, configuration change and process death.
*
@@ -36,6 +37,7 @@ data class PaneSelection(
val stageKey: String? = null,
val stageVisit: Int = 0,
val sectionKey: String? = null,
val detailTabKey: String? = null,
) {
/** How many panes are stacked: 0 list, 1 detail, 2 stage, 3 section. */
val depth: Int
@@ -105,6 +107,7 @@ internal fun encodePaneSelection(selection: PaneSelection): List<Any> = listOf(
selection.stageKey ?: "",
selection.stageVisit,
selection.sectionKey ?: "",
selection.detailTabKey ?: "",
)
/** Restores a [PaneSelection] encoded by [encodePaneSelection]. */
@@ -116,6 +119,7 @@ internal fun decodePaneSelection(encoded: List<Any>): PaneSelection = PaneSelect
stageKey = (encoded[4] as String).takeIf { it.isNotEmpty() },
stageVisit = encoded[5] as Int,
sectionKey = (encoded[6] as String).takeIf { it.isNotEmpty() },
detailTabKey = encoded.getOrNull(7)?.let { it as String }?.takeIf { it.isNotEmpty() },
)
/**
@@ -89,6 +89,13 @@ internal val destinations = listOf(
TopDestination("settings", "Settings", Icons.Default.Settings),
)
/** The home route remains beneath top-level navigation, so Back returns to Runs. */
internal const val HOME_ROUTE = "runs"
/** Returning to home clears the accumulated top-level stack; other destinations keep it. */
internal fun topLevelPopUpToHomeInclusive(destination: String): Boolean =
destination == HOME_ROUTE
/**
* Whether [route] is the current destination. Detail panes are no longer
* separate routes (they are saved state inside a destination), so this is a
@@ -210,14 +217,14 @@ fun PipelinesApp(
is SearchTarget.Pipeline -> {
pipelineSelection = PaneSelection(MasterPane.Detail, target.pipelineId, target.version)
navController.navigate("pipelines") {
popUpTo("pipelines") { inclusive = false }
popUpTo(HOME_ROUTE) { inclusive = false }
launchSingleTop = true
}
}
is SearchTarget.Run -> {
runSelection = PaneSelection(MasterPane.Detail, target.runId)
runSearchNav = target.takeIf { it.sequence > 0 }
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
}
null -> Unit
}
@@ -231,7 +238,7 @@ fun PipelinesApp(
val openRunFromAttention: (Long) -> Unit = { runId ->
vm.arrivedAtRun(runId)
runSelection = PaneSelection(pane = MasterPane.Detail, itemId = runId)
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
}
// A deep link (or the notification's click action) opens its run once. The
@@ -274,7 +281,9 @@ fun PipelinesApp(
val onNavigate: (TopDestination) -> Unit = { destination ->
if (currentRoute != destination.route) {
navController.navigate(destination.route) {
popUpTo("pipelines") { inclusive = destination.route == "pipelines" }
popUpTo(HOME_ROUTE) {
inclusive = topLevelPopUpToHomeInclusive(destination.route)
}
launchSingleTop = true
}
}
@@ -317,7 +326,7 @@ fun PipelinesApp(
)
NavHost(
navController = navController,
startDestination = "pipelines",
startDestination = HOME_ROUTE,
// While the banner is visible it owns the status-bar inset, so
// the inner app bars below must not apply it a second time.
modifier = Modifier
@@ -344,11 +353,11 @@ fun PipelinesApp(
pane = MasterPane.Detail,
itemId = runId,
)
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
},
)
}
composable("runs") {
composable(HOME_ROUTE) {
RunsDestination(
vm = vm,
wide = wide,
@@ -11,8 +11,8 @@ import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.flow.collect
import net.awan.pipelines.ui.components.SlidingPaneStack
import net.awan.pipelines.ui.components.clampTabIndex
import net.awan.pipelines.ui.components.rememberPaneContent
import net.awan.pipelines.ui.components.runDetailTabIndex
import net.awan.pipelines.ui.components.runDetailTabs
import net.awan.pipelines.ui.graph.RunStagePane
import net.awan.pipelines.ui.screens.RunDetailScreen
@@ -91,8 +91,15 @@ internal fun RunsDestination(
vm = vm,
runId = itemId,
onBack = onBack,
selectedSection = clampTabIndex(sectionIndex, runDetailTabs.size),
onSelectSection = { onSelectionChange(selection.copy(sectionIndex = it)) },
selectedSection = runDetailTabIndex(selection.detailTabKey, sectionIndex),
onSelectSection = { index ->
onSelectionChange(
selection.copy(
sectionIndex = index,
detailTabKey = runDetailTabs[index].key,
),
)
},
modifier = paneModifier,
wide = wide,
onOpenStage = { key, visit ->
@@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.FactCheck
import androidx.compose.material.icons.automirrored.filled.Input
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.automirrored.filled.Send
@@ -63,10 +62,25 @@ val runDetailTabs: List<DetailTab> = listOf(
DetailTab("graph", "Graph", Icons.Default.Hub),
DetailTab("input", "Input", Icons.AutoMirrored.Filled.Input),
DetailTab("output", "Output", Icons.AutoMirrored.Filled.Send),
DetailTab("evidence", "Evidence", Icons.AutoMirrored.Filled.FactCheck),
DetailTab("steps", "Timeline", Icons.AutoMirrored.Filled.List),
)
/**
* Resolves a run-detail selection from its stable [key], falling back to its
* index when it was produced by this version of the app. Saved selections from
* before Evidence was removed use the old index order: Evidence (4) deliberately
* returns to Summary and Timeline (5) moves to its new last index.
*/
fun runDetailTabIndex(key: String?, index: Int): Int {
val keyedIndex = key?.let { selectedKey -> runDetailTabs.indexOfFirst { it.key == selectedKey } }
if (keyedIndex != null && keyedIndex >= 0) return keyedIndex
return when (index) {
4 -> 0
5 -> runDetailTabs.lastIndex
else -> clampTabIndex(index, runDetailTabs.size)
}
}
/** Pipeline-detail tabs, Summary first (the version list lives inside it). */
val pipelineDetailTabs: List<DetailTab> = listOf(
DetailTab("summary", "Summary", Icons.Default.Info),
@@ -40,7 +40,6 @@ import net.awan.pipelines.ui.components.LoadPhase
import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.PaneIdentity
import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.clampTabIndex
import net.awan.pipelines.ui.components.detailLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.rememberPaneContent
@@ -72,7 +71,6 @@ fun RunDetailScreen(
) {
val state by vm.runDetail.collectAsStateWithLifecycle()
val runsState by vm.runs.collectAsStateWithLifecycle()
val evidenceState by vm.evidence.collectAsStateWithLifecycle()
val configuredServerUrl by vm.configuredServerUrl.collectAsStateWithLifecycle()
val runStream by vm.runStream.collectAsStateWithLifecycle()
var confirmCancel by remember { mutableStateOf(false) }
@@ -88,11 +86,7 @@ fun RunDetailScreen(
// Reaching a run clears its notification, whichever path opened it (the
// notification's own tap, the attention list, the runs list or a search).
vm.arrivedAtRun(runId)
// Scope evidence to this run: drop the previous run's records, then fetch
// this run's evidence once (on demand; live pushes carry no evidence).
vm.resetEvidence()
vm.loadRun(runId)
vm.loadEvidence(runId)
}
val run = state.data?.takeIf { it.id == runId }
@@ -115,7 +109,7 @@ fun RunDetailScreen(
val candidateArtifacts = remember(artifactGroups) {
artifactGroups.flatMap { it.artifacts }.distinctBy { it.url }
}
val summaryTab = runDetailTabs.getOrNull(clampTabIndex(selectedSection, runDetailTabs.size))?.key
val summaryTab = runDetailTabs.getOrNull(selectedSection)?.key
// A covered pane shows its compact identity only; the tab rail, timeline and
// graphs must never be drawn squeezed into the peek strip. The run belongs to
@@ -268,13 +262,6 @@ fun RunDetailScreen(
wide = wide,
modifier = contentModifier,
)
"evidence" -> RunEvidenceTab(
evidenceState = evidenceState,
steps = shownRun.steps,
onLoadEvidence = { vm.loadEvidence(runId) },
wide = wide,
modifier = contentModifier,
)
else -> RunTimelineTab(
run = shownRun,
wide = wide,
@@ -1,136 +0,0 @@
package net.awan.pipelines.ui.screens
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import net.awan.pipelines.data.protocol.RunStep
import net.awan.pipelines.data.protocol.SessionEvidence
import net.awan.pipelines.ui.LoadState
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S
import net.awan.pipelines.ui.theme.SPACING_XS
import net.awan.pipelines.ui.theme.pipelinesText
/** One inner collapsible section per session-evidence entry (data block inside). */
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun RunEvidenceTab(
evidenceState: LoadState<List<SessionEvidence>>,
steps: List<RunStep>,
onLoadEvidence: () -> Unit,
wide: Boolean,
modifier: Modifier,
) {
val text = pipelinesText()
val evidence = evidenceState.data.orEmpty()
val expansion = rememberSectionExpansion(evidence)
// Correlate each evidence record with its step once per data change, by the
// protocol's shared sequence, never per recomposition.
val stepBySequence = remember(steps) { steps.associateBy { it.sequence } }
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "evidence-reload") {
Row(
modifier = Modifier.fillMaxWidth().padding(horizontal = SPACING_L),
horizontalArrangement = Arrangement.spacedBy(SPACING_S),
) {
OutlinedButton(onClick = onLoadEvidence, enabled = !evidenceState.loading) {
Text(if (evidenceState.loading) "Loading…" else "Reload session evidence")
}
}
}
when {
evidenceState.loading && evidenceState.data == null -> item(key = "evidence-loading") {
Text(
"Loading session evidence…",
style = text.meta,
modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S),
)
}
evidenceState.error != null -> item(key = "evidence-error") {
Text(
evidenceState.error!!,
color = MaterialTheme.colorScheme.error,
style = text.meta,
modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S),
)
}
evidenceState.loaded && evidence.isEmpty() -> item(key = "evidence-empty") {
Text(
"No session evidence recorded.",
style = text.meta,
modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S),
)
}
else -> evidence.forEach { record ->
val sectionKey = "evidence-${record.sequence}-${record.sessionId}"
collapsibleSection(
title = evidenceSectionTitle(record, stepBySequence[record.sequence]),
key = sectionKey,
expanded = expansion.isExpanded(sectionKey),
onToggle = { expansion.toggle(sectionKey) },
) {
EvidenceDetails(record, Modifier.padding(horizontal = SPACING_L, vertical = SPACING_XS))
}
}
}
}
}
}
/**
* A self-describing evidence-section title: the step, and when the matching
* step is known the stage and visit, plus the backend (or, when absent, the
* session id) identity. Never a bare index; falls back gracefully when the
* record cannot be correlated with a step.
*/
internal fun evidenceSectionTitle(record: SessionEvidence, step: RunStep?): String {
val parts = ArrayList<String>()
if (record.sequence > 0) parts += "step ${record.sequence}"
if (step != null) {
val visit = step.control?.visit?.takeIf { it > 0 }
val stage = buildString {
if (step.stage.isNotBlank()) append(step.stage)
if (visit != null) {
if (isNotEmpty()) append(' ')
append("visit $visit")
}
}
if (stage.isNotBlank()) parts += stage
}
val identity = record.backend.ifBlank { record.sessionId }
if (identity.isNotBlank()) parts += identity
return if (parts.isEmpty()) "Evidence" else "Evidence - " + parts.joinToString(", ")
}
/** A session-evidence entry's fields plus its data/diagnostic code blocks. */
@Composable
private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modifier) {
val text = pipelinesText()
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(SPACING_XS)) {
if (evidence.sessionId.isNotBlank()) Text("session ${evidence.sessionId}", style = text.mono)
if (evidence.backend.isNotBlank()) Text("backend ${evidence.backend}", style = text.meta)
if (evidence.directory.isNotBlank()) Text("directory ${evidence.directory}", style = text.meta)
CodeBlock("Diagnostic", evidence.diagnostic.orEmpty())
CodeBlock("Data", evidence.data.orEmpty())
}
}
@@ -405,6 +405,44 @@ class ChatProtocolTest {
assertEquals(1792112367999L, decodedReply.chatClose!!.closedAt)
}
@Test
fun shellOutputRequestAndPageUseBoundedWireNames() {
val defaults = ChatProtocol.shellOutputRequest("ses_1", "sh_1")
val defaultJson = PipelinesJson.encodeToString(Message.serializer(), defaults)
assertTrue(defaultJson.contains("\"cursor\":0"))
assertTrue(defaultJson.contains("\"limit\":65536"))
val decodedDefaults = PipelinesJson.decodeFromString(Message.serializer(), defaultJson)
assertEquals(0L, decodedDefaults.chatShellOutputQuery!!.cursor)
assertEquals(ChatProtocol.SHELL_OUTPUT_LIMIT, decodedDefaults.chatShellOutputQuery!!.limit)
val request = ChatProtocol.shellOutputRequest("ses_1", "sh_1", 7, 128)
val decoded = PipelinesJson.decodeFromString(Message.serializer(), PipelinesJson.encodeToString(Message.serializer(), request))
assertEquals(Protocol.CHAT_SHELL_OUTPUT, decoded.type)
assertEquals("ses_1", decoded.chatShellOutputQuery!!.sessionId)
assertEquals("sh_1", decoded.chatShellOutputQuery!!.shellId)
assertEquals(7L, decoded.chatShellOutputQuery!!.cursor)
assertEquals(128, decoded.chatShellOutputQuery!!.limit)
val page = PipelinesJson.decodeFromString(Message.serializer(), """
{"type":"chat_shell_output","chat_shell_output":{"shell":{"id":"sh_1","status":"running"},"output":"marker","cursor":13,"size":20,"truncated":true}}
""".trimIndent())
assertEquals("marker", page.chatShellOutput!!.output)
assertTrue(page.chatShellOutput!!.truncated)
}
@Test
fun shellsRequestUsesSessionQueryAndPreservesListWireName() {
val request = ChatProtocol.shellsRequest("ses_1")
val decoded = PipelinesJson.decodeFromString(Message.serializer(), PipelinesJson.encodeToString(Message.serializer(), request))
assertEquals(Protocol.CHAT_SHELLS, decoded.type)
assertEquals("ses_1", decoded.chatQuery!!.sessionId)
val reply = PipelinesJson.decodeFromString(Message.serializer(), """
{"type":"chat_shells","chat_shells":[{"id":"sh_1","status":"running","command":"printf marker"}]}
""".trimIndent())
assertEquals("sh_1", reply.chatShells!!.single().id)
assertEquals(ChatProtocol.SHELL_RUNNING, reply.chatShells.single().status)
}
private fun toolDuration(part: ChatPart): Long? {
val time = part.time ?: return null
return time.completed - time.ran
@@ -285,8 +285,8 @@ class OmniSearchResultsTest {
fun aTextFieldTargetOpensTheRunDetailSectionHoldingIt() {
assertEquals(2, searchFieldSection("input"))
assertEquals(3, searchFieldSection("output"))
assertEquals(4, searchFieldSection("evidence"))
assertEquals(4, searchFieldSection("transcript"))
assertEquals(0, searchFieldSection("evidence"))
assertEquals(0, searchFieldSection("transcript"))
assertEquals(0, searchFieldSection("other"))
assertEquals(
@@ -146,6 +146,14 @@ class PaneStateTest {
}
}
@Test
fun legacySavedSelectionWithoutATabKeyRemainsReadable() {
assertEquals(
PaneSelection(MasterPane.Detail, 9L, 2, 4),
decodePaneSelection(listOf("Detail", 9L, 2, 4, "", 0, "")),
)
}
@Test
fun encodedPayloadIsPrimitivesOnly() {
// Process-death restoration stays small: only Strings, ints and a long,
@@ -160,13 +168,13 @@ class PaneStateTest {
stageVisit = 4,
),
)
assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4, ""), encoded)
assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4, "", ""), encoded)
assertEquals(
PaneSelection(MasterPane.Stage, 9L, 2, 1, "planner", 4),
decodePaneSelection(encoded),
)
assertEquals(
listOf("Detail", 9L, 2, 1, "", 0, ""),
listOf("Detail", 9L, 2, 1, "", 0, "", ""),
encodePaneSelection(PaneSelection(MasterPane.Detail, 9L, 2, 1)),
)
val section = PaneSelection(
@@ -178,7 +186,7 @@ class PaneStateTest {
stageVisit = 4,
sectionKey = "artifacts",
)
assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts"), encodePaneSelection(section))
assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts", ""), encodePaneSelection(section))
assertEquals(section, decodePaneSelection(encodePaneSelection(section)))
}
}
@@ -13,6 +13,19 @@ import org.junit.Test
class PipelinesNavTest {
@Test
fun runsIsTheHomeRouteForColdLaunchAndTopLevelBack() {
assertEquals("runs", HOME_ROUTE)
}
@Test
fun returningToHomeIsTheOnlyTopLevelNavigationThatClearsHome() {
assertTrue(topLevelPopUpToHomeInclusive(HOME_ROUTE))
assertFalse(topLevelPopUpToHomeInclusive("pipelines"))
assertFalse(topLevelPopUpToHomeInclusive("chat"))
assertFalse(topLevelPopUpToHomeInclusive("settings"))
}
@Test
fun thePillDoesNotHoldTemplates() {
// Templates is configuration and moved to the Settings page; the pill keeps
@@ -12,11 +12,11 @@ class DetailTabsTest {
fun runDetailTabsStartWithSummaryAndCoverEverySection() {
assertEquals("summary", runDetailTabs.first().key)
assertEquals(
listOf("summary", "graph", "input", "output", "evidence", "steps"),
listOf("summary", "graph", "input", "output", "steps"),
runDetailTabs.map { it.key },
)
assertEquals(
listOf("Summary", "Graph", "Input", "Output", "Evidence", "Timeline"),
listOf("Summary", "Graph", "Input", "Output", "Timeline"),
runDetailTabs.map { it.title },
)
}
@@ -39,9 +39,9 @@ class DetailTabsTest {
@Test
fun clampTabIndexKeepsAValidSelection() {
assertEquals(0, clampTabIndex(0, 6))
assertEquals(5, clampTabIndex(5, 6))
assertEquals(3, clampTabIndex(3, 6))
assertEquals(0, clampTabIndex(0, 5))
assertEquals(4, clampTabIndex(4, 5))
assertEquals(3, clampTabIndex(3, 5))
}
@Test
@@ -52,6 +52,15 @@ class DetailTabsTest {
assertEquals(0, clampTabIndex(1, 0))
}
@Test
fun runDetailTabSelectionUsesStableKeysAndSafelyMigratesLegacyEvidence() {
assertEquals(4, runDetailTabIndex("steps", 5))
assertEquals(0, runDetailTabIndex("evidence", 4))
assertEquals(0, runDetailTabIndex(null, 4))
assertEquals(4, runDetailTabIndex(null, 5))
assertEquals(4, runDetailTabIndex("steps", 4))
}
@Test
fun sectionsStartCollapsedAndToggleIsRemembered() {
val state = SectionExpansionState(mutableStateOf<Set<String>>(emptySet()))
@@ -2,7 +2,6 @@ package net.awan.pipelines.ui.screens
import net.awan.pipelines.data.protocol.ControlEvidence
import net.awan.pipelines.data.protocol.RunStep
import net.awan.pipelines.data.protocol.SessionEvidence
import net.awan.pipelines.data.protocol.StageArtifact
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -136,23 +135,4 @@ class TimelineTest {
assertTrue(fieldSectionTitle("", "input").isNotBlank())
}
@Test
fun evidenceSectionTitleDescribesStepStageVisitAndIdentity() {
val step = RunStep(
sequence = 4,
stage = "ui_reviewer",
control = ControlEvidence(visit = 1),
)
assertEquals(
"Evidence - step 4, ui_reviewer visit 1, opencode",
evidenceSectionTitle(SessionEvidence(sequence = 4, backend = "opencode"), step),
)
// Unmatched evidence still names the step and falls back to the session id.
assertEquals(
"Evidence - step 4, sess-9",
evidenceSectionTitle(SessionEvidence(sequence = 4, sessionId = "sess-9"), null),
)
// Never a bare index and never empty, even with nothing to say.
assertEquals("Evidence", evidenceSectionTitle(SessionEvidence(), null))
}
}