2026-09-07 04:46:20 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
2026-11-20 05:15:43 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
"os"
|
2026-09-07 04:46:20 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
2026-11-20 05:15:43 +00:00
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
|
|
|
"go.maximumdirect.net/commandkit"
|
2026-09-07 04:46:20 +00:00
|
|
|
)
|
|
|
|
|
|
2026-11-20 05:15:43 +00:00
|
|
|
func catalogReportForTest(t *testing.T, args []string) *artifactCatalogReport {
|
|
|
|
|
t.Helper()
|
|
|
|
|
output := nativeInspectionForTest(t, append([]string{"artifacts", "list", "--format", "json"}, args...))
|
|
|
|
|
var report artifactCatalogReport
|
|
|
|
|
if err := json.Unmarshal([]byte(output), &report); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
return &report
|
|
|
|
|
}
|
2026-09-07 04:46:20 +00:00
|
|
|
|
2026-11-20 05:15:43 +00:00
|
|
|
func TestArtifactCatalogCommandWithoutCampaignPreservesDependencies(t *testing.T) {
|
2026-09-07 04:46:20 +00:00
|
|
|
dir := t.TempDir()
|
2026-11-20 05:15:43 +00:00
|
|
|
pipeline := filepath.Join(dir, "pipeline.yml")
|
|
|
|
|
mustWriteTestFile(t, pipeline, `workspace:
|
2026-09-07 04:46:20 +00:00
|
|
|
root: `+filepath.Join(dir, "workspace")+`
|
2026-11-20 05:15:43 +00:00
|
|
|
whisperx: {transcribe_url: https://transcription.example.test/transcribe}
|
2026-09-07 04:46:20 +00:00
|
|
|
scriptorium:
|
|
|
|
|
artifacts:
|
2026-11-20 05:15:43 +00:00
|
|
|
zeta: {enabled: false, output_path: artifacts/zeta.md}
|
2026-09-07 04:46:20 +00:00
|
|
|
alpha:
|
|
|
|
|
enabled: false
|
|
|
|
|
output_path: artifacts/alpha.md
|
|
|
|
|
inputs:
|
|
|
|
|
upstream: {source: narratio.artifact.zeta, required: true}
|
|
|
|
|
`)
|
2026-11-20 05:15:43 +00:00
|
|
|
report := catalogReportForTest(t, []string{"--config", pipeline})
|
|
|
|
|
found := map[string]artifactDefinitionReport{}
|
|
|
|
|
for _, entry := range report.Artifacts {
|
|
|
|
|
found[entry.Source] = entry
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
alpha := found["narratio.artifact.alpha"]
|
|
|
|
|
if alpha.Producer != "analyze" || alpha.Enabled == nil || *alpha.Enabled || !reflect.DeepEqual(alpha.Dependencies, []string{"zeta"}) || !reflect.DeepEqual(alpha.DefinitionSources, []string{pipeline}) {
|
|
|
|
|
t.Fatalf("alpha=%#v", alpha)
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
if found["narratio.transcript.base"].Producer != "merge" {
|
|
|
|
|
t.Fatal("catalog omitted built-in producer")
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
if _, err := os.Stat(filepath.Join(dir, "workspace")); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("listing created workspace: %v", err)
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 05:15:43 +00:00
|
|
|
func TestArtifactCatalogCommandUsesExplicitRosterAndNativeConfiguration(t *testing.T) {
|
|
|
|
|
pipeline, _ := writeInspectionFamilyConfig(t)
|
|
|
|
|
overlay := filepath.Join(filepath.Dir(pipeline), "overlays", "testing.yml")
|
|
|
|
|
mustWriteTestFile(t, overlay, "scriptorium:\n artifact_families:\n character_note:\n prompt_id: dnd.character_note.testing\n")
|
|
|
|
|
roster := filepath.Join(t.TempDir(), "selected.yml")
|
|
|
|
|
mustWriteTestFile(t, roster, "schema_version: narratio.party.v1\ncharacters:\n synthetic_character:\n player: {name: Synthetic Player}\n character: {name: Synthetic Character, classes: [{name: ranger}]}\n")
|
|
|
|
|
selected := "testing"
|
|
|
|
|
loaded, err := config.LoadPipelineWithOptions(pipeline, config.PipelineLoadOptions{Overlay: &selected})
|
|
|
|
|
if err != nil {
|
2026-09-07 04:46:20 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
var before, after bytes.Buffer
|
|
|
|
|
if err := loaded.ConfigKitResult().WriteEffective(&before); err != nil {
|
2026-09-07 04:46:20 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
app, err := newApplication(commandDependencies{loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) { return loaded, nil }}, executePlan)
|
|
|
|
|
if err != nil {
|
2026-09-07 12:08:19 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
var out, diagnostic bytes.Buffer
|
|
|
|
|
outcome := app.Execute(context.Background(), []string{"artifacts", "list", "--config", pipeline, "--overlay", selected, "--party-file", roster, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
|
|
|
|
if outcome.Status != 0 {
|
|
|
|
|
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
2026-09-07 12:08:19 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
var report artifactCatalogReport
|
|
|
|
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
2026-09-07 04:46:20 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
found := false
|
|
|
|
|
for _, entry := range report.Artifacts {
|
|
|
|
|
if entry.Family == "character_note" {
|
|
|
|
|
if entry.CharacterID != "synthetic_character" || entry.PartySource != roster || entry.Key != "character_note_synthetic_character" {
|
|
|
|
|
t.Fatalf("member=%#v", entry)
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(entry.DefinitionSources, []string{overlay, pipeline}) {
|
|
|
|
|
t.Fatalf("definition sources=%v", entry.DefinitionSources)
|
|
|
|
|
}
|
|
|
|
|
found = true
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
if !found {
|
|
|
|
|
t.Fatal("catalog omitted selected family member")
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
if err := loaded.ConfigKitResult().WriteEffective(&after); err != nil {
|
|
|
|
|
t.Fatal(err)
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
2026-11-20 05:15:43 +00:00
|
|
|
if !bytes.Equal(before.Bytes(), after.Bytes()) {
|
|
|
|
|
t.Fatal("catalog derivation changed native configuration")
|
2026-09-07 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
}
|