From bf6971e470a5041202b49d7c58f27dac5a2b9fc8 Mon Sep 17 00:00:00 2001 From: dwrz Date: Sat, 26 Sep 2026 17:20:32 +0000 Subject: [PATCH] Refactor config package validation --- internal/config/config.go | 4 ++- internal/config/config_test.go | 49 +++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 33dba2b..a2d8389 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0f34dbb..55fdb01 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -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, },