archied's own build has carried a compiled-in gatewayVersion and an internal/installtype stamp since archie-core-522/2873cbb, but archie-agent's build had neither -- its Taskfile.yml and Dockerfile build steps passed no -ldflags at all, so even a daemon that wanted to verify what agent build is actually in service had nothing to check against. daemonRunningVersions said as much explicitly: the agent was left out of every verification on purpose, because nothing self-reported a real value. Every archie-agent process is task-scoped and ephemeral (spawned per task, dies after), not a long-lived process the daemon can poll on demand the way it polls Telegram's gateway. So there's no "ask the agent its version" request -- the only channel back is whatever a worker includes in the taskrun.Response it already sends on every completed task. Stamp archie-agent's build the same way archied's is (installtype, plus a new agentworker.Version()), have executeTaskRequest report both in its Response, and have the daemon record the latest observation in a new mutex-guarded AgentStatus, fed from runViaAgent on every successful response only -- never off a request that never reached an agent, or one describing a failed/parked task. daemonRunningVersions now includes the agent component once (and only once) something has actually been observed, so Report.Verify gets a real value to check future update claims against instead of omitting the component entirely. Part 1/3 of archie-core-1786751948782-3-837a8fd0 point 4. Closes archie-core-1786751948782-3-837a8fd0.1.
32 lines
967 B
Go
32 lines
967 B
Go
package daemon
|
|
|
|
import "testing"
|
|
|
|
func TestAgentStatusSnapshotBeforeObserveIsUnverified(t *testing.T) {
|
|
var s AgentStatus
|
|
if version, installType, ok := s.Snapshot(); ok || version != "" || installType != "" {
|
|
t.Fatalf("Snapshot() = (%q, %q, %v), want zero values and ok=false before any Observe", version, installType, ok)
|
|
}
|
|
}
|
|
|
|
func TestAgentStatusObserveThenSnapshot(t *testing.T) {
|
|
var s AgentStatus
|
|
s.Observe("1.9.11", "container")
|
|
|
|
version, installType, ok := s.Snapshot()
|
|
if !ok || version != "1.9.11" || installType != "container" {
|
|
t.Fatalf("Snapshot() = (%q, %q, %v), want (\"1.9.11\", \"container\", true)", version, installType, ok)
|
|
}
|
|
}
|
|
|
|
func TestAgentStatusObserveOverwritesPrevious(t *testing.T) {
|
|
var s AgentStatus
|
|
s.Observe("1.9.10", "container")
|
|
s.Observe("1.9.11", "container")
|
|
|
|
version, _, _ := s.Snapshot()
|
|
if version != "1.9.11" {
|
|
t.Fatalf("Snapshot() version = %q, want the most recent observation %q", version, "1.9.11")
|
|
}
|
|
}
|