Merge pull request #827 from samcharles93/fix/webui-config-projection-chat-setup

fix(webui): count every chat front-end in the published projection
This commit is contained in:
sam authored and GitHub committed 2026-09-15 00:26:55 +10:00
commit 3b60ec23ba
8 files changed
+548 -34

No files matched your search

+30 -9
View File
@@ -384,6 +384,35 @@ func (b *boot) loadCatalog(ctx context.Context, cfgPath string) {
b.log.Info("model catalog loaded", "providers", len(catalog.Providers), "models", len(b.catalogModels))
}
// channelDescriptors projects the configured chat front-ends into the
// dashboard's channel-status descriptors.
//
// Configured comes from config.ChatConfig.FrontEnds so this list and the
// configuration projection published for the extracted UI process cannot
// disagree about whether a front-end is set up (GitHub #821). ReloadSupported
// and Detail stay here because they are channel-lifecycle facts about the bot
// the daemon runs, not configuration: only Telegram can be reloaded in place
// today, and its allowlist caveat is about who the running bot answers.
func channelDescriptors(chat config.ChatConfig) []status.Descriptor {
frontEnds := chat.FrontEnds()
descriptors := make([]status.Descriptor, 0, len(frontEnds))
for _, frontEnd := range frontEnds {
descriptor := status.Descriptor{
ID: frontEnd.ID,
Name: frontEnd.Name,
Configured: frontEnd.Configured,
}
if frontEnd.ID == "telegram" {
descriptor.ReloadSupported = frontEnd.Configured
if frontEnd.Configured && len(chat.Telegram.AllowedUserIDs) == 0 {
descriptor.Detail = "Token set, but the allowlist is empty -- the bot answers nobody."
}
}
descriptors = append(descriptors, descriptor)
}
return descriptors
}
// setupObservability builds the event bus, channel manager and dashboard
// server. Every event is logged to SQLite (stamped with its row id) and
// then fanned out to live dashboard connections.
@@ -392,15 +421,7 @@ func (b *boot) setupObservability(ctx context.Context) {
bus := events.NewBus()
b.bus = bus
b.addCleanup(func() { bus.Close() })
telegramDetail := ""
if (cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "") && len(cfg.Chat.Telegram.AllowedUserIDs) == 0 {
telegramDetail = "Token set, but the allowlist is empty -- the bot answers nobody."
}
b.channelManager = status.NewManager([]status.Descriptor{
{ID: "telegram", Name: "Telegram", Configured: cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "", ReloadSupported: cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "", Detail: telegramDetail},
{ID: "email", Name: "Email", Configured: cfg.Chat.Email.ListenAddr != ""},
{ID: "webhook", Name: "Webhook gateway", Configured: cfg.Chat.WebhookAddr != ""},
})
b.channelManager = status.NewManager(channelDescriptors(cfg.Chat))
b.cfgHolder = config.NewHolder(cfg)
b.web = &webui.Server{Log: log.With("component", "webui"), Channels: b.channelManager, Skills: skillCatalogAdapter{b.cfgHolder}}
// The watchdog leaves its verdict in a file on this host, so the daemon
@@ -0,0 +1,92 @@
package archied
import (
"encoding/json"
"log/slog"
"path/filepath"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/webui"
)
// TestPublishedProjectionAgreesWithTheChannelManagerOnConfiguredChannels: the
// daemon answers "is a chat channel configured" twice -- once through the
// channel status manager it exposes on /api/channels, and once through the
// ChatView.ChannelConfigured boolean it publishes for the dashboard's setup
// checklist. Those two answers are read by different pages of the same
// extracted process, so a deployment that the manager calls configured must
// not be told by the checklist to connect a channel it already has. Both sides
// now derive from one definition (config.ChatConfig.FrontEnds); this test is
// what keeps them from being re-decided separately.
func TestPublishedProjectionAgreesWithTheChannelManagerOnConfiguredChannels(t *testing.T) {
tests := []struct {
name string
cfg config.Config
}{
{name: "nothing configured", cfg: config.Config{}},
{
name: "telegram token",
cfg: config.Config{Chat: config.ChatConfig{
Telegram: config.TelegramConfig{TokenEnv: "TELEGRAM_TOKEN"},
}},
},
{
name: "telegram token through the secret engine",
cfg: config.Config{Chat: config.ChatConfig{
Telegram: config.TelegramConfig{Token: config.SecretRef{Engine: "builtin", Key: "telegram"}},
}},
},
{
name: "webhook gateway",
cfg: config.Config{Chat: config.ChatConfig{WebhookAddr: "127.0.0.1:9099"}},
},
{
name: "inbound mail gateway",
cfg: config.Config{Chat: config.ChatConfig{Email: config.EmailConfig{ListenAddr: "127.0.0.1:2525"}}},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = st.Close() })
b := &boot{
cfg: tc.cfg,
log: slog.New(slog.DiscardHandler),
stateStore: st,
cfgHolder: config.NewHolder(tc.cfg),
}
b.setupObservability(t.Context())
// What the dashboard's /api/channels page reads.
managerSaysConfigured := false
for _, descriptor := range b.channelManager.Snapshot() {
if descriptor.Configured {
managerSaysConfigured = true
}
}
// What the dashboard's setup checklist reads, through the
// same round trip a reading process performs.
document, err := json.Marshal(webui.BuildConfigView(b.configViewInput(t.Context())))
if err != nil {
t.Fatalf("render the published projection: %v", err)
}
var published webui.ConfigView
if err := json.Unmarshal(document, &published); err != nil {
t.Fatalf("decode the published projection: %v", err)
}
if published.Chat.ChannelConfigured != managerSaysConfigured {
t.Errorf("published Chat.ChannelConfigured = %v, but the channel manager reports a configured front-end = %v (%+v)",
published.Chat.ChannelConfigured, managerSaysConfigured, published.Chat)
}
})
}
}