Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// The service rotation mapping every client shares: one ordered list and// mode per service, read from a lead profile and written to every profile// of the extension that is not pinned.package daemon
import ( "encoding/json" "reflect" "testing"
"albedo/cli/internal/config")
func TestServiceRotationReadsTheLeadProfile(t *testing.T) { accounts := []string{"a", "b", "c"} cases := []struct { profiles config.Profiles name string mode string order []string }{ {name: "no profile keeps auth order", profiles: config.Profiles{Providers: map[string]config.Settings{}}, order: []string{"a", "b", "c"}, mode: RotationFailover}, {name: "automatic lead with several accounts reads as first", profiles: config.Profiles{Providers: map[string]config.Settings{ "claude": {Extension: "claude"}, }}, order: []string{"a", "b", "c"}, mode: RotationFirst}, {name: "default profile leads, gone ids are dropped, the rest follow", profiles: config.Profiles{Active: "work", Providers: map[string]config.Settings{ "alpha": {Extension: "claude", AccountIDs: []string{"a"}, Rotation: "first"}, "work": {Extension: "claude", AccountIDs: []string{"c", "gone", "a"}, Rotation: "spread"}, }}, order: []string{"c", "a", "b"}, mode: RotationSpread}, {name: "a default of another extension does not lead", profiles: config.Profiles{Active: "gpt", Providers: map[string]config.Settings{ "gpt": {Extension: "codex", AccountIDs: []string{"x"}}, "plain": {Extension: "claude"}, "zeta": {Extension: "claude", AccountIDs: []string{"b", "a"}}, }}, order: []string{"b", "a", "c"}, mode: RotationFailover}, } for _, c := range cases { order, mode := ServiceRotation("claude", c.profiles, accounts) if !reflect.DeepEqual(order, c.order) || mode != c.mode { t.Errorf("%s: got %v %s, want %v %s", c.name, order, mode, c.order, c.mode) } } if _, mode := ServiceRotation("claude", config.Profiles{Providers: map[string]config.Settings{"c": {Extension: "claude"}}}, []string{"a"}); mode != RotationFailover { t.Errorf("one automatic account reads as %s", mode) }}
func TestRotationPatchSkipsPinnedAndKeyedProfiles(t *testing.T) { profiles := config.Profiles{Providers: map[string]config.Settings{ "claude": {Extension: "claude"}, "team": {Extension: "claude", AccountIDs: []string{"a"}}, "pinned": {Extension: "claude", AccountID: new("a")}, "keyed": {Extension: "claude", HasKey: true}, "chatgpt": {Extension: "codex"}, }} got := RotationPatch("claude", profiles, []string{"b", "a"}, RotationSpread) wire, err := json.Marshal(got) if err != nil { t.Fatal(err) } want := `{"profiles":{"claude":{"account_id":null,"account_ids":["b","a"],"rotation":"spread"},"team":{"account_id":null,"account_ids":["b","a"],"rotation":"spread"}}}` if string(wire) != want { t.Fatalf("patch %s, want %s", wire, want) }
if RotationPatch("gemini", profiles, []string{"a"}, RotationFailover) != nil { t.Fatal("a service no profile runs got a patch") }}