feat(releaseupdate): enrich components with install type and reference

Component.Installed/Available come from an operator-owned external
check command, which reports what version exists but has no way to
know how THIS process/deployment actually installed it -- native
binary, container, or embedded process. Two sources for that already
exist and were previously unused for this: internal/installtype
(this process's own build-time stamp) and daemon.AgentStatus (an
archie-agent version observed at runtime, landed in the prior commit).

Add Component.InstallType/Reference and a Service.Enrich hook that
fills them in per component ID after the check command runs, without
overwriting whatever a check command already reported for an ID it
doesn't recognise. Wire the actual sources in cmd/archied via
componentInstallTypeEnricher: the daemon's own installtype.Type(),
the agent's most recently observed install type, and -- for NATS, a
third-party dependency this repo doesn't build -- "embedded" or
"external" (with its URL) read straight from [nats] configuration,
which is already the deployment profile's own record of how NATS is
run. This is wired into the single Service construction shared by
Telegram and the dashboard, so both surfaces get it for free.

Part 2/3 of archie-core-1786751948782-3-837a8fd0 point 4. Closes
archie-core-1786751948782-3-837a8fd0.2.
This commit is contained in:
sam committed 2026-08-23 23:28:52 +10:00
1 parent ed33ab5380
commit de23e0b1c0
6 files changed
+217 -2

No files matched your search

+35
View File
@@ -157,6 +157,40 @@ func daemonRunningVersions(agentStatus *daemon.AgentStatus) map[string]string {
return versions
}
// componentInstallTypeEnricher builds Service.Enrich: it knows how to
// describe the three component kinds this daemon can say anything true
// about. Anything else (a check command reporting a component ID this
// process has no source for) is left alone -- an empty return leaves
// whatever the check command itself set.
func componentInstallTypeEnricher(agentStatus *daemon.AgentStatus, nats config.NATSConfig) func(string) (string, string) {
return func(componentID string) (installType, reference string) {
switch componentID {
case releaseupdate.ComponentDaemon:
return installtype.Type(), ""
case releaseupdate.ComponentAgent:
if agentStatus == nil {
return "", ""
}
_, observedInstallType, ok := agentStatus.Snapshot()
if !ok {
return "", ""
}
return observedInstallType, ""
case releaseupdate.ComponentNATS:
switch nats.Mode {
case config.NATSModeEmbedded:
return config.NATSModeEmbedded, ""
case config.NATSModeExternal:
return config.NATSModeExternal, nats.URL
default:
return "", ""
}
default:
return "", ""
}
}
}
func configureTelegramUpdates(tg *telegram.Gateway, s telegramSetup) {
if updates := makeUpdateService(s); updates != nil {
tg.Updates = updates
@@ -172,6 +206,7 @@ func makeUpdateService(s telegramSetup) *releaseupdate.Service {
Catalog: releaseupdate.CommandCatalog{Command: cfg.Chat.Telegram.UpdateCheckCommand},
StatePath: filepath.Join(cfg.WorkDir, "telegram-update-deferrals.json"),
InstallType: installtype.Type(),
Enrich: componentInstallTypeEnricher(s.AgentStatus, cfg.NATS),
}
if len(cfg.Chat.Telegram.UpdateInstallCommand) != 0 {
updates.Installer = releaseupdate.CommandInstaller{Command: cfg.Chat.Telegram.UpdateInstallCommand}
+74
View File
@@ -27,6 +27,80 @@ func TestMakeUpdateServiceWiresInstallType(t *testing.T) {
if service.InstallType != installtype.Type() {
t.Errorf("Service.InstallType = %q, want installtype.Type() = %q", service.InstallType, installtype.Type())
}
if service.Enrich == nil {
t.Fatal("Service.Enrich is nil; component InstallType/Reference will never be populated")
}
}
func TestComponentInstallTypeEnricherDaemon(t *testing.T) {
enrich := componentInstallTypeEnricher(nil, config.NATSConfig{})
gotType, gotRef := enrich(releaseupdate.ComponentDaemon)
if gotType != installtype.Type() || gotRef != "" {
t.Errorf("daemon = (%q, %q), want (%q, \"\")", gotType, gotRef, installtype.Type())
}
}
func TestComponentInstallTypeEnricherAgentBeforeAnyObservation(t *testing.T) {
var status daemon.AgentStatus
enrich := componentInstallTypeEnricher(&status, config.NATSConfig{})
gotType, gotRef := enrich(releaseupdate.ComponentAgent)
if gotType != "" || gotRef != "" {
t.Errorf("agent before any Observe = (%q, %q), want (\"\", \"\")", gotType, gotRef)
}
}
func TestComponentInstallTypeEnricherAgentAfterObservation(t *testing.T) {
var status daemon.AgentStatus
status.Observe("1.9.11", "container")
enrich := componentInstallTypeEnricher(&status, config.NATSConfig{})
gotType, _ := enrich(releaseupdate.ComponentAgent)
if gotType != "container" {
t.Errorf("agent InstallType = %q, want the observed install type %q", gotType, "container")
}
}
func TestComponentInstallTypeEnricherAgentNilStatus(t *testing.T) {
enrich := componentInstallTypeEnricher(nil, config.NATSConfig{})
gotType, gotRef := enrich(releaseupdate.ComponentAgent)
if gotType != "" || gotRef != "" {
t.Errorf("agent with nil AgentStatus = (%q, %q), want (\"\", \"\")", gotType, gotRef)
}
}
func TestComponentInstallTypeEnricherNATS(t *testing.T) {
tests := []struct {
name string
nats config.NATSConfig
wantType string
wantRef string
}{
{name: "embedded", nats: config.NATSConfig{Mode: "embedded"}, wantType: "embedded", wantRef: ""},
{name: "external", nats: config.NATSConfig{Mode: "external", URL: "nats://nats.internal:4222"}, wantType: "external", wantRef: "nats://nats.internal:4222"},
{name: "off", nats: config.NATSConfig{Mode: "off"}, wantType: "", wantRef: ""},
{name: "unset", nats: config.NATSConfig{}, wantType: "", wantRef: ""},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
enrich := componentInstallTypeEnricher(nil, test.nats)
gotType, gotRef := enrich(releaseupdate.ComponentNATS)
if gotType != test.wantType || gotRef != test.wantRef {
t.Errorf("nats(%+v) = (%q, %q), want (%q, %q)", test.nats, gotType, gotRef, test.wantType, test.wantRef)
}
})
}
}
func TestComponentInstallTypeEnricherUnknownComponent(t *testing.T) {
enrich := componentInstallTypeEnricher(nil, config.NATSConfig{})
gotType, gotRef := enrich("something-else")
if gotType != "" || gotRef != "" {
t.Errorf("unknown component = (%q, %q), want (\"\", \"\")", gotType, gotRef)
}
}
// TestDaemonRunningVersionsVouchesOnlyForItselfWithoutAgentStatus: the point