76 lines
2.6 KiB
Go
76 lines
2.6 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"path/filepath"
|
|
"reflect"
|
|
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
)
|
|
|
|
func TestRunPassesBoundedPlanToRunner(t *testing.T) {
|
|
workspaceRoot := t.TempDir()
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
|
|
var capturedStages []string
|
|
var capturedPlan BoundedPlan
|
|
var capturedOptions RunOptions
|
|
executor := func(_ context.Context, _ *config.Config, plan BoundedPlan, options RunOptions) (*RunSummary, error) {
|
|
capturedStages = plan.Names()
|
|
capturedPlan = plan
|
|
capturedOptions = options
|
|
return &RunSummary{SessionID: "2026-05-03", ManifestPath: filepath.Join(workspaceRoot, "manifest.json")}, nil
|
|
}
|
|
|
|
var out bytes.Buffer
|
|
err := invokeNativeCommandWith(context.Background(), []string{"run", "2026-05-03",
|
|
"--from", "render",
|
|
"--through", "extract",
|
|
"--force",
|
|
"--config", pipelinePath,
|
|
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
|
}, &out, executor, commandDependencies{})
|
|
if err != nil {
|
|
t.Fatalf("Run() error = %v", err)
|
|
}
|
|
want := []string{"render", "extract"}
|
|
if !reflect.DeepEqual(capturedStages, want) || !reflect.DeepEqual(capturedPlan.Names(), want) || !capturedOptions.Force {
|
|
t.Fatalf("stages = %#v options = %#v", capturedStages, capturedOptions)
|
|
}
|
|
}
|
|
|
|
func TestPlanPrintsOnlyBoundedRange(t *testing.T) {
|
|
workspaceRoot := t.TempDir()
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
m := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
|
|
m.Campaign = "sample-campaign"
|
|
for _, name := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim"} {
|
|
m.MarkStageSucceeded(name, time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
}
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
if err := (&manifest.LocalStore{}).Save(context.Background(), manifestPath, m); err != nil {
|
|
t.Fatalf("save prerequisite manifest: %v", err)
|
|
}
|
|
var out bytes.Buffer
|
|
err := invokeNativeCommand(context.Background(), []string{"session", "plan", "2026-05-03",
|
|
"--from", "render",
|
|
"--through", "extract",
|
|
"--config", pipelinePath,
|
|
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
|
}, &out)
|
|
if err != nil {
|
|
t.Fatalf("Plan() error = %v", err)
|
|
}
|
|
report := decodeNativeReport[sessionPlanReport](t, out.Bytes())
|
|
if len(report.Stages) != 2 || report.Stages[0].Name != "render" || report.Stages[1].Name != "extract" || report.Stages[0].Action != "run" || report.Stages[1].Action != "run" {
|
|
t.Fatalf("bounded plan=%#v", report)
|
|
}
|
|
|
|
}
|