Explorar o código

fix(nodes): report dev builds as dev+<commit> so updated nodes aren't flagged stale

A node's status reported config.GetVersion() (3.4.0) even on a dev build, so the master compared it against its own dev latestVersion (dev+<sha>) and every node showed 'update available'. Nodes on a dev build now report dev+<short commit>, matching the master's format, so a node on the current dev commit compares as up to date.
MHSanaei hai 8 horas
pai
achega
bcd1358032
Modificáronse 3 ficheiros con 37 adicións e 1 borrados
  1. 16 0
      internal/config/config.go
  2. 20 0
      internal/config/config_test.go
  3. 1 1
      internal/web/service/server.go

+ 16 - 0
internal/config/config.go

@@ -68,6 +68,22 @@ func IsDevBuild() bool {
 	return GetBuildCommit() != ""
 }
 
+// GetReportedVersion returns the version a panel advertises to a managing master
+// node: the plain version for stable builds, or "dev+<short commit>" for dev
+// builds. The dev form mirrors the master's getPanelUpdateInfo latestVersion so
+// a node on the current dev commit compares as up to date instead of always
+// showing "update available".
+func GetReportedVersion() string {
+	if !IsDevBuild() {
+		return GetVersion()
+	}
+	commit := GetBuildCommit()
+	if len(commit) > 8 {
+		commit = commit[:8]
+	}
+	return "dev+" + commit
+}
+
 // GetLogLevel returns the current logging level based on environment variables or defaults to Info.
 func GetLogLevel() LogLevel {
 	if IsDebug() {

+ 20 - 0
internal/config/config_test.go

@@ -5,6 +5,26 @@ import (
 	"testing"
 )
 
+func TestGetReportedVersion(t *testing.T) {
+	orig := buildCommit
+	t.Cleanup(func() { buildCommit = orig })
+
+	buildCommit = ""
+	if got := GetReportedVersion(); got != GetVersion() {
+		t.Fatalf("stable build: GetReportedVersion = %q, want %q", got, GetVersion())
+	}
+
+	buildCommit = "1d1128cf"
+	if got := GetReportedVersion(); got != "dev+1d1128cf" {
+		t.Fatalf("dev build: GetReportedVersion = %q, want %q", got, "dev+1d1128cf")
+	}
+
+	buildCommit = "1d1128cf945c4615efa05cf41ba7fa766e2ee428"
+	if got := GetReportedVersion(); got != "dev+1d1128cf" {
+		t.Fatalf("dev build (full sha): GetReportedVersion = %q, want %q", got, "dev+1d1128cf")
+	}
+}
+
 func TestGetPortOverride(t *testing.T) {
 	tests := []struct {
 		name       string

+ 1 - 1
internal/web/service/server.go

@@ -604,7 +604,7 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
 		status.Xray.ErrorMsg = s.xrayService.GetXrayResult()
 	}
 	status.Xray.Version = s.xrayService.GetXrayVersion()
-	status.PanelVersion = config.GetVersion()
+	status.PanelVersion = config.GetReportedVersion()
 	if guid, err := s.settingService.GetPanelGuid(); err == nil {
 		status.PanelGuid = guid
 	}