package agent import ( "fmt" "slices" "strings" "testing" llmgwv1 "gitea.mynodes.xyz/ilker/llmgw/api/gen/llmgw/v1" ) func TestTheLogRingKeepsTheNewestLinesInOrder(t *testing.T) { r := newLogRing(3) if got := r.tail(10); len(got) != 0 { t.Fatalf("empty ring gave %v", got) } for i := 1; i <= 5; i++ { fmt.Fprintf(r, "line %d\n", i) } if got := r.tail(10); !slices.Equal(got, []string{"line 3", "line 4", "line 5"}) { t.Errorf("after wrapping: %v", got) } if got := r.tail(2); !slices.Equal(got, []string{"line 4", "line 5"}) { t.Errorf("tail(2): %v", got) } } func TestANodeAnswersForItsOwnLog(t *testing.T) { cfg := Config{Server: "127.0.0.1:7443", NodeID: "n1", WeightsCache: t.TempDir(), EnginesDir: t.TempDir()} cfg.Superv.WorkDir = t.TempDir() a, err := New(cfg, nil, nil) if err != nil { t.Fatal(err) } a.log.Info("engine installation", "state", "installing") r := a.logsReply(&llmgwv1.LogsRequest{RequestId: "x", Source: "agent", Lines: 50}) if r.GetRequestId() != "x" || !strings.Contains(strings.Join(r.GetLines(), "\n"), "engine installation") { t.Errorf("the agent's own line is not in its log: %v", r.GetLines()) } if !slices.Contains(r.GetSources(), "agent") { t.Errorf("sources %v", r.GetSources()) } r = a.logsReply(&llmgwv1.LogsRequest{RequestId: "y", Source: "no-such-shard"}) if r.GetError() == "" { t.Error("an unknown engine was answered as if it existed") } }