package config import ( "os" "path/filepath" "strings" "testing" ) func TestLoadersRejectTrailingYAMLDocuments(t *testing.T) { dir := t.TempDir() pipelinePath := filepath.Join(dir, "pipeline.yml") campaignPath := filepath.Join(dir, "campaign.yml") if err := os.WriteFile(pipelinePath, []byte("workspace:\n root: /tmp/narratio\n---\nworkspace:\n root: /other\n"), 0o644); err != nil { t.Fatalf("write pipeline.yml: %v", err) } if err := os.WriteFile(campaignPath, []byte("campaign_id: sample-campaign\n---\nnull\n"), 0o644); err != nil { t.Fatalf("write campaign.yml: %v", err) } tests := []struct { name string load func() error }{ { name: "pipeline", load: func() error { _, err := LoadPipeline(pipelinePath) return err }, }, { name: "campaign", load: func() error { _, err := LoadCampaign(campaignPath) return err }, }, { name: "remote session bytes", load: func() error { _, err := LoadSessionBytesWithOptions("s3://bucket/session.yml", []byte("session_id: 2026-05-03\n---\n# another document\nnull\n"), SessionLoadOptions{}) return err }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.load() if err == nil || (!strings.Contains(err.Error(), "exactly one YAML document") && !strings.Contains(err.Error(), "yaml.multiple_documents")) { t.Fatalf("load error = %v, want exactly-one-document error", err) } }) } }