From bc70fd7d6674f051ff4790f69defbabfb9da76f2 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 22 Oct 2026 17:36:24 +1100 Subject: [PATCH] fix(config): give a non-system org only the aliases its policy resolves --- internal/config/model_alias.go | 12 ++++++++---- internal/config/orgmodels_test.go | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/config/model_alias.go b/internal/config/model_alias.go index 73b46cabf..51a2ebf6b 100644 --- a/internal/config/model_alias.go +++ b/internal/config/model_alias.go @@ -5,6 +5,8 @@ import ( "maps" "slices" "strings" + + "github.com/samcharles93/archie-core/internal/domain/org" ) // ModelPurpose is what a model is used for. Each purpose has a default alias @@ -67,11 +69,11 @@ 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. 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. +// providers with the org's own beside them. Only the system org with no +// stored aliases keeps the ones c carries; any other org gets exactly what its +// policy resolved, even when that is nothing. func (c Config) WithOrgModels(models OrgModels) Config { - if len(models.Aliases) > 0 { + if len(models.Aliases) > 0 || !systemOrg(models.Org) { c.Models = models.Aliases } if len(models.Providers) > 0 { @@ -84,3 +86,5 @@ func (c Config) WithOrgModels(models OrgModels) Config { } return c } + +func systemOrg(id string) bool { return id == "" || id == string(org.DefaultOrgID) } diff --git a/internal/config/orgmodels_test.go b/internal/config/orgmodels_test.go index 58fbb97b1..ac9d6c780 100644 --- a/internal/config/orgmodels_test.go +++ b/internal/config/orgmodels_test.go @@ -6,8 +6,8 @@ import ( ) // 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. +// aliases are not an empty model set for the system org, while any other org +// gets only what its policy resolved, and defined aliases replace them outright. func TestWithOrgModelsKeepsAliasesTheOrgDoesNotOverride(t *testing.T) { instance := map[string]string{"default": "a/large", "embedding": "b/embed"} tests := []struct { @@ -15,7 +15,8 @@ func TestWithOrgModelsKeepsAliasesTheOrgDoesNotOverride(t *testing.T) { org OrgModels want map[string]string }{ - {"an org with no aliases of its own keeps the instance's", OrgModels{}, instance}, + {"the system org with no stored aliases keeps the instance's", OrgModels{}, instance}, + {"another org resolving no aliases gets none", OrgModels{Org: "acme"}, nil}, {"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 {