runner: gate stage handoff on settled verified session export

This commit is contained in:
2026-10-20 20:54:51 +01:00
parent 3d35e8a863
commit f87e1ed488
18 changed files with 791 additions and 26 deletions
+28 -5
View File
@@ -12,6 +12,7 @@ import (
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/opencode"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
@@ -25,8 +26,8 @@ const sessionExportBody = `{"info":{"id":"ses_run"},"messages":[` +
`{"type":"text","text":"done"},` +
`{"type":"tool","name":"shell","state":{"status":"completed","input":{"cmd":"ls"},"content":[{"type":"text","text":"output here"}]}}]}]}`
// sessionExportCLI points PIPELINES_OPENCODE at a fake `opencode export` that
// returns sessionExportBody, so the runner's real export path runs.
// sessionExportCLI isolates both the authenticated V2 API and legacy CLI.
// Neither export transport may fall through to the operator's real service.
func sessionExportCLI(t *testing.T) {
t.Helper()
path := filepath.Join(t.TempDir(), "opencode")
@@ -38,6 +39,28 @@ func sessionExportCLI(t *testing.T) {
t.Fatal(err)
}
t.Setenv("PIPELINES_OPENCODE", path)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, password, ok := r.BasicAuth()
if !ok || user != "opencode" || password != "fixture-password" {
w.WriteHeader(http.StatusUnauthorized)
return
}
if r.Method != "GET" || r.URL.Path != "/api/experimental/session/ses_run/export" || r.URL.Query().Get("sanitize") != "false" {
t.Errorf("unexpected export operation: %s %s", r.Method, r.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, `{"data":`+sessionExportBody+`}`)
}))
t.Cleanup(srv.Close)
passwordPath := filepath.Join(t.TempDir(), "password")
if err := os.WriteFile(passwordPath, []byte("fixture-password"), 0600); err != nil {
t.Fatal(err)
}
t.Setenv(opencode.EndpointEnvKey, srv.URL)
t.Setenv(opencode.EndpointPasswordFileEnvKey, passwordPath)
t.Setenv(opencode.EndpointUsernameEnvKey, "")
}
// sessionExportRunner runs one stage that records a session for the run, so the
@@ -145,7 +168,7 @@ func TestRunnerExportsTheHTMLSessionIntoArtifactsAndServesIt(t *testing.T) {
}
// TestRunnerSessionExportFailureTruncationAndUnavailableHarness proves the three
// non-success export outcomes are recorded as evidence and never fail the run.
// non-success exports block success without replacing the completed computation.
func TestRunnerSessionExportFailureTruncationAndUnavailableHarness(t *testing.T) {
cases := []struct {
name string
@@ -188,8 +211,8 @@ func TestRunnerSessionExportFailureTruncationAndUnavailableHarness(t *testing.T)
if err != nil {
t.Fatal(err)
}
if detail.Status != "succeeded" {
t.Fatalf("export outcome failed the run: %+v", detail.Status)
if detail.Status != "failed" || !strings.Contains(detail.Diagnostic, "Session export gate blocked") || detail.Output["summary"] != "done" {
t.Fatalf("export gate did not preserve and block computation: %+v", detail)
}
step := detail.Steps[0]
if step.Status != "completed" || step.Outcome != "success" {