Files
unibots/pkg/transport/flags_test.go
T
agent fc644ecd6e feat: import agents_and_robots platform as unibots (Matrix-out, unibus transport)
Reemplaza el scaffold del echobot por la plataforma completa de bots traida
desde ~/DataProyects/Github/agents_and_robots tras la operacion Matrix-out:
los bots ya no hablan por Matrix sino por el bus unibus (modelo todo-rooms +
E2E via shell/transportunibus sobre github.com/enmanuel/unibus/pkg/client).

- go.mod: replace de unibus -> ../unibus y de fn-registry -> ../../../.. (paths
  relativos reajustados a la nueva ubicacion dentro de fn_registry).
- app.md: bump a 0.2.0, descripcion + arquitectura + comandos + gotchas reales.
- modulo Go conservado como github.com/enmanuel/agents (sin reescribir imports).

agents_and_robots queda archivado como museo de la era Matrix.
2026-06-07 11:50:13 +02:00

61 lines
1.7 KiB
Go

package transport
import (
"os"
"path/filepath"
"testing"
)
// TestSelect covers the branch-by-abstraction toggle: unibus only when the flag
// is on AND the bot opted in; Matrix in every other combination (the default,
// so unmigrated bots keep working).
func TestSelect(t *testing.T) {
cases := []struct {
flag, optIn bool
want Kind
}{
{true, true, KindUnibus},
{true, false, KindMatrix},
{false, true, KindMatrix},
{false, false, KindMatrix},
}
for _, c := range cases {
if got := Select(c.flag, c.optIn); got != c.want {
t.Errorf("Select(flag=%v, optIn=%v) = %q, want %q", c.flag, c.optIn, got, c.want)
}
}
}
func TestFlagEnabled(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "feature_flags.json")
const content = `{"flags":{"unibus-transport":{"enabled":true,"issue":"x"},"off":{"enabled":false}}}`
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
t.Fatalf("write flags: %v", err)
}
on, err := FlagEnabled(path, "unibus-transport")
if err != nil {
t.Fatalf("FlagEnabled: %v", err)
}
if !on {
t.Errorf("expected unibus-transport enabled")
}
off, err := FlagEnabled(path, "off")
if err != nil {
t.Fatalf("FlagEnabled off: %v", err)
}
if off {
t.Errorf("expected off flag disabled")
}
// Missing flag and missing file both read as false (fail-safe to Matrix).
if missing, err := FlagEnabled(path, "does-not-exist"); err != nil || missing {
t.Errorf("missing flag should be (false, nil), got (%v, %v)", missing, err)
}
if absent, err := FlagEnabled(filepath.Join(dir, "nope.json"), "x"); err != nil || absent {
t.Errorf("absent file should be (false, nil), got (%v, %v)", absent, err)
}
}