2026-05-02 11:38:42 -05:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
2026-05-03 17:49:26 -05:00
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
2026-05-02 11:38:42 -05:00
|
|
|
"path/filepath"
|
2026-11-20 06:32:47 +00:00
|
|
|
|
2026-05-02 11:38:42 -05:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-09-02 14:09:32 +00:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
2026-05-02 11:38:42 -05:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-23 11:25:08 -05:00
|
|
|
func TestRunContinuesAfterCompletedStages(t *testing.T) {
|
2026-05-02 11:38:42 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
2026-05-02 11:38:42 -05:00
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
2026-08-30 18:51:20 +00:00
|
|
|
materializePrepareResumeFixture(t, pipelinePath, campaignPath, sessionPath)
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load prepared manifest: %v", err)
|
|
|
|
|
}
|
2026-05-02 11:38:42 -05:00
|
|
|
m.MarkStageSucceeded("transcribe", time.Date(2026, 5, 3, 10, 2, 0, 0, time.UTC), nil)
|
2026-08-30 12:54:38 +00:00
|
|
|
seedCurrentSemanticEvidence(t, loadConfigForSemanticEvidence(t, pipelinePath, campaignPath, sessionPath), m, "prepare", "transcribe")
|
2026-05-02 11:38:42 -05:00
|
|
|
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
|
|
|
|
t.Fatalf("save manifest: %v", err)
|
|
|
|
|
}
|
2026-05-17 20:57:27 +00:00
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-05-03 22:17:17 -05:00
|
|
|
mustWriteTestFile(t, filepath.Join(workRoot, "transcripts", "raw", "alice.json"), `{"segments":[]}`)
|
2026-05-02 11:38:42 -05:00
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err = invokeNativeCommand(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("Run() error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 10, 4, "") {
|
2026-09-05 15:27:08 +00:00
|
|
|
t.Fatalf("output = %q, want executed=10 skipped=4", out.String())
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loaded, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest: %v", err)
|
|
|
|
|
}
|
2026-05-08 16:51:01 +00:00
|
|
|
if loaded.Stages["trim"] == nil || loaded.Stages["trim"].Status != manifest.StatusSucceeded {
|
|
|
|
|
t.Fatalf("trim stage = %#v, want succeeded", loaded.Stages["trim"])
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 11:25:08 -05:00
|
|
|
func TestRunNoRemainingStagesRecordsSkippedStages(t *testing.T) {
|
2026-05-02 11:38:42 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
2026-05-02 11:38:42 -05:00
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
2026-08-30 18:51:20 +00:00
|
|
|
materializePrepareResumeFixture(t, pipelinePath, campaignPath, sessionPath)
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load prepared manifest: %v", err)
|
|
|
|
|
}
|
2026-05-25 00:40:06 +00:00
|
|
|
for _, name := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "analyze", "publish", "notify"} {
|
2026-05-02 11:38:42 -05:00
|
|
|
m.MarkStageSucceeded(name, time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
|
|
|
}
|
2026-08-10 01:38:24 +00:00
|
|
|
m.MarkStageSkipped("extract", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), "notarius_disabled")
|
2026-08-30 13:14:33 +00:00
|
|
|
seedCurrentSemanticEvidence(t, loadConfigForSemanticEvidence(t, pipelinePath, campaignPath, sessionPath), m, "prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "publish", "notify")
|
2026-05-02 11:38:42 -05:00
|
|
|
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
|
|
|
|
t.Fatalf("save manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err = invokeNativeCommand(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("Run() error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 2, 12, "") {
|
2026-08-10 00:14:46 +00:00
|
|
|
t.Fatalf("output = %q, want disabled extraction to self-skip", out.String())
|
|
|
|
|
}
|
|
|
|
|
loaded, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load migrated manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if loaded.Stages["extract"] == nil || loaded.Stages["extract"].Status != manifest.StatusSkipped {
|
2026-08-10 01:38:24 +00:00
|
|
|
t.Fatalf("extract record = %#v, want stable disabled skip", loaded.Stages["extract"])
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 11:25:08 -05:00
|
|
|
func TestRunForceRerunsSucceeded(t *testing.T) {
|
2026-05-02 11:38:42 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-03 17:49:26 -05:00
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
2026-05-23 11:25:08 -05:00
|
|
|
_, _ = w.Write([]byte(`{"source":"run-force-test","segments":[{"speaker":"alice"}]}`))
|
2026-05-03 17:49:26 -05:00
|
|
|
}))
|
|
|
|
|
defer srv.Close()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot, srv.URL)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
2026-05-02 11:38:42 -05:00
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
|
2026-09-05 15:27:08 +00:00
|
|
|
for _, name := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "extract", "render", "analyze", "publish", "notify", "cleanup"} {
|
2026-05-02 11:38:42 -05:00
|
|
|
m.MarkStageSucceeded(name, time.Date(2026, 5, 3, 10, 1, 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
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--force"}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("Run() error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 12, 2, "") {
|
2026-05-02 11:38:42 -05:00
|
|
|
t.Fatalf("output = %q, want forced full rerun", out.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageExecutesOnlySelectedStage(t *testing.T) {
|
2026-05-02 11:38:42 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
basePath := filepath.Join(workRoot, "transcripts", "base.json")
|
|
|
|
|
mustWriteTestFile(t, basePath, `{"segments":[]}`)
|
|
|
|
|
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
2026-05-04 08:05:27 -05:00
|
|
|
mustWriteTestFile(t, filepath.Join(workRoot, "inputs", "glossary.yml"), "terms: []\n")
|
2026-05-02 11:38:42 -05:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "polish")
|
|
|
|
|
|
2026-05-02 11:38:42 -05:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "polish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "polish") {
|
2026-05-02 11:38:42 -05:00
|
|
|
t.Fatalf("output = %q, want stage executed", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if m.Stages["polish"] == nil || m.Stages["polish"].Status != manifest.StatusSucceeded {
|
|
|
|
|
t.Fatalf("polish stage = %#v, want succeeded", m.Stages["polish"])
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if m.Stages["prepare"] != nil && m.Stages["prepare"].StartedAt != nil {
|
|
|
|
|
t.Fatalf("prepare was attempted outside the selected range: %#v", m.Stages["prepare"])
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageExtractIsAcceptedAndSelfSkipsWhenDisabled(t *testing.T) {
|
2026-08-10 00:14:46 +00:00
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "extract")
|
|
|
|
|
|
2026-08-10 00:14:46 +00:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "extract", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-08-10 00:14:46 +00:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (extract) error = %v", err)
|
2026-08-10 00:14:46 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 1, "extract") {
|
2026-08-10 00:14:46 +00:00
|
|
|
t.Fatalf("output = %q, want disabled extraction self-skip", out.String())
|
|
|
|
|
}
|
|
|
|
|
loaded, err := (&manifest.LocalStore{}).Load(context.Background(), filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Load() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if loaded.Stages["extract"] == nil || loaded.Stages["extract"].Status != manifest.StatusSkipped {
|
|
|
|
|
t.Fatalf("extract record = %#v, want skipped", loaded.Stages["extract"])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageSkipAndForce(t *testing.T) {
|
2026-05-02 11:38:42 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
basePath := filepath.Join(workRoot, "transcripts", "base.json")
|
|
|
|
|
mustWriteTestFile(t, basePath, `{"segments":[]}`)
|
2026-05-04 08:05:27 -05:00
|
|
|
mustWriteTestFile(t, filepath.Join(workRoot, "inputs", "glossary.yml"), "terms: []\n")
|
2026-05-02 11:38:42 -05:00
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
|
2026-09-02 14:09:32 +00:00
|
|
|
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
2026-05-02 11:38:42 -05:00
|
|
|
m.MarkStageSucceeded("polish", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
2026-08-30 13:03:13 +00:00
|
|
|
seedCurrentSemanticEvidence(t, loadConfigForSemanticEvidence(t, pipelinePath, campaignPath, sessionPath), m, "polish")
|
2026-05-02 11:38:42 -05:00
|
|
|
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
|
|
|
|
t.Fatalf("save manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "polish")
|
|
|
|
|
|
2026-05-02 11:38:42 -05:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "polish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 0, 1, "polish") {
|
2026-05-02 11:38:42 -05:00
|
|
|
t.Fatalf("output = %q, want skip", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out.Reset()
|
2026-11-20 06:32:47 +00:00
|
|
|
err = invokeNativeCommand(context.Background(), []string{"run", "--stage", "polish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--force"}, &out)
|
2026-05-02 11:38:42 -05:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (force) error = %v", err)
|
2026-05-02 11:38:42 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "polish") {
|
2026-05-02 11:38:42 -05:00
|
|
|
t.Fatalf("output = %q, want force rerun", out.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-08 16:51:01 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageForceMarksDownstreamStaleAndRunContinuesFromStale(t *testing.T) {
|
2026-05-18 01:50:51 +00:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-18 01:50:51 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
basePath := filepath.Join(workRoot, "transcripts", "base.json")
|
|
|
|
|
mustWriteTestFile(t, basePath, `{"segments":[]}`)
|
|
|
|
|
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
2026-05-18 01:50:51 +00:00
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
2026-08-30 18:51:20 +00:00
|
|
|
materializePrepareResumeFixture(t, pipelinePath, campaignPath, sessionPath)
|
|
|
|
|
seed, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load prepared manifest: %v", err)
|
|
|
|
|
}
|
2026-09-05 15:27:08 +00:00
|
|
|
for _, name := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "extract", "render", "analyze", "publish", "notify", "cleanup"} {
|
2026-05-18 01:50:51 +00:00
|
|
|
seed.MarkStageSucceeded(name, time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
|
|
|
}
|
2026-09-02 14:09:32 +00:00
|
|
|
setCurrentBuiltInEvidence(t, seed, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
2026-08-30 12:54:38 +00:00
|
|
|
seedCurrentSemanticEvidence(t, loadConfigForSemanticEvidence(t, pipelinePath, campaignPath, sessionPath), seed, "prepare", "transcribe", "merge")
|
2026-05-18 01:50:51 +00:00
|
|
|
if err := store.Save(context.Background(), manifestPath, seed); err != nil {
|
|
|
|
|
t.Fatalf("save manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err = invokeNativeCommand(context.Background(), []string{"run", "--stage", "polish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--force"}, &out)
|
2026-05-18 01:50:51 +00:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (force) error = %v", err)
|
2026-05-18 01:50:51 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "polish") {
|
2026-05-18 01:50:51 +00:00
|
|
|
t.Fatalf("output = %q, want forced polish rerun", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
afterForce, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest after force: %v", err)
|
|
|
|
|
}
|
2026-09-05 15:27:08 +00:00
|
|
|
for _, name := range []string{"normalize", "trim", "render", "extract", "analyze", "publish", "notify", "cleanup"} {
|
2026-05-18 01:50:51 +00:00
|
|
|
if afterForce.Stages[name] == nil || afterForce.Stages[name].Status != manifest.StatusStale {
|
|
|
|
|
t.Fatalf("stage %q = %#v, want stale", name, afterForce.Stages[name])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out.Reset()
|
2026-11-20 06:32:47 +00:00
|
|
|
err = invokeNativeCommand(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-18 01:50:51 +00:00
|
|
|
if err != nil {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("Run() error = %v", err)
|
2026-05-18 01:50:51 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 8, 6, "") {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("output = %q, want run to execute stale downstream stages", out.String())
|
2026-05-18 01:50:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageTrimExecutes(t *testing.T) {
|
2026-05-08 16:51:01 +00:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
finalPath := filepath.Join(workRoot, "transcripts", "final.json")
|
|
|
|
|
mustWriteTestFile(t, finalPath, `{"segments":[{"id":1},{"id":2}]}`)
|
|
|
|
|
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "normalize", artifacts.TranscriptOutputKindFinal, artifacts.ArtifactTranscriptFinal, finalPath)
|
2026-05-08 16:51:01 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "trim")
|
|
|
|
|
|
2026-05-08 16:51:01 +00:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "trim", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-08 16:51:01 +00:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (trim) error = %v", err)
|
2026-05-08 16:51:01 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "trim") {
|
2026-05-08 16:51:01 +00:00
|
|
|
t.Fatalf("output = %q, want stage=trim executed", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if m.Stages["trim"] == nil || m.Stages["trim"].Status != manifest.StatusSucceeded {
|
|
|
|
|
t.Fatalf("trim stage = %#v, want succeeded", m.Stages["trim"])
|
|
|
|
|
}
|
2026-05-27 08:35:02 -05:00
|
|
|
if m.Stages["trim"].Metadata == nil || m.Stages["trim"].Metadata["trim_action"] != "copy" {
|
|
|
|
|
t.Fatalf("trim stage metadata = %#v, want trim_action=copy", m.Stages["trim"].Metadata)
|
2026-05-08 16:51:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-05-10 21:26:53 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageNormalizeExecutes(t *testing.T) {
|
2026-05-10 21:26:53 +00:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-17 20:57:27 +00:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
polishedPath := filepath.Join(workRoot, "transcripts", "polished.json")
|
|
|
|
|
mustWriteTestFile(t, polishedPath, `{"segments":[{"id":1},{"id":2}]}`)
|
|
|
|
|
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "polish", artifacts.TranscriptOutputKindPolished, artifacts.ArtifactTranscriptPolished, polishedPath)
|
2026-05-10 21:26:53 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "normalize")
|
|
|
|
|
|
2026-05-10 21:26:53 +00:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "normalize", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-10 21:26:53 +00:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (normalize) error = %v", err)
|
2026-05-10 21:26:53 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "normalize") {
|
2026-05-10 21:26:53 +00:00
|
|
|
t.Fatalf("output = %q, want stage=normalize executed", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if m.Stages["normalize"] == nil || m.Stages["normalize"].Status != manifest.StatusSucceeded {
|
|
|
|
|
t.Fatalf("normalize stage = %#v, want succeeded", m.Stages["normalize"])
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-25 00:40:06 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageRenderExecutes(t *testing.T) {
|
2026-05-25 00:40:06 +00:00
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
2026-09-02 14:09:32 +00:00
|
|
|
finalPath := filepath.Join(workRoot, "transcripts", "final.json")
|
|
|
|
|
trimmedPath := filepath.Join(workRoot, "transcripts", "final.trimmed.json")
|
|
|
|
|
mustWriteTestFile(t, finalPath, `{"segments":[{"id":1}]}`)
|
|
|
|
|
mustWriteTestFile(t, trimmedPath, `{"segments":[{"id":2}]}`)
|
|
|
|
|
seed := manifest.New("2026-05-03", time.Now().UTC())
|
|
|
|
|
seed.Campaign = "sample-campaign"
|
|
|
|
|
setCurrentBuiltInEvidence(t, seed, "normalize", artifacts.TranscriptOutputKindFinal, artifacts.ArtifactTranscriptFinal, finalPath)
|
|
|
|
|
setCurrentBuiltInEvidence(t, seed, "trim", artifacts.TranscriptOutputKindFinalTrimmed, artifacts.ArtifactTranscriptFinalTrimmed, trimmedPath)
|
|
|
|
|
if err := (&manifest.LocalStore{}).Save(context.Background(), manifestPath, seed); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-05-25 00:40:06 +00:00
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "render")
|
|
|
|
|
|
2026-05-25 00:40:06 +00:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(context.Background(), []string{"run", "--stage", "render", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &out)
|
2026-05-25 00:40:06 +00:00
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run (render) error = %v", err)
|
2026-05-25 00:40:06 +00:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "render") {
|
2026-05-25 00:40:06 +00:00
|
|
|
t.Fatalf("output = %q, want stage=render executed", out.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
m, err := store.Load(context.Background(), manifestPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("load manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if m.Stages["render"] == nil || m.Stages["render"].Status != manifest.StatusSucceeded {
|
|
|
|
|
t.Fatalf("render stage = %#v, want succeeded", m.Stages["render"])
|
|
|
|
|
}
|
|
|
|
|
}
|