fix(config): give a non-system org only the aliases its policy resolves

This commit is contained in:
sam committed 2026-10-22 17:36:24 +11:00
1 parent 2ca7c9b2b9
commit 2e6c493487
2 files changed
+12 -7

No files matched your search

+8 -4
View File
@@ -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) }
+4 -3
View File
@@ -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 {