Files
archie/internal/app/archied/config_snapshot_channels_test.go
T
sam 73aa86181e fix(webui): count every chat front-end in the published projection
GitHub #821 reported two dashboard behaviours degrading in the extracted UI
process because webui.Server.Cfg is nil there. Half of it was already closed:
03afd2e ("take configuration off the dashboard server", on main since
2026-09-12) moved the daemon's ConfigView renderer off webui.Server, gave
ConfigView a chat section carrying show_tool_calls, the operator name and a
channel flag, and pointed chatShowToolCalls and handleSetup at the projection.
The chat page and the checklist do read published values now.

The channel flag was still wrong. It was derived from telegram and the webhook
gateway only, while the daemon's own channel status manager lists three
front-ends and counts the inbound mail gateway as one. An email-only
deployment therefore read as configured on /api/channels and unconfigured on
the setup checklist at the same time, and the checklist told the operator to
connect a channel they already had.

Fix at the producer: config.ChatConfig gains FrontEnds, the single definition
of "this front-end is configured", enumerating telegram, email and the webhook
gateway. Both the published projection (ChannelConfigured) and the daemon's
channel descriptors (status.NewManager) now derive from it, so the two surfaces
cannot drift apart again. A front-end added to [chat] is counted by both or
neither. Whitespace-only values are not configured: an env var name of " "
resolves to nothing and " " cannot be listened on.

The setup checklist stays. It renders each step as a title, a detail and a done
mark with no control behind it, so it answers "what is this deployment
missing?" rather than promising to fix it; the process that cannot apply setup
never offered to. Removing it would delete the one surface that distinguishes a
fresh deployment from a finished one, and the values it reads already cross the
boundary in ConfigView at no cost to the daemon. The write path stays descoped
for Phase 3 (docs/prds/ui-service-boundary.md, /api/config (write) row): the
checklist reports configuration, it does not change it.

docs/prds/ui-service-boundary.md records that judgement and corrects the
"Real-process evidence" paragraph, which claimed the channel flag covered every
chat channel.
2026-09-14 10:53:16 +00:00

93 lines
3.1 KiB
Go

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)
}
})
}
}