fix(webui): compare a describe build's release, not its raw version, for drift

This commit is contained in:
sam committed 2026-10-24 02:17:53 +11:00
1 parent f63bab8908
commit fde50803e8
4 files changed
+38 -6

No files matched your search

+6 -4
View File
@@ -65,7 +65,7 @@ func (c *GitHubCatalog) Check(ctx context.Context) (Snapshot, error) {
}
}
return Snapshot{Components: []Component{
component("daemon", "Gateway", installedVersion(buildinfo.Version)),
component("daemon", "Gateway", ReleaseVersion(buildinfo.Version)),
component("agent", "Runtime", installedAgent(executableDir())),
}}, nil
}
@@ -192,7 +192,9 @@ func installable(r githubRelease) string {
return asset
}
func installedVersion(version string) string {
// ReleaseVersion is the release a build was cut from: a git-describe build
// ("1.55.0-218-gabc123") is the same release as its tag.
func ReleaseVersion(version string) string {
return buildSuffix.ReplaceAllString(version, "")
}
@@ -202,13 +204,13 @@ func installedVersion(version string) string {
func installedAgent(binDir string) string {
data, err := os.ReadFile(filepath.Join(binDir, agentVersionFile))
if binDir == "" || errors.Is(err, os.ErrNotExist) {
return installedVersion(buildinfo.Runtime)
return ReleaseVersion(buildinfo.Runtime)
}
version := strings.TrimSpace(string(data))
if err != nil || strings.ContainsAny(version, " \n") || ValidateChannel("exact-pin", version) != nil {
return ""
}
return installedVersion(version)
return ReleaseVersion(version)
}
func executableDir() string {
+1 -1
View File
@@ -163,7 +163,7 @@ func (t *Transaction) snapshotHost(ctx context.Context, req PrepareRequest, mani
Phase: phasePrepared,
Version: req.Version,
Previous: map[string]string{
ComponentDaemon: installedVersion(buildinfo.Version),
ComponentDaemon: ReleaseVersion(buildinfo.Version),
ComponentAgent: installedAgent(t.BinDir),
},
Units: manifest.Required.Units,
+1 -1
View File
@@ -44,7 +44,7 @@ type componentVersionStatus struct {
// versionStatusFor compares a component's claimed version with the running
// one. Drift is reported before update_available.
func versionStatusFor(component releaseupdate.Component, running string, ok bool) string {
if ok && component.Installed != "" && running != component.Installed {
if ok && component.Installed != "" && releaseupdate.ReleaseVersion(running) != component.Installed {
return statusDrift
}
if !ok || component.Installed == "" {
+30
View File
@@ -0,0 +1,30 @@
package webui
import (
"testing"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
func TestVersionStatusFor(t *testing.T) {
tests := []struct {
name string
installed, running string
available string
ok bool
want string
}{
{"describe build of the latest release", "1.55.0", "1.55.0-218-g96a7f083", "1.55.0", true, statusOK},
{"running a different release", "1.55.0", "1.54.3", "1.55.0", true, statusDrift},
{"older release installed", "1.54.3", "1.54.3", "1.55.0", true, statusUpdateAvailable},
{"nothing running reported", "1.55.0", "", "1.55.0", false, statusUnknown},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := releaseupdate.Component{Installed: tt.installed, Available: tt.available}
if got := versionStatusFor(c, tt.running, tt.ok); got != tt.want {
t.Fatalf("versionStatusFor = %q, want %q", got, tt.want)
}
})
}
}