feat: config, OpenAI-compatible streaming provider and safe tools

This commit is contained in:
OpenClaw Dev 2026-10-25 03:10:13 +01:00
commit c1c7b0e005
13 changed files with 1031 additions and 0 deletions

View file

@ -0,0 +1,44 @@
package config
import (
"os"
"path/filepath"
"testing"
)
func TestLoadYAMLAndEnv(t *testing.T) {
dir := t.TempDir()
p := filepath.Join(dir, "c.yaml")
os.WriteFile(p, []byte("auth_token: aaaaaaaaaaaaaaaaaaaa\nllm:\n model: llama3\n"), 0o600)
t.Setenv("OPENCLAW_LLM_BASE_URL", "http://localhost:11434/v1")
t.Setenv("OPENCLAW_ALLOWED_ORIGINS", "https://a.example, https://b.example")
c, err := Load(p)
if err != nil {
t.Fatal(err)
}
if c.LLM.Model != "llama3" || c.LLM.BaseURL != "http://localhost:11434/v1" {
t.Fatalf("unexpected llm cfg %+v", c.LLM)
}
if len(c.AllowedOrigins) != 2 || c.AllowedOrigins[1] != "https://b.example" {
t.Fatalf("origins %v", c.AllowedOrigins)
}
if c.Listen != "127.0.0.1:8787" {
t.Fatalf("default listen changed: %s", c.Listen)
}
}
func TestLoadJSON(t *testing.T) {
p := filepath.Join(t.TempDir(), "c.json")
os.WriteFile(p, []byte(`{"auth_token":"bbbbbbbbbbbbbbbbbbbb","listen":":9000"}`), 0o600)
c, err := Load(p)
if err != nil || c.Listen != ":9000" {
t.Fatalf("%v %v", c.Listen, err)
}
}
func TestValidateRequiresToken(t *testing.T) {
t.Setenv("OPENCLAW_AUTH_TOKEN", "")
if _, err := Load(""); err == nil {
t.Fatal("expected error without token")
}
}