Preserve partial run results and terminal failure causes
This commit is contained in:
@@ -4,7 +4,12 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
@@ -101,3 +106,102 @@ func TestExecutionCommandsRejectInvalidSelectionBeforeBootstrap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type releaseObservedStore struct {
|
||||
artifacts.Store
|
||||
released bool
|
||||
}
|
||||
|
||||
func (s *releaseObservedStore) ReleaseSessionLock(lock *artifacts.LockHandle) error {
|
||||
err := s.Store.ReleaseSessionLock(lock)
|
||||
s.released = true
|
||||
return err
|
||||
}
|
||||
|
||||
type failingRunReportWriter struct {
|
||||
t *testing.T
|
||||
store *releaseObservedStore
|
||||
err error
|
||||
}
|
||||
|
||||
func (w failingRunReportWriter) Write([]byte) (int, error) {
|
||||
if !w.store.released {
|
||||
w.t.Fatal("report written before lock release")
|
||||
}
|
||||
return 0, w.err
|
||||
}
|
||||
|
||||
func TestExecutionCommandReportFailurePreservesCompletedWork(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
writeErr := errors.New("report destination unavailable")
|
||||
var saved *RunSummary
|
||||
var local *releaseObservedStore
|
||||
app, err := newApplication(commandDependencies{}, func(ctx context.Context, cfg *config.Config, _ BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
||||
local = &releaseObservedStore{Store: artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)}
|
||||
opts.Env = &Env{ArtifactStore: local}
|
||||
var err error
|
||||
saved, err = executeStages(ctx, cfg, []stage.Stage{resultStage{name: "prepare"}}, opts)
|
||||
return saved, err
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Defer resolving the store until Report invokes Write.
|
||||
writer := runReportWriteFunc(func(p []byte) (int, error) {
|
||||
return (failingRunReportWriter{t: t, store: local, err: writeErr}).Write(p)
|
||||
})
|
||||
var diagnostic bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"run", "2026-05-03", "--stage", "prepare", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}, commandkit.Streams{Out: writer, Err: &diagnostic})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, writeErr) {
|
||||
t.Fatalf("outcome=%#v diagnostics=%s", outcome, diagnostic.String())
|
||||
}
|
||||
if saved == nil || !saved.Complete {
|
||||
t.Fatalf("completed domain result=%#v", saved)
|
||||
}
|
||||
durable, err := (&manifest.LocalStore{}).Load(context.Background(), saved.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if durable.Stages["prepare"].Status != manifest.StatusSucceeded || durable.LastError != nil {
|
||||
t.Fatalf("report failure changed domain state: %#v", durable)
|
||||
}
|
||||
}
|
||||
|
||||
type runReportWriteFunc func([]byte) (int, error)
|
||||
|
||||
func (f runReportWriteFunc) Write(p []byte) (int, error) { return f(p) }
|
||||
|
||||
func TestExecutionCommandPresentsPartialFailureThroughNativeVisibility(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
cause := errors.New("synthetic terminal operation failure")
|
||||
app, err := newApplication(commandDependencies{}, func(_ context.Context, cfg *config.Config, _ BoundedPlan, _ RunOptions) (*RunSummary, error) {
|
||||
return &RunSummary{SessionID: cfg.Session.SessionID, RunID: "synthetic-run", Executed: []string{"prepare", "transcribe"}, StageResults: []RunStageResult{{Name: "prepare", Attempted: true, Outcome: "completed"}, {Name: "transcribe", Attempted: true, Outcome: "failed"}}}, cause
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, quiet := range []bool{false, true} {
|
||||
args := []string{"run", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}
|
||||
if quiet {
|
||||
args = append(args, "--quiet")
|
||||
}
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, cause) || strings.Count(diagnostic.String(), cause.Error()) != 1 {
|
||||
t.Fatalf("outcome=%#v diagnostics=%s", outcome, diagnostic.String())
|
||||
}
|
||||
if quiet {
|
||||
if out.Len() != 0 {
|
||||
t.Fatal("quiet emitted a report")
|
||||
}
|
||||
continue
|
||||
}
|
||||
var report runReport
|
||||
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if report.Complete || len(report.StageResults) != 2 || report.StageResults[1].Outcome != "failed" {
|
||||
t.Fatalf("report=%#v", report)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user