Session configuration templates are now proceeded by narratio session init; all other commands require concrete configuration
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadSessionWithOptionsRendersCompactPlaceholder(t *testing.T) {
|
||||
func TestLoadSessionWithOptionsRejectsCompactPlaceholder(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: "{{session_id}}"
|
||||
@@ -22,40 +22,14 @@ inputs:
|
||||
t.Fatalf("write session.yml: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{SessionID: "2026-04-04"})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadSessionWithOptions() error = %v", err)
|
||||
}
|
||||
if cfg.SessionID != "2026-04-04" {
|
||||
t.Fatalf("SessionID = %q, want 2026-04-04", cfg.SessionID)
|
||||
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{SessionID: "2026-04-04"})
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
assertConcreteSessionTemplateError(t, err, "session_id")
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsRendersSpacedPlaceholder(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: "{{ session_id }}"
|
||||
campaign: sample-campaign
|
||||
inputs:
|
||||
audio_dir: ./audio
|
||||
speakers_file: ./speakers.yml
|
||||
autocorrect_file: ./autocorrect.yml
|
||||
glossary_file: ./glossary.yml
|
||||
`
|
||||
if err := os.WriteFile(sessionPath, []byte(sessionYAML), 0o644); err != nil {
|
||||
t.Fatalf("write session.yml: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{SessionID: "2026-04-04"})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadSessionWithOptions() error = %v", err)
|
||||
}
|
||||
if cfg.SessionID != "2026-04-04" {
|
||||
t.Fatalf("SessionID = %q, want 2026-04-04", cfg.SessionID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsRendersPreviousSessionPlaceholder(t *testing.T) {
|
||||
func TestLoadSessionWithOptionsRejectsSpacedPlaceholder(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: "{{ session_id }}"
|
||||
@@ -71,74 +45,14 @@ inputs:
|
||||
t.Fatalf("write session.yml: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{
|
||||
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{
|
||||
SessionID: "2026-04-04",
|
||||
PreviousSessionID: "2026-03-28",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadSessionWithOptions() error = %v", err)
|
||||
}
|
||||
if cfg.PreviousSessionID != "2026-03-28" {
|
||||
t.Fatalf("PreviousSessionID = %q, want 2026-03-28", cfg.PreviousSessionID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsUnresolvedPlaceholderFails(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: "{{ session_id }}"
|
||||
campaign: sample-campaign
|
||||
inputs:
|
||||
audio_dir: ./audio
|
||||
speakers_file: ./speakers.yml
|
||||
autocorrect_file: ./autocorrect.yml
|
||||
glossary_file: ./glossary.yml
|
||||
`
|
||||
if err := os.WriteFile(sessionPath, []byte(sessionYAML), 0o644); err != nil {
|
||||
t.Fatalf("write session.yml: %v", err)
|
||||
}
|
||||
|
||||
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "unresolved template variable") {
|
||||
t.Fatalf("error = %q, want unresolved-variable context", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "session_id") {
|
||||
t.Fatalf("error = %q, want session_id variable", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsUnresolvedPreviousSessionPlaceholderFails(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: 2026-05-03
|
||||
previous_session_id: "{{ previous_session_id }}"
|
||||
campaign: sample-campaign
|
||||
inputs:
|
||||
audio_dir: ./audio
|
||||
speakers_file: ./speakers.yml
|
||||
autocorrect_file: ./autocorrect.yml
|
||||
glossary_file: ./glossary.yml
|
||||
`
|
||||
if err := os.WriteFile(sessionPath, []byte(sessionYAML), 0o644); err != nil {
|
||||
t.Fatalf("write session.yml: %v", err)
|
||||
}
|
||||
|
||||
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "unresolved template variable") {
|
||||
t.Fatalf("error = %q, want unresolved-variable context", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "previous_session_id") {
|
||||
t.Fatalf("error = %q, want previous_session_id variable", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "--previous-session-id") {
|
||||
t.Fatalf("error = %q, want previous-session-id guidance", err.Error())
|
||||
}
|
||||
assertConcreteSessionTemplateError(t, err, "session_id", "previous_session_id")
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsMismatchFails(t *testing.T) {
|
||||
@@ -163,6 +77,9 @@ inputs:
|
||||
if !strings.Contains(err.Error(), "session_id mismatch") {
|
||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
||||
}
|
||||
if strings.Contains(err.Error(), "rendered") {
|
||||
t.Fatalf("error = %q, should not mention rendered session", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsPreviousSessionMismatchFails(t *testing.T) {
|
||||
@@ -191,12 +108,15 @@ inputs:
|
||||
if !strings.Contains(err.Error(), "previous_session_id mismatch") {
|
||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
||||
}
|
||||
if strings.Contains(err.Error(), "rendered") {
|
||||
t.Fatalf("error = %q, should not mention rendered session", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionWithOptionsUnknownFieldStillRejectedAfterRendering(t *testing.T) {
|
||||
func TestLoadSessionWithOptionsUnknownFieldStillRejected(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
sessionYAML := `session_id: "{{ session_id }}"
|
||||
sessionYAML := `session_id: 2026-04-04
|
||||
campaign: sample-campaign
|
||||
unknown_field: true
|
||||
inputs:
|
||||
@@ -242,7 +162,7 @@ inputs:
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSessionBytesWithOptionsUsesSameTemplateAndStrictDecode(t *testing.T) {
|
||||
func TestLoadSessionBytesWithOptionsRejectsPlaceholder(t *testing.T) {
|
||||
sessionYAML := []byte(`session_id: "{{ session_id }}"
|
||||
campaign: sample-campaign
|
||||
inputs:
|
||||
@@ -250,7 +170,15 @@ inputs:
|
||||
prefix: audio/
|
||||
`)
|
||||
|
||||
cfg, err := LoadSessionBytesWithOptions("s3://bucket/session.yml", sessionYAML, SessionLoadOptions{SessionID: "2026-05-03"})
|
||||
_, err := LoadSessionBytesWithOptions("s3://bucket/session.yml", sessionYAML, SessionLoadOptions{SessionID: "2026-05-03"})
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
assertConcreteSessionTemplateError(t, err, "session_id")
|
||||
}
|
||||
|
||||
func TestLoadSessionBytesWithOptionsStrictDecode(t *testing.T) {
|
||||
cfg, err := LoadSessionBytesWithOptions("s3://bucket/session.yml", []byte("session_id: 2026-05-03\n"), SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("LoadSessionBytesWithOptions() error = %v", err)
|
||||
}
|
||||
@@ -276,3 +204,18 @@ func TestLoadSessionBytesWithOptionsMismatchFails(t *testing.T) {
|
||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func assertConcreteSessionTemplateError(t *testing.T, err error, vars ...string) {
|
||||
t.Helper()
|
||||
if !strings.Contains(err.Error(), "session.yml must be concrete") {
|
||||
t.Fatalf("error = %q, want concrete session guidance", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "run narratio session init") {
|
||||
t.Fatalf("error = %q, want session init guidance", err.Error())
|
||||
}
|
||||
for _, name := range vars {
|
||||
if !strings.Contains(err.Error(), name) {
|
||||
t.Fatalf("error = %q, want variable %q", err.Error(), name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user