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:
@@ -1225,9 +1225,7 @@ func (r *runner) exportStageSession(ctx context.Context, owner pipeline.SessionO
|
||||
return evidence
|
||||
}
|
||||
evidence.Source = result.Source
|
||||
evidence.Markdown = result.Markdown
|
||||
evidence.HTML = result.HTML
|
||||
evidence.MarkdownBytes = result.MarkdownBytes
|
||||
evidence.HTMLBytes = result.HTMLBytes
|
||||
evidence.Messages = result.Messages
|
||||
evidence.Truncated = result.Truncated
|
||||
|
||||
@@ -30,8 +30,8 @@ func sessionExportLiveSource(provider, model string) string {
|
||||
|
||||
// TestSessionExportLive is an opt-in live check: it runs one real OpenCode stage
|
||||
// on a temporary store and artifacts root using the configured host harness,
|
||||
// then proves the real session.md/session.html are written, listed and served
|
||||
// 200. It is gated so the default suite never spends inference.
|
||||
// then proves the real session.html is written, listed and served 200. It is
|
||||
// gated so the default suite never spends inference.
|
||||
func TestSessionExportLive(t *testing.T) {
|
||||
if os.Getenv("PIPELINES_SESSION_EXPORT_LIVE") != "1" {
|
||||
t.Skip("set PIPELINES_SESSION_EXPORT_LIVE=1 and PIPELINES_SESSION_EXPORT_MODEL to run chargeable session-export inference")
|
||||
@@ -89,15 +89,18 @@ func TestSessionExportLive(t *testing.T) {
|
||||
t.Fatalf("live run did not succeed: %+v", detail)
|
||||
}
|
||||
step := detail.Steps[0]
|
||||
if step.SessionExport == nil || step.SessionExport.Source != "native_export" || step.SessionExport.MarkdownBytes == 0 || step.SessionExport.HTMLBytes == 0 {
|
||||
if step.SessionExport == nil || step.SessionExport.Source != "native_export" || step.SessionExport.HTML != "session.html" || step.SessionExport.HTMLBytes == 0 {
|
||||
t.Fatalf("live session export evidence missing: %+v", step.SessionExport)
|
||||
}
|
||||
if step.SessionExport.Messages == 0 || step.SessionExport.Truncated {
|
||||
t.Fatalf("live session export was empty or truncated: %+v", step.SessionExport)
|
||||
}
|
||||
if _, ok := artifactNamed(step.Artifacts, stage.SessionMarkdownFile); ok {
|
||||
t.Fatalf("live run produced a legacy session.md: %+v", step.Artifacts)
|
||||
}
|
||||
srv := httptest.NewServer(handler)
|
||||
defer srv.Close()
|
||||
for _, name := range []string{"session.md", "session.html"} {
|
||||
for _, name := range []string{stage.SessionHTMLFile} {
|
||||
artifact, ok := artifactNamed(step.Artifacts, name)
|
||||
if !ok {
|
||||
t.Fatalf("%s not in live artifact listing: %+v", name, step.Artifacts)
|
||||
@@ -150,19 +153,23 @@ func TestSessionExportRecorded(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("recorded session export failed: %v", err)
|
||||
}
|
||||
for _, name := range []string{stage.SessionMarkdownFile, stage.SessionHTMLFile} {
|
||||
info, err := os.Stat(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, _ := os.ReadFile(filepath.Join(dir, name))
|
||||
first := string(data)
|
||||
if idx := strings.IndexByte(first, '\n'); idx >= 0 {
|
||||
first = first[:idx]
|
||||
}
|
||||
t.Logf("recorded export (NOT a fresh runner stage) %s: path=%s size=%d first_line=%q", name, filepath.Join(dir, name), info.Size(), first)
|
||||
if result.HTML != stage.SessionHTMLFile || result.HTMLBytes == 0 {
|
||||
t.Fatalf("recorded export wrote no html: %+v", result)
|
||||
}
|
||||
if result.MarkdownBytes == 0 || result.HTMLBytes == 0 {
|
||||
t.Fatalf("recorded export wrote no files: %+v", result)
|
||||
htmlPath := filepath.Join(dir, stage.SessionHTMLFile)
|
||||
info, err := os.Stat(htmlPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, _ := os.ReadFile(htmlPath)
|
||||
first := string(data)
|
||||
if idx := strings.IndexByte(first, '\n'); idx >= 0 {
|
||||
first = first[:idx]
|
||||
}
|
||||
t.Logf("recorded export (NOT a fresh runner stage) %s: path=%s size=%d first_line=%q", stage.SessionHTMLFile, htmlPath, info.Size(), first)
|
||||
if _, err := os.Stat(filepath.Join(dir, stage.SessionMarkdownFile)); err == nil {
|
||||
// A pre-existing session.md from an older run may sit here; the export
|
||||
// must not have produced or rewritten it.
|
||||
t.Logf("pre-existing %s left in place; the export writes no markdown", stage.SessionMarkdownFile)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ func sessionExportRunner(t *testing.T, backend string, seam func(stage.SessionEx
|
||||
return handler, store, run.ID
|
||||
}
|
||||
|
||||
// TestRunnerExportsSessionFilesIntoArtifactsAndServesThem proves the real export
|
||||
// path writes both files into the step's artifacts directory, lists them with
|
||||
// artifact URLs and serves them 200, without changing the step's status, outcome
|
||||
// or target.
|
||||
func TestRunnerExportsSessionFilesIntoArtifactsAndServesThem(t *testing.T) {
|
||||
// TestRunnerExportsTheHTMLSessionIntoArtifactsAndServesIt proves the real export
|
||||
// path writes the one html session file into the step's artifacts directory,
|
||||
// lists it with an artifact URL and serves it 200, without changing the step's
|
||||
// status, outcome or target, and produces no legacy session.md.
|
||||
func TestRunnerExportsTheHTMLSessionIntoArtifactsAndServesIt(t *testing.T) {
|
||||
sessionExportCLI(t)
|
||||
handler, store, runID := sessionExportRunner(t, "v2", nil)
|
||||
detail, err := store.GetRun(context.Background(), runID)
|
||||
@@ -110,45 +110,37 @@ func TestRunnerExportsSessionFilesIntoArtifactsAndServesThem(t *testing.T) {
|
||||
if step.SessionExport == nil || step.SessionExport.SessionID != "ses_run" || step.SessionExport.Source != "native_export" {
|
||||
t.Fatalf("export evidence missing: %+v", step.SessionExport)
|
||||
}
|
||||
if step.SessionExport.Messages != 2 || step.SessionExport.MarkdownBytes == 0 || step.SessionExport.HTMLBytes == 0 {
|
||||
if step.SessionExport.HTML != "session.html" || step.SessionExport.Messages != 2 || step.SessionExport.HTMLBytes == 0 {
|
||||
t.Fatalf("export evidence wrong: %+v", step.SessionExport)
|
||||
}
|
||||
for _, name := range []string{"session.md", "session.html"} {
|
||||
artifact, ok := artifactNamed(step.Artifacts, name)
|
||||
if !ok {
|
||||
t.Fatalf("%s not in the artifact listing: %+v", name, step.Artifacts)
|
||||
}
|
||||
wantURL := fmt.Sprintf("/artifacts/%d/1/%s", runID, name)
|
||||
if artifact.URL != wantURL || artifact.SizeBytes == 0 {
|
||||
t.Fatalf("%s listing wrong: %+v", name, artifact)
|
||||
}
|
||||
if _, ok := artifactNamed(step.Artifacts, stage.SessionMarkdownFile); ok {
|
||||
t.Fatalf("legacy session.md must not be produced: %+v", step.Artifacts)
|
||||
}
|
||||
artifact, ok := artifactNamed(step.Artifacts, "session.html")
|
||||
if !ok {
|
||||
t.Fatalf("session.html not in the artifact listing: %+v", step.Artifacts)
|
||||
}
|
||||
wantURL := fmt.Sprintf("/artifacts/%d/1/session.html", runID)
|
||||
if artifact.URL != wantURL || artifact.SizeBytes == 0 {
|
||||
t.Fatalf("session.html listing wrong: %+v", artifact)
|
||||
}
|
||||
|
||||
srv := httptest.NewServer(handler)
|
||||
defer srv.Close()
|
||||
for _, name := range []string{"session.md", "session.html"} {
|
||||
resp, err := http.Get(srv.URL + fmt.Sprintf("/artifacts/%d/1/%s", runID, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK || len(body) == 0 {
|
||||
t.Fatalf("%s served %d (%d bytes)", name, resp.StatusCode, len(body))
|
||||
}
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
if name == "session.md" && !strings.HasPrefix(contentType, "text/markdown") && !strings.HasPrefix(contentType, "text/plain") {
|
||||
t.Fatalf("session.md content type = %q", contentType)
|
||||
}
|
||||
if name == "session.html" && !strings.HasPrefix(contentType, "text/html") {
|
||||
t.Fatalf("session.html content type = %q", contentType)
|
||||
}
|
||||
if name == "session.md" && !strings.Contains(string(body), "do the task") {
|
||||
t.Fatalf("served markdown missing session text")
|
||||
}
|
||||
if name == "session.html" && !strings.Contains(string(body), "output here") {
|
||||
t.Fatalf("served html missing tool output")
|
||||
}
|
||||
resp, err := http.Get(srv.URL + wantURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK || len(body) == 0 {
|
||||
t.Fatalf("session.html served %d (%d bytes)", resp.StatusCode, len(body))
|
||||
}
|
||||
if contentType := resp.Header.Get("Content-Type"); !strings.HasPrefix(contentType, "text/html") {
|
||||
t.Fatalf("session.html content type = %q", contentType)
|
||||
}
|
||||
if !strings.Contains(string(body), "output here") {
|
||||
t.Fatal("served html missing tool output")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user