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