188 lines
5.1 KiB
Go
188 lines
5.1 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTrimLoadAndValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
trimYAML string
|
|
wantLoadErr string
|
|
wantValidateErr string
|
|
assert func(t *testing.T, cfg *Config)
|
|
}{
|
|
{
|
|
name: "valid trim config",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
profile_id: ""
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
timeout: 10m
|
|
render_debug: false
|
|
render_output_path: artifacts/session_bounds.render.json
|
|
seriatim:
|
|
report: false
|
|
`,
|
|
assert: func(t *testing.T, cfg *Config) {
|
|
t.Helper()
|
|
if cfg.Pipeline.Trim == nil {
|
|
t.Fatal("trim config should be present")
|
|
}
|
|
if cfg.Pipeline.Trim.Enabled != true {
|
|
t.Fatalf("trim.enabled = %t, want true", cfg.Pipeline.Trim.Enabled)
|
|
}
|
|
if cfg.Pipeline.Trim.Bounds.ProfileID != "" {
|
|
t.Fatalf("trim.bounds.profile_id = %q, want empty", cfg.Pipeline.Trim.Bounds.ProfileID)
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: "enabled omitted defaults disabled",
|
|
trimYAML: `trim:
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
`,
|
|
assert: func(t *testing.T, cfg *Config) {
|
|
t.Helper()
|
|
if cfg.Pipeline.Trim == nil {
|
|
t.Fatal("trim config should be present")
|
|
}
|
|
if cfg.Pipeline.Trim.Enabled {
|
|
t.Fatal("trim.enabled should default to false when omitted")
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: "missing prompt id fails when enabled",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
`,
|
|
wantValidateErr: "pipeline.trim.bounds.prompt_id is required when pipeline.trim.enabled is true",
|
|
},
|
|
{
|
|
name: "missing transcript input name fails when enabled",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
output_path: artifacts/session_bounds.json
|
|
`,
|
|
wantValidateErr: "pipeline.trim.bounds.transcript_input_name is required when pipeline.trim.enabled is true",
|
|
},
|
|
{
|
|
name: "missing bounds output path fails when enabled",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
`,
|
|
wantValidateErr: "pipeline.trim.bounds.output_path is required when pipeline.trim.enabled is true",
|
|
},
|
|
{
|
|
name: "missing trimmed output path fails when enabled",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
`,
|
|
wantValidateErr: "pipeline.trim.output_path is required when pipeline.trim.enabled is true",
|
|
},
|
|
{
|
|
name: "invalid timeout fails",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
timeout: definitely-not-a-duration
|
|
`,
|
|
wantValidateErr: "pipeline.trim.bounds.timeout must be a valid duration",
|
|
},
|
|
{
|
|
name: "render debug true requires render output path",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
render_debug: true
|
|
`,
|
|
wantValidateErr: "pipeline.trim.bounds.render_output_path is required when pipeline.trim.bounds.render_debug is true",
|
|
},
|
|
{
|
|
name: "unknown trim field fails strict decoding",
|
|
trimYAML: `trim:
|
|
enabled: true
|
|
output_path: transcripts/final.trimmed.json
|
|
bounds:
|
|
prompt_id: dnd_session.bounds
|
|
transcript_input_name: transcript
|
|
output_path: artifacts/session_bounds.json
|
|
bogus: true
|
|
`,
|
|
wantLoadErr: "strict decode failed",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
pipelineYAML := testPipelineBaseYAML + "\n" + tt.trimYAML
|
|
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
|
|
|
cfg, err := Load(pipelinePath, sessionPath)
|
|
if tt.wantLoadErr != "" {
|
|
if err == nil {
|
|
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
|
}
|
|
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
|
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("Load() error = %v", err)
|
|
}
|
|
|
|
if tt.assert != nil {
|
|
tt.assert(t, cfg)
|
|
}
|
|
|
|
err = Validate(cfg)
|
|
if tt.wantValidateErr != "" {
|
|
if err == nil {
|
|
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
|
}
|
|
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
|
t.Fatalf("validation error = %q, want to contain %q", err.Error(), tt.wantValidateErr)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("Validate() error = %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|