package app import ( "bytes" "context" "io" "reflect" "strings" "testing" "gitea.maximumdirect.net/eric/narratio/internal/config" ) func TestRegenerateArtifactsForwardsCanonicalPipelineRequest(t *testing.T) { workspaceRoot := t.TempDir() pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot) enableCommandTestOverlays(t, pipelinePath) 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 } code := executeWithPipelineExecutor([]string{ "artifacts", "regenerate", "2026-05-03", "--artifacts", "session_recap,player_handout", "--artifacts=player_handout", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--overlay", "testing", }, io.Discard, io.Discard, executor) if code != 0 { t.Fatalf("executeWithPipelineExecutor() code = %d, want 0", code) } if got, want := capturedPlan.Names(), []string{"extract", "analyze"}; !reflect.DeepEqual(got, want) { t.Fatalf("plan = %#v, want %#v", got, want) } 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) } } func TestRegenerateArtifactsHelpDoesNotInvokeRun(t *testing.T) { called := false executor := func(context.Context, *config.Config, BoundedPlan, RunOptions) (*RunSummary, error) { called = true return nil, nil } var stdout bytes.Buffer var stderr bytes.Buffer if code := executeWithPipelineExecutor([]string{"artifacts", "regenerate", "--help"}, &stdout, &stderr, executor); code != 0 { t.Fatalf("executeForTest() code = %d, stderr = %q", code, stderr.String()) } if called { t.Fatal("help invoked canonical run handler") } for _, detail := range []string{ "regenerate", "--artifacts", "--session-file", } { 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()) } }