fix(agent): fall back to install record for sing-box core version (item 12)
Locally built sing-box v1.13.21 carries no version stamp and reports 'unknown', leaving the panel core-version column empty. The agent probe now falls back to /etc/nexusgate/sing-box/version when the binary reports no version; agent-singbox.sh writes that record (version without the v prefix) on every successful install path, including the already-installed early exit. Agent version stays 0.6.8.
This commit is contained in:
@@ -71,6 +71,49 @@ func TestSingBoxVersionProbeCachesByMtime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Round-3 item 12: when the binary reports "unknown" (the locally built
|
||||
// sing-box has no version stamp), the probe falls back to the install
|
||||
// record written by agent-singbox.sh.
|
||||
func TestSingBoxVersionFallsBackToInstallRecord(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
binPath, _ := writeFakeSingBox(t, dir, "unknown")
|
||||
recordPath := filepath.Join(dir, "version")
|
||||
if err := os.WriteFile(recordPath, []byte("1.13.21\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
oldBin, oldRecord := cfg.SingBoxBin, cfg.SingBoxVersionFile
|
||||
cfg.SingBoxBin, cfg.SingBoxVersionFile = binPath, recordPath
|
||||
defer func() { cfg.SingBoxBin, cfg.SingBoxVersionFile = oldBin, oldRecord }()
|
||||
singBoxVersionCache.probed = false
|
||||
defer func() { singBoxVersionCache.probed = false }()
|
||||
|
||||
if got := singBoxVersion(); got != "1.13.21" {
|
||||
t.Fatalf("fallback probe = %q, want 1.13.21", got)
|
||||
}
|
||||
// A stamped binary wins over the record.
|
||||
writeFakeSingBox(t, dir, "1.13.22")
|
||||
if got := singBoxVersion(); got != "1.13.22" {
|
||||
t.Fatalf("stamped probe = %q, want 1.13.22 (record must not shadow it)", got)
|
||||
}
|
||||
// A garbage record is ignored.
|
||||
if err := os.WriteFile(recordPath, []byte("not-a-version\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFakeSingBox(t, dir, "unknown")
|
||||
if got := singBoxVersion(); got != "" {
|
||||
t.Fatalf("garbage record: got %q, want empty", got)
|
||||
}
|
||||
if got := installedSingBoxVersion(); got != "" {
|
||||
t.Fatalf("installedSingBoxVersion(garbage) = %q, want empty", got)
|
||||
}
|
||||
if err := os.WriteFile(recordPath, []byte("v1.13.21\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := installedSingBoxVersion(); got != "1.13.21" {
|
||||
t.Fatalf("installedSingBoxVersion(v-prefixed) = %q, want 1.13.21", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSingBoxVersionMissingBinary(t *testing.T) {
|
||||
oldBin := cfg.SingBoxBin
|
||||
cfg.SingBoxBin = filepath.Join(t.TempDir(), "does-not-exist")
|
||||
|
||||
Reference in New Issue
Block a user