archie-core-8cda.6.8's carrier. The service now records channel lifecycle and has nowhere to put it: /api/channels answered with nothing because webui.Server.Channels had no production source, and reload answered 501 for the same reason. This adds the surface the register decided on, following the split archie-core-ymut established for config snapshots -- a pair of administrative RPCs whose writer is one process and whose reader is the UI -- and wires both ends. Wire and store: PutChannelStatus / ListChannelStatus, with ChannelStatus carrying id, name, state, detail, configured, reload_supported and observed_at. The store holds one row per channel and replaces the reported set, so a channel the reporter no longer mentions is deleted rather than left standing as a stale "running"; an empty report clears the table, because hosting no channels is a fact worth reporting. A row without an id is refused: it could never be replaced or removed by a later report. Writer: the service publishes on every lifecycle transition through a coalescing signal -- a burst of transitions is one write, since a reader only wants the latest state of every channel -- plus a start-up report and a final report after shutdown, so a stopped service leaves the store honest. A failed write is logged and retried on the next signal; the dashboard losing channel state is worth a warning and never worth failing a channel start over. Reader: webui.Server.Channels becomes a source rather than a concrete manager, and webui.RemoteChannelStatus reads the store the way RemoteConfigView reads the config snapshot. A store it cannot reach reports nothing rather than a stale "running", and a state the reader does not recognise is carried through rather than dropped. The contract's own index gains the group in the same change that adds the RPCs -- a surface the grouped table does not list is one nobody finds -- and the count moves to 51. The register records why the surface is the State Store rather than a resource kind, and why reload gets its own surface rather than a field here: reading status must not be able to retrigger an action, a transient request is not distinguishable from state once anything polls it, and it would invert the writer/reader relationship the precedent establishes. Verified: task check exit 0. New coverage: the store's replace-the-set semantics and its refusal of an id-less row, the reader's mapping including an unknown state, and the publisher's start-up, transition and final reports.
80 lines
2.9 KiB
Go
80 lines
2.9 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestChannelStatusReplacesTheReportedSet: the process hosting the channels owns
|
|
// the set it reports, so a channel it stops reporting must disappear. Leaving it
|
|
// behind would show a stale "running" for a channel that is gone, which is worse
|
|
// than showing nothing.
|
|
func TestChannelStatusReplacesTheReportedSet(t *testing.T) {
|
|
st := openTest(t)
|
|
ctx := t.Context()
|
|
|
|
if rows, err := st.ChannelStatus(ctx); err != nil || len(rows) != 0 {
|
|
t.Fatalf("ChannelStatus on an empty store = (%+v, %v), want (none, nil)", rows, err)
|
|
}
|
|
|
|
observed := time.Date(2026, 9, 22, 8, 0, 0, 0, time.UTC)
|
|
first := []ChannelStatus{
|
|
{ID: "telegram", Name: "telegram", State: "running", Configured: true, ReloadSupported: true, ObservedAt: observed},
|
|
{ID: "webhook", Name: "webhook", State: "failed", Detail: "listen: address in use", Configured: true, ObservedAt: observed},
|
|
}
|
|
if err := st.PutChannelStatus(ctx, first); err != nil {
|
|
t.Fatalf("PutChannelStatus: %v", err)
|
|
}
|
|
rows, err := st.ChannelStatus(ctx)
|
|
if err != nil {
|
|
t.Fatalf("ChannelStatus: %v", err)
|
|
}
|
|
if len(rows) != 2 {
|
|
t.Fatalf("rows = %+v, want both channels", rows)
|
|
}
|
|
// Ordered by id, so a reader and this test see the same list twice.
|
|
if rows[0].ID != "telegram" || rows[1].ID != "webhook" {
|
|
t.Errorf("rows = %+v, want telegram then webhook", rows)
|
|
}
|
|
if rows[1].Detail != "listen: address in use" || rows[1].State != "failed" {
|
|
t.Errorf("webhook row = %+v, want the failure it reported", rows[1])
|
|
}
|
|
if !rows[0].ReloadSupported || !rows[0].Configured {
|
|
t.Errorf("telegram row = %+v, want its declared capabilities", rows[0])
|
|
}
|
|
if !rows[0].ObservedAt.Equal(observed) {
|
|
t.Errorf("ObservedAt = %v, want %v", rows[0].ObservedAt, observed)
|
|
}
|
|
|
|
// The reporter no longer mentions webhook: its row goes.
|
|
if err := st.PutChannelStatus(ctx, first[:1]); err != nil {
|
|
t.Fatalf("PutChannelStatus: %v", err)
|
|
}
|
|
rows, err = st.ChannelStatus(ctx)
|
|
if err != nil {
|
|
t.Fatalf("ChannelStatus: %v", err)
|
|
}
|
|
if len(rows) != 1 || rows[0].ID != "telegram" {
|
|
t.Fatalf("rows = %+v, want only telegram after the shorter report", rows)
|
|
}
|
|
|
|
// An empty report is a report: a process that hosts no channels clears the set
|
|
// rather than leaving the previous one standing.
|
|
if err := st.PutChannelStatus(ctx, nil); err != nil {
|
|
t.Fatalf("PutChannelStatus(empty): %v", err)
|
|
}
|
|
if rows, err := st.ChannelStatus(ctx); err != nil || len(rows) != 0 {
|
|
t.Fatalf("rows after an empty report = (%+v, %v), want none", rows, err)
|
|
}
|
|
}
|
|
|
|
// TestChannelStatusRequiresAnID: a row without an id cannot be replaced or
|
|
// removed by a later report, so it is refused at the producer rather than
|
|
// inserted as an orphan the reporter can never clear.
|
|
func TestChannelStatusRequiresAnID(t *testing.T) {
|
|
st := openTest(t)
|
|
if err := st.PutChannelStatus(t.Context(), []ChannelStatus{{State: "running"}}); err == nil {
|
|
t.Fatal("PutChannelStatus with no id = nil, want a refusal")
|
|
}
|
|
}
|