From e6f766eb87f86d969236ff0ecf1bbc94abf894c8 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 20 Oct 2026 03:44:21 +1100 Subject: [PATCH] fix(config): keep the resolved aliases when an org supplies none --- internal/config/model_alias.go | 8 ++++++-- internal/config/orgmodels_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 internal/config/orgmodels_test.go diff --git a/internal/config/model_alias.go b/internal/config/model_alias.go index 311d1eb04..73b46cabf 100644 --- a/internal/config/model_alias.go +++ b/internal/config/model_alias.go @@ -67,9 +67,13 @@ type OrgModels struct { } // WithOrgModels is c for a run in models.Org: its aliases, and the instance -// providers with the org's own beside them. +// providers with the org's own beside them. An org that supplies no aliases +// keeps the ones c already carries, which for a task config outside the +// system org are empty -- so nothing here widens what the org may use. func (c Config) WithOrgModels(models OrgModels) Config { - c.Models = models.Aliases + if len(models.Aliases) > 0 { + c.Models = models.Aliases + } if len(models.Providers) > 0 { providers := maps.Clone(c.Providers) if providers == nil { diff --git a/internal/config/orgmodels_test.go b/internal/config/orgmodels_test.go new file mode 100644 index 000000000..58fbb97b1 --- /dev/null +++ b/internal/config/orgmodels_test.go @@ -0,0 +1,29 @@ +package config + +import ( + "maps" + "testing" +) + +// TestWithOrgModelsKeepsAliasesTheOrgDoesNotOverride pins that an org's absent +// aliases are not an empty model set: a run keeps the aliases it already +// resolved, and an org that does define aliases replaces them outright. +func TestWithOrgModelsKeepsAliasesTheOrgDoesNotOverride(t *testing.T) { + instance := map[string]string{"default": "a/large", "embedding": "b/embed"} + tests := []struct { + name string + org OrgModels + want map[string]string + }{ + {"an org with no aliases of its own keeps the instance's", OrgModels{}, instance}, + {"an org's own aliases replace the instance's", OrgModels{Aliases: map[string]string{"fast": "c/small"}}, map[string]string{"fast": "c/small"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + models := Config{Models: instance}.WithOrgModels(tt.org).Models + if !maps.Equal(models, tt.want) { + t.Fatalf("models = %v, want %v", models, tt.want) + } + }) + } +}