71 lines
2.5 KiB
Go
71 lines
2.5 KiB
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bytes"
|
||
|
|
"context"
|
||
|
|
"encoding/json"
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||
|
|
"go.maximumdirect.net/commandkit"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestSessionPlanCommandReportsWorkWithoutRuntimeState(t *testing.T) {
|
||
|
|
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
|
||
|
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||
|
|
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||
|
|
t.Fatalf("fixture session root=%v", err)
|
||
|
|
}
|
||
|
|
app, err := newApplication(commandDependencies{}, func(context.Context, *config.Config, BoundedPlan, RunOptions) (*RunSummary, error) {
|
||
|
|
t.Fatal("planning executed pipeline")
|
||
|
|
return nil, nil
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
var out, diagnostic bytes.Buffer
|
||
|
|
outcome := app.Execute(context.Background(), []string{"session", "plan", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--force", "--artifacts", "session_recap", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||
|
|
if outcome.Status != 0 {
|
||
|
|
t.Fatalf("status=%d error=%v diagnostics=%s", outcome.Status, outcome.Cause, diagnostic.String())
|
||
|
|
}
|
||
|
|
var report sessionPlanReport
|
||
|
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if report.SessionID != "2026-05-03" || len(report.Stages) != len(BuildFullPlan()) {
|
||
|
|
t.Fatalf("plan=%#v", report)
|
||
|
|
}
|
||
|
|
foundAnalysis := false
|
||
|
|
for _, entry := range report.Stages {
|
||
|
|
if entry.Action != "run" || entry.Reason != "forced" {
|
||
|
|
t.Fatalf("stage=%#v", entry)
|
||
|
|
}
|
||
|
|
if entry.Name == "analyze" {
|
||
|
|
foundAnalysis = entry.Analysis != nil && len(entry.Analysis.Targets) > 0
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if !foundAnalysis {
|
||
|
|
t.Fatal("plan omitted artifact work")
|
||
|
|
}
|
||
|
|
if len(report.Publication) != len(cfg.PublicationOutputs()) {
|
||
|
|
t.Fatalf("publication actions=%#v", report.Publication)
|
||
|
|
}
|
||
|
|
for _, action := range report.Publication {
|
||
|
|
if action.Destination == "" {
|
||
|
|
t.Fatalf("unresolved publication action=%#v", action)
|
||
|
|
}
|
||
|
|
if action.Source == "narratio.artifact.player_handout" && action.Selected {
|
||
|
|
t.Fatal("plan selected an unrequested publication target")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||
|
|
t.Fatalf("planning created runtime state: %v", err)
|
||
|
|
}
|
||
|
|
}
|