Files
narratio/internal/app/bounded_run_test.go

76 lines
2.6 KiB
Go
Raw Normal View History

2026-08-29 18:07:24 +00:00
package app
import (
"bytes"
"context"
2026-08-29 18:07:24 +00:00
"path/filepath"
"reflect"
2026-08-29 18:07:24 +00:00
"testing"
2026-08-29 18:17:05 +00:00
"time"
2026-08-29 18:07:24 +00:00
"gitea.maximumdirect.net/eric/narratio/internal/config"
2026-08-29 18:17:05 +00:00
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
2026-08-29 18:07:24 +00:00
)
func TestRunPassesBoundedPlanToRunner(t *testing.T) {
workspaceRoot := t.TempDir()
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
var capturedStages []string
var capturedPlan BoundedPlan
2026-08-29 18:07:24 +00:00
var capturedOptions RunOptions
2026-09-04 01:21:37 +00:00
executor := func(_ context.Context, _ *config.Config, plan BoundedPlan, options RunOptions) (*RunSummary, error) {
capturedStages = plan.Names()
capturedPlan = plan
2026-08-29 18:07:24 +00:00
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",
2026-08-29 18:07:24 +00:00
"--from", "render",
"--through", "extract",
"--force",
"--config", pipelinePath,
"--campaign-file", campaignPath, "--session-file", sessionPath,
}, &out, executor, commandDependencies{})
2026-08-29 18:07:24 +00:00
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 {
2026-08-29 18:07:24 +00:00
t.Fatalf("stages = %#v options = %#v", capturedStages, capturedOptions)
}
}
func TestPlanPrintsOnlyBoundedRange(t *testing.T) {
workspaceRoot := t.TempDir()
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
2026-08-29 18:17:05 +00:00
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)
}
2026-08-29 18:07:24 +00:00
var out bytes.Buffer
err := invokeNativeCommand(context.Background(), []string{"session", "plan", "2026-05-03",
2026-08-29 18:07:24 +00:00
"--from", "render",
"--through", "extract",
"--config", pipelinePath,
"--campaign-file", campaignPath, "--session-file", sessionPath,
2026-08-29 18:07:24 +00:00
}, &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)
2026-08-29 18:07:24 +00:00
}
}