Files
sift/internal/fleetctx/fleetctx_test.go
T
kyle 2f9d3d97e6 p2: digest with in-sift FIFO, SQLite caches, Honcho context, recover
Dixie is capped (max_inflight 2, queue_depth 8, queue_wait 20s) and
never queued on llama-server. Streaming chat, thinking off, 45s
fallback to clean. Digest and chunk-embedding caches are
content-addressed SQLite (Honcho context is not cached). Recover
uses the guarded Fetcher. guardian-star is refused in code.
2026-09-22 23:54:49 -07:00

74 lines
2.0 KiB
Go

package fleetctx
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestGuardianStarRefusedEvenIfAllowlisted(t *testing.T) {
c := &Client{Base: "http://127.0.0.1:1", Allow: []string{"guardian-star", "hermes-fleet"}}
items, warn := c.Search(context.Background(), "guardian-star", "anything")
if len(items) != 0 {
t.Fatalf("items %v", items)
}
if warn == "" {
t.Fatal("want warning")
}
}
func TestAllowlist(t *testing.T) {
c := &Client{Base: "http://127.0.0.1:1", Allow: []string{"hermes-fleet"}}
_, warn := c.Search(context.Background(), "other-ws", "q")
if warn == "" {
t.Fatal("want skip")
}
}
func TestTimeoutWarning(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(4 * time.Second)
w.WriteHeader(200)
_, _ = w.Write([]byte("[]"))
}))
defer ts.Close()
c := &Client{Base: ts.URL, Allow: []string{"hermes-fleet"}, HTTP: ts.Client()}
start := time.Now()
_, warn := c.Search(context.Background(), "hermes-fleet", "q")
if time.Since(start) > 3500*time.Millisecond {
t.Fatalf("took %s", time.Since(start))
}
if warn == "" {
t.Fatal("want warning on timeout")
}
}
func TestHappyPath(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, _ := io.ReadAll(r.Body)
var req map[string]any
_ = json.Unmarshal(b, &req)
if req["limit"] != float64(5) {
t.Errorf("limit %v", req["limit"])
}
_ = json.NewEncoder(w).Encode([]map[string]any{{
"content": "fleet already knows X",
"created_at": "2026-09-22T00:00:00Z",
"peer_id": "kyle",
"session_id": "s1",
"workspace_id": "hermes-fleet",
"token_count": 4,
}})
}))
defer ts.Close()
c := &Client{Base: ts.URL, Allow: []string{"hermes-fleet"}, HTTP: ts.Client()}
items, warn := c.Search(context.Background(), "hermes-fleet", "X")
if warn != "" || len(items) != 1 || items[0].Peer != "kyle" {
t.Fatalf("%v %q", items, warn)
}
}