session export: write only session.html, retire the markdown export

A stage's session was exported twice, as session.md and session.html, and both
files were presented. It is now one html file; the markdown export is retired.

- internal/stage/session_export.go: ExportSession renders and writes exactly one
  file, session.html, via writeSessionFile; renderSessionMarkdown and its helpers
  are gone; SessionExportResult carries HTML/HTMLBytes only. The source read, the
  8 MiB source / 2 MiB rendered bounds, the truncation banner, the
  never-overwrite rule and the honest empty-session handling are unchanged.
- internal/protocol/runs.go: SessionExport drops markdown/markdown_bytes (a
  record written before the change still decodes; unknown fields are ignored),
  and adds LegacySessionMarkdownArtifact with RunStep.PresentedArtifacts(), the
  one Go rule that hides the retired session.md from every artifact listing.
- internal/server/runner.go: evidence.Markdown/MarkdownBytes are no longer copied.
- internal/tui: the artifacts panel, the recorded count and the per-visit summary
  derive from PresentedArtifacts(), so the terminal never lists session.md.
- web/src/app.js: the spike's renderArtifacts applies the same filter.
- android: the Session section is the html export alone in a WebView — SessionView,
  the Markdown/HTML toggle and the session markdown path are removed;
  presentedArtifacts(step) filters the retired session.md out of the per-visit
  gallery, the run gallery and its count, the verdict/selection lists and the
  timeline indicator; data/protocol SessionExport drops the markdown fields.
- Tests pin the single html file, prove no session.md is written and that a
  pre-existing one is neither overwritten nor presented, and prove a legacy
  export record still loads and its session.md is hidden.

The legacy session.md of an older run stays on disk (dated evidence); it is only
no longer produced and no longer presented.

Checks (macOS, Go 1.24, Android Gradle 8.11.1, 18 Oct 2026): gofmt -l . prints
nothing; go build ./... && go vet ./... clean; go test ./internal/... ./cmd/...
-> 19 packages ok, 0 failures; node --check web/src/app.js ok and node --test
web/test -> 20/20; gradle --offline --no-daemon :app:assembleDebug
:app:testDebugUnitTest -> BUILD SUCCESSFUL.

