Harden configuration validation
This commit is contained in:
52
internal/app/operator_session_init_test.go
Normal file
52
internal/app/operator_session_init_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSessionInitRejectsRenderedTemplateThatOmitsExpectedPreviousSession(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
campaignDir := filepath.Dir(campaignPath)
|
||||
templatePath := filepath.Join(campaignDir, "session.template.yml")
|
||||
template := `session_id: {{ session_id }}
|
||||
campaign: sample-campaign
|
||||
inputs:
|
||||
audio_dir: ./audio
|
||||
`
|
||||
if err := os.WriteFile(templatePath, []byte(template), 0o644); err != nil {
|
||||
t.Fatalf("write session template: %v", err)
|
||||
}
|
||||
campaign := `campaign_id: sample-campaign
|
||||
session_template_file: session.template.yml
|
||||
inputs:
|
||||
speakers_file: ./speakers.yml
|
||||
autocorrect_file: ./autocorrect.yml
|
||||
glossary_file: ./glossary.yml
|
||||
players_file: ./players.yml
|
||||
party_file: ./party.yml
|
||||
`
|
||||
if err := os.WriteFile(campaignPath, []byte(campaign), 0o644); err != nil {
|
||||
t.Fatalf("write campaign config: %v", err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
err := SessionInit(context.Background(), []string{
|
||||
"2026-05-03",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
"--output", filepath.Join(t.TempDir(), "session.yml"),
|
||||
"--previous-session-id", "2026-04-26",
|
||||
}, &out)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "unused template variable value(s): previous_session_id") {
|
||||
t.Fatalf("SessionInit() error = %q, want missing previous-session template error", err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user