diff --git a/android/README.md b/android/README.md index d8754c9b..2e0bee55 100644 --- a/android/README.md +++ b/android/README.md @@ -3840,3 +3840,85 @@ wrapping is asserted against an injected measurer, not rendered pixels; the whole-word guarantee therefore rests on `TextMeasurer` and the drawn `Text` using the same role and width, which is why both read `text.cardTitle` and the identity's own `SPACING_S` padding. + +## Stage sections open as their own pane, not inline (17 Oct 2026) + +The reported stage-screen defect is reproducible and this pass fixes it by +opening every stage section as its own pane and by laying a collapsible body out +in one column. `android/` only; nothing in the Pipelines server, its Go source, +the Docker/compose files or the installer was touched, no dependency was added +and no run was started from the app. + +- **The defect and its cause.** Expanding a stage section drew its rows stacked + at the top of the section: the section's content lambda emits one composable + per field (`fields.forEach { StageFieldRow(it) }`) straight into + `CollapsibleSectionBody`'s `AnimatedVisibility`. `AnimatedVisibility` lays out + a *single* child, so several siblings were placed on top of each other at the + section's origin instead of one below the next; the body took the height of its + tallest single row and showed only the last one, so the content did not sit + cleanly under — or under all of — its header. +- **Sections are panes.** The stage screen now keeps a **compact list** of its + section rows (`Artifacts`, `Output`, `Input`, `This run`, `Stage definition`) + and tapping one opens that section as the next pane of the stack — a + full-window screen over the stage on a narrow window, a panel to the stage + pane's right on a wide one — with its own `Scaffold`/`TopAppBar` named for the + section, its own scroll and its own top spacing. Back (the app bar, the gesture + or a peek) returns exactly one level, to the stage screen. `MasterPane` gained + the `Section` level (`MAX_PANE_DEPTH = 3`) and `PaneSelection.sectionKey` (a + primitive saved with the pane selection), so the open section survives rotation + and process death. +- **No trivial inline exceptions.** None of the five sections is kept inline: + each can hold an arbitrarily long value (the definition's prompt/output + contract, the input/output maps, the run evidence, the artifacts gallery), so + an inline body would both risk the layout with many rows and push the run + context off screen; one uniform rule keeps the screen predictable. +- **Rows read as navigation, not as disclosures.** The stage screen's section + rows go through the shared `SectionHeader` with `navigation = true`: the + chevron becomes the static forward arrow (`Icons.AutoMirrored.Filled + .KeyboardArrowRight`, mirrored for RTL) instead of a rotating disclosure + chevron, and the row announces as `Artifacts` with an `Open Artifacts` action + instead of `Artifacts, collapsed` / `Expand Artifacts`. Assistive tech is + therefore never told the row expands in place after it started opening a pane. + The disclosure rows (the run/pipeline detail lists) are unchanged. The + `rememberSectionExpansion` seed that existed only to start the stage pane's + definition expanded (`initiallyExpanded`) is gone with its last caller, so the + shared component no longer carries docs or a parameter for the removed inline + stage behaviour. +- **The shared body fix.** `CollapsibleSectionBody` now lays its content out in a + single full-width `Column`, so *any* collapsible section with more than one row + (it also backs the run/pipeline detail `collapsibleSection` lists) stacks its + rows under the header instead of overlapping them. +- **Semantics kept.** Sections start collapsed; the operator's choice — which + section is open, and the visit — is saved with the pane selection; and each + section's content is derived from the same pure `stageSectionSpecs` + (`stageDefinitionFields`/`runStepFields`/`evidenceFields`), so nothing shown + before is lost. The artifacts section keeps the shared + `ArtifactSelectionScaffold`. + +Verification (macOS, JDK 17 from Homebrew `openjdk@17`, +`ANDROID_HOME=/Users/alan/Library/Android/sdk`, cached Gradle 8.11.1, +`--no-daemon --offline`): + +- `gradle :app:testDebugUnitTest :app:assembleDebug --no-daemon --offline` → + `BUILD SUCCESSFUL` (`compileDebugKotlin` and `compileDebugUnitTestKotlin` + executed on the edited sources); the test-result XMLs aggregate to **303 tests, + 0 failures, 0 errors, 0 skipped** across 34 classes (`PaneStateTest` gained the + Section-level backStep, popTo, encode/decode and depth cases; + `StageDetailSheetTest` replaced the definition-expansion seed with the + `stageSectionSpecs` order/blank-section cases). The `navigation` affordance is + Compose UI semantics, which this module has no unit harness for, so it is + covered by compilation only, not by a test. +- `app/build/outputs/apk/debug/app-debug.apk` is 18,272,941 bytes, sha256 + `dccce3ca1a3c5acc724dec376709f694e11a29b68ffd85eae4d5114c4f8989a1`; it was + copied to + `~/.local/share/pipelines/data/artifacts/216/1/pipelines-debug-wip-dcd58b8.apk` + (`dcd58b8` = `git rev-parse --short HEAD`; the tree is uncommitted WIP on top + of it). `curl -sSI + http://10.0.0.249:8080/artifacts/216/1/pipelines-debug-wip-dcd58b8.apk` + returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`, + `Content-Length: 18272941`, matching the local file's size. + +Not verified in this pass: the on-device narrow/wide renders (a section opening +over the stage and returning, and the wide panel beside the stage pane) and any +screenshot of the former inline case — the brief keeps implementation +verification to the build and the unit tests, and visual review owns the device. diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt b/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt index aff1dfe5..99ff82d7 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt @@ -4,26 +4,26 @@ import androidx.compose.runtime.saveable.Saver /** * Which pane of the sliding stack is showing: the list (level 0), the selected - * item's detail (level 1) and, when a stage/node is open, the stage pane - * (level 2). On a wide window the panes stack left to right and share a fixed - * peek budget; on a narrow window only the topmost pane is visible and it fills - * the window. + * item's detail (level 1), the stage/node pane (level 2) and, when a stage + * section is opened, that section's pane (level 3). On a wide window the panes + * stack left to right and share a fixed peek budget; on a narrow window only the + * topmost pane is visible and it fills the window. */ -enum class MasterPane { List, Detail, Stage } +enum class MasterPane { List, Detail, Stage, Section } /** - * The declared bound on the stack: list (0), detail (1), stage (2). The stack can - * never grow deeper than this; selecting a different stage or list item replaces - * the rightmost pane instead of pushing a new level. + * The declared bound on the stack: list (0), detail (1), stage (2), section (3). + * The stack can never grow deeper than this; selecting a different stage, list + * item or section replaces the rightmost pane instead of pushing a new level. */ -const val MAX_PANE_DEPTH = 2 +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, and which - * stage/visit the stage pane is on. Every field is a primitive, so the state - * round-trips through a Bundle cheaply and survives rotation, configuration - * change and process death. + * 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. + * Every field is a primitive, so the state round-trips through a Bundle cheaply + * and survives rotation, configuration change and process death. * * Geometry (peek width, insets, measured pane widths) is deliberately *not* part * of this model; it is derived from layout so nothing is hardcoded here. @@ -35,13 +35,15 @@ data class PaneSelection( val sectionIndex: Int = 0, val stageKey: String? = null, val stageVisit: Int = 0, + val sectionKey: String? = null, ) { - /** How many panes are stacked: 0 list, 1 detail, 2 stage. */ + /** How many panes are stacked: 0 list, 1 detail, 2 stage, 3 section. */ val depth: Int get() = when (pane) { MasterPane.List -> 0 MasterPane.Detail -> 1 MasterPane.Stage -> 2 + MasterPane.Section -> 3 } } @@ -55,29 +57,39 @@ sealed interface BackResult { } /** - * Exactly one pane level of Back. Inside the stage pane it steps back to the - * detail; inside the detail it steps back to the list; at the list it leaves the - * app. Sections are navigated only by their own tab row/pager, never by Back, so - * the peek tap and the Back button/gesture always pop the same single level. + * Exactly one pane level of Back. Inside a stage section it steps back to the + * stage pane; inside the stage pane it steps back to the detail; inside the + * detail it steps back to the list; at the list it leaves the app. The peek tap + * and the Back button/gesture therefore always pop the same single level. */ fun backStep(selection: PaneSelection): BackResult = when (selection.pane) { MasterPane.List -> BackResult.Exit MasterPane.Detail -> BackResult.Show(PaneSelection(pane = MasterPane.List)) MasterPane.Stage -> BackResult.Show( - selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0), + selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0, sectionKey = null), + ) + MasterPane.Section -> BackResult.Show( + selection.copy(pane = MasterPane.Stage, sectionKey = null), ) } /** * The selection after tapping the peek of the pane at [level]: every pane to its * right is closed. Level 0 (the list) shows a bare list; level 1 shows the same - * item's detail with no stage; a [level] at or beyond the current depth is a - * no-op (there is nothing to its right). Peeks exist only on a wide window; - * narrow windows use Back/gesture for the same one-level step. + * item's detail with no stage; level 2 shows the same item's stage with no + * section; a [level] at or beyond the current depth is a no-op (there is nothing + * to its right). Peeks exist only on a wide window; narrow windows use + * Back/gesture for the same one-level step. */ fun popTo(selection: PaneSelection, level: Int): PaneSelection = when { level <= 0 -> PaneSelection() - level == 1 -> selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0) + level == 1 -> selection.copy( + pane = MasterPane.Detail, + stageKey = null, + stageVisit = 0, + sectionKey = null, + ) + level == 2 -> selection.copy(pane = MasterPane.Stage, sectionKey = null) else -> selection } @@ -92,6 +104,7 @@ internal fun encodePaneSelection(selection: PaneSelection): List = listOf( selection.sectionIndex, selection.stageKey ?: "", selection.stageVisit, + selection.sectionKey ?: "", ) /** Restores a [PaneSelection] encoded by [encodePaneSelection]. */ @@ -102,6 +115,7 @@ internal fun decodePaneSelection(encoded: List): PaneSelection = PaneSelect sectionIndex = encoded[3] as Int, stageKey = (encoded[4] as String).takeIf { it.isNotEmpty() }, stageVisit = encoded[5] as Int, + sectionKey = (encoded[6] as String).takeIf { it.isNotEmpty() }, ) /** diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt index 420f6f54..0c1a7e4f 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt @@ -237,7 +237,17 @@ private fun PipelineDestination( onPopTo = { level -> selection = popTo(selection, level) }, compactLabel = "Pipelines", compactIcon = Icons.Filled.AccountTree, - backContentDescription = { level -> if (level == 0) "Back to pipelines" else "Back to pipeline" }, + // Every covered pane in this stack (the list, or a pipeline's detail) carries + // a statistics block, so the region is sized for it and a single covered + // pane can show the last-run and average lines rather than only counts. + compactStats = true, + backContentDescription = { level -> + when (level) { + 0 -> "Back to pipelines" + 1 -> "Back to pipeline" + else -> "Back to stage" + } + }, pane = { level, covered, paneModifier -> when (level) { 0 -> PipelineListScreen( @@ -281,6 +291,33 @@ private fun PipelineDestination( pipelineId = itemId, version = version, stageKey = key, + openSection = null, + onOpenSection = { sectionKey -> + selection = selection.copy( + pane = MasterPane.Section, + sectionKey = sectionKey, + ) + }, + onBack = onBack, + wide = wide, + modifier = paneModifier, + covered = covered, + ) + } + 3 -> rememberPaneContent( + selection.sectionKey?.let { + Triple(selection.itemId, it, selection.stageKey) + }, + )?.let { (itemId, sectionKey, key) -> + // A closing section pane keeps the identity that opened it, so + // it renders its content until it is fully off-screen. + PipelineStagePane( + vm = vm, + pipelineId = itemId, + version = selection.itemVersion, + stageKey = key.orEmpty(), + openSection = sectionKey, + onOpenSection = {}, onBack = onBack, wide = wide, modifier = paneModifier, @@ -319,7 +356,18 @@ private fun RunsDestination( onPopTo = { level -> onSelectionChange(popTo(selection, level)) }, compactLabel = "Runs", compactIcon = Icons.Filled.History, - backContentDescription = { level -> if (level == 0) "Back to runs" else "Back to run" }, + // Every covered pane in this stack (the runs list, or a run's detail) carries + // a statistics block, so the region is sized for it and the runs list's + // counts and most-recent run are actually shown rather than dropped by the + // title-only tier. + compactStats = true, + backContentDescription = { level -> + when (level) { + 0 -> "Back to runs" + 1 -> "Back to run" + else -> "Back to stage" + } + }, pane = { level, covered, paneModifier -> when (level) { 0 -> RunHistoryScreen( @@ -359,6 +407,34 @@ private fun RunsDestination( runId = itemId, stageKey = key, visitIndex = visit, + openSection = null, + onOpenSection = { sectionKey -> + onSelectionChange( + selection.copy(pane = MasterPane.Section, sectionKey = sectionKey), + ) + }, + onVisitChange = { onSelectionChange(selection.copy(stageVisit = it)) }, + onBack = onBack, + wide = wide, + modifier = paneModifier, + covered = covered, + ) + } + 3 -> rememberPaneContent( + selection.sectionKey?.let { + Triple(selection.itemId, it, selection.stageKey) + }, + )?.let { (itemId, sectionKey, key) -> + // A closing section pane keeps the identity that opened it, so + // it renders its content until it is fully off-screen. + RunStagePane( + vm = vm, + runId = itemId, + stageKey = key.orEmpty(), + visitIndex = selection.stageVisit, + openSection = sectionKey, + onOpenSection = {}, + onVisitChange = { onSelectionChange(selection.copy(stageVisit = it)) }, onBack = onBack, wide = wide, modifier = paneModifier, diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt index adb2c557..16c48ced 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt @@ -245,13 +245,9 @@ fun DetailTabBody( /** * Remembers which inner sections are expanded, keyed by their stable section - * key and saved across configuration changes. Sections start collapsed unless - * [initiallyExpanded] names some, which only a screen whose sections would - * otherwise read as empty does (see the pipeline stage pane's definition); the + * key and saved across configuration changes. Sections start collapsed; the * operator's own expand/collapse choices are then persisted (as an [ArrayList] - * a Bundle can hold). [initiallyExpanded] participates in the save key, so a pane - * switching between run and definition contexts reseeds rather than inheriting - * the other context's choices. + * a Bundle can hold). */ @Stable class SectionExpansionState internal constructor( @@ -270,12 +266,9 @@ private val expandedKeysSaver: Saver, ArrayList> = Saver( ) @Composable -fun rememberSectionExpansion( - vararg inputs: Any?, - initiallyExpanded: Set = emptySet(), -): SectionExpansionState { - val expanded = rememberSaveable(*inputs, initiallyExpanded, stateSaver = expandedKeysSaver) { - mutableStateOf(initiallyExpanded) +fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState { + val expanded = rememberSaveable(*inputs, stateSaver = expandedKeysSaver) { + mutableStateOf(emptySet()) } return remember(expanded) { SectionExpansionState(expanded) } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/Sections.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/Sections.kt index 2c0a2222..8f010319 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/Sections.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/Sections.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon @@ -38,20 +39,25 @@ import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.pipelinesText /** - * The one collapsible section header shared by both detail screens: the section - * title in the theme's section-header style, a trailing chevron that rotates - * with the state (animated, no jump cut), an opaque background so content - * passing underneath a stuck header stays readable, and a subtle divider. + * The one section header shared by both detail screens and the stage screen's + * compact section list: the section title in the theme's section-header style, a + * trailing chevron, an opaque background so content passing underneath a stuck + * header stays readable, and a subtle divider. + * + * [navigation] distinguishes the two behaviours the same row shape carries. A + * disclosure row (the default) toggles [expanded], its chevron rotates with the + * state (animated, no jump cut) and it reads as e.g. "Steps, expanded" with an + * "Expand Steps"/"Collapse Steps" action. A navigation row ([navigation] true) + * opens the section as its own pane instead: [expanded] is ignored, the chevron + * is the static forward arrow (mirrored for RTL) and it reads as "Steps" with an + * "Open Steps" action, so assistive tech is never told the row expands in place + * when it actually opens a surface of its own. * * [containerColor] is the opaque colour the header covers with. It defaults to * the screen background so a stuck header on an ordinary page hides the content * scrolling under it; a caller whose surface is a different container (the stage * pane) passes that same colour so the header never reads as a differently toned * band across its pane. - * - * Accessibility is exposed without relying on the chevron: the header is a - * single button node described as e.g. "Steps, expanded" and carries the - * `expanded`/`collapsed` state. */ @Composable fun SectionHeader( @@ -60,12 +66,19 @@ fun SectionHeader( onToggle: () -> Unit, modifier: Modifier = Modifier, containerColor: Color = MaterialTheme.colorScheme.background, + navigation: Boolean = false, ) { - val rotation = animateFloatAsState( - targetValue = if (expanded) 0f else -90f, - animationSpec = MotionQuick.spec(), - label = "section-chevron", - ) + // Only a disclosure row animates its chevron; a navigation row shows the + // static forward arrow, so no animator is composed for it. + val rotation = if (navigation) { + null + } else { + animateFloatAsState( + targetValue = if (expanded) 0f else -90f, + animationSpec = MotionQuick.spec(), + label = "section-chevron", + ) + } Column( modifier = modifier .fillMaxWidth() @@ -73,11 +86,20 @@ fun SectionHeader( .background(containerColor) .clickable(role = Role.Button, onClick = onToggle) .clearAndSetSemantics { - contentDescription = "$title, ${if (expanded) "expanded" else "collapsed"}" - role = Role.Button - onClick(label = if (expanded) "Collapse $title" else "Expand $title") { - onToggle() - true + if (navigation) { + contentDescription = title + role = Role.Button + onClick(label = "Open $title") { + onToggle() + true + } + } else { + contentDescription = "$title, ${if (expanded) "expanded" else "collapsed"}" + role = Role.Button + onClick(label = if (expanded) "Collapse $title" else "Expand $title") { + onToggle() + true + } } }, ) { @@ -96,11 +118,19 @@ fun SectionHeader( modifier = Modifier.weight(1f), ) Icon( - imageVector = Icons.Default.KeyboardArrowDown, + imageVector = if (navigation) { + Icons.AutoMirrored.Filled.KeyboardArrowRight + } else { + Icons.Default.KeyboardArrowDown + }, contentDescription = null, // Read the animating angle inside the layer so the chevron turns // without recomposing the header on every frame. - modifier = Modifier.graphicsLayer { rotationZ = rotation.value }, + modifier = if (rotation != null) { + Modifier.graphicsLayer { rotationZ = rotation.value } + } else { + Modifier + }, ) } HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant) @@ -115,6 +145,13 @@ fun SectionHeader( * section does no work and the resting layout is the collapsed header alone. * With animations disabled Compose maps the platform animator duration scale * onto the specs, so the body is at its final state at once. + * + * [content] is laid out in a single full-width [Column]: [AnimatedVisibility] + * measures *one* child, so several composables emitted straight into the body + * would be stacked on top of each other at the section's top instead of under + * their header (the "renders oddly at the top of the section" defect). The + * wrapper gives the transition exactly one child and lets a section hold any + * number of rows. */ @Composable fun CollapsibleSectionBody( @@ -130,7 +167,7 @@ fun CollapsibleSectionBody( fadeOut(animationSpec = MotionQuick.spec()), modifier = modifier, ) { - content() + Column(Modifier.fillMaxWidth()) { content() } } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt index f35f3f21..3b95570f 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt @@ -18,6 +18,7 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.PrimaryScrollableTabRow +import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Tab import androidx.compose.material3.Text @@ -25,10 +26,7 @@ import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.semantics.heading import androidx.compose.ui.semantics.semantics @@ -43,14 +41,11 @@ import net.awan.pipelines.data.protocol.Stage import net.awan.pipelines.data.protocol.edges import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.components.CodeBlock -import net.awan.pipelines.ui.components.CollapsibleSectionBody import net.awan.pipelines.ui.components.DetailTabBody import net.awan.pipelines.ui.components.KeyValueRow import net.awan.pipelines.ui.components.PaneIdentity -import net.awan.pipelines.ui.components.SectionExpansionState import net.awan.pipelines.ui.components.SectionHeader import net.awan.pipelines.ui.components.paneSafeArea -import net.awan.pipelines.ui.components.rememberSectionExpansion import net.awan.pipelines.ui.displayMap import net.awan.pipelines.ui.fileChangeLine import net.awan.pipelines.ui.fileChangesSummary @@ -169,7 +164,7 @@ internal fun headlineFields(fields: List): List = internal fun evidenceFields(fields: List): List = fields.filter { it.label !in STAGE_HEADLINE_LABELS && it.label != "Input" && it.label != "Output" } -/** The section key of the one stage-definition section (expansion is saved on it). */ +/** The section key of the one stage-definition section, addressable by the pane selection. */ internal const val STAGE_DEFINITION_KEY = "definition" /** The stage-definition section's title, naming clearly what it holds. */ @@ -185,24 +180,16 @@ internal const val STAGE_DEFINITION_TITLE = "Stage definition" @Composable internal fun paneContainerColor() = MaterialTheme.colorScheme.surfaceContainer -/** - * Whether the stage-definition section starts expanded. It is the only content of - * a pane opened without a run context (a pipeline's own stage definition, see - * [PipelineStagePane]), and starts collapsed in a run pane, where the run's - * results lead and the definition sits at the bottom. An operator's own - * expand/collapse choice is still remembered on top of this default. - */ -internal fun definitionStartsExpanded(runContext: Boolean): Boolean = !runContext - /** * One run-side result section of the stage pane. The order is the operator's * stated preference: the artifacts gallery first, then the output the stage - * produced for that visit, then the input it received. + * produced for that visit, then the input it received. [title] is the section's + * own visible name (its pane's title and its row on the stage screen). */ -internal enum class StageResultSection(val key: String) { - Artifacts("artifacts"), - Output("output"), - Input("input"), +internal enum class StageResultSection(val key: String, val title: String) { + Artifacts("artifacts", "Artifacts"), + Output("output", "Output"), + Input("input", "Input"), } /** The run-side result sections, in display order (the artifacts gallery first). */ @@ -212,6 +199,74 @@ internal val STAGE_RESULT_SECTIONS: List = listOf( StageResultSection.Input, ) +/** The evidence section key/title ("This run" holds the remaining run evidence). */ +internal const val STAGE_EVIDENCE_KEY = "run" +internal const val STAGE_EVIDENCE_TITLE = "This run" + +/** + * One section of the stage screen: its stable [key] (what the pane selection and + * the section pane address it by), its own [title], the [fields] it shows when it + * is a plain field section, and [artifacts] when it is the per-visit gallery + * (which renders the shared [ArtifactsSection] instead of [fields]). + */ +internal data class StageSectionSpec( + val key: String, + val title: String, + val fields: List = emptyList(), + val artifacts: Boolean = false, +) + +/** + * The ordered sections of the stage screen for one stage and visit: a run pane + * leads with the visit's Artifacts gallery, then Output, Input and the remaining + * evidence (`This run`); the stage's own definition is the last section in both + * contexts and the only section when there is no run. Blank field sections are + * skipped; the artifacts section always shows for a reached visit, even when the + * visit recorded none, so the operator always finds the gallery. Pure, so the + * compact stage screen's list and the section pane's content are derived from + * exactly the same spec. + */ +internal fun stageSectionSpecs( + stageKey: String, + graph: Graph, + runSteps: List, + visitIndex: Int, + runContext: Boolean, +): List { + val specs = ArrayList() + val stage = graph.stages.firstOrNull { it.key == stageKey } + val definition = stage?.let(::stageDefinitionFields) ?: terminalFields(graph, stageKey) + val selectedStep = runSteps.getOrNull(clampVisitIndex(visitIndex, runSteps.size)) + if (runContext && selectedStep != null) { + val runFields = runStepFields(selectedStep) + STAGE_RESULT_SECTIONS.forEach { section -> + when (section) { + StageResultSection.Artifacts -> specs += StageSectionSpec( + key = section.key, + title = section.title, + artifacts = true, + ) + StageResultSection.Output -> { + val fields = runFields.filter { it.label == "Output" } + if (fields.isNotEmpty()) specs += StageSectionSpec(section.key, section.title, fields) + } + StageResultSection.Input -> { + val fields = runFields.filter { it.label == "Input" } + if (fields.isNotEmpty()) specs += StageSectionSpec(section.key, section.title, fields) + } + } + } + val evidence = evidenceFields(runFields) + if (evidence.isNotEmpty()) { + specs += StageSectionSpec(STAGE_EVIDENCE_KEY, STAGE_EVIDENCE_TITLE, evidence) + } + } + if (definition.isNotEmpty()) { + specs += StageSectionSpec(STAGE_DEFINITION_KEY, STAGE_DEFINITION_TITLE, definition) + } + return specs +} + /** * The pure run view of one [RunStep] for the selected stage: status, outcome, * duration, visit against the control's max_visits, target, session id, @@ -301,17 +356,19 @@ internal fun clampVisitIndex(index: Int, visitCount: Int): Int = internal fun showVisitTabs(visitCount: Int): Boolean = visitCount > 1 /** - * The stage pane's content: opened as the rightmost level of the sliding stack - * from a timeline entry or a graph node, exactly like the list and detail panes, - * so there is no popup anywhere. It carries its own Scaffold/[TopAppBar] with a - * back arrow that pops one level (the same step as the peek tap and system Back). + * The stage screen: the pane shown when no section is open. It carries its own + * Scaffold/[TopAppBar] with a back arrow that pops one level (the same step as + * the peek tap and system Back), leads with the run-side headline, and keeps a + * **compact list of the stage's sections**: tapping a section opens it as its own + * pane ([StageSectionPane]) rather than growing this screen inline. * * [runSteps] is every recorded visit of the stage in order; when there is more - * than one the pane shows a visit tab row (visit 1..N) and starts on - * [initialVisitIndex] (the tapped timeline entry, or the most recent visit when - * opened from the graph). A stage the run never reached has no run section; the - * identity heading and type always show, so a freshly opened pane never reads as - * empty. + * than one the pane shows a visit tab row (visit 1..N) and reports the chosen + * visit through [onVisitIndexChange]. The selection is owned by the caller (part + * of the saved pane selection), so this screen and the section pane always agree + * and it survives rotation. A stage the run never reached lists only its + * definition; the identity heading and type always show, so a freshly opened + * pane never reads as empty. */ @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -319,9 +376,9 @@ fun StageDetailPane( stageKey: String, graph: Graph, runSteps: List = emptyList(), - initialVisitIndex: Int = 0, - configuredServerUrl: String = "", - fetchArtifactBytes: suspend (String) -> ByteArray? = { null }, + visitIndex: Int = 0, + onVisitIndexChange: (Int) -> Unit = {}, + onOpenSection: (String) -> Unit = {}, onBack: () -> Unit, wide: Boolean = false, modifier: Modifier = Modifier, @@ -340,32 +397,10 @@ fun StageDetailPane( ) return } - - // The selected visit is owned here so the selection's copy/share actions in - // the top bar and the body's per-visit artifacts section read the same step. - // Reset when the stage changes; saved across configuration. - var visitIndex by rememberSaveable(stageKey) { - mutableIntStateOf(clampVisitIndex(initialVisitIndex, runSteps.size)) - } - val clampedVisit = clampVisitIndex(visitIndex, runSteps.size) - val selectedStep = runSteps.getOrNull(clampedVisit) - val visitArtifacts = remember(selectedStep) { selectedStep?.artifacts.orEmpty() } - - // The artifact selection for this visit: a long-press enters it, a tap - // toggles. Keyed on the visit, so switching visits leaves selection mode; it - // restores fully (or not at all) after rotation. - val selectionState = rememberArtifactSelection(stageKey, clampedVisit) - - // The shared selection host owns the selection, the contextual bar, the bulk - // copy/share actions and Back-leaves-selection-first; the two artifact - // surfaces go through it so they can never drift. - ArtifactSelectionScaffold( - selectionState = selectionState, - candidates = visitArtifacts, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, + Scaffold( modifier = modifier, containerColor = paneContainerColor(), + contentWindowInsets = paneSafeArea(), topBar = { TopAppBar( title = { Text(GraphSemantics.nodeLabel(stageKey)) }, @@ -378,68 +413,47 @@ fun StageDetailPane( colors = TopAppBarDefaults.topAppBarColors(containerColor = paneContainerColor()), ) }, - ) { selection, onSelectionChange, padding -> + ) { padding -> StageDetailBody( stageKey = stageKey, graph = graph, runSteps = runSteps, - selectedStep = selectedStep, - visitIndex = clampedVisit, - onVisitIndexChange = { visitIndex = it }, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, + visitIndex = visitIndex, + onVisitIndexChange = onVisitIndexChange, + onOpenSection = onOpenSection, wide = wide, runContext = runContext, - selection = selection, - onSelectionChange = onSelectionChange, modifier = Modifier.padding(padding), ) } } -/** The stage detail's content, wrapped by [StageDetailPane]. */ -@OptIn(ExperimentalMaterial3Api::class) +/** The stage screen's content, wrapped by [StageDetailPane]. */ @Composable private fun StageDetailBody( stageKey: String, graph: Graph, runSteps: List, - selectedStep: RunStep?, visitIndex: Int, onVisitIndexChange: (Int) -> Unit, - configuredServerUrl: String, - fetchArtifactBytes: suspend (String) -> ByteArray?, + onOpenSection: (String) -> Unit, wide: Boolean, runContext: Boolean, - selection: ArtifactSelection, - onSelectionChange: (ArtifactSelection) -> Unit, modifier: Modifier = Modifier, ) { val text = pipelinesText() val stage = graph.stages.firstOrNull { it.key == stageKey } - val definition = remember(stage, graph, stageKey) { - stage?.let(::stageDefinitionFields) ?: terminalFields(graph, stageKey) - } val typeLabel = if (stage != null) effectiveStageType(stage.type) else "terminal" val clampedVisit = clampVisitIndex(visitIndex, runSteps.size) - // Derived once per selected step, not per recomposition. Only the run-side - // facts lead the pane; the stage's own configs stay in the definition section. + val selectedStep = runSteps.getOrNull(clampedVisit) + // The run-side headline: always visible, never behind a section, so a freshly + // opened screen never reads as empty. val runFields = remember(selectedStep) { selectedStep?.let(::runStepFields).orEmpty() } val headline = headlineFields(runFields) - val inputFields = remember(runFields) { runFields.filter { it.label == "Input" } } - val outputFields = remember(runFields) { runFields.filter { it.label == "Output" } } - val evidence = evidenceFields(runFields) - // The stage definition is the only content of a pane without a run context, - // so it starts expanded there and collapsed at the bottom of a run pane. - val expansion = rememberSectionExpansion( - stageKey, - initiallyExpanded = if (definitionStartsExpanded(runContext)) { - setOf(STAGE_DEFINITION_KEY) - } else { - emptySet() - }, - ) + val sections = remember(stageKey, graph, runSteps, clampedVisit, runContext) { + stageSectionSpecs(stageKey, graph, runSteps, clampedVisit, runContext) + } DetailTabBody(wide, modifier) { columnModifier -> Column( @@ -454,106 +468,237 @@ private fun StageDetailBody( modifier = Modifier.semantics { heading() }, ) StageTypeChip(typeLabel) - if (showVisitTabs(runSteps.size)) { - PrimaryScrollableTabRow( - selectedTabIndex = clampedVisit, - edgePadding = 0.dp, - containerColor = paneContainerColor(), - modifier = Modifier.fillMaxWidth().padding(top = SPACING_S), - ) { - runSteps.forEachIndexed { index, _ -> - Tab( - selected = index == clampedVisit, - onClick = { onVisitIndexChange(index) }, - text = { Text("visit ${index + 1}", maxLines = 1) }, - ) - } - } - } - - // Identity and result: always visible, never behind a collapse, so a - // freshly opened pane never reads as empty. + StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange) headline.forEach { field -> StageFieldRow(field) } - if (headline.isEmpty() && selectedStep == null && stage == null && definition.isEmpty()) { + if (headline.isEmpty() && selectedStep == null && stage == null && sections.isEmpty()) { Text("No details recorded for this node.", style = text.meta) } - // A run pane leads with the run's results: the artifacts gallery - // first, then the output and the input, then the remaining evidence. - if (runContext && selectedStep != null) { - STAGE_RESULT_SECTIONS.forEach { section -> - when (section) { - StageResultSection.Artifacts -> StageSection(expansion, section.key) { - ArtifactsSection( - step = selectedStep, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, - selection = selection, - onSelectionChange = onSelectionChange, - ) - } - StageResultSection.Output -> if (outputFields.isNotEmpty()) { - StageSection(expansion, section.key) { - outputFields.forEach { StageFieldRow(it) } - } - } - StageResultSection.Input -> if (inputFields.isNotEmpty()) { - StageSection(expansion, section.key) { - inputFields.forEach { StageFieldRow(it) } - } - } - } - } - if (evidence.isNotEmpty()) { - StageSection(expansion, "run", "This run") { - evidence.forEach { field -> StageFieldRow(field) } - } - } - } - - // The stage's own definition sits in one clearly named section: it is - // the pane's only content without a run context (so it starts - // expanded) and the collapsed last section of a run pane. - if (definition.isNotEmpty()) { - StageSection(expansion, STAGE_DEFINITION_KEY, STAGE_DEFINITION_TITLE) { - definition.forEach { field -> StageFieldRow(field) } - } + // The compact list of sections: each row opens that section as its own + // pane instead of growing this screen inline (which stacked a section's + // several rows at the top of its header). The row is a navigation row, + // so it reads as "Open Artifacts" with a forward chevron rather than an + // in-place "Expand Artifacts"/collapsed disclosure. + sections.forEach { section -> + SectionHeader( + title = section.title, + expanded = false, + onToggle = { onOpenSection(section.key) }, + containerColor = paneContainerColor(), + navigation = true, + ) } } } } /** - * One collapsible section of the stage pane: its header toggles [expansion] - * under [key] and its body animates open/closed with the shared - * [CollapsibleSectionBody], so the content and the chevron move together. The - * title defaults to the capitalised key (e.g. `artifacts` → `Artifacts`), so the - * pane names every section the same way. + * The shared visit tab row: rendered only when [visitCount] is more than one, so + * a single-visit stage never shows a pointless one-tab row. Both the stage screen + * and a run-section pane use it, so a visit always reads the same way. */ +@OptIn(ExperimentalMaterial3Api::class) @Composable -private fun StageSection( - expansion: SectionExpansionState, - key: String, - title: String = key.capitalized(), - content: @Composable () -> Unit, +internal fun StageVisitTabs( + visitCount: Int, + selectedIndex: Int, + onSelect: (Int) -> Unit, + modifier: Modifier = Modifier, ) { - val expanded = expansion.isExpanded(key) - SectionHeader( - title, - expanded, - { expansion.toggle(key) }, + if (!showVisitTabs(visitCount)) return + PrimaryScrollableTabRow( + selectedTabIndex = selectedIndex, + edgePadding = 0.dp, containerColor = paneContainerColor(), - ) - CollapsibleSectionBody(expanded) { content() } + modifier = modifier.fillMaxWidth().padding(top = SPACING_S), + ) { + repeat(visitCount) { index -> + Tab( + selected = index == selectedIndex, + onClick = { onSelect(index) }, + text = { Text("visit ${index + 1}", maxLines = 1) }, + ) + } + } } -/** The stage pane hosted directly by the run destination, reading the run detail. */ +/** + * One stage section opened as its own pane: its own Scaffold/[TopAppBar] titled + * with the section's own name, its own scroll and its own top spacing, so the + * content always sits cleanly under its header. It is the section level of the + * sliding stack (a full-window screen over the stage on a narrow window, a panel + * to the stage pane's right on a wide one); Back — the app bar, system Back or + * the peek — pops exactly one level, back to the stage. + * + * The artifacts section keeps the shared [ArtifactSelectionScaffold], so its + * gallery retains long-press selection, the contextual bar and + * Back-leaves-selection-first; every other section is plain fields. The visited + * section is derived from the same [stageSectionSpecs] the stage screen lists, so + * the two can never disagree. + */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun StageSectionPane( + stageKey: String, + sectionKey: String, + graph: Graph, + runSteps: List = emptyList(), + visitIndex: Int = 0, + onVisitIndexChange: (Int) -> Unit = {}, + configuredServerUrl: String = "", + fetchArtifactBytes: suspend (String) -> ByteArray? = { null }, + onBack: () -> Unit, + wide: Boolean = false, + modifier: Modifier = Modifier, + covered: Boolean = false, + runContext: Boolean = false, +) { + val clampedVisit = clampVisitIndex(visitIndex, runSteps.size) + val selectedStep = runSteps.getOrNull(clampedVisit) + val spec = remember(stageKey, graph, runSteps, clampedVisit, runContext, sectionKey) { + stageSectionSpecs(stageKey, graph, runSteps, clampedVisit, runContext) + .firstOrNull { it.key == sectionKey } + } + val title = spec?.title ?: sectionKey + if (covered) { + PaneIdentity( + title = title, + subtitle = GraphSemantics.nodeLabel(stageKey), + modifier = modifier.fillMaxSize(), + ) + return + } + val bar: @Composable () -> Unit = { + TopAppBar( + title = { Text(title) }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") + } + }, + windowInsets = paneSafeArea().only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal), + colors = TopAppBarDefaults.topAppBarColors(containerColor = paneContainerColor()), + ) + } + if (spec?.artifacts == true) { + // The gallery keeps the one selection host (long-press selection, the + // contextual bar and Back-leaves-selection-first) it had inline. + val selectionState = rememberArtifactSelection(stageKey, clampedVisit) + ArtifactSelectionScaffold( + selectionState = selectionState, + candidates = selectedStep?.artifacts.orEmpty(), + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + modifier = modifier, + containerColor = paneContainerColor(), + topBar = bar, + ) { selection, onSelectionChange, padding -> + StageSectionBody( + stageKey = stageKey, + spec = spec, + step = selectedStep, + runSteps = runSteps, + visitIndex = clampedVisit, + onVisitIndexChange = onVisitIndexChange, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + selection = selection, + onSelectionChange = onSelectionChange, + wide = wide, + modifier = Modifier.padding(padding), + ) + } + } else { + Scaffold( + modifier = modifier, + containerColor = paneContainerColor(), + contentWindowInsets = paneSafeArea(), + topBar = bar, + ) { padding -> + StageSectionBody( + stageKey = stageKey, + spec = spec, + step = selectedStep, + runSteps = runSteps, + visitIndex = clampedVisit, + onVisitIndexChange = onVisitIndexChange, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + selection = ArtifactSelection(), + onSelectionChange = {}, + wide = wide, + modifier = Modifier.padding(padding), + ) + } + } +} + +/** + * One section's content: its own single scroll, a context line naming the stage, + * its own top spacing, and — for a visit's result section — the visit tab row, + * so the operator can switch visits in place. The stage definition skips the tab + * row (it does not change per visit). Plain sections render their rows; the + * artifacts section renders the shared [ArtifactsSection] gallery. + */ +@Composable +private fun StageSectionBody( + stageKey: String, + spec: StageSectionSpec?, + step: RunStep?, + runSteps: List, + visitIndex: Int, + onVisitIndexChange: (Int) -> Unit, + configuredServerUrl: String, + fetchArtifactBytes: suspend (String) -> ByteArray?, + selection: ArtifactSelection, + onSelectionChange: (ArtifactSelection) -> Unit, + wide: Boolean, + modifier: Modifier = Modifier, +) { + val text = pipelinesText() + DetailTabBody(wide, modifier) { columnModifier -> + Column( + modifier = columnModifier + .verticalScroll(rememberScrollState()) + .padding(horizontal = SPACING_L, vertical = SPACING_L), + verticalArrangement = Arrangement.spacedBy(SPACING_XS), + ) { + Text(GraphSemantics.nodeLabel(stageKey), style = text.meta) + if (spec != null && spec.key != STAGE_DEFINITION_KEY) { + StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) + } + when { + spec == null -> Text("This section is not recorded for this stage.", style = text.meta) + spec.artifacts -> if (step != null) { + ArtifactsSection( + step = step, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + selection = selection, + onSelectionChange = onSelectionChange, + ) + } + else -> spec.fields.forEach { field -> StageFieldRow(field) } + } + } + } +} + +/** + * The run-side stage level: with no [openSection] it is the compact stage screen + * ([StageDetailPane]); with one it is that section's pane ([StageSectionPane]). + * Both read the same run detail and derive the stage's visits the same way, so + * the two levels can never disagree and no state is read twice. + */ @Composable fun RunStagePane( vm: AppViewModel, runId: Long, stageKey: String, visitIndex: Int, + openSection: String?, + onOpenSection: (String) -> Unit, + onVisitChange: (Int) -> Unit, onBack: () -> Unit, wide: Boolean, modifier: Modifier = Modifier, @@ -565,28 +710,55 @@ fun RunStagePane( val steps = run?.steps.orEmpty() // One aggregation per step-list change; the stage's visits are read from it. val timeline = remember(steps) { runTimeline(steps) } - StageDetailPane( - stageKey = stageKey, - graph = run?.graph ?: Graph(), - runSteps = timeline.visitsByStage[stageKey].orEmpty(), - initialVisitIndex = visitIndex, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = vm::fetchArtifactBytes, - onBack = onBack, - wide = wide, - modifier = modifier, - covered = covered, - runContext = true, - ) + val runSteps = remember(timeline, stageKey) { timeline.visitsByStage[stageKey].orEmpty() } + val graph = run?.graph ?: Graph() + if (openSection == null) { + StageDetailPane( + stageKey = stageKey, + graph = graph, + runSteps = runSteps, + visitIndex = visitIndex, + onVisitIndexChange = onVisitChange, + onOpenSection = onOpenSection, + onBack = onBack, + wide = wide, + modifier = modifier, + covered = covered, + runContext = true, + ) + } else { + StageSectionPane( + stageKey = stageKey, + sectionKey = openSection, + graph = graph, + runSteps = runSteps, + visitIndex = visitIndex, + onVisitIndexChange = onVisitChange, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = vm::fetchArtifactBytes, + onBack = onBack, + wide = wide, + modifier = modifier, + covered = covered, + runContext = true, + ) + } } -/** The stage pane hosted by the pipeline destination; a definition has no run. */ +/** + * The pipeline-side stage level: with no [openSection] it is the stage screen + * (a definition has no run, so it lists just that section); with one it is the + * definition section's pane. The two share the stage screen and the section pane + * with the run side. + */ @Composable fun PipelineStagePane( vm: AppViewModel, pipelineId: Long, version: Int, stageKey: String, + openSection: String?, + onOpenSection: (String) -> Unit, onBack: () -> Unit, wide: Boolean, modifier: Modifier = Modifier, @@ -594,14 +766,28 @@ fun PipelineStagePane( ) { val state by vm.pipelineDetail.collectAsStateWithLifecycle() val detail = state.data?.takeIf { it.id == pipelineId && it.version == version } - StageDetailPane( - stageKey = stageKey, - graph = detail?.graph ?: Graph(), - onBack = onBack, - wide = wide, - modifier = modifier, - covered = covered, - ) + val graph = detail?.graph ?: Graph() + if (openSection == null) { + StageDetailPane( + stageKey = stageKey, + graph = graph, + onOpenSection = onOpenSection, + onBack = onBack, + wide = wide, + modifier = modifier, + covered = covered, + ) + } else { + StageSectionPane( + stageKey = stageKey, + sectionKey = openSection, + graph = graph, + onBack = onBack, + wide = wide, + modifier = modifier, + covered = covered, + ) + } } /** One field as either the shared code card (blocks) or a key/value row. */ @@ -629,7 +815,3 @@ internal fun StageTypeChip(label: String) { ) } } - -/** A section key as its visible title ("definition" → "Definition"). */ -private fun String.capitalized(): String = - replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt index d2f1908e..e9f9d112 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt @@ -44,11 +44,38 @@ class PaneStateTest { assertEquals(1, result.selection.depth) } + @Test + fun backInsideSectionReturnsToTheStageKeepingTheStage() { + val section = PaneSelection( + pane = MasterPane.Section, + itemId = 7L, + itemVersion = 3, + sectionIndex = 1, + stageKey = "planner", + stageVisit = 2, + sectionKey = "artifacts", + ) + val result = backStep(section) as BackResult.Show + // Exactly one level: section -> stage, keeping the stage and its visit, + // clearing only the open section. + assertEquals(MasterPane.Stage, result.selection.pane) + assertEquals(7L, result.selection.itemId) + assertEquals(3, result.selection.itemVersion) + assertEquals("planner", result.selection.stageKey) + assertEquals(2, result.selection.stageVisit) + assertEquals(null, result.selection.sectionKey) + assertEquals(2, result.selection.depth) + } + @Test fun depthIsBoundedByTheDeclaredMaximum() { assertEquals(0, PaneSelection(MasterPane.List).depth) assertEquals(1, PaneSelection(MasterPane.Detail, itemId = 1L).depth) assertEquals(2, PaneSelection(MasterPane.Stage, itemId = 1L, stageKey = "s").depth) + assertEquals( + 3, + PaneSelection(MasterPane.Section, itemId = 1L, stageKey = "s", sectionKey = "artifacts").depth, + ) // Every pane's depth is within the bound; the stack can never grow deeper. MasterPane.entries.forEach { pane -> assertTrue(PaneSelection(pane = pane).depth <= MAX_PANE_DEPTH) @@ -65,18 +92,26 @@ class PaneStateTest { stageKey = "s", stageVisit = 3, ) + val section = stage.copy(pane = MasterPane.Section, sectionKey = "artifacts") // Level 0 (list): everything closes. - assertEquals(PaneSelection(), popTo(stage, 0)) - // Level 1 (detail): only the stage closes, the item is kept. - val detail = popTo(stage, 1) + assertEquals(PaneSelection(), popTo(section, 0)) + // Level 1 (detail): the stage and its section close, the item is kept. + val detail = popTo(section, 1) assertEquals(MasterPane.Detail, detail.pane) assertEquals(9L, detail.itemId) assertEquals(2, detail.itemVersion) assertEquals(1, detail.sectionIndex) assertEquals(null, detail.stageKey) + assertEquals(null, detail.sectionKey) + // Level 2 (stage): only the section closes, the stage is kept. + val stageAgain = popTo(section, 2) + assertEquals(MasterPane.Stage, stageAgain.pane) + assertEquals("s", stageAgain.stageKey) + assertEquals(null, stageAgain.sectionKey) // A level at or beyond the current depth is a no-op. assertEquals(stage, popTo(stage, 2)) - assertEquals(stage, popTo(stage, 5)) + assertEquals(section, popTo(section, 3)) + assertEquals(section, popTo(section, 5)) assertEquals(PaneSelection(MasterPane.Detail, 4L), popTo(PaneSelection(MasterPane.Detail, 4L), 3)) } @@ -95,6 +130,15 @@ class PaneStateTest { stageKey = "planner", stageVisit = 3, ), + PaneSelection( + pane = MasterPane.Section, + itemId = 8L, + itemVersion = 2, + sectionIndex = 4, + stageKey = "planner", + stageVisit = 3, + sectionKey = "artifacts", + ), ) cases.forEach { selection -> val saved = with(PaneSelectionSaver) { scope.save(selection) } @@ -105,7 +149,7 @@ class PaneStateTest { @Test fun encodedPayloadIsPrimitivesOnly() { // Process-death restoration stays small: only Strings, ints and a long, - // with a null stage key encoded as an empty string. + // with a null stage or section key encoded as an empty string. val encoded = encodePaneSelection( PaneSelection( pane = MasterPane.Stage, @@ -116,14 +160,25 @@ 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( + pane = MasterPane.Section, + itemId = 9L, + itemVersion = 2, + sectionIndex = 1, + stageKey = "planner", + stageVisit = 4, + sectionKey = "artifacts", + ) + assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts"), encodePaneSelection(section)) + assertEquals(section, decodePaneSelection(encodePaneSelection(section))) } } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/graph/StageDetailSheetTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/graph/StageDetailSheetTest.kt index d0854328..8595ac49 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/graph/StageDetailSheetTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/graph/StageDetailSheetTest.kt @@ -195,11 +195,49 @@ class StageDetailSheetTest { } @Test - fun theDefinitionStartsExpandedOnlyWithoutARunContext() { - // A pipeline's stage definition is the pane's only content, so it starts - // expanded; a run pane leads with results and collapses the definition. - assertTrue(definitionStartsExpanded(runContext = false)) - assertFalse(definitionStartsExpanded(runContext = true)) + fun theStageScreenListsItsSectionsInOrderAndTheDefinitionLast() { + val stage = Stage(key = "implementer", type = "model", prompt = "do", output = "done") + val graph = Graph(stages = listOf(stage)) + val step = RunStep( + status = "succeeded", + outcome = "success", + target = "reviewer", + input = mapOf("prompt" to JsonPrimitive("do it")), + output = mapOf("result" to JsonPrimitive("done")), + diagnostic = "why", + ) + val specs = stageSectionSpecs("implementer", graph, listOf(step), visitIndex = 0, runContext = true) + // The run's results lead (artifacts first) and the stage's own definition + // is the last section, named with its own visible title. + assertEquals(listOf("artifacts", "output", "input", "run", "definition"), specs.map { it.key }) + assertEquals( + listOf("Artifacts", "Output", "Input", "This run", "Stage definition"), + specs.map { it.title }, + ) + // The artifacts section is the gallery (no fields); the definition keeps + // the stage's own fields. + assertTrue(specs.first().artifacts) + assertTrue(specs.first().fields.isEmpty()) + assertTrue(specs.first { it.key == "definition" }.fields.isNotEmpty()) + } + + @Test + fun aDefinitionOnlyStageListsJustItsDefinition() { + val graph = Graph(stages = listOf(Stage(key = "planner", type = "model", prompt = "do"))) + // No run context (a pipeline stage): only the definition section. + val specs = stageSectionSpecs("planner", graph, emptyList(), visitIndex = 0, runContext = false) + assertEquals(listOf("definition"), specs.map { it.key }) + } + + @Test + fun aVisitThatRecordedNoOutputOrInputListsArtifactsAndTheDefinition() { + val graph = Graph(stages = listOf(Stage(key = "s", type = "model"))) + val step = RunStep(status = "succeeded") + val specs = stageSectionSpecs("s", graph, listOf(step), visitIndex = 0, runContext = true) + // The artifacts gallery always shows for a reached visit; empty + // output/input/evidence sections are omitted rather than listed blank. + assertEquals(listOf("artifacts", "definition"), specs.map { it.key }) + assertTrue(specs.none { !it.artifacts && it.fields.isEmpty() }) } @Test