V2.0.1: listen override fix, sing-box core fetch, probe settings page + fast report, spx removal, core mem env
CI / go-test (push) Waiting to run
CI / postgres-durable-first (push) Waiting to run
CI / codegen (push) Waiting to run
CI / govulncheck (push) Waiting to run
CI / race (push) Waiting to run
CI / fuzz-smoke (push) Waiting to run
CI / golangci (push) Waiting to run
CI / frontend (push) Waiting to run
Docs CI / build (push) Waiting to run
Docs Deploy (GitHub Pages) / build (push) Waiting to run
Docs Deploy (GitHub Pages) / deploy (push) Blocked by required conditions
Release 3X-UI / build (386) (push) Waiting to run
Release 3X-UI / build (amd64) (push) Waiting to run
Release 3X-UI / build (arm64) (push) Waiting to run
Release 3X-UI / build (armv5) (push) Waiting to run
Release 3X-UI / build (armv6) (push) Waiting to run
Release 3X-UI / build (armv7) (push) Waiting to run
Release 3X-UI / build (s390x) (push) Waiting to run
Release 3X-UI / Build for Windows (amd64) (push) Waiting to run
Release 3X-UI / Publish rolling dev release (push) Blocked by required conditions
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run

- 0: sing-box gen overrides fragment listen/port from the inbound row
  (empty listen -> "::"), Update/Add recompute the stored fragment;
  non-loopback E2E against the real core binary.
- 1: agent fetches the sing-box core from the Gitea release when
  missing, self-checks it, and only then latches the switch.
- 2: node list shows the sing-box core version (heartbeat field,
  persisted on the node row), xray version as fallback.
- 3: public-page fallback returns 404 to anonymous visitors when the
  page is disabled.
- 4: settings restart hint bar removed, dead i18n keys cleaned.
- 5: two PUT calls missing JSON headers fixed (audit: only those two),
  batch probe-task creation endpoint + UI.
- 6: cf-probe retirement card and coverage pipeline removed.
- 7: generated vless links no longer carry spx (panel export + sub);
  parser still accepts spx; golden fixtures updated.
- probe batch: dedicated probe settings tab (public-page settings,
  tasks, per-node meta), retention_days editable, per-node traffic
  calibration + stat-interface pinning, runtime metrics split into a
  lightweight fast report (default 3s, 1-60s adjustable).
- 8: sing-box core processes start with GOMEMLIMIT=32MiB, GOGC=50.
- 9: dead /getTwoFactorEnable docs entries removed (frontend call and
  contract entry already gone at base; verified by grep).
This commit is contained in:
Rogue
2026-10-23 07:53:11 +00:00
parent c2f1840535
commit 29de9761c8
67 changed files with 3081 additions and 832 deletions
+130
View File
@@ -0,0 +1,130 @@
package agent
import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"sync/atomic"
"testing"
"github.com/mhsanaei/3x-ui/v3/internal/config"
)
// V2.0.1 ①: a node missing its sing-box core fetches the pinned
// release build, self-checks it, and only then reports ready. A
// failed fetch installs nothing and backs off instead of hammering
// the release host on every config poll.
// fakeFetchedCore mimics the self-built release binary: it runs,
// and its `version` carries no stamp ("unknown") — the shape that
// makes telemetry fall back to the install-time version record.
const fakeFetchedCore = "#!/bin/sh\necho 'sing-box version unknown'\n"
func fakeCoreServer(t *testing.T, hits *atomic.Int32, status int) *httptest.Server {
t.Helper()
asset, err := singboxCoreAssetName()
if err != nil {
t.Skipf("no core asset for this arch: %v", err)
}
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hits.Add(1)
if status != http.StatusOK {
w.WriteHeader(status)
return
}
if strings.HasSuffix(r.URL.Path, asset) {
_, _ = w.Write([]byte(fakeFetchedCore))
return
}
http.NotFound(w, r)
}))
}
func useCoreBase(t *testing.T, url string) {
t.Helper()
orig := singboxCoreBaseURL
singboxCoreBaseURL = url
t.Cleanup(func() { singboxCoreBaseURL = orig })
}
func TestFetchSingboxCoreInstallsAndSelfChecks(t *testing.T) {
binDir := t.TempDir()
t.Setenv("XUI_BIN_FOLDER", binDir)
var hits atomic.Int32
srv := fakeCoreServer(t, &hits, http.StatusOK)
defer srv.Close()
useCoreBase(t, srv.URL)
a := &Agent{httpClient: http.DefaultClient}
if !a.singboxCoreReady() {
t.Fatal("core not ready after fetch")
}
dest := filepath.Join(binDir, singboxBinaryName())
info, err := os.Stat(dest)
if err != nil {
t.Fatalf("core not installed: %v", err)
}
if info.Mode()&0o111 == 0 {
t.Errorf("installed core is not executable: %v", info.Mode())
}
if got, ok := a.cachedSingboxVersion(); !ok || got != singboxCoreVersion {
t.Errorf("reported core version = %q (ok %v), want %q (from the version record)", got, ok, singboxCoreVersion)
}
if config.GetBinFolderPath() != binDir {
t.Fatalf("bin folder override not in effect")
}
// Second call: binary present, no further download.
if !a.singboxCoreReady() || hits.Load() != 1 {
t.Errorf("ready check re-downloaded: hits = %d", hits.Load())
}
}
func TestFetchSingboxCoreFailureKeepsNothingAndBacksOff(t *testing.T) {
binDir := t.TempDir()
t.Setenv("XUI_BIN_FOLDER", binDir)
var hits atomic.Int32
srv := fakeCoreServer(t, &hits, http.StatusBadGateway)
defer srv.Close()
useCoreBase(t, srv.URL)
a := &Agent{httpClient: http.DefaultClient}
if a.singboxCoreReady() {
t.Fatal("core reported ready after a failed fetch")
}
if _, err := os.Stat(filepath.Join(binDir, singboxBinaryName())); !os.IsNotExist(err) {
t.Errorf("failed fetch left a core binary behind: %v", err)
}
// Backoff: an immediate retry must not hit the server again.
if err := a.fetchSingboxCoreThrottled(); err == nil {
t.Fatal("throttled retry returned no error")
}
if hits.Load() != 1 {
t.Errorf("backoff violated: server hits = %d, want 1", hits.Load())
}
// And the switch gate stays closed: ready remains false.
if a.singboxCoreReady() {
t.Error("core became ready during backoff")
}
}
func TestFetchSingboxCoreRejectsBrokenDownload(t *testing.T) {
binDir := t.TempDir()
t.Setenv("XUI_BIN_FOLDER", binDir)
var hits atomic.Int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hits.Add(1)
_, _ = w.Write([]byte("this is not a binary at all"))
}))
defer srv.Close()
useCoreBase(t, srv.URL)
a := &Agent{httpClient: http.DefaultClient}
if err := a.fetchSingboxCore(); err == nil {
t.Fatal("broken download passed the self-check")
}
if _, err := os.Stat(filepath.Join(binDir, singboxBinaryName())); !os.IsNotExist(err) {
t.Errorf("broken download was installed: %v", err)
}
}