115 lines
3.9 KiB
Go
115 lines
3.9 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/diagnostics"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
)
|
|
|
|
func TestApplyEnvOverridesOperationalValues(t *testing.T) {
|
|
cfg := Default()
|
|
cfg.Pipelines["example"] = pipeline.PipelineProfile{ID: "example", Input: pipeline.Binding("before")}
|
|
|
|
err := cfg.applyEnvOverridesWithLookup(mapLookup(map[string]string{
|
|
"NOTARIUS_TOTAL_LLM_CONCURRENCY": "3",
|
|
"NOTARIUS_WORK_DIR": "/tmp/notarius-env",
|
|
"NOTARIUS_DIAGNOSTICS_RETENTION": "never",
|
|
"NOTARIUS_WORKSPACE_DIR": "/var/lib/notarius-env",
|
|
"NOTARIUS_WORKSPACE_DIAGNOSTICS_ENABLED": "false",
|
|
"NOTARIUS_WORKSPACE_DIAGNOSTICS_RETENTION": "always",
|
|
"NOTARIUS_WORKSPACE_RESUME_ENABLED": "true",
|
|
"NOTARIUS_WORKSPACE_DEBUG_ENABLED": "true",
|
|
"NOTARIUS_PIPELINE_INPUT": "after",
|
|
}))
|
|
if err != nil {
|
|
t.Fatalf("ApplyEnvOverrides: %v", err)
|
|
}
|
|
|
|
if cfg.Scriptorium.ProfileDir != "" || cfg.Scriptorium.ProfileFile != "" {
|
|
t.Fatalf("LLM environment overrides must not change Scriptorium config: %+v", cfg.Scriptorium)
|
|
}
|
|
if cfg.Concurrency.TotalLLM != 3 {
|
|
t.Fatalf("unexpected total concurrency: %d", cfg.Concurrency.TotalLLM)
|
|
}
|
|
if cfg.Workspace.Directory != "/var/lib/notarius-env" {
|
|
t.Fatalf("unexpected workspace directory: %q", cfg.Workspace.Directory)
|
|
}
|
|
if cfg.DiagnosticsEnabled() {
|
|
t.Fatalf("expected workspace diagnostics disabled")
|
|
}
|
|
if cfg.Diagnostics.WorkDir != "/var/lib/notarius-env/diagnostics" || cfg.Diagnostics.Retention != diagnostics.RetentionAlways {
|
|
t.Fatalf("unexpected diagnostics config: %+v", cfg.Diagnostics)
|
|
}
|
|
if !cfg.Workspace.Resume.Enabled {
|
|
t.Fatalf("expected workspace resume enabled")
|
|
}
|
|
if !cfg.Workspace.Debug.Enabled {
|
|
t.Fatalf("expected workspace debug enabled")
|
|
}
|
|
if cfg.Pipelines["example"].Input.Module != "before" {
|
|
t.Fatalf("environment overrides must not change pipeline wiring: %+v", cfg.Pipelines["example"])
|
|
}
|
|
}
|
|
|
|
func TestApplyEnvOverridesRejectsInvalidIntegers(t *testing.T) {
|
|
cfg := Default()
|
|
err := cfg.applyEnvOverridesWithLookup(mapLookup(map[string]string{
|
|
"NOTARIUS_TOTAL_LLM_CONCURRENCY": "many",
|
|
}))
|
|
if err == nil || !strings.Contains(err.Error(), "NOTARIUS_TOTAL_LLM_CONCURRENCY") {
|
|
t.Fatalf("expected named integer error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestApplyEnvOverridesRejectsInvalidBooleans(t *testing.T) {
|
|
for _, name := range []string{
|
|
"NOTARIUS_WORKSPACE_DIAGNOSTICS_ENABLED",
|
|
"NOTARIUS_WORKSPACE_RESUME_ENABLED",
|
|
"NOTARIUS_WORKSPACE_DEBUG_ENABLED",
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
cfg := Default()
|
|
err := cfg.applyEnvOverridesWithLookup(mapLookup(map[string]string{name: "maybe"}))
|
|
if err == nil || !strings.Contains(err.Error(), name) {
|
|
t.Fatalf("expected named boolean error, got %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestApplyEnvOverridesLegacyDiagnosticsRemainCompatibleWithoutWorkspace(t *testing.T) {
|
|
cfg := Default()
|
|
|
|
err := cfg.applyEnvOverridesWithLookup(mapLookup(map[string]string{
|
|
"NOTARIUS_WORK_DIR": "/tmp/notarius-env",
|
|
"NOTARIUS_DIAGNOSTICS_RETENTION": "never",
|
|
}))
|
|
if err != nil {
|
|
t.Fatalf("ApplyEnvOverrides: %v", err)
|
|
}
|
|
|
|
if cfg.Diagnostics.WorkDir != "/tmp/notarius-env" {
|
|
t.Fatalf("diagnostics work dir = %q, want legacy env", cfg.Diagnostics.WorkDir)
|
|
}
|
|
if cfg.Diagnostics.Retention != diagnostics.RetentionNever {
|
|
t.Fatalf("diagnostics retention = %q, want legacy env", cfg.Diagnostics.Retention)
|
|
}
|
|
}
|
|
|
|
func TestLoadFromEnvUsesDefaultConfig(t *testing.T) {
|
|
t.Setenv("NOTARIUS_TOTAL_LLM_CONCURRENCY", "2")
|
|
|
|
cfg, err := LoadFromEnv()
|
|
if err != nil {
|
|
t.Fatalf("LoadFromEnv: %v", err)
|
|
}
|
|
if cfg.Scriptorium.ProfileDir != "" || cfg.Scriptorium.ProfileFile != "" {
|
|
t.Fatalf("unexpected Scriptorium config from env: %+v", cfg.Scriptorium)
|
|
}
|
|
if cfg.Concurrency.TotalLLM != 2 {
|
|
t.Fatalf("expected env concurrency override, got %+v", cfg.Concurrency)
|
|
}
|
|
}
|