Files
llmgw/internal/cli/serverinit_memory_test.go
T
Ilker ManapandClaude Opus 5.5 b986ea180d
CI / test (push) Successful in 9m47s
Fixes from review: setup's memory check, MCP secrets, VS Code, bandwidth
- server init run again on a machine already set up is not refused its
  memory (the docs fix a certificate with --host so), and judges count
  only when one will be installed (judgeComes: not without a mirror, nor
  from a bundle without it).
- A server's sealed secrets that it no longer reads are removed when it is
  put or deleted; replacing a credential replaces every header it was
  sent, rather than adding one beside the old.
- llmgw.gatewayUrl is a machine setting and restricted in untrusted
  workspaces: a cloned repository's settings cannot send a sign-in to
  another gateway.
- The bandwidth buffer is at least eight times the CPU's last cache and at
  most a quarter of free memory, else nothing is measured until there is
  room; a registration carries the figure measured so far.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 08:23:00 +01:00

47 lines
1.7 KiB
Go

package cli
import (
"os"
"testing"
"gitea.mynodes.xyz/ilker/llmgw/internal/preflight"
)
func TestTheMemoryAMachineNeedsCountsWhatItServes(t *testing.T) {
in := &serverInit{}
mb, what := in.servingMemoryMB(false)
need := preflight.Needs[preflight.RoleControl].MemoryMB + mb
if what == "" || need <= 7941 || need > 11961 {
t.Errorf("node, starter and judges here: need %d MB (%q); an 8 GB machine must fail and a 12 GB one pass", need, what)
}
// Judges on machines of their own take their share off this one.
if mb2, _ := in.servingMemoryMB(true); mb2 >= mb {
t.Errorf("with judge machines %d MB, without %d", mb2, mb)
}
// A control plane that serves nothing needs only its own.
if mb, what := (&serverInit{noNode: true}).servingMemoryMB(false); mb != 0 || what != "" {
t.Errorf("no node: %d %q", mb, what)
}
if mb, _ := (&serverInit{noModel: true, noGuardModel: true}).servingMemoryMB(false); mb != 0 {
t.Errorf("nothing served: %d", mb)
}
// Without a mirror no judge is fetched, so none is counted.
if mb, what := (&serverInit{noMirror: true}).servingMemoryMB(false); mb != 0 {
t.Errorf("no mirror, nothing to fetch: %d %q", mb, what)
}
}
func TestSetupRunAgainOnAMachineAlreadySetUpIsNotRefusedItsMemory(t *testing.T) {
// The docs fix a certificate with server init --host on a machine set up
// before the check: it installs nothing it does not already serve.
dir := t.TempDir()
cfg := dir + "/server.yaml"
if err := os.WriteFile(cfg, []byte("listen: :8080\n"), 0o600); err != nil {
t.Fatal(err)
}
in := &serverInit{unitPath: dir + "/llmgw-server.service", etcDir: dir}
if err := in.checkMemory(); err != nil {
t.Errorf("refused: %v", err)
}
}