api/v2: list devices sorted by name

SaaS sorts by name. NodeStore order moved on every write, so
order-sensitive Terraform configs showed changes.
This commit is contained in:
Kristoffer Dalby committed 2026-11-03 17:05:00 +01:00
1 parent 88339d8ff1
commit e99d8f3f88
2 files changed
+16

No files matched your search

+6
View File
@@ -1,6 +1,7 @@
package apiv2
import (
"cmp"
"context"
"net/http"
"net/netip"
@@ -175,6 +176,11 @@ func registerDevices(api huma.API, b Backend) {
out.Body.Devices = append(out.Body.Devices, deviceFromView(node, allFields, b.Cfg.BaseDomain))
}
// The NodeStore holds no order, and Tailscale lists devices by name.
slices.SortFunc(out.Body.Devices, func(a, b Device) int {
return cmp.Compare(a.Name, b.Name)
})
return out, nil
})
+10
View File
@@ -851,6 +851,16 @@ func (r *apiReplay) deviceListChecks(t *testing.T, a testcapture.Action, resp []
wantBy, gotBy := byLabel(want.Devices), byLabel(got.Devices)
checks := []apiCheck{{"listed", sortedStrings(slices.Collect(maps.Keys(wantBy))), sortedStrings(slices.Collect(maps.Keys(gotBy)))}}
order := func(devs []apiBody) string {
labels := make([]string, 0, len(devs))
for _, d := range devs {
labels = append(labels, r.label("device", d.ID))
}
return strings.Join(labels, ",")
}
checks = append(checks, apiCheck{"order", order(want.Devices), order(got.Devices)})
for _, l := range slices.Sorted(maps.Keys(wantBy)) {
g, ok := gotBy[l]
if !ok {