Files
archie/internal/app/archied/readiness_test.go
T
sam 03afd2e8ad refactor(webui): take configuration off the dashboard server
webui.Server declared Cfg *config.Holder with eight read sites, none of
which ran in the UI process: composition leaves it nil there. The field
survived because the daemon kept a webui.Server it never served, using it
to render the published ConfigView snapshot and to hold the readiness
probes (archie-core-ml30).

Split at the producer. LocalConfigView becomes webui.BuildConfigView, a
pure function over a ConfigViewInput the configuration owner assembles;
the DTO and its schema stay where the UI renders them. The daemon builds
that input from its own state (boot.configViewInput) and publishes the
result. Readiness reads the daemon's Holder, channel manager and chat
contract, and the registry it produces is a daemon field, not a field on
a server with no listener. Boot now owns one Holder instead of seeding a
second and replacing it in buildDaemon; operator retry caps read it too,
so they follow a reload rather than a boot-time snapshot.

Server loses Cfg, ConfigProvenance, LastReload, ConfigOverrides and
SetProvenance. The nil-guarded branches they fed went with them, each
checked first against what the UI process actually serves:

- chat.show_tool_calls and the /api/setup checklist were degraded, not
  dead. ConfigView gains a chat section carrying show_tool_calls, the
  operator name and whether a channel is configured, and both surfaces
  read the projection. The end-to-end suite asserts the checklist renders
  from the published snapshot.
- /api/logs takes its path as a process-local option. The history is on
  the daemon's disk, so a dashboard elsewhere cannot read it by learning
  the path; that route still needs a contract.
- handleChannels drops its config-derived fallback, superseded by the
  status manager, which already carries the descriptions and detail.
- trustForwardedHeaders keeps only the process's own setting, which the
  UI process already sets.
- resolveForge keeps the published-projection path it already had.

ConfigView.Editable moves to handleConfig, decided by whether this
process holds UpdateConfig. It describes the writer, not the document, so
the write contract (archie-core-j28m) makes the page editable by wiring
one field. The write handlers and their seams stay for it.

overlay.Store gains Keys: Snapshot nests dotted keys for decoding, so the
overridden-key list was publishing section names ("budgets") where the
dashboard marks and resets rows by stored key ("budgets.max_steps").

Multi-identity forge links move to archie-core-pv6t: forgeConfigForTask
resolved a task's forge from config.Config, had no reachable caller once
the holder was gone, and belongs in the projection rather than the
rendering package.
2026-09-11 23:57:38 +10:00

125 lines
4.1 KiB
Go

package archied
import (
"context"
"path/filepath"
"testing"
"github.com/samcharles93/archie-core/internal/channels/status"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/webui"
)
func TestDiskProbePath_PrefersDBPath(t *testing.T) {
cfg := config.Config{DBPath: "/data/archie/tasks.db", WorkDir: "/srv/archie"}
if got := diskProbePath(cfg); got != "/data/archie" {
t.Fatalf("diskProbePath = %q, want /data/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)
}
}
func TestChannelStates_ProjectsSnapshot(t *testing.T) {
m := status.NewManager([]status.Descriptor{
{ID: "telegram", Name: "Telegram", Configured: true},
{ID: "email", Name: "Email", Configured: false},
})
m.MarkRunning("telegram")
states := channelStates(m)
if len(states) != 2 {
t.Fatalf("states = %d, want 2", len(states))
}
if states[0].ID != "telegram" || !states[0].Configured || states[0].State != "running" {
t.Fatalf("states[0] = %+v, want telegram running", states[0])
}
if states[1].ID != "email" || states[1].Configured || states[1].State != "stopped" {
t.Fatalf("states[1] = %+v, want email stopped", states[1])
}
}
func TestChannelStates_NilManager(t *testing.T) {
if got := channelStates(nil); got != nil {
t.Fatalf("channelStates(nil) = %#v, want nil", got)
}
}
func TestSessionCount_ToleratesUnwiredChat(t *testing.T) {
if got := sessionCount(context.Background(), nil); got != 0 {
t.Fatalf("sessionCount(nil chat) = %d, want 0", got)
}
if got := sessionCount(context.Background(), &webui.ChatService{}); got != 0 {
t.Fatalf("sessionCount(unwired Sessions) = %d, want 0", got)
}
}
// 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, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = st.Close() })
cfg := config.Config{
BotUser: "archie-bot",
DBPath: filepath.Join(t.TempDir(), "tasks.db"),
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),
channelManager: status.NewManager([]status.Descriptor{{ID: "telegram", Name: "Telegram", Configured: true}}),
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())
if len(report.Components) != 5 {
t.Fatalf("components = %d, want 5: %+v", len(report.Components), report.Components)
}
want := []string{"state_db", "config", "disk", "model", "gateway"}
for i, name := range want {
if report.Components[i].Name != name {
t.Fatalf("component[%d] = %q, want %q", i, report.Components[i].Name, name)
}
}
}