Readiness probe test asserts each subsystem registers exactly once instead of an ordered five-item list. Config descriptor test drops the exact-count check and its stale settings.js rationale. Container defaults test references the production constant. Refs #1229 #1231 #1232
97 lines
3.2 KiB
Go
97 lines
3.2 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
func TestDiskProbePath_PrefersStateDir(t *testing.T) {
|
|
cfg := config.Config{StateDir: "/var/lib/archie", WorkDir: "/srv/archie"}
|
|
if got := diskProbePath(cfg); got != "/var/lib/archie" {
|
|
t.Fatalf("diskProbePath = %q, want /var/lib/archie", got)
|
|
}
|
|
}
|
|
|
|
func TestDiskProbePath_FallsBackToWorkDir(t *testing.T) {
|
|
cfg := config.Config{WorkDir: "/srv/archie"}
|
|
if got := diskProbePath(cfg); got != "/srv/archie" {
|
|
t.Fatalf("diskProbePath = %q, want /srv/archie", got)
|
|
}
|
|
}
|
|
|
|
func TestDiskProbePath_FallsBackToCwd(t *testing.T) {
|
|
if got := diskProbePath(config.Config{}); got != "." {
|
|
t.Fatalf("diskProbePath = %q, want .", got)
|
|
}
|
|
}
|
|
|
|
// TestPingChat_ReportsUnwiredChat pins that a daemon with no Gateway contract
|
|
// degrades its gateway probe rather than passing it: chat is served entirely
|
|
// by the Gateway now, so an unwired contract means no chat at all.
|
|
func TestPingChat_ReportsUnwiredChat(t *testing.T) {
|
|
if err := pingChat(context.Background(), nil); err == nil {
|
|
t.Fatal("pingChat(nil chat) = nil, want an error")
|
|
}
|
|
if err := pingChat(context.Background(), &webui.ChatService{}); err == nil {
|
|
t.Fatal("pingChat(unwired contract) = nil, want an error")
|
|
}
|
|
}
|
|
|
|
// TestSetupReadinessProbes_WiresEverySubsystem proves the composition root
|
|
// registers all five readiness probes and that the registry surfaces them in
|
|
// the detailed report. It does not assert their status -- real state depends
|
|
// on the store, config, disk, model and gateway in the running daemon -- only
|
|
// that every subsystem the epic names is actually wired.
|
|
func TestSetupReadinessProbes_WiresEverySubsystem(t *testing.T) {
|
|
st := pgstore.Open(t)
|
|
t.Cleanup(func() { _ = st.Close() })
|
|
|
|
cfg := config.Config{
|
|
BotUser: "archie-bot",
|
|
PollInterval: config.Duration(60_000_000_000), // 60s, satisfies validate
|
|
Dispatch: config.Dispatch{Trigger: "assignee"},
|
|
Forge: config.Forge{Type: "none"},
|
|
Containers: config.ContainerConfig{
|
|
Image: "ghcr.io/samcharles93/archie-agent:latest",
|
|
},
|
|
Providers: map[string]config.Provider{
|
|
"openai": {Class: "openai"},
|
|
},
|
|
}
|
|
|
|
b := &boot{
|
|
st: st,
|
|
cfgHolder: config.NewHolder(cfg),
|
|
chat: &webui.ChatService{
|
|
Contract: &gateway.LocalChatAdapter{
|
|
Router: &gateway.Router{},
|
|
Sessions: gateway.NewSessionStoreMemory(),
|
|
Models: newChatModelManager(map[string]string{"chat": "openai/gpt-4o"}, nil),
|
|
},
|
|
},
|
|
chatModels: newChatModelManager(map[string]string{"chat": "openai/gpt-4o"}, nil),
|
|
cfg: cfg,
|
|
}
|
|
|
|
b.setupReadinessProbes()
|
|
if b.healthRegistry == nil {
|
|
t.Fatal("b.healthRegistry is nil after setupReadinessProbes")
|
|
}
|
|
|
|
report := b.healthRegistry.Run(context.Background())
|
|
got := map[string]int{}
|
|
for _, c := range report.Components {
|
|
got[c.Name]++
|
|
}
|
|
for _, name := range []string{"state_db", "config", "disk", "model", "gateway"} {
|
|
if got[name] != 1 {
|
|
t.Errorf("component %q registered %d times, want 1: %+v", name, got[name], report.Components)
|
|
}
|
|
}
|
|
}
|