Files
pipelines/internal/protocol/runs_test.go
T
alan 95362134aa 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.
2026-10-18 10:06:49 +01:00

76 lines
2.3 KiB
Go

package protocol
import (
"encoding/json"
"strings"
"testing"
)
func TestRunStepArtifactsRoundTrip(t *testing.T) {
step := RunStep{
Sequence: 2,
Stage: "review",
Artifacts: []StageArtifact{{
Name: "captures/shot.png",
SizeBytes: 1234,
ContentType: "image/png",
URL: "/artifacts/9/2/captures/shot.png",
}},
ArtifactsSkipped: 1,
ArtifactsTruncated: 3,
}
encoded, err := json.Marshal(step)
if err != nil {
t.Fatal(err)
}
var decoded RunStep
if err := json.Unmarshal(encoded, &decoded); err != nil {
t.Fatal(err)
}
if len(decoded.Artifacts) != 1 || decoded.Artifacts[0] != step.Artifacts[0] {
t.Fatalf("artifacts lost in round trip: %+v", decoded.Artifacts)
}
if decoded.ArtifactsSkipped != 1 || decoded.ArtifactsTruncated != 3 {
t.Fatalf("counters lost in round trip: %+v", decoded)
}
}
func TestRunStepOmitsAbsentArtifacts(t *testing.T) {
encoded, err := json.Marshal(RunStep{Sequence: 1, Stage: "one"})
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(encoded), "artifacts") {
t.Fatalf("empty artifacts must be omitted: %s", encoded)
}
var decoded RunStep
if err := json.Unmarshal([]byte(`{"sequence":1}`), &decoded); err != nil {
t.Fatal(err)
}
if decoded.Artifacts != nil || decoded.ArtifactsSkipped != 0 || decoded.ArtifactsTruncated != 0 {
t.Fatalf("absent field must decode empty: %+v", decoded)
}
}
func TestPresentedArtifactsHidesRetiredSessionMarkdown(t *testing.T) {
step := RunStep{Artifacts: []StageArtifact{
{Name: "session.md", URL: "/artifacts/344/1/session.md"},
{Name: "session.html", URL: "/artifacts/344/1/session.html"},
{Name: "shot.png", URL: "/artifacts/344/1/shot.png"},
}}
presented := step.PresentedArtifacts()
if len(presented) != 2 || presented[0].Name != "session.html" || presented[1].Name != "shot.png" {
t.Fatalf("presented = %+v", presented)
}
if len(step.Artifacts) != 3 {
t.Fatalf("PresentedArtifacts mutated the stored record: %+v", step.Artifacts)
}
if got := (RunStep{}).PresentedArtifacts(); got != nil {
t.Fatalf("empty step presented %+v, want nil", got)
}
onlyLegacy := RunStep{Artifacts: []StageArtifact{{Name: LegacySessionMarkdownArtifact}}}
if got := onlyLegacy.PresentedArtifacts(); got != nil {
t.Fatalf("legacy-only step presented %+v, want nil", got)
}
}