Files
llmgw/internal/store/licences_test.go
T
Ilker ManapandClaude Opus 5.5 4bbac0833d A person leaves licences out, and no key of theirs reaches a model under one
A game sold in the EU cannot ship what a licence excluding the EU made. On
the profile page a person leaves out licences one by one, or by rule:
every licence forbidding commercial use, every licence granting nothing in
a region. The rules cover models added later. The choice reaches every
principal through the resolved limits, so permits() leaves such models out
of /v1/models, requests, jobs, fallbacks and the portal's pickers, and a
request for one is refused 403 licence_excluded saying which choice did.

Kept in user_excluded_licences (migration 0046), copied with the store and
gone with the person.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 16:10:22 +02:00

37 lines
1.1 KiB
Go

package store
import (
"slices"
"testing"
"time"
)
func TestAPersonsExcludedLicencesReachEveryWayTheyAsk(t *testing.T) {
db := openDB(t)
ctx := t.Context()
if err := db.CreateUser(ctx, User{ID: "usr-1", Email: "a@b.c", State: UserActive, CreatedAt: time.Now()}); err != nil {
t.Fatal(err)
}
if err := db.SetUserExcludedLicences(ctx, "usr-1", []string{"tencent-hunyuan-community", " CC-BY-NC-4.0", "", "CC-BY-NC-4.0", "rule:region:EU"}); err != nil {
t.Fatal(err)
}
got, err := db.UserExcludedLicences(ctx, "usr-1")
want := []string{"CC-BY-NC-4.0", "rule:region:EU", "tencent-hunyuan-community"}
if err != nil || !slices.Equal(got, want) {
t.Errorf("excluded %v %v, want %v", got, err, want)
}
// A session, which has no key row, gets them as a key does.
eff, err := db.ResolveFor(ctx, "session:usr-1", "usr-1", "")
if err != nil || !slices.Equal(eff.ExcludedLicences, want) {
t.Errorf("session: %v %v", eff.ExcludedLicences, err)
}
if err := db.SetUserExcludedLicences(ctx, "usr-1", nil); err != nil {
t.Fatal(err)
}
if got, _ := db.UserExcludedLicences(ctx, "usr-1"); len(got) != 0 {
t.Errorf("cleared, still %v", got)
}
}