2026-08-29 18:19:54 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"io"
|
|
|
|
|
"reflect"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
2026-09-04 01:21:37 +00:00
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
2026-08-29 18:19:54 +00:00
|
|
|
)
|
|
|
|
|
|
2026-09-04 01:21:37 +00:00
|
|
|
func TestRegenerateArtifactsForwardsCanonicalPipelineRequest(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
2026-09-25 15:24:03 +00:00
|
|
|
enableCommandTestOverlays(t, pipelinePath)
|
2026-09-04 01:21:37 +00:00
|
|
|
var capturedPlan BoundedPlan
|
|
|
|
|
var capturedOptions RunOptions
|
|
|
|
|
executor := func(_ context.Context, cfg *config.Config, plan BoundedPlan, options RunOptions) (*RunSummary, error) {
|
|
|
|
|
capturedPlan = plan
|
|
|
|
|
capturedOptions = options
|
|
|
|
|
return &RunSummary{SessionID: cfg.Session.SessionID, ManifestPath: "manifest.json"}, nil
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-04 01:21:37 +00:00
|
|
|
code := executeWithPipelineExecutor([]string{
|
2026-11-20 05:10:04 +00:00
|
|
|
"artifacts", "regenerate", "2026-05-03",
|
2026-08-29 18:19:54 +00:00
|
|
|
"--artifacts", "session_recap,player_handout",
|
|
|
|
|
"--artifacts=player_handout",
|
2026-09-04 01:21:37 +00:00
|
|
|
"--config", pipelinePath,
|
|
|
|
|
"--campaign-file", campaignPath,
|
2026-11-20 05:10:04 +00:00
|
|
|
"--session-file", sessionPath,
|
2026-09-25 15:24:03 +00:00
|
|
|
"--overlay", "testing",
|
2026-09-04 01:21:37 +00:00
|
|
|
}, io.Discard, io.Discard, executor)
|
2026-08-29 18:19:54 +00:00
|
|
|
if code != 0 {
|
2026-09-04 01:21:37 +00:00
|
|
|
t.Fatalf("executeWithPipelineExecutor() code = %d, want 0", code)
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
2026-09-04 01:21:37 +00:00
|
|
|
if got, want := capturedPlan.Names(), []string{"extract", "analyze"}; !reflect.DeepEqual(got, want) {
|
|
|
|
|
t.Fatalf("plan = %#v, want %#v", got, want)
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
2026-09-04 01:21:37 +00:00
|
|
|
if !capturedOptions.Force {
|
|
|
|
|
t.Fatal("force = false, want true")
|
|
|
|
|
}
|
|
|
|
|
if got, want := capturedOptions.SelectedArtifacts, []string{"player_handout", "session_recap"}; !reflect.DeepEqual(got, want) {
|
|
|
|
|
t.Fatalf("selected artifacts = %#v, want %#v", got, want)
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRegenerateArtifactsHelpDoesNotInvokeRun(t *testing.T) {
|
|
|
|
|
called := false
|
2026-09-04 01:21:37 +00:00
|
|
|
executor := func(context.Context, *config.Config, BoundedPlan, RunOptions) (*RunSummary, error) {
|
2026-08-29 18:19:54 +00:00
|
|
|
called = true
|
2026-09-04 01:21:37 +00:00
|
|
|
return nil, nil
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 05:10:04 +00:00
|
|
|
if code := executeWithPipelineExecutor([]string{"artifacts", "regenerate", "--help"}, &stdout, &stderr, executor); code != 0 {
|
2026-11-20 04:13:05 +00:00
|
|
|
t.Fatalf("executeForTest() code = %d, stderr = %q", code, stderr.String())
|
2026-08-29 18:19:54 +00:00
|
|
|
}
|
|
|
|
|
if called {
|
|
|
|
|
t.Fatal("help invoked canonical run handler")
|
|
|
|
|
}
|
|
|
|
|
for _, detail := range []string{
|
2026-11-20 05:10:04 +00:00
|
|
|
"regenerate",
|
|
|
|
|
"--artifacts",
|
|
|
|
|
"--session-file",
|
2026-08-29 18:19:54 +00:00
|
|
|
} {
|
|
|
|
|
if !strings.Contains(stdout.String(), detail) {
|
|
|
|
|
t.Fatalf("help = %q, want %q", stdout.String(), detail)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if stderr.Len() != 0 {
|
|
|
|
|
t.Fatalf("stderr = %q, want empty", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|