chore: align forest AI development setup
This commit is contained in:
@@ -3,11 +3,38 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDevelopmentConfigMatchesLocalWorkspaceContract(t *testing.T) {
|
||||
t.Setenv("SENLIN_APP_MODE", "dev")
|
||||
|
||||
cfg, err := LoadFromDir(filepath.Join("..", "..", "etc"))
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "development", cfg.Env)
|
||||
require.Equal(t, "9150", cfg.Port)
|
||||
require.Equal(t, "postgres://agent:agent@localhost:5432/agent?sslmode=disable", cfg.DSN)
|
||||
require.NotEmpty(t, strings.TrimSpace(cfg.StorageDir))
|
||||
require.Equal(t, int64(32<<20), cfg.MaxUploadBytes)
|
||||
require.ElementsMatch(t, []string{
|
||||
"http://localhost:5173",
|
||||
"http://127.0.0.1:5173",
|
||||
"http://localhost:4173",
|
||||
"http://127.0.0.1:4173",
|
||||
"http://localhost:4174",
|
||||
"http://127.0.0.1:4174",
|
||||
"http://localhost:4175",
|
||||
"http://127.0.0.1:4175",
|
||||
"http://localhost:4176",
|
||||
"http://127.0.0.1:4176",
|
||||
"http://tauri.localhost",
|
||||
}, cfg.AllowedOrigins)
|
||||
}
|
||||
|
||||
func TestLoadFromDirDefaultsToDevYAML(t *testing.T) {
|
||||
configDir := t.TempDir()
|
||||
writeConfig(t, configDir, "agent.dev.yaml", "development", "18080", "postgres://dev", "./dev-files", "dev-auth", "dev-system", "dev-ai")
|
||||
@@ -47,6 +74,32 @@ func TestLoadFromDirUsesSENLINAppMode(t *testing.T) {
|
||||
require.Equal(t, []string{"https://workbench.example.com"}, cfg.AllowedOrigins)
|
||||
}
|
||||
|
||||
func TestLoadFromDirRejectsMissingStorageDir(t *testing.T) {
|
||||
configDir := t.TempDir()
|
||||
writeConfig(t, configDir, "agent.dev.yaml", "development", "9150", "postgres://agent", "", "dev-auth", "", "dev-ai")
|
||||
t.Setenv("SENLIN_APP_MODE", "dev")
|
||||
|
||||
_, err := LoadFromDir(configDir)
|
||||
|
||||
require.ErrorContains(t, err, "storage_dir")
|
||||
}
|
||||
|
||||
func TestLoadFromDirRejectsMissingAllowedOrigins(t *testing.T) {
|
||||
configDir := t.TempDir()
|
||||
content := []byte("env: development\n" +
|
||||
"port: \"9150\"\n" +
|
||||
"dsn: \"postgres://agent\"\n" +
|
||||
"storage_dir: \"./data/files\"\n" +
|
||||
"auth_secret: \"dev-auth\"\n" +
|
||||
"ai_key_encryption_secret: \"dev-ai\"\n")
|
||||
require.NoError(t, os.WriteFile(filepath.Join(configDir, "agent.dev.yaml"), content, 0o600))
|
||||
t.Setenv("SENLIN_APP_MODE", "dev")
|
||||
|
||||
_, err := LoadFromDir(configDir)
|
||||
|
||||
require.ErrorContains(t, err, "allowed_origins")
|
||||
}
|
||||
|
||||
func writeConfig(t *testing.T, dir string, name string, env string, port string, databaseURL string, storageDir string, authSecret string, systemAIKey string, aiKeySecret string) {
|
||||
t.Helper()
|
||||
allowedOrigins := " - http://localhost:5173\n - http://tauri.localhost\n"
|
||||
|
||||
Reference in New Issue
Block a user