Files
agents_and_robots/cmd/launcher/registry_test.go
T
egutierrez a6100b5154 test: tests para privileged ACL y isSpecialConfig
- TestResolveACL_PrivilegedVsGeneral: verifica que father-bot solo
  es accesible por admins y que agentes generales son accesibles
  por todos. Reproduce la config real de produccion.
- TestIsSpecialConfig_*: 3 tests para la funcion que detecta
  configs de SpecialConfig ya cargados (orchestrator) y los salta
  en el loop de discovery normal del launcher.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 22:05:41 +00:00

115 lines
2.9 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
)
func TestReadReloadTarget_missing(t *testing.T) {
got := readReloadTarget(filepath.Join(t.TempDir(), "reload.txt"))
if got != "" {
t.Fatalf("expected empty string for missing file, got %q", got)
}
}
func TestReadReloadTarget_empty(t *testing.T) {
f := filepath.Join(t.TempDir(), "reload.txt")
if err := os.WriteFile(f, []byte(""), 0o644); err != nil {
t.Fatal(err)
}
got := readReloadTarget(f)
if got != "" {
t.Fatalf("expected empty string for empty file, got %q", got)
}
}
func TestReadReloadTarget_star(t *testing.T) {
f := filepath.Join(t.TempDir(), "reload.txt")
if err := os.WriteFile(f, []byte("*\n"), 0o644); err != nil {
t.Fatal(err)
}
got := readReloadTarget(f)
if got != "" {
t.Fatalf("expected empty string for '*', got %q", got)
}
}
func TestReadReloadTarget_agentID(t *testing.T) {
f := filepath.Join(t.TempDir(), "reload.txt")
if err := os.WriteFile(f, []byte("assistant-bot\n"), 0o644); err != nil {
t.Fatal(err)
}
got := readReloadTarget(f)
if got != "assistant-bot" {
t.Fatalf("expected 'assistant-bot', got %q", got)
}
}
func TestReadReloadTarget_whitespace(t *testing.T) {
f := filepath.Join(t.TempDir(), "reload.txt")
if err := os.WriteFile(f, []byte(" asistente-2 \n"), 0o644); err != nil {
t.Fatal(err)
}
got := readReloadTarget(f)
if got != "asistente-2" {
t.Fatalf("expected 'asistente-2', got %q", got)
}
}
// ── isSpecialConfig tests ─────────────────────────────────────────────────
func TestIsSpecialConfig_matchesLoadedSpecial(t *testing.T) {
dir := t.TempDir()
cfg := filepath.Join(dir, "config.yaml")
if err := os.WriteFile(cfg, []byte(`
special:
id: orchestrator
type: orchestrator
enabled: true
llm:
primary:
provider: openai
`), 0o644); err != nil {
t.Fatal(err)
}
loaded := map[string]bool{"orchestrator": true}
if !isSpecialConfig(cfg, loaded) {
t.Fatal("expected isSpecialConfig to return true for loaded orchestrator")
}
}
func TestIsSpecialConfig_agentConfigNotSpecial(t *testing.T) {
dir := t.TempDir()
cfg := filepath.Join(dir, "config.yaml")
// An AgentConfig doesn't have special.id, so LoadSpecial will fail validation.
if err := os.WriteFile(cfg, []byte(`
agent:
id: father-bot
enabled: true
matrix:
homeserver: "https://example.com"
user_id: "@father:example.com"
llm:
primary:
provider: claude-code
`), 0o644); err != nil {
t.Fatal(err)
}
loaded := map[string]bool{"orchestrator": true}
if isSpecialConfig(cfg, loaded) {
t.Fatal("expected isSpecialConfig to return false for agent config")
}
}
func TestIsSpecialConfig_emptyLoadedMap(t *testing.T) {
if isSpecialConfig("any-path", nil) {
t.Fatal("expected false when no specials loaded")
}
if isSpecialConfig("any-path", map[string]bool{}) {
t.Fatal("expected false when empty specials map")
}
}