102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
)
|
|
|
|
func TestPlanCreatesAndReusesWorkdir(t *testing.T) {
|
|
workspaceRoot := t.TempDir()
|
|
pipelinePath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
|
|
var out bytes.Buffer
|
|
args := []string{"--config", pipelinePath, "--session", sessionPath}
|
|
|
|
if err := Plan(context.Background(), args, &out); err != nil {
|
|
t.Fatalf("first Plan() error = %v", err)
|
|
}
|
|
got := out.String()
|
|
if !strings.Contains(got, "narratio plan: workdir prepared at") {
|
|
t.Fatalf("first output = %q, want workdir prepared", got)
|
|
}
|
|
for _, name := range []string{"prepare", "transcribe", "normalize", "merge", "polish", "analyze", "archive", "notify"} {
|
|
if !strings.Contains(got, name+": run") {
|
|
t.Fatalf("first output = %q, missing stage %q", got, name)
|
|
}
|
|
}
|
|
if !strings.Contains(got, "totals: run=8 skip=0") {
|
|
t.Fatalf("first output = %q, want totals", got)
|
|
}
|
|
|
|
sessionWorkdir := artifacts.SessionWorkDir(workspaceRoot, "2026-05-03")
|
|
expectedDirs := []string{
|
|
sessionWorkdir,
|
|
filepath.Join(sessionWorkdir, "inputs"),
|
|
filepath.Join(sessionWorkdir, "audio"),
|
|
filepath.Join(sessionWorkdir, "transcripts", "raw"),
|
|
filepath.Join(sessionWorkdir, "transcripts", "normalized"),
|
|
filepath.Join(sessionWorkdir, "artifacts"),
|
|
filepath.Join(sessionWorkdir, "config"),
|
|
filepath.Join(sessionWorkdir, "logs"),
|
|
}
|
|
for _, dir := range expectedDirs {
|
|
assertDir(t, dir)
|
|
}
|
|
|
|
out.Reset()
|
|
if err := Plan(context.Background(), args, &out); err != nil {
|
|
t.Fatalf("second Plan() error = %v", err)
|
|
}
|
|
if !strings.Contains(out.String(), "narratio plan: workdir prepared at") {
|
|
t.Fatalf("second output = %q, want workdir prepared", out.String())
|
|
}
|
|
}
|
|
|
|
func TestPlanShowsRunAndSkipFromManifest(t *testing.T) {
|
|
workspaceRoot := t.TempDir()
|
|
pipelinePath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "2026-05-03", "manifest.json")
|
|
|
|
store := &manifest.LocalStore{}
|
|
m := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
|
|
m.MarkStageSucceeded("prepare", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
m.MarkStageSucceeded("transcribe", time.Date(2026, 5, 3, 10, 2, 0, 0, time.UTC), nil)
|
|
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
|
t.Fatalf("save manifest: %v", err)
|
|
}
|
|
|
|
var out bytes.Buffer
|
|
if err := Plan(context.Background(), []string{"--config", pipelinePath, "--session", sessionPath}, &out); err != nil {
|
|
t.Fatalf("Plan() error = %v", err)
|
|
}
|
|
got := out.String()
|
|
if !strings.Contains(got, "prepare: skip") || !strings.Contains(got, "transcribe: skip") {
|
|
t.Fatalf("output = %q, want prepare/transcribe skipped", got)
|
|
}
|
|
if !strings.Contains(got, "normalize: run") {
|
|
t.Fatalf("output = %q, want normalize run", got)
|
|
}
|
|
if !strings.Contains(got, "totals: run=6 skip=2") {
|
|
t.Fatalf("output = %q, want totals run=6 skip=2", got)
|
|
}
|
|
}
|
|
|
|
func assertDir(t *testing.T, path string) {
|
|
t.Helper()
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatalf("Stat(%q) error = %v", path, err)
|
|
}
|
|
if !info.IsDir() {
|
|
t.Fatalf("%q is not a directory", path)
|
|
}
|
|
}
|