fix(config): keep the resolved aliases when an org supplies none

This commit is contained in:
sam committed 2026-10-20 03:44:21 +11:00
1 parent 84560126c8
commit fb8a2ae1ea
2 files changed
+35 -2

No files matched your search

+6 -2
View File
@@ -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 {
+29
View File
@@ -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)
}
})
}
}