Accept composed ConfigKit artifact definitions
This commit is contained in:
@@ -80,41 +80,151 @@ func TestPipelineOverlayDoesNotDiscoverLegacyDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPipelineConfigKitRejectsDuplicateBaseDeclarations(t *testing.T) {
|
||||
func TestPipelineConfigKitComposesDisjointDefinitionsAndHonorsOverlay(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, first, second, clearedContainer string
|
||||
name, first, second, replacement, removal string
|
||||
}{
|
||||
{name: "artifact", first: "scriptorium:\n artifacts:\n recap:\n prompt_id: recap\n", second: "scriptorium:\n artifacts:\n recap:\n output_path: artifacts/recap.md\n", clearedContainer: "scriptorium:\n artifacts: null\n"},
|
||||
{name: "artifact family", first: "scriptorium:\n artifact_families:\n recap:\n for_each: party.characters\n", second: "scriptorium:\n artifact_families:\n recap:\n output_path_pattern: artifacts/{character_id}.md\n", clearedContainer: "scriptorium:\n artifact_families: null\n"},
|
||||
{
|
||||
name: "artifact",
|
||||
first: "scriptorium:\n artifacts:\n recap:\n enabled: true\n prompt_id: dnd.recap\n",
|
||||
second: "scriptorium:\n artifacts:\n recap:\n output_path: artifacts/recap.md\n",
|
||||
replacement: "scriptorium:\n artifacts:\n recap:\n output_path: artifacts/replaced.md\n",
|
||||
removal: "scriptorium:\n artifacts: null\n",
|
||||
},
|
||||
{
|
||||
name: "artifact family",
|
||||
first: "scriptorium:\n artifact_families:\n recap:\n enabled: true\n for_each: party.characters\n prompt_id: dnd.recap\n profile_id: production\n",
|
||||
second: "scriptorium:\n artifact_families:\n recap:\n output_path_pattern: artifacts/{character_id}.md\n",
|
||||
replacement: "scriptorium:\n artifact_families:\n recap:\n output_path_pattern: artifacts/{character_id}_replaced.md\n",
|
||||
removal: "scriptorium:\n artifact_families: null\n",
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writePipelineFixture(t, dir, "pipeline.yml", `configkit:
|
||||
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), `schema_version: narratio.party.v1
|
||||
characters:
|
||||
alice:
|
||||
player: {name: Alice Player}
|
||||
character:
|
||||
name: Alice
|
||||
classes: [{name: wizard}]
|
||||
`)
|
||||
pipeline := `configkit:
|
||||
imports:
|
||||
- path: first.yml
|
||||
- path: second.yml
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
`
|
||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
|
||||
writePipelineFixture(t, dir, "first.yml", test.first)
|
||||
writePipelineFixture(t, dir, "second.yml", test.second)
|
||||
writePipelineFixture(t, dir, "overlays/replacement.yml", test.replacement)
|
||||
writePipelineFixture(t, dir, "overlays/removal.yml", test.removal)
|
||||
|
||||
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("load disjoint contributions: %v", err)
|
||||
}
|
||||
if test.name == "artifact" {
|
||||
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap"]
|
||||
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/recap.md" {
|
||||
t.Fatalf("composed artifact = %#v", artifact)
|
||||
}
|
||||
} else {
|
||||
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap_alice"]
|
||||
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/alice.md" {
|
||||
t.Fatalf("composed artifact family member = %#v", artifact)
|
||||
}
|
||||
}
|
||||
|
||||
replacement := "replacement"
|
||||
cfg, err = LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{Overlay: &replacement})
|
||||
if err != nil {
|
||||
t.Fatalf("load replacement overlay: %v", err)
|
||||
}
|
||||
if test.name == "artifact" && cfg.Pipeline.Scriptorium.Artifacts["recap"].OutputPath != "artifacts/replaced.md" {
|
||||
t.Fatalf("overlay artifact replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap"])
|
||||
}
|
||||
if test.name == "artifact family" && cfg.Pipeline.Scriptorium.Artifacts["recap_alice"].OutputPath != "artifacts/alice_replaced.md" {
|
||||
t.Fatalf("overlay family replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap_alice"])
|
||||
}
|
||||
|
||||
removal := "removal"
|
||||
cfg, err = LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{Overlay: &removal})
|
||||
if err != nil {
|
||||
t.Fatalf("load removal overlay: %v", err)
|
||||
}
|
||||
if len(cfg.Pipeline.Scriptorium.Artifacts) != 0 {
|
||||
t.Fatalf("overlay left artifacts after removal: %#v", cfg.Pipeline.Scriptorium.Artifacts)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("structural conflict remains a loader error", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writePipelineFixture(t, dir, "pipeline.yml", `configkit:
|
||||
imports:
|
||||
- path: first.yml
|
||||
- path: second.yml
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
`)
|
||||
writePipelineFixture(t, dir, "first.yml", test.first)
|
||||
writePipelineFixture(t, dir, "second.yml", test.second)
|
||||
writePipelineFixture(t, dir, "overlays/clear-container.yml", test.clearedContainer)
|
||||
writePipelineFixture(t, dir, "overlays/clear-scriptorium.yml", "scriptorium: null\n")
|
||||
writePipelineFixture(t, dir, "first.yml", "workspace:\n root: /srv/first\n")
|
||||
writePipelineFixture(t, dir, "second.yml", "workspace:\n root: /srv/second\n")
|
||||
if _, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err == nil || !strings.Contains(strings.ToLower(err.Error()), "conflict") {
|
||||
t.Fatalf("structural conflict error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, profile := range []string{"", "clear-container", "clear-scriptorium"} {
|
||||
t.Run(profile, func(t *testing.T) {
|
||||
options := PipelineLoadOptions{}
|
||||
if profile != "" {
|
||||
options.Overlay = &profile
|
||||
}
|
||||
_, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), options)
|
||||
if err == nil || !strings.Contains(err.Error(), "declared by multiple base files") ||
|
||||
!strings.Contains(err.Error(), "first.yml") || !strings.Contains(err.Error(), "second.yml") {
|
||||
t.Fatalf("duplicate declaration error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
func TestPipelineConfigKitInheritsArtifactAcrossImports(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), `schema_version: narratio.party.v1
|
||||
characters:
|
||||
alice:
|
||||
player: {name: Alice Player}
|
||||
character:
|
||||
name: Alice
|
||||
classes: [{name: wizard}]
|
||||
`)
|
||||
pipeline := `configkit:
|
||||
imports:
|
||||
- path: artifacts/parent.yml
|
||||
- path: artifacts/child.yml
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
`
|
||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
|
||||
writePipelineFixture(t, dir, "artifacts/parent.yml", `scriptorium:
|
||||
artifacts:
|
||||
session_recap:
|
||||
enabled: true
|
||||
prompt_id: dnd.session_recap
|
||||
profile_id: production
|
||||
output_path: artifacts/session_recap.md
|
||||
`)
|
||||
writePipelineFixture(t, dir, "artifacts/child.yml", `scriptorium:
|
||||
artifacts:
|
||||
session_notes:
|
||||
extends: session_recap
|
||||
output_path: artifacts/session_notes.md
|
||||
`)
|
||||
|
||||
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parent := cfg.Pipeline.Scriptorium.Artifacts["session_recap"]
|
||||
child, ok := cfg.Pipeline.Scriptorium.Artifacts["session_notes"]
|
||||
if !ok {
|
||||
t.Fatal("inherited child artifact identity was not retained")
|
||||
}
|
||||
if parent.OutputPath != "artifacts/session_recap.md" || child.OutputPath != "artifacts/session_notes.md" {
|
||||
t.Fatalf("artifact destinations = parent %q, child %q", parent.OutputPath, child.OutputPath)
|
||||
}
|
||||
if !child.Enabled || child.PromptID != "dnd.session_recap" || child.ProfileID != "production" {
|
||||
t.Fatalf("inherited child artifact = %#v", child)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user