fix(aliases): dedupe listing against emitted entries, not raw owners

listFor's alias dedupe keyed on the raw owners map, so a colliding
discovered model whose provider is group-denied caused BOTH the real
entry and the alias to be skipped - the id vanished from the listing
entirely even though resolve still serves it via the alias.

Track ids actually appended to out in a listed map instead, and skip
the alias only when listed[alias] is true. Extends
TestModelRegistry_ListFor_Alias_DedupedAgainstDiscoveredCollision with
a provider-denied variant: group providers:["openai"], collision on
the denied "acme" provider -> alias listed exactly once, owned_by
openai.
This commit is contained in:
2026-08-20 21:11:34 +01:00
parent f0730a70d7
commit ed2119cc99
2 changed files with 45 additions and 4 deletions
+31
View File
@@ -1254,6 +1254,14 @@ func TestModelRegistry_ListFor_Alias_NotAuthorized_Omitted(t *testing.T) {
// and a second, duplicate one from the alias loop. resolve's own
// precedence (registry.go's resolve doc comment) must still have the
// alias win at request time regardless of which entry the listing shows.
//
// A second scenario (review fix, second pass) shares this fixture: when
// grp cannot reach the COLLIDING provider at all (provider-denied), the
// real model's own entry is never emitted in the first place — the
// dedupe must key off entries actually LISTED, not the raw,
// authorization-blind owners map, or the id would vanish from the
// listing entirely (neither the real entry nor the alias appears) even
// though resolve still serves it through the alias.
func TestModelRegistry_ListFor_Alias_DedupedAgainstDiscoveredCollision(t *testing.T) {
t.Parallel()
adapters := map[string]providerAdapter{
@@ -1299,4 +1307,27 @@ func TestModelRegistry_ListFor_Alias_DedupedAgainstDiscoveredCollision(t *testin
if canonical != "openai/gpt-test" {
t.Errorf("canonical = %q, want %q", canonical, "openai/gpt-test")
}
// Provider-denied variant: grp can reach only "openai" — "acme", the
// colliding discovered model's own provider, is denied, so its raw
// entry is never emitted at all. The alias must still be listed
// exactly once, owned by its own target's provider ("openai") — the
// earlier owners-keyed dedupe would have wrongly skipped it too here,
// vanishing "shared-id" from the listing entirely.
narrowGrp := &group{name: "openai-only", providers: []string{"openai"}}
gotNarrow := reg.listFor(narrowGrp)
var narrowCount int
var ownedBy string
for _, entry := range gotNarrow {
if entry["id"] == "shared-id" {
narrowCount++
ownedBy, _ = entry["owned_by"].(string)
}
}
if narrowCount != 1 {
t.Fatalf("listFor (provider-denied collision) has %d entries for id %q, want exactly 1 (the alias)", narrowCount, "shared-id")
}
if ownedBy != "openai" {
t.Errorf("owned_by = %q, want %q (the alias's own target provider)", ownedBy, "openai")
}
}