Refactor config package validation
This commit is contained in:
@@ -125,7 +125,6 @@ type JobConfig struct {
|
||||
// Timeout limits the job execution time (e.g., "10m").
|
||||
Timeout time.Duration `yaml:"timeout,omitempty"`
|
||||
// UserId identifies the user that owns conversations created by this job.
|
||||
// It is assigned by the service until jobs are stored in the database.
|
||||
UserId string `yaml:"user_id,omitempty"`
|
||||
}
|
||||
|
||||
@@ -145,6 +144,9 @@ func (cfg JobConfig) Validate() error {
|
||||
if cfg.Timeout < 0 {
|
||||
return fmt.Errorf("invalid timeout %v: must not be negative", cfg.Timeout)
|
||||
}
|
||||
if cfg.UserId == "" {
|
||||
return fmt.Errorf("missing user_id")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -208,6 +208,9 @@ tts:
|
||||
{
|
||||
name: "invalid shutdown_timeout",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
shutdown_timeout: "not-a-duration"
|
||||
|
||||
default_model:
|
||||
@@ -388,6 +391,9 @@ tools:
|
||||
{
|
||||
name: "invalid tool",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -413,6 +419,9 @@ tools:
|
||||
{
|
||||
name: "invalid tool timeout",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -539,6 +548,7 @@ jobs:
|
||||
task: "Summarize today's news about AI."
|
||||
timeout: "10m"
|
||||
max_iterations: 20
|
||||
user_id: default
|
||||
`,
|
||||
check: func(t *testing.T, cfg *Config) {
|
||||
if len(cfg.Jobs) != 1 {
|
||||
@@ -587,6 +597,7 @@ jobs:
|
||||
- name: log_job
|
||||
schedule: "*/5 * * * *"
|
||||
task: "Check system health."
|
||||
user_id: default
|
||||
`,
|
||||
check: func(t *testing.T, cfg *Config) {
|
||||
if len(cfg.Jobs) != 1 {
|
||||
@@ -601,6 +612,9 @@ jobs:
|
||||
{
|
||||
name: "job missing name",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -619,12 +633,16 @@ tts:
|
||||
jobs:
|
||||
- schedule: "0 9 * * *"
|
||||
task: "do something"
|
||||
user_id: default
|
||||
`,
|
||||
shouldErr: true,
|
||||
},
|
||||
{
|
||||
name: "job missing task",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -642,7 +660,36 @@ tts:
|
||||
|
||||
jobs:
|
||||
- name: no_task
|
||||
schedule: "0 9 * * *"
|
||||
schedule: "0 9 * * * *"
|
||||
user_id: default
|
||||
`,
|
||||
shouldErr: true,
|
||||
},
|
||||
{
|
||||
name: "job missing user_id",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
|
||||
providers:
|
||||
- name: testprovider
|
||||
url: http://localhost:8080
|
||||
|
||||
stt:
|
||||
url: http://localhost:8178
|
||||
|
||||
tts:
|
||||
url: http://localhost:8880
|
||||
voice: af_heart
|
||||
|
||||
jobs:
|
||||
- name: no_user
|
||||
schedule: "0 9 * * * *"
|
||||
task: "do something"
|
||||
`,
|
||||
shouldErr: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user