Packaged references checked: internal/author/skill/references/delivery.md and
operations.md both described the session.md+session.html pair, so both are
updated here to describe the single session.html export and the retired, hidden
session.md. README.md and internal/author/skill/SKILL.md carry no session.md
reference and install.go's managed inventory is unchanged (no reference added or
removed). docs/notes/session-html-only.md records the remaining stale shared
documentation (docs/stage-artifacts.md, docs/app-integration-verification.md) for
the docs-fold writer; shared docs are not edited by this item.
This commit is contained in:
2026-10-18 10:06:49 +01:00
parent 5a4cfc2e9c
commit 95362134aa
25 changed files with 666 additions and 571 deletions
@@ -293,20 +293,20 @@ data class SessionEvidence(
/**
* The recorded evidence of one stage's session file export, mirroring
* internal/protocol/runs.go SessionExport exactly: the file names written under
* the step's artifacts directory, their byte sizes, the decoded message count,
* the source, whether the export was truncated and a sanitized diagnostic. An
* absent (null) value means the step recorded no export (a non-OpenCode harness,
* a failed export or a pre-export server), so no Session section is shown.
* internal/protocol/runs.go SessionExport exactly: the html file name written
* under the step's artifacts directory, its byte size, the decoded message
* count, the source, whether the export was truncated and a sanitized
* diagnostic. An absent (null) value means the step recorded no export (a
* non-OpenCode harness, a failed export or a pre-export server), so no Session
* section is shown. A record written before the HTML-only change also carried
* markdown and markdown_bytes; unknown keys are ignored.
*/
@Serializable
data class SessionExport(
@SerialName("session_id") val sessionId: String = "",
val backend: String = "",
val source: String = "",
val markdown: String = "",
val html: String = "",
@SerialName("markdown_bytes") val markdownBytes: Long = 0,
@SerialName("html_bytes") val htmlBytes: Long = 0,
val messages: Int = 0,
val truncated: Boolean = false,
@@ -15,6 +15,25 @@ data class ArtifactGroup(
val artifacts: List<StageArtifact>,
)
/**
* The retired markdown session export file name. Nothing writes it any more, but
* a run recorded before the HTML-only change still has `session.md` on disk: it
* is dated evidence that is never presented, so it is hidden from every artifact
* listing rather than shown beside the session html.
*/
const val LEGACY_SESSION_MARKDOWN_ARTIFACT = "session.md"
/**
* The artifacts of one visit as the operator sees them: the recorded files with
* the retired markdown session export filtered out. Every artifact listing — the
* per-visit summary, the run gallery, the timeline indicator and the selection
* candidates — derives from this one function, so a stage's artifacts never show
* a session markdown beside the session html and the recorded counts can never
* disagree with the tiles. Pure, O(artifacts) per step.
*/
fun presentedArtifacts(step: RunStep): List<StageArtifact> =
step.artifacts.orEmpty().filterNot { it.name == LEGACY_SESSION_MARKDOWN_ARTIFACT }
/**
* Groups a run's artifacts by stage and visit, purely and deterministically.
* Order follows [runTimeline]: stages in first-appearance order and each stage's
@@ -32,7 +51,7 @@ fun runArtifactGroups(steps: List<RunStep>): List<ArtifactGroup> {
val groups = ArrayList<ArtifactGroup>()
timeline.visitsByStage.forEach { (stageKey, visits) ->
visits.forEach { step ->
val artifacts = step.artifacts.orEmpty()
val artifacts = presentedArtifacts(step)
if (artifacts.isNotEmpty()) {
val visit = visitByStageSequence[stageKey to step.sequence] ?: 1
groups += ArtifactGroup(stageKey, visit, artifacts)
@@ -67,7 +86,7 @@ fun artifactsEmptyMessage(executing: Boolean): String =
* disagree. Pure.
*/
fun runArtifactsHeader(steps: List<RunStep>, executing: Boolean): String {
val recorded = steps.sumOf { it.artifacts.orEmpty().size }
val recorded = steps.sumOf { presentedArtifacts(it).size }
if (recorded == 0) return artifactsEmptyMessage(executing)
val partial = steps.any { it.artifactsSkipped > 0 || it.artifactsTruncated > 0 }
return buildString {
@@ -197,7 +197,7 @@ const val ARTIFACT_CAPTURE_PENDING = "capture pending"
* count plus " · partial capture" when files were excluded or omitted.
*/
fun artifactsSummary(step: RunStep): String {
val artifacts = step.artifacts.orEmpty()
val artifacts = presentedArtifacts(step)
if (artifacts.isEmpty()) {
val state = if (step.status == "running") {
ARTIFACT_CAPTURE_PENDING
@@ -218,7 +218,7 @@ fun artifactsSummary(step: RunStep): String {
* the notes never accompany the empty-state summary.
*/
fun artifactCaptureNotes(step: RunStep): List<String> = buildList {
if (step.artifacts.isNullOrEmpty()) return@buildList
if (presentedArtifacts(step).isEmpty()) return@buildList
if (step.artifactsSkipped > 0) add("${step.artifactsSkipped} files excluded from artifact capture.")
if (step.artifactsTruncated > 0) add("${step.artifactsTruncated} files omitted by artifact capture limits.")
}
@@ -53,6 +53,7 @@ import net.awan.pipelines.ui.artifactsSummary
import net.awan.pipelines.ui.components.copyText
import net.awan.pipelines.ui.components.galleryGrid
import net.awan.pipelines.ui.humanBytes
import net.awan.pipelines.ui.presentedArtifacts
import net.awan.pipelines.ui.theme.ARTIFACT_BADGE_DP
import net.awan.pipelines.ui.theme.ARTIFACT_PLAY_BADGE_DP
import net.awan.pipelines.ui.theme.ARTIFACT_TILE_ACTION_DP
@@ -85,7 +86,7 @@ internal fun ArtifactsSection(
) {
val text = pipelinesText()
// Derived once per data change, never per recomposition (performance requirement).
val artifacts = remember(step) { step.artifacts.orEmpty() }
val artifacts = remember(step) { presentedArtifacts(step) }
val summary = remember(step) { artifactsSummary(step) }
val notes = remember(step) { artifactCaptureNotes(step) }
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(SPACING_XS)) {
@@ -4,13 +4,10 @@ import android.webkit.WebView
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
@@ -18,7 +15,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -29,115 +25,61 @@ import kotlinx.coroutines.withContext
import net.awan.pipelines.data.protocol.GraphSemantics
import net.awan.pipelines.data.protocol.RunStep
import net.awan.pipelines.data.protocol.StageArtifact
import net.awan.pipelines.ui.chat.MarkdownBlocks
import net.awan.pipelines.ui.chat.MdBlock
import net.awan.pipelines.ui.chat.parseMarkdown
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S
import net.awan.pipelines.ui.theme.pipelinesText
/**
* The session export's files of one visit, resolved against the visit's recorded
* artifacts. Either file may be missing (a partially exported or truncated
* listing); a visit with neither has no export to show.
* The html session export [step] recorded, resolved against the visit's recorded
* artifacts, or null when the visit has no export to open. The server writes one
* html file per session; a visit that recorded no export (a Pi harness, a failed
* export or a pre-export server) or whose file is missing from a truncated
* artifact listing yields null, so the stage pane lists no Session section for a
* visit that has nothing to show. The retired `session.md` export is never named
* by the server record and is never presented.
*/
internal data class SessionExportFiles(
val markdown: StageArtifact?,
val html: StageArtifact?,
)
/**
* The files [step]'s session export actually wrote, matched by the names the
* server recorded in `session_export` against the step's artifact listing. Null
* when the visit recorded no export, when it recorded only a limitation (a Pi
* harness, `source: "unavailable"`, or a failure with a diagnostic and no file
* names) or when the listing holds neither recorded file. The stage pane derives
* the Session section from exactly this, so a section is never listed for a visit
* that has no session file to open.
*/
internal fun sessionExportFiles(step: RunStep): SessionExportFiles? {
internal fun sessionExportFile(step: RunStep): StageArtifact? {
val export = step.sessionExport ?: return null
val markdownName = export.markdown.takeIf { it.isNotBlank() }
val htmlName = export.html.takeIf { it.isNotBlank() }
if (markdownName == null && htmlName == null) return null
val artifacts = step.artifacts.orEmpty()
val markdown = markdownName?.let { name -> artifacts.firstOrNull { it.name == name } }
val html = htmlName?.let { name -> artifacts.firstOrNull { it.name == name } }
if (markdown == null && html == null) return null
return SessionExportFiles(markdown = markdown, html = html)
val name = export.html.takeIf { it.isNotBlank() } ?: return null
return step.artifacts.orEmpty().firstOrNull { it.name == name }
}
/** The two ways of reading an exported session: the rendered markdown or the html document. */
internal enum class SessionView { Markdown, Html }
/**
* The view the session section opens in: the markdown export, rendered with the
* app's existing markdown renderer, is the default. The html export is only the
* default when there is no markdown to render; otherwise it is reached through the
* section's own "HTML view" toggle and shown in a WebView for fidelity.
*/
internal fun defaultSessionView(files: SessionExportFiles): SessionView =
if (files.markdown != null) SessionView.Markdown else SessionView.Html
/** Whether the operator can switch between the two exports (both were written). */
internal fun sessionViewToggle(files: SessionExportFiles): Boolean =
files.markdown != null && files.html != null
/** The file the section shows in [view], or null when that export is missing. */
internal fun sessionArtifact(files: SessionExportFiles, view: SessionView): StageArtifact? =
when (view) {
SessionView.Markdown -> files.markdown
SessionView.Html -> files.html
}
/**
* One exported session file, loaded: its markdown parsed into the app's shared
* blocks, its html kept as the document text, its absence a distinct error. A null
* url means no server was configured to fetch it from.
* One exported session file, loaded: its html kept as the document text, its
* absence a distinct error. A null url means no server was configured to fetch
* it from.
*/
internal sealed interface SessionLoad {
data object Loading : SessionLoad
data object Unavailable : SessionLoad
data object Error : SessionLoad
data class Markdown(val blocks: List<MdBlock>) : SessionLoad
data class Html(val document: String) : SessionLoad
}
/**
* Classifies one fetched session file: a failed fetch ([bytes] null) is a distinct
* error state, never rendered as an empty session, and a fetched file decodes to
* its view. Pure, so the decode/parse and the failure branch are unit tested.
* its document text. Pure (the UTF-8 decode replaces malformed sequences rather
* than throwing), so the viewer passes it off the main thread and it is unit
* tested.
*/
internal fun sessionLoad(bytes: ByteArray?, markdown: Boolean): SessionLoad =
if (bytes == null) SessionLoad.Error else decodeSessionFile(bytes, markdown)
/**
* Decodes one session file: markdown into the shared parsed blocks, html into its
* document text. Pure (the UTF-8 decode replaces malformed sequences rather than
* throwing), so the viewer passes it off the main thread and it is unit tested.
*/
internal fun decodeSessionFile(bytes: ByteArray, markdown: Boolean): SessionLoad {
val text = bytes.toString(Charsets.UTF_8)
return if (markdown) SessionLoad.Markdown(parseMarkdown(text)) else SessionLoad.Html(text)
}
internal fun sessionLoad(bytes: ByteArray?): SessionLoad =
if (bytes == null) SessionLoad.Error else SessionLoad.Html(bytes.toString(Charsets.UTF_8))
/**
* The Session section pane: the exported session of the selected visit, read like
* the artifacts beside it. The markdown export is the default and is rendered with
* the app's existing markdown renderer in a lazy list (one parsed block per item),
* so a session of several hundred kilobytes scrolls without composing every block.
* When both files were exported the section offers an "HTML view" toggle that
* swaps in the html document in a WebView for fidelity, and switches back. The
* context line stays pinned above the scroll, exactly as the other section panes
* keep their chrome. On a wide window [visitTabs] renders the pinned visit row in
* that header; on a narrow one the caller owns the visit strip below instead, so the
* header must not double it.
* the artifacts beside it. The one session export is html, shown in a WebView for
* fidelity — there is no markdown view and no view toggle. The context line stays
* pinned above the scroll, exactly as the other section panes keep their chrome.
* On a wide window [visitTabs] renders the pinned visit row in that header; on a
* narrow one the caller owns the visit strip below instead, so the header must not
* double it.
*
* The file is fetched once per url through the app's shared artifact byte cache and
* the fetch/parse run off the main thread, so switching views or reopening the pane
* never re-hits the network and never blocks the pane. A missing server URL shows
* that state, and a failed fetch shows its own error in this pane only: the stage
* screen and every other section are unaffected.
* the fetch runs off the main thread, so reopening the pane never re-hits the
* network and never blocks the pane. A missing server URL shows that state, and a
* failed fetch shows its own error in this pane only: the stage screen and every
* other section are unaffected.
*/
@Composable
internal fun SessionExportSection(
@@ -151,46 +93,17 @@ internal fun SessionExportSection(
visitTabs: Boolean = true,
modifier: Modifier = Modifier,
) {
val text = pipelinesText()
val files = remember(step) { sessionExportFiles(step) }
val file = remember(step) { sessionExportFile(step) }
Column(modifier.fillMaxSize()) {
if (files == null) {
if (file == null) {
SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange, visitTabs) {
Text("No session was exported for this visit.", style = text.meta)
Text("No session was exported for this visit.", style = pipelinesText().meta)
}
return@Column
}
var view by rememberSaveable(step.sequence, files.markdown?.url, files.html?.url) {
mutableStateOf(defaultSessionView(files))
}
val toggle = sessionViewToggle(files)
val artifact = sessionArtifact(files, view)
val url = artifact?.let { resolvedArtifactUrl(it, configuredServerUrl) }
SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange, visitTabs) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(SPACING_S),
) {
Text(
if (view == SessionView.Markdown) "Markdown" else "HTML",
style = text.label,
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.weight(1f),
)
if (toggle) {
OutlinedButton(
onClick = {
view = if (view == SessionView.Markdown) SessionView.Html else SessionView.Markdown
},
) {
Text(if (view == SessionView.Markdown) "HTML view" else "Markdown view")
}
}
}
}
SessionHeader(stageKey, runSteps, visitIndex, onVisitIndexChange, visitTabs) {}
SessionBody(
load = rememberSessionLoad(url, view == SessionView.Markdown, fetchArtifactBytes),
load = rememberSessionLoad(resolvedArtifactUrl(file, configuredServerUrl), fetchArtifactBytes),
modifier = Modifier.weight(1f),
)
}
@@ -198,11 +111,11 @@ internal fun SessionExportSection(
/**
* The session pane's pinned header: the context line naming the stage and — on a
* wide window — the visit row, followed by the caller's [content] (the view toggle,
* or the missing-export notice). It stays above the session's own scroll, exactly as
* the other section panes keep their chrome. On a narrow window [visitTabs] is false
* and the visit selector is the caller's bottom strip instead, so the header does not
* show it twice.
* wide window — the visit row, followed by the caller's [content] (the
* missing-export notice, or nothing when a session is shown). It stays above the
* session's own scroll, exactly as the other section panes keep their chrome. On a
* narrow window [visitTabs] is false and the visit selector is the caller's bottom
* strip instead, so the header does not show it twice.
*/
@Composable
private fun SessionHeader(
@@ -227,9 +140,8 @@ private fun SessionHeader(
}
/**
* The loaded session file's body: the parsed markdown in a lazy list, the html in
* a WebView, or the loading/unavailable/error notice. The one branch that draws a
* session, so the markdown and html paths share the section's fetch and state.
* The loaded session's body: the html document in a WebView, or the
* loading/unavailable/error notice. The one branch that draws a session.
*/
@Composable
private fun SessionBody(load: SessionLoad, modifier: Modifier = Modifier) {
@@ -247,7 +159,6 @@ private fun SessionBody(load: SessionLoad, modifier: Modifier = Modifier) {
message = "Couldn't load the exported session.",
modifier = modifier,
)
is SessionLoad.Markdown -> MarkdownBlocks(blocks = load.blocks, modifier = modifier)
is SessionLoad.Html -> SessionHtml(document = load.document, modifier = modifier)
}
}
@@ -268,11 +179,10 @@ private fun SessionNotice(message: String, modifier: Modifier = Modifier, spinne
}
/**
* The html export in a WebView. The markdown default is rendered natively; the
* html is the fidelity fallback for the structure the app's renderer does not
* reproduce. The document is self-contained, so it is loaded with a null base URL
* (no file or network origin), scripting is off, and the view is destroyed with
* the composition.
* The html export in a WebView, the fidelity view of the one session export. The
* document is self-contained, so it is loaded with a null base URL (no file or
* network origin), scripting is off, and the view is destroyed with the
* composition.
*/
@Composable
private fun SessionHtml(document: String, modifier: Modifier = Modifier) {
@@ -296,27 +206,25 @@ private fun SessionHtml(document: String, modifier: Modifier = Modifier) {
/**
* Loads the resolved session [url] once and classifies it. A null url is
* [SessionLoad.Unavailable] with no request attempted. The bytes are fetched
* through the app's shared [ArtifactBytesCache], so re-opening the section or
* switching views reuses them instead of loading the file a second time; the
* decode and markdown parse run off the main thread so a large session never
* blocks the UI. A canceled effect (the url or view changed) never publishes its
* stale result.
* through the app's shared [ArtifactBytesCache], so re-opening the section reuses
* them instead of loading the file a second time; the decode runs off the main
* thread so a large session never blocks the UI. A canceled effect (the url
* changed) never publishes its stale result.
*/
@Composable
private fun rememberSessionLoad(
url: String?,
markdown: Boolean,
fetchBytes: suspend (String) -> ByteArray?,
): SessionLoad {
if (url == null) return SessionLoad.Unavailable
var load by remember(url) { mutableStateOf<SessionLoad>(SessionLoad.Loading) }
LaunchedEffect(url, markdown) {
LaunchedEffect(url) {
val cached = ArtifactBytesCache.get(url)
val bytes = cached ?: runCatching {
withContext(Dispatchers.IO) { fetchBytes(url) }
}.getOrNull()
if (cached == null && bytes != null) ArtifactBytesCache.put(url, bytes)
load = withContext(Dispatchers.Default) { sessionLoad(bytes, markdown) }
load = withContext(Dispatchers.Default) { sessionLoad(bytes) }
}
return load
}
@@ -59,6 +59,7 @@ import net.awan.pipelines.ui.fileChangesSummary
import net.awan.pipelines.ui.formatDuration
import net.awan.pipelines.ui.notificationLine
import net.awan.pipelines.ui.pendingDecision
import net.awan.pipelines.ui.presentedArtifacts
import net.awan.pipelines.ui.runLabel
import net.awan.pipelines.ui.screens.runTimeline
import net.awan.pipelines.ui.theme.SPACING_L
@@ -259,7 +260,7 @@ internal fun stageSectionSpecs(
// artifacts it was written with: both are the visit's recorded files, and
// the operator reads them the same way. A visit without an export lists no
// Session row at all, rather than an empty section.
val session = sessionExportFiles(selectedStep) != null
val session = sessionExportFile(selectedStep) != null
STAGE_RESULT_SECTIONS.forEach { section ->
when (section) {
StageResultSection.Artifacts -> {
@@ -553,7 +554,7 @@ private fun StageDetailBody(
verdict = selectedStep.verdict,
outcome = selectedStep.outcome,
status = selectedStep.status,
artifacts = selectedStep.artifacts.orEmpty(),
artifacts = presentedArtifacts(selectedStep),
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
)
@@ -701,7 +702,7 @@ fun StageSectionPane(
val selectionState = rememberArtifactSelection(stageKey, clampedVisit)
ArtifactSelectionScaffold(
selectionState = selectionState,
candidates = selectedStep?.artifacts.orEmpty(),
candidates = selectedStep?.let { presentedArtifacts(it) }.orEmpty(),
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
modifier = modifier,
@@ -2,6 +2,7 @@ package net.awan.pipelines.ui.screens
import net.awan.pipelines.data.protocol.GraphSemantics
import net.awan.pipelines.data.protocol.RunStep
import net.awan.pipelines.ui.LEGACY_SESSION_MARKDOWN_ARTIFACT
import net.awan.pipelines.ui.formatDuration
/**
@@ -79,6 +80,9 @@ internal fun timelineDescription(step: RunStep): String {
/**
* Whether a visit recorded any artifacts. The single predicate behind the
* timeline's subtle artifact indicator, so the timeline and the sheet never
* disagree about whether a visit produced files.
* disagree about whether a visit produced files. The retired session markdown is
* not presented, so it never counts; the check does not allocate, unlike
* [presentedArtifacts], and is safe to call on every recomposition.
*/
internal fun hasArtifacts(step: RunStep): Boolean = !step.artifacts.isNullOrEmpty()
internal fun hasArtifacts(step: RunStep): Boolean =
step.artifacts.orEmpty().any { it.name != LEGACY_SESSION_MARKDOWN_ARTIFACT }
@@ -194,4 +194,31 @@ class ArtifactGroupsTest {
runArtifactsHeader(steps, executing = false),
)
}
@Test
fun theLegacySessionMarkdownIsNeverPresented() {
// A run recorded before the HTML-only change still has both files: only the
// html session is presented, never a session markdown beside it.
val withBoth = step(
"implementer",
sequence = 1,
visit = 1,
artifacts = listOf(
artifact("session.md", "/artifacts/9/1/session.md"),
artifact("session.html", "/artifacts/9/1/session.html"),
),
)
assertEquals(listOf("session.html"), presentedArtifacts(withBoth).map { it.name })
assertEquals("Artifacts · 1 recorded", artifactsSummary(withBoth))
assertEquals(listOf("session.html"), runArtifactGroups(listOf(withBoth)).single().artifacts.map { it.name })
assertEquals("Artifact · 1 recorded", runArtifactsHeader(listOf(withBoth), executing = false))
// A visit whose only session file is the retired markdown shows none of it:
// no tile, no group and no recorded count.
val legacyOnly = step("implementer", sequence = 1, visit = 1, artifacts = listOf(artifact("session.md")))
assertTrue(presentedArtifacts(legacyOnly).isEmpty())
assertTrue(runArtifactGroups(listOf(legacyOnly)).isEmpty())
assertEquals("Artifacts · not recorded for this visit", artifactsSummary(legacyOnly))
assertEquals(artifactsEmptyMessage(executing = false), runArtifactsHeader(listOf(legacyOnly), executing = false))
}
}
@@ -17,20 +17,18 @@ class SessionExportTest {
sessionId = "ses_1",
backend = "v2",
source = "native_export",
markdown = "session.md",
html = "session.html",
markdownBytes = 12,
htmlBytes = 34,
messages = 2,
)
@Test
fun aVisitWithNoSessionExportHasNoFiles() {
assertNull(sessionExportFiles(RunStep()))
fun aVisitWithNoSessionExportHasNoSessionFile() {
assertNull(sessionExportFile(RunStep()))
// A limitation-only export (a Pi harness) records names for nothing and
// must not produce an empty section.
assertNull(
sessionExportFiles(
sessionExportFile(
RunStep(
sessionExport = SessionExport(source = "unavailable", diagnostic = "no native export path"),
artifacts = listOf(artifact("session.md", "text/markdown")),
@@ -40,42 +38,36 @@ class SessionExportTest {
}
@Test
fun theRecordedExportNamesResolveToTheListedArtifacts() {
fun theRecordedHTMLExportResolvesToTheListedArtifact() {
val artifacts = listOf(
artifact("shot.png", "image/png"),
artifact("session.md", "text/markdown"),
artifact("session.html", "text/html"),
)
val files = sessionExportFiles(RunStep(sessionExport = nativeExport, artifacts = artifacts))
?: error("expected files")
assertEquals("session.md", files.markdown?.name)
assertEquals("session.html", files.html?.name)
assertEquals(SessionView.Markdown, defaultSessionView(files))
assertTrue(sessionViewToggle(files))
assertEquals(files.markdown, sessionArtifact(files, SessionView.Markdown))
assertEquals(files.html, sessionArtifact(files, SessionView.Html))
val file = sessionExportFile(RunStep(sessionExport = nativeExport, artifacts = artifacts))
?: error("expected the html session file")
// The retired markdown export is never chosen: only the html is presented,
// so the operator never sees a markdown and an html session together.
assertEquals("session.html", file.name)
}
@Test
fun htmlIsTheDefaultAndTheOnlyViewWhenMarkdownIsMissing() {
val export = SessionExport(html = "session.html", source = "native_export")
val files = sessionExportFiles(
RunStep(sessionExport = export, artifacts = listOf(artifact("session.html", "text/html"))),
) ?: error("expected files")
assertNull(files.markdown)
assertEquals(SessionView.Html, defaultSessionView(files))
// The toggle only exists when both exports were written; a single export
// has nothing to switch to.
assertFalse(sessionViewToggle(files))
assertNull(sessionArtifact(files, SessionView.Markdown))
}
@Test
fun aTruncatedListingOrAnAbsentOneLeavesNoFilesToShow() {
assertNull(sessionExportFiles(RunStep(sessionExport = nativeExport)))
assertNull(sessionExportFiles(RunStep(sessionExport = nativeExport, artifacts = emptyList())))
fun aLegacyMarkdownOnlyRecordHasNothingToShow() {
// An older record that named only session.md has no html to present.
val legacy = SessionExport(sessionId = "ses_old", backend = "v2", source = "native_export")
assertNull(
sessionExportFiles(
sessionExportFile(
RunStep(sessionExport = legacy, artifacts = listOf(artifact("session.md", "text/markdown"))),
),
)
}
@Test
fun aTruncatedListingOrAnAbsentOneLeavesNothingToShow() {
assertNull(sessionExportFile(RunStep(sessionExport = nativeExport)))
assertNull(sessionExportFile(RunStep(sessionExport = nativeExport, artifacts = emptyList())))
assertNull(
sessionExportFile(
RunStep(sessionExport = nativeExport, artifacts = listOf(artifact("other.log", "text/plain"))),
),
)
@@ -114,34 +106,15 @@ class SessionExportTest {
@Test
fun aFailedFetchIsItsOwnErrorAndNeverAnEmptySession() {
assertEquals(SessionLoad.Error, sessionLoad(bytes = null, markdown = true))
assertEquals(SessionLoad.Error, sessionLoad(bytes = null, markdown = false))
assertEquals(SessionLoad.Error, sessionLoad(bytes = null))
}
@Test
fun aFetchedFileDecodesToItsView() {
val bytes = "# Title\n\nbody".toByteArray()
assertTrue(sessionLoad(bytes, markdown = true) is SessionLoad.Markdown)
val html = sessionLoad(bytes, markdown = false)
assertTrue(html is SessionLoad.Html)
assertEquals("# Title\n\nbody", (html as SessionLoad.Html).document)
}
@Test
fun aLargeSessionParsesIntoBlocksOffTheViewer() {
// Several hundred kilobytes of markdown: the viewer parses it once into
// blocks (off the main thread) and composes them lazily, so this must not
// fail, throw or drop the document.
val large = buildString {
repeat(6_000) { index ->
append("# Heading $index\n\n")
append("A body line with *emphasis*, `code` and a [link](https://example.test/$index).\n\n")
}
}
assertTrue(large.length > 300_000)
val load = sessionLoad(large.toByteArray(), markdown = true)
assertTrue(load is SessionLoad.Markdown)
assertTrue((load as SessionLoad.Markdown).blocks.size >= 6_000)
fun aFetchedFileDecodesToItsDocument() {
val bytes = "<!doctype html><p>body</p>".toByteArray()
val load = sessionLoad(bytes)
assertTrue(load is SessionLoad.Html)
assertEquals("<!doctype html><p>body</p>", (load as SessionLoad.Html).document)
}
private fun artifact(name: String, contentType: String): StageArtifact =
@@ -122,6 +122,9 @@ class TimelineTest {
// An explicitly empty capture is not an artifact.
assertFalse(hasArtifacts(RunStep(sequence = 1, stage = "a", artifacts = emptyList())))
assertTrue(hasArtifacts(RunStep(sequence = 1, stage = "a", artifacts = listOf(StageArtifact(name = "x.png")))))
// The retired session markdown is not presented, so it is not an artifact.
assertFalse(hasArtifacts(RunStep(sequence = 1, stage = "a", artifacts = listOf(StageArtifact(name = "session.md")))))
assertTrue(hasArtifacts(RunStep(sequence = 1, stage = "a", artifacts = listOf(StageArtifact(name = "session.md"), StageArtifact(name = "session.html")))))
}
@Test