130 lines
5.7 KiB
Go
130 lines
5.7 KiB
Go
|
|
package config
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"gopkg.in/yaml.v3"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestNotariusNativeControlsAndOutputs(t *testing.T) {
|
||
|
|
base := testPipelineBaseYAML + `
|
||
|
|
notarius:
|
||
|
|
enabled: true
|
||
|
|
config_path: notarius.yml
|
||
|
|
pipeline_id: example
|
||
|
|
outputs:
|
||
|
|
people: {lane_id: people}
|
||
|
|
places: {lane_id: locations, filename: locations.json}
|
||
|
|
`
|
||
|
|
for _, mode := range []string{"", "auto", "bypass", "refresh"} {
|
||
|
|
t.Run("cache="+mode, func(t *testing.T) {
|
||
|
|
doc := base
|
||
|
|
if mode != "" {
|
||
|
|
doc += " cache: " + mode + "\n debug: true\n"
|
||
|
|
}
|
||
|
|
path := filepath.Join(t.TempDir(), "pipeline.yml")
|
||
|
|
if err := os.WriteFile(path, []byte(doc), 0o644); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
cfg, err := LoadPipeline(path)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(configurationErrorText(err))
|
||
|
|
}
|
||
|
|
if mode == "" && (cfg.Notarius.Cache != nil || cfg.Notarius.Debug) || mode != "" && (cfg.Notarius.Cache == nil || *cfg.Notarius.Cache != mode || !cfg.Notarius.Debug) {
|
||
|
|
t.Fatalf("controls = %#v", cfg.Notarius)
|
||
|
|
}
|
||
|
|
if ExtractionFilename("people", cfg.Notarius.Outputs["people"]) != "people.json" || ExtractionFilename("places", cfg.Notarius.Outputs["places"]) != "locations.json" {
|
||
|
|
t.Fatal("incorrect extraction filenames")
|
||
|
|
}
|
||
|
|
encoded, err := yaml.Marshal(cfg.Notarius)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if mode == "" && strings.Contains(string(encoded), "cache:") {
|
||
|
|
t.Fatalf("cache unexpectedly serialized: %s", encoded)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
for _, old := range []string{" resume: true\n", " chunk_cache: auto\n", " cache: invalid\n"} {
|
||
|
|
doc := base + old
|
||
|
|
path := filepath.Join(t.TempDir(), "pipeline.yml")
|
||
|
|
if err := os.WriteFile(path, []byte(doc), 0o644); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if _, err := LoadPipeline(path); err == nil {
|
||
|
|
t.Fatalf("retired setting accepted: %s", old)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
path := filepath.Join(t.TempDir(), "pipeline.yml")
|
||
|
|
if err := os.WriteFile(path, []byte(strings.Replace(base, "{lane_id: people}", "{lane_id: people, media_type: application/json}", 1)), 0o644); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if _, err := LoadPipeline(path); err == nil {
|
||
|
|
t.Fatal("retired output descriptor accepted")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestProductDestinationCollisions(t *testing.T) {
|
||
|
|
root := t.TempDir()
|
||
|
|
cfg := &Config{Pipeline: &PipelineConfig{Workspace: WorkspaceConfig{Root: root}, Notarius: &NotariusConfig{Enabled: true, Outputs: map[string]NotariusOutputConfig{"people": {LaneID: "people"}}}}, Session: &SessionConfig{Campaign: "campaign", SessionID: "session"}}
|
||
|
|
catalog := &ArtifactCatalog{Artifacts: map[string]ScriptoriumArtifactConfig{}}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
catalog.Artifacts["recap"] = ScriptoriumArtifactConfig{OutputPath: filepath.Join(root, PathWorkDirSegment, "campaign", "session", "artifacts", "people.json")}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err == nil || !strings.Contains(err.Error(), "people") || !strings.Contains(err.Error(), "recap") {
|
||
|
|
t.Fatalf("collision error = %v", err)
|
||
|
|
}
|
||
|
|
catalog.Artifacts["recap"] = ScriptoriumArtifactConfig{OutputPath: "artifacts/nested/recap.md"}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err == nil {
|
||
|
|
t.Fatal("nested artifact accepted")
|
||
|
|
}
|
||
|
|
catalog.Artifacts["recap"] = ScriptoriumArtifactConfig{OutputPath: "artifacts/recap.md"}
|
||
|
|
cfg.Pipeline.Normalize = &NormalizeConfig{OutputPath: "transcripts/base.json"}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err == nil || !strings.Contains(err.Error(), "base") || !strings.Contains(err.Error(), "final") {
|
||
|
|
t.Fatalf("transcript collision error = %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestExpandedFamilyDestinationCollisions(t *testing.T) {
|
||
|
|
cfg := &Config{Pipeline: &PipelineConfig{
|
||
|
|
Workspace: WorkspaceConfig{Root: t.TempDir()},
|
||
|
|
Notarius: &NotariusConfig{Enabled: true, Outputs: map[string]NotariusOutputConfig{"characters": {LaneID: "characters", Filename: "ada.json"}}},
|
||
|
|
Scriptorium: &ScriptoriumConfig{ArtifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{
|
||
|
|
"character": {ForEach: "party.characters", OutputPathPattern: "artifacts/{character_id}.json"},
|
||
|
|
}},
|
||
|
|
}, Session: &SessionConfig{Campaign: "campaign", SessionID: "session"}, Party: ResolvedParty{Canonical: &CanonicalParty{Characters: []PartyCharacter{{ID: "ada"}}}}}
|
||
|
|
catalog, err := DeriveArtifactCatalog(cfg.Pipeline, cfg.Party)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err == nil || !strings.Contains(err.Error(), "characters") || !strings.Contains(err.Error(), "character_ada") {
|
||
|
|
t.Fatalf("family collision error = %v", err)
|
||
|
|
}
|
||
|
|
cfg.Pipeline.Notarius.Outputs["characters"] = NotariusOutputConfig{LaneID: "characters", Filename: "separate.json"}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
cfg.Pipeline.Trim = &TrimConfig{OutputPath: "transcripts/final.trimmed.json", Bounds: TrimBoundsConfig{OutputPath: "artifacts/ada.json"}}
|
||
|
|
if err := validateProductDestinations(cfg, catalog); err == nil || !strings.Contains(err.Error(), "bounds") || !strings.Contains(err.Error(), "character_ada") {
|
||
|
|
t.Fatalf("bounds collision error = %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestProductDestinationsPreserveExplicitRemotePaths(t *testing.T) {
|
||
|
|
cfg := &PipelineConfig{
|
||
|
|
Notarius: &NotariusConfig{Enabled: true, Outputs: map[string]NotariusOutputConfig{"people": {LaneID: "people", Filename: "people-local.json"}}},
|
||
|
|
Publish: &PublishConfig{Outputs: []PublishOutputRule{{Source: "narratio.extraction.people", Dest: "archive/session/people.json"}}},
|
||
|
|
}
|
||
|
|
applyMissingPublishDestinations(cfg.Publish, nil, cfg.Notarius)
|
||
|
|
if got := cfg.Publish.Outputs[0].Dest; got != "archive/session/people.json" {
|
||
|
|
t.Fatalf("remote destination = %q", got)
|
||
|
|
}
|
||
|
|
if err := validatePublishedOutputs(cfg.Publish.Outputs, nil, notariusOutputKeySet(cfg.Notarius)); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
}
|