The console manages people, keys, organizations and the mirror, and scrolls a tall sidebar
Accounts, API keys and Organizations views read the store and change it by running the users, keys and org commands in-process, so their checks and messages are the ones shown. A Mirror view lists what the mirror holds and which models use it, downloads into it and removes from it. Models gain adding from a definition file. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c7d5ee16b5
commit
eb7dac8a67
6 files changed
+949
-8
No files matched your search
@@ -5,13 +5,16 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
type seen struct {
|
||||
@@ -151,3 +154,106 @@ func TestAQuotaIsAddedWithOnlyWhatIsGiven(t *testing.T) {
|
||||
t.Fatalf("sent %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeopleAreManagedFromTheConsoleAgainstItsStore(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfgPath := dir + "/server.yaml"
|
||||
yaml := "auth:\n store: " + dir + "/llmgw.db\n"
|
||||
if err := os.WriteFile(cfgPath, []byte(yaml), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := config.Load(cfgPath); err != nil {
|
||||
t.Fatalf("the test's configuration: %v", err)
|
||||
}
|
||||
m := newConsoleModel("127.0.0.1:1", cfgPath)
|
||||
defer m.st.close()
|
||||
m.loaded, m.inPanel = true, true
|
||||
|
||||
refresh := func(tm tea.Model) tea.Model {
|
||||
cm := tm.(consoleModel)
|
||||
msg := cm.fetchPeople()()
|
||||
tm, _ = tm.Update(msg)
|
||||
return tm
|
||||
}
|
||||
submit := func(tm tea.Model, vals ...string) tea.Model {
|
||||
f := tm.(consoleModel).formD
|
||||
if f == nil {
|
||||
t.Fatal("no form")
|
||||
}
|
||||
for i, v := range vals {
|
||||
f.fields[i].text.SetValue(v)
|
||||
}
|
||||
f.focus = len(f.fields)
|
||||
tm = pressRun(tm, "enter")
|
||||
if v := tm.View(); !strings.Contains(v, "✓") {
|
||||
t.Fatalf("did not work:\n%s", v)
|
||||
}
|
||||
return refresh(press(tm, "x"))
|
||||
}
|
||||
|
||||
m.menu = cOrgs
|
||||
var tm tea.Model = m
|
||||
tm = submit(press(tm, "a"), "Acme")
|
||||
// Into the organization: a team, then a project in it.
|
||||
tm = submit(press(tm, "enter", "enter"), "ml")
|
||||
cm := tm.(consoleModel)
|
||||
if len(cm.people.orgs) != 2 || cm.people.orgs[1].path != "Acme/ml" {
|
||||
t.Fatalf("tree: %+v", cm.people.orgs)
|
||||
}
|
||||
tm = submit(press(tm, "down", "enter", "enter"), "training")
|
||||
|
||||
cm = tm.(consoleModel)
|
||||
cm.menu, cm.row = cAccounts, 0
|
||||
tm = submit(press(cm, "a"), "ayse@example.com", "a-long-s3cret-pass", "Acme/ml/training")
|
||||
cm = tm.(consoleModel)
|
||||
if len(cm.people.users) != 1 || cm.people.users[0].State != store.UserActive ||
|
||||
!strings.Contains(strings.Join(cm.people.where[cm.people.users[0].ID], ","), "training") {
|
||||
t.Fatalf("account: %+v %v", cm.people.users, cm.people.where)
|
||||
}
|
||||
|
||||
cm.menu, cm.row = cKeys, 0
|
||||
tm = press(cm, "a")
|
||||
f := tm.(consoleModel).formD
|
||||
f.fields[0].text.SetValue("ci")
|
||||
f.fields[1].text.SetValue("Acme/ml/training")
|
||||
f.focus = len(f.fields)
|
||||
tm = pressRun(tm, "enter")
|
||||
if v := tm.View(); !strings.Contains(v, "sk-") {
|
||||
t.Fatalf("the new key was not shown:\n%s", v)
|
||||
}
|
||||
tm = refresh(press(tm, "x"))
|
||||
if n := len(tm.(consoleModel).people.keys); n != 1 {
|
||||
t.Fatalf("%d keys", n)
|
||||
}
|
||||
// Limits on the project, read back in its row.
|
||||
cm = tm.(consoleModel)
|
||||
cm.menu, cm.row = cOrgs, 2
|
||||
tm = press(cm, "enter")
|
||||
items := tm.(consoleModel).menuD.items
|
||||
i := 0
|
||||
for ; items[i].label != "Limits…"; i++ {
|
||||
}
|
||||
keys := []string{}
|
||||
for range i {
|
||||
keys = append(keys, "down")
|
||||
}
|
||||
tm = submit(press(tm, append(keys, "enter")...), "60")
|
||||
if c := limitsCell(tm.(consoleModel).people.limits[store.LimitOwner{Scope: store.ScopeProject,
|
||||
ID: tm.(consoleModel).people.orgs[2].id}.CounterKey()]); c != "60 rpm" {
|
||||
t.Fatalf("limits: %q", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheSidebarFitsAShortScreen(t *testing.T) {
|
||||
m, _ := consoleWith(t, cOrgs)
|
||||
m.inPanel = false
|
||||
for _, h := range []int{20, 30, 50} {
|
||||
m.height = h
|
||||
if n := len(strings.Split(m.View(), "\n")); n > h {
|
||||
t.Errorf("height %d: %d lines drawn", h, n)
|
||||
}
|
||||
if !strings.Contains(m.View(), "Organizations") {
|
||||
t.Errorf("height %d: the current entry is not shown", h)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user