mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 08:25:26 +03:00
c483882e56
Replace the unbounded Detach Clients modal with server-paged candidate loading, debounced search and a virtualized list. Preserve explicit-ID selection and add frozen all-matching scopes with exclusions so selection remains stable across pages and searches without sending an N-sized client list from the browser. Execute large detach requests as idempotent background jobs. Revalidate source-inbound membership in bounded batches, atomically apply membership deltas, preserve ClientRecords and traffic, and queue reconciliation for remote nodes. Keep the legacy email-based bulkDetach API compatible. Add PostgreSQL/SQLite regression coverage for concurrent membership changes, stale scopes, exclusions, retries, rollback and legacy callers, plus real master/node coverage for offline-node reconciliation. Regenerate and validate the API contract and OpenAPI artifacts.
78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
package nodee2e
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestScopedDetachReconcilesOfflineNode(t *testing.T) {
|
|
bin := panelBinary(t)
|
|
master, node := newPanel(t, bin, "detach-master"), newPanel(t, bin, "detach-node")
|
|
master.start()
|
|
node.start()
|
|
port := freePort(t)
|
|
node.call(http.MethodPost, "/panel/api/inbounds/add",
|
|
vlessInbound("detach-source", port, nil, vlessClient("detach-me"), vlessClient("keep-me")))
|
|
enrollTrafficNode(t, master, node)
|
|
var source inboundView
|
|
eventually(t, settleTimeout, "master adopts both clients", func() (bool, string) {
|
|
var ok bool
|
|
source, ok = master.inboundOnPort(port)
|
|
return ok && len(source.emails()) == 2, fmt.Sprint(source.emails())
|
|
})
|
|
var page struct {
|
|
Items []struct {
|
|
ID int `json:"id"`
|
|
Email string `json:"email"`
|
|
}
|
|
}
|
|
if err := json.Unmarshal(master.call(http.MethodGet, fmt.Sprintf("/panel/api/clients/detachCandidates?inboundId=%d", source.Id), nil), &page); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var keep int
|
|
for _, item := range page.Items {
|
|
if item.Email == "keep-me" {
|
|
keep = item.ID
|
|
}
|
|
}
|
|
if keep == 0 || len(page.Items) != 2 {
|
|
t.Fatalf("source candidates: %+v", page)
|
|
}
|
|
var frozen struct{ ScopeToken string }
|
|
if err := json.Unmarshal(master.call(http.MethodPost, "/panel/api/clients/detachCandidates/freeze", map[string]any{"inboundId": source.Id}), &frozen); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
node.stop()
|
|
id := uuid.NewString()
|
|
master.call(http.MethodPost, "/panel/api/clients/bulkDetach", map[string]any{
|
|
"inboundIds": []int{source.Id}, "requestId": id,
|
|
"selection": map[string]any{"mode": "allMatching", "scopeToken": frozen.ScopeToken, "excludedClientIds": []int{keep}},
|
|
})
|
|
eventually(t, 10*time.Second, "scoped detachment commits and queues reconciliation", func() (bool, string) {
|
|
var status struct {
|
|
Running bool
|
|
Error string
|
|
Result struct {
|
|
Detached, Skipped, Errors int
|
|
NodePending bool
|
|
}
|
|
}
|
|
raw := master.call(http.MethodGet, "/panel/api/clients/bulkDetach/"+id, nil)
|
|
if err := json.Unmarshal(raw, &status); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return !status.Running && status.Error == "" && status.Result.Detached == 1 &&
|
|
status.Result.Skipped == 0 && status.Result.Errors == 0 && status.Result.NodePending, string(raw)
|
|
})
|
|
node.start()
|
|
eventually(t, 90*time.Second, "node applies detach and keeps the excluded client", func() (bool, string) {
|
|
ib, ok := node.inboundOnPort(port)
|
|
return ok && len(ib.emails()) == 1 && ib.client("keep-me") != nil, fmt.Sprint(ib.emails())
|
|
})
|
|
}
|