95362134aa
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.
176 lines
6.7 KiB
Go
176 lines
6.7 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"git.a-wan.net/alan/pipelines/internal/stage"
|
|
)
|
|
|
|
// sessionExportLiveSource is a one-stage pipeline that declares the read tool so
|
|
// the stage runs as an agent (the V2 path that persists session messages) while
|
|
// the prompt tells it not to use any tool.
|
|
func sessionExportLiveSource(provider, model string) string {
|
|
return "# stage one\n\n```output\n{ summary }\n```\n\n" +
|
|
"```prompt\nReturn success with summary exactly: session export live check. Do not use any tool.\n```\n\n" +
|
|
"```tools\nread\n```\n\n" +
|
|
"```configs\nprovider=" + provider + "\nmodel=" + model + "\nretries=0\ntimeout=2m\n```\n\n" +
|
|
"```edges\nsuccess -> #success\nerror -> #failure\n```\n\n"
|
|
}
|
|
|
|
// 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.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")
|
|
}
|
|
model := os.Getenv("PIPELINES_SESSION_EXPORT_MODEL")
|
|
provider, id, ok := strings.Cut(model, "/")
|
|
if !ok || !stage.ValidModel(provider, id) {
|
|
t.Fatal("explicit valid PIPELINES_SESSION_EXPORT_MODEL required")
|
|
}
|
|
// Isolate notifications from the operator's real ntfy service.
|
|
endpoint := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
fmt.Fprint(w, `{"id":"session-export-live-receipt","event":"message"}`)
|
|
}))
|
|
defer endpoint.Close()
|
|
t.Setenv("PIPELINES_NTFY_URL", endpoint.URL+"/live")
|
|
t.Setenv("PIPELINES_NTFY_TOKEN", "")
|
|
t.Setenv("PIPELINES_NTFY_TOKEN_FILE", "")
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute)
|
|
defer cancel()
|
|
root := t.TempDir()
|
|
store, err := pipeline.Open(filepath.Join(root, "runs.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
if _, err := store.Submit(ctx, "session-export-live", sessionExportLiveSource(provider, id)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items, err := store.List(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
handler := Handler(ctx, store).(*runHandler)
|
|
handler.runner.artifactsRoot = filepath.Join(root, "artifacts")
|
|
defer func() { cancel(); WaitRuns(handler) }()
|
|
workspace := filepath.Join(root, "ws")
|
|
if err := os.Mkdir(workspace, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
run, err := handler.runner.start(protocol.Message{
|
|
PipelineID: items[0].ID, Version: 1, RequestKey: "session-export-live",
|
|
Workspace: workspace, Input: map[string]any{"prompt": "Return the fixed session export live check."},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
handler.runner.wg.Wait()
|
|
detail, err := store.GetRun(context.Background(), run.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if detail.Status != "succeeded" || len(detail.Steps) != 1 {
|
|
t.Fatalf("live run did not succeed: %+v", detail)
|
|
}
|
|
step := detail.Steps[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{stage.SessionHTMLFile} {
|
|
artifact, ok := artifactNamed(step.Artifacts, name)
|
|
if !ok {
|
|
t.Fatalf("%s not in live artifact listing: %+v", name, step.Artifacts)
|
|
}
|
|
resp, err := http.Get(srv.URL + artifact.URL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body, _ := io.ReadAll(resp.Body)
|
|
resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("%s served HTTP %d", name, resp.StatusCode)
|
|
}
|
|
path := filepath.Join(handler.runner.artifactsRoot, fmt.Sprint(run.ID), "1", name)
|
|
if evidenceDir := os.Getenv("PIPELINES_SESSION_EXPORT_LIVE_DIR"); evidenceDir != "" {
|
|
if err := os.MkdirAll(evidenceDir, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(evidenceDir, name), body, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
first := string(body)
|
|
if idx := strings.IndexByte(first, '\n'); idx >= 0 {
|
|
first = first[:idx]
|
|
}
|
|
t.Logf("live export %s: path=%s size=%d messages=%d url=%s http=%d first_line=%q", name, path, len(body), step.SessionExport.Messages, artifact.URL, resp.StatusCode, first)
|
|
}
|
|
}
|
|
|
|
// TestSessionExportRecorded is the fallback evidence path: with no chargeable
|
|
// inference, it exports one real recorded session read-only through the same
|
|
// code path, clearly labelled as not produced by a fresh runner stage.
|
|
func TestSessionExportRecorded(t *testing.T) {
|
|
session := os.Getenv("PIPELINES_SESSION_EXPORT_RECORDED_ID")
|
|
if session == "" {
|
|
t.Skip("set PIPELINES_SESSION_EXPORT_RECORDED_ID and _DIR to export a recorded session read-only (no inference)")
|
|
}
|
|
dir := os.Getenv("PIPELINES_SESSION_EXPORT_RECORDED_DIR")
|
|
if dir == "" {
|
|
t.Fatal("PIPELINES_SESSION_EXPORT_RECORDED_DIR required")
|
|
}
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
result, err := stage.ExportSession(context.Background(), stage.SessionExportRequest{
|
|
SessionID: session, Backend: "v2", Directory: dir, ArtifactsDir: dir,
|
|
RunID: 0, Sequence: 0, Stage: "recorded",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("recorded session export failed: %v", err)
|
|
}
|
|
if result.HTML != stage.SessionHTMLFile || result.HTMLBytes == 0 {
|
|
t.Fatalf("recorded export wrote no html: %+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)
|
|
}
|
|
}
|