2026-05-19 18:36:30 -05:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-05-21 23:02:19 -05:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
2026-05-19 18:36:30 -05:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestExecuteRunSingleStageArtifactsUnsupportedStageFails(t *testing.T) {
|
2026-05-19 18:36:30 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
2026-05-19 18:36:30 -05:00
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 04:13:05 +00:00
|
|
|
code := executeForTest(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "2026-05-03", "--stage", "extract", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "session_recap"},
|
2026-05-19 18:36:30 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
|
|
|
|
)
|
|
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !strings.Contains(stderr.String(), `--artifacts requires a selected range containing analyze or publish`) {
|
2026-05-19 18:36:30 -05:00
|
|
|
t.Fatalf("stderr = %q, want stage-gating error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestExecuteRunSingleStagePublishPropagatesSelectedArtifacts(t *testing.T) {
|
2026-05-22 18:01:05 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var capturedStages []string
|
|
|
|
|
var capturedArtifacts []string
|
2026-09-04 01:21:37 +00:00
|
|
|
executor := func(_ context.Context, _ *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
2026-08-29 20:49:43 +00:00
|
|
|
for _, s := range plan.Stages() {
|
2026-05-22 18:01:05 -05:00
|
|
|
capturedStages = append(capturedStages, s.Name())
|
|
|
|
|
}
|
|
|
|
|
capturedArtifacts = append([]string(nil), opts.SelectedArtifacts...)
|
2026-05-23 04:30:45 +00:00
|
|
|
return &RunSummary{ManifestPath: filepath.Join(workspaceRoot, "manifest.json"), Executed: []string{"publish"}}, nil
|
2026-05-22 18:01:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-09-04 01:21:37 +00:00
|
|
|
code := executeWithPipelineExecutor(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "2026-05-03", "--stage", "publish",
|
2026-05-22 18:01:05 -05:00
|
|
|
"--config", pipelinePath,
|
2026-11-20 06:32:47 +00:00
|
|
|
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
2026-05-22 18:01:05 -05:00
|
|
|
"--artifacts", "session_recap",
|
|
|
|
|
},
|
|
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
2026-09-04 01:21:37 +00:00
|
|
|
executor,
|
2026-05-22 18:01:05 -05:00
|
|
|
)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
|
|
|
|
}
|
2026-05-23 04:30:45 +00:00
|
|
|
if len(capturedStages) != 1 || capturedStages[0] != "publish" {
|
|
|
|
|
t.Fatalf("captured stages = %#v, want [publish]", capturedStages)
|
2026-05-22 18:01:05 -05:00
|
|
|
}
|
|
|
|
|
if strings.Join(capturedArtifacts, ",") != "session_recap" {
|
|
|
|
|
t.Fatalf("captured artifacts = %#v, want [session_recap]", capturedArtifacts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 18:36:30 -05:00
|
|
|
func TestExecuteUnknownArtifactsFailValidation(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
2026-05-19 18:36:30 -05:00
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 04:13:05 +00:00
|
|
|
code := executeForTest(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "unknown_artifact"},
|
2026-05-19 18:36:30 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
|
|
|
|
)
|
|
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !strings.Contains(stderr.String(), `--artifacts includes unknown artifact "unknown_artifact"`) {
|
2026-05-19 18:36:30 -05:00
|
|
|
t.Fatalf("stderr = %q, want unknown-artifact validation error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestRunSingleStageArtifactsDoesNotImplyForce(t *testing.T) {
|
2026-05-19 18:36:30 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
2026-05-19 18:36:30 -05:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
|
|
|
|
seed := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
|
|
|
|
|
seed.MarkStageSucceeded("analyze", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
|
|
|
if err := store.Save(context.Background(), manifestPath, seed); err != nil {
|
|
|
|
|
t.Fatalf("save manifest: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
seedInvocationPrerequisites(t, workspaceRoot, "analyze")
|
|
|
|
|
|
2026-05-19 18:36:30 -05:00
|
|
|
var out bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
err := invokeNativeCommand(
|
2026-05-19 18:36:30 -05:00
|
|
|
context.Background(),
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "analyze", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "session_recap,session_recap"},
|
2026-05-19 18:36:30 -05:00
|
|
|
&out,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
2026-11-20 06:32:47 +00:00
|
|
|
t.Fatalf("single-stage run error = %v", err)
|
2026-05-19 18:36:30 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 1, 0, "analyze") {
|
2026-08-29 20:01:57 +00:00
|
|
|
t.Fatalf("output = %q, want legacy analyze evidence rebuilt without implying force", out.String())
|
2026-05-19 18:36:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 11:25:08 -05:00
|
|
|
func TestRunArtifactsWithSucceededAnalyzeSkipsUnlessForced(t *testing.T) {
|
2026-05-19 18:43:55 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
2026-05-19 18:43:55 -05:00
|
|
|
manifestPath := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json")
|
|
|
|
|
|
|
|
|
|
store := &manifest.LocalStore{}
|
2026-11-20 06:32:47 +00:00
|
|
|
if err := invokeNativeCommand(
|
2026-08-30 18:51:20 +00:00
|
|
|
context.Background(),
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "prepare", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath},
|
2026-08-30 18:51:20 +00:00
|
|
|
&bytes.Buffer{},
|
|
|
|
|
); err != nil {
|
|
|
|
|
t.Fatalf("seed prepare stage: %v", err)
|
|
|
|
|
}
|
|
|
|
|
seed, 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 _, stageName := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "analyze", "publish", "notify"} {
|
2026-05-19 18:43:55 -05:00
|
|
|
seed.MarkStageSucceeded(stageName, time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
|
|
|
|
|
}
|
2026-08-10 01:38:24 +00:00
|
|
|
seed.MarkStageSkipped("extract", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), "notarius_disabled")
|
2026-08-30 13:03:13 +00:00
|
|
|
seedCurrentSemanticEvidence(t, loadConfigForSemanticEvidence(t, pipelinePath, campaignPath, sessionPath), seed, "prepare", "transcribe", "merge", "polish", "normalize", "trim", "render")
|
2026-05-19 18:43:55 -05: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(
|
2026-05-19 18:43:55 -05:00
|
|
|
context.Background(),
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "session_recap"},
|
2026-05-19 18:43:55 -05:00
|
|
|
&out,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
2026-05-23 11:25:08 -05:00
|
|
|
t.Fatalf("Run() error = %v", err)
|
2026-05-19 18:43:55 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, out.Bytes(), 5, 9, "") {
|
2026-08-29 20:01:57 +00:00
|
|
|
t.Fatalf("output = %q, want extract reconsidered and legacy analyze plus delivery rebuilt", out.String())
|
2026-05-19 18:43:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 23:02:19 -05:00
|
|
|
func TestExecuteAnalyzeForceRunsAnalyze(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var capturedStages []string
|
|
|
|
|
var capturedForce bool
|
2026-09-04 01:21:37 +00:00
|
|
|
executor := func(_ context.Context, _ *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
2026-08-29 20:49:43 +00:00
|
|
|
for _, s := range plan.Stages() {
|
2026-05-21 23:02:19 -05:00
|
|
|
capturedStages = append(capturedStages, s.Name())
|
|
|
|
|
}
|
|
|
|
|
capturedForce = opts.Force
|
|
|
|
|
return &RunSummary{
|
|
|
|
|
ManifestPath: filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json"),
|
|
|
|
|
Executed: []string{"analyze"},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-09-04 01:21:37 +00:00
|
|
|
code := executeWithPipelineExecutor(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "analyze", "--force", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath},
|
2026-05-21 23:02:19 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
2026-09-04 01:21:37 +00:00
|
|
|
executor,
|
2026-05-21 23:02:19 -05:00
|
|
|
)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
|
|
|
|
}
|
|
|
|
|
if len(capturedStages) != 1 || capturedStages[0] != "analyze" {
|
|
|
|
|
t.Fatalf("captured stages = %#v, want [analyze]", capturedStages)
|
|
|
|
|
}
|
|
|
|
|
if !capturedForce {
|
|
|
|
|
t.Fatal("captured force = false, want true")
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, stdout.Bytes(), 1, 0, "") {
|
2026-05-21 23:02:19 -05:00
|
|
|
t.Fatalf("stdout = %q, want analyze summary", stdout.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExecuteAnalyzePropagatesSelectedArtifacts(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var capturedArtifacts []string
|
2026-09-04 01:21:37 +00:00
|
|
|
executor := func(_ context.Context, _ *config.Config, _ BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
2026-05-21 23:02:19 -05:00
|
|
|
capturedArtifacts = append([]string(nil), opts.SelectedArtifacts...)
|
|
|
|
|
return &RunSummary{ManifestPath: filepath.Join(workspaceRoot, "manifest.json"), Executed: []string{"analyze"}}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-09-04 01:21:37 +00:00
|
|
|
code := executeWithPipelineExecutor(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "analyze", "--force", "2026-05-03",
|
2026-05-21 23:02:19 -05:00
|
|
|
"--config", pipelinePath,
|
2026-11-20 06:32:47 +00:00
|
|
|
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
2026-05-21 23:02:19 -05:00
|
|
|
"--artifacts", "player_handout,session_recap",
|
|
|
|
|
},
|
|
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
2026-09-04 01:21:37 +00:00
|
|
|
executor,
|
2026-05-21 23:02:19 -05:00
|
|
|
)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
|
|
|
|
}
|
|
|
|
|
if strings.Join(capturedArtifacts, ",") != "player_handout,session_recap" {
|
|
|
|
|
t.Fatalf("captured artifacts = %#v, want sorted selected artifacts", capturedArtifacts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExecuteAnalyzeUnknownArtifactFailsValidation(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 04:13:05 +00:00
|
|
|
code := executeForTest(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "analyze", "--force", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "unknown_artifact"},
|
2026-05-21 23:02:19 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
|
|
|
|
)
|
|
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !strings.Contains(stderr.String(), `--artifacts includes unknown artifact "unknown_artifact"`) {
|
2026-05-21 23:02:19 -05:00
|
|
|
t.Fatalf("stderr = %q, want unknown-artifact validation error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestExecuteAnalyzeMissingConfigUsesSharedAcquisition(t *testing.T) {
|
2026-11-17 22:06:29 +00:00
|
|
|
deps, _, executor := guardedMissingPipelineDiscovery(t)
|
2026-05-21 23:02:19 -05:00
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
code := executeWithDependencies([]string{"run", "2026-05-03", "--stage", "analyze", "--force"}, &stdout, &stderr, deps, executor)
|
2026-05-21 23:02:19 -05:00
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-09-16 04:26:24 +00:00
|
|
|
if stdout.Len() != 0 {
|
|
|
|
|
t.Fatalf("stdout = %q, want empty", stdout.String())
|
|
|
|
|
}
|
2026-11-17 22:06:29 +00:00
|
|
|
if got := stderr.String(); !strings.Contains(got, "source.missing") {
|
2026-05-21 23:02:19 -05:00
|
|
|
t.Fatalf("stderr = %q, want pipeline discovery error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 13:39:15 +00:00
|
|
|
func TestExecutePublishForceRunsPublish(t *testing.T) {
|
2026-05-22 11:28:38 -05:00
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var capturedStages []string
|
|
|
|
|
var capturedForce bool
|
|
|
|
|
var capturedArtifacts []string
|
2026-09-04 01:21:37 +00:00
|
|
|
executor := func(_ context.Context, _ *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
2026-08-29 20:49:43 +00:00
|
|
|
for _, s := range plan.Stages() {
|
2026-05-22 11:28:38 -05:00
|
|
|
capturedStages = append(capturedStages, s.Name())
|
|
|
|
|
}
|
|
|
|
|
capturedForce = opts.Force
|
|
|
|
|
capturedArtifacts = append([]string(nil), opts.SelectedArtifacts...)
|
|
|
|
|
return &RunSummary{
|
|
|
|
|
ManifestPath: filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03", "manifest.json"),
|
2026-05-23 04:30:45 +00:00
|
|
|
Executed: []string{"publish"},
|
2026-05-22 11:28:38 -05:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-09-04 01:21:37 +00:00
|
|
|
code := executeWithPipelineExecutor(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "publish", "--force", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "session_recap"},
|
2026-05-22 11:28:38 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
2026-09-04 01:21:37 +00:00
|
|
|
executor,
|
2026-05-22 11:28:38 -05:00
|
|
|
)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
|
|
|
|
}
|
2026-05-23 04:30:45 +00:00
|
|
|
if len(capturedStages) != 1 || capturedStages[0] != "publish" {
|
|
|
|
|
t.Fatalf("captured stages = %#v, want [publish]", capturedStages)
|
2026-05-22 11:28:38 -05:00
|
|
|
}
|
|
|
|
|
if !capturedForce {
|
|
|
|
|
t.Fatal("captured force = false, want true")
|
|
|
|
|
}
|
2026-05-22 18:01:05 -05:00
|
|
|
if strings.Join(capturedArtifacts, ",") != "session_recap" {
|
|
|
|
|
t.Fatalf("captured artifacts = %#v, want [session_recap]", capturedArtifacts)
|
2026-05-22 11:28:38 -05:00
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !runCountsMatch(t, stdout.Bytes(), 1, 0, "") {
|
2026-05-22 11:28:38 -05:00
|
|
|
t.Fatalf("stdout = %q, want publish summary", stdout.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 18:01:05 -05:00
|
|
|
func TestExecutePublishUnknownArtifactFailsValidation(t *testing.T) {
|
|
|
|
|
workspaceRoot := t.TempDir()
|
|
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
|
|
|
|
|
|
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 04:13:05 +00:00
|
|
|
code := executeForTest(
|
2026-11-20 06:32:47 +00:00
|
|
|
[]string{"run", "--stage", "publish", "--force", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--artifacts", "unknown_artifact"},
|
2026-05-22 18:01:05 -05:00
|
|
|
&stdout,
|
|
|
|
|
&stderr,
|
|
|
|
|
)
|
|
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
if !strings.Contains(stderr.String(), `--artifacts includes unknown artifact "unknown_artifact"`) {
|
2026-05-22 18:01:05 -05:00
|
|
|
t.Fatalf("stderr = %q, want unknown-artifact validation error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 06:32:47 +00:00
|
|
|
func TestExecutePublishMissingConfigUsesSharedAcquisition(t *testing.T) {
|
2026-11-17 22:06:29 +00:00
|
|
|
deps, _, executor := guardedMissingPipelineDiscovery(t)
|
2026-05-22 11:28:38 -05:00
|
|
|
var stdout bytes.Buffer
|
|
|
|
|
var stderr bytes.Buffer
|
2026-11-20 06:32:47 +00:00
|
|
|
code := executeWithDependencies([]string{"run", "2026-05-03", "--stage", "publish", "--force"}, &stdout, &stderr, deps, executor)
|
2026-05-22 11:28:38 -05:00
|
|
|
if code == 0 {
|
|
|
|
|
t.Fatal("exit code = 0, want non-zero")
|
|
|
|
|
}
|
2026-09-16 04:26:24 +00:00
|
|
|
if stdout.Len() != 0 {
|
|
|
|
|
t.Fatalf("stdout = %q, want empty", stdout.String())
|
|
|
|
|
}
|
2026-11-17 22:06:29 +00:00
|
|
|
if got := stderr.String(); !strings.Contains(got, "source.missing") {
|
2026-05-22 11:28:38 -05:00
|
|
|
t.Fatalf("stderr = %q, want pipeline discovery error", stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 20:41:28 -05:00
|
|
|
func writeValidConfigFilesWithScriptoriumArtifacts(t *testing.T, workspaceRoot string) (string, string, string) {
|
2026-05-19 18:36:30 -05:00
|
|
|
t.Helper()
|
|
|
|
|
|
2026-05-20 20:41:28 -05:00
|
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
2026-05-19 18:36:30 -05:00
|
|
|
f, err := os.OpenFile(pipelinePath, os.O_APPEND|os.O_WRONLY, 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("open pipeline config for append: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
extra := `
|
|
|
|
|
scriptorium:
|
|
|
|
|
binary: scriptorium
|
|
|
|
|
artifacts:
|
|
|
|
|
session_recap:
|
|
|
|
|
enabled: true
|
|
|
|
|
prompt_id: dnd.session_recap
|
|
|
|
|
output_path: artifacts/session_recap.md
|
|
|
|
|
player_handout:
|
|
|
|
|
enabled: true
|
|
|
|
|
prompt_id: dnd.player_handout
|
|
|
|
|
output_path: artifacts/player_handout.md
|
|
|
|
|
depends_on:
|
|
|
|
|
- session_recap
|
|
|
|
|
inputs:
|
|
|
|
|
recap:
|
|
|
|
|
source: narratio.artifact.session_recap
|
|
|
|
|
required: true
|
|
|
|
|
`
|
|
|
|
|
if _, err := f.WriteString(extra); err != nil {
|
|
|
|
|
t.Fatalf("append scriptorium config: %v", err)
|
|
|
|
|
}
|
2026-05-20 20:41:28 -05:00
|
|
|
return pipelinePath, campaignPath, sessionPath
|
2026-05-19 18:36:30 -05:00
|
|
|
}
|