style: drop the line comments added with the triage fixes

CLAUDE.md rules out // line comments in committed Go. The rationale they
carried is in the commit messages for each fix; doc comments that already
existed are kept, updated where the code they describe changed.

Also replaces reflect.Ptr with reflect.Pointer and rewrites the YAML keyword
alternation as a lookup table, both flagged by golangci-lint.
This commit is contained in:
Sanaei
2026-07-27 14:37:57 +02:00
parent 6f4cc1e53c
commit 8bc00d1e90
8 changed files with 14 additions and 87 deletions
@@ -91,9 +91,6 @@ func TestDepletedCond_ProbeGuard(t *testing.T) {
}
}
// A master that stopped pushing leaves its last snapshot behind forever. Those
// frozen counters must not keep enforcing quota, or a client well inside its
// limit is disabled on every traffic poll with no way back (#6113).
func TestStaleGlobalTraffic_Ignored(t *testing.T) {
db := initTrafficTestDB(t)
svc := &InboundService{}
@@ -112,7 +109,6 @@ func TestStaleGlobalTraffic_Ignored(t *testing.T) {
}
t.Run("stale row alone neither enforces nor selects the cross-panel predicate", func(t *testing.T) {
// 200 of 1000 used locally, 1900 reported by a master gone for a day.
seedClientRow(t, "cap", 1, 100, 100, 1000)
seedStaleGlobal(t, "dead-master", "cap", 1000, 900)
@@ -138,8 +134,6 @@ func TestStaleGlobalTraffic_Ignored(t *testing.T) {
})
t.Run("a live master still enforces alongside the stale row", func(t *testing.T) {
// This is the #6113 shape: one dead master frozen over quota, one live
// master well under it. Only the live one may decide.
if err := svc.AcceptGlobalTraffic("live-master", []*xray.ClientTraffic{{Email: "cap", Up: 1, Down: 1}}); err != nil {
t.Fatalf("AcceptGlobalTraffic: %v", err)
}
@@ -152,7 +146,6 @@ func TestStaleGlobalTraffic_Ignored(t *testing.T) {
t.Fatalf("the live master reports usage well under quota, disabled %d", count)
}
// And once the live master reports real depletion, it takes effect.
if err := svc.AcceptGlobalTraffic("live-master", []*xray.ClientTraffic{{Email: "cap", Up: 600, Down: 500}}); err != nil {
t.Fatalf("AcceptGlobalTraffic: %v", err)
}
-9
View File
@@ -49,15 +49,6 @@ func (s *InboundService) disableInvalidInbounds(tx *gorm.DB) (bool, int64, error
return needRestart, count, err
}
// globalTrafficFreshWindow bounds how long a pushed client_global_traffics row
// stays authoritative. Masters refresh their rows every nodeGlobalPushInterval
// (30s), so a row older than this belongs to a master that stopped pushing —
// decommissioned, reinstalled under a new GUID, or detached from this node.
// Such a row keeps its last-seen counters forever, and without this bound a
// long-dead master's numbers permanently trip the cross-panel quota check and
// disable clients that are nowhere near their limit (#6113). The window is far
// wider than any real push gap, so a master that is merely unreachable for a
// while keeps enforcing.
const globalTrafficFreshWindow = 24 * time.Hour
func globalTrafficFreshSince() int64 {
@@ -28,9 +28,6 @@ func seedVlessInbound(t *testing.T, tag string, port int, clients []model.Client
}
}
// ClientRecord.Enable carries gorm:"default:true", so a false on insert is
// replaced by the default. Production disables through an UPDATE
// (disableInvalidClients); do the same here.
func disableClients(t *testing.T, emails ...string) {
t.Helper()
if err := database.GetDB().Model(&model.ClientRecord{}).
@@ -62,9 +59,6 @@ func emittedClients(t *testing.T, tag string) (any, bool) {
return nil, false
}
// An inbound whose clients are all filtered out must hand xray-core an empty
// array. It used to emit "clients": null, which the panel treats as invalid
// data elsewhere and coerces to [] at startup (#6117).
func TestGetXrayConfig_EmptyClientListIsArrayNotNull(t *testing.T) {
seedVlessInbound(t, "vless-empty", 43101, []model.Client{
{Email: "gone@x", ID: "11111111-1111-1111-1111-111111111111", Enable: true},
@@ -87,8 +81,6 @@ func TestGetXrayConfig_EmptyClientListIsArrayNotNull(t *testing.T) {
}
}
// The disabled/depleted filter must keep working — an empty array is only
// correct because those clients are genuinely excluded.
func TestGetXrayConfig_EnabledClientsStillEmitted(t *testing.T) {
seedVlessInbound(t, "vless-mixed", 43102, []model.Client{
{Email: "live@x", ID: "22222222-2222-2222-2222-222222222222", Enable: true},