From 3df47aece0465af2ef28880029c453c0fdc4dab4 Mon Sep 17 00:00:00 2001 From: bluebluesoda <300733005+bluebluesoda@users.noreply.github.com> Date: Sat, 12 Sep 2026 08:31:33 +0000 Subject: [PATCH] fix(panel): show whole GiB for large switcher memory - MachineSpecs keeps raw MiB up to 9600, then switches to a rounded whole GiB (e.g. 10000 -> "2c 10g") - cover the boundary and rounding in the group tests Co-authored-by: CommandCodeBot --- src/internal/mgr/group.go | 12 +++++++++--- src/internal/mgr/group_test.go | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/internal/mgr/group.go b/src/internal/mgr/group.go index 4a48b97..0fcec4d 100644 --- a/src/internal/mgr/group.go +++ b/src/internal/mgr/group.go @@ -2,6 +2,7 @@ package mgr import ( "errors" + "math" "regexp" "strconv" "strings" @@ -21,11 +22,16 @@ func UserGroupLabel(name string) string { } // MachineSpecs renders a compact quota tag for the container switcher: -// "c m g", e.g. "2c 2048m 15g". CPU reuses FormatCPU (tenths -// of a core, so 0.5 stays fractional); memory is the raw MiB value; disk is +// "c g", e.g. "2c 2048m 15g". CPU reuses FormatCPU (tenths of +// a core, so 0.5 stays fractional); memory is the raw MiB value, switching to +// a rounded whole GiB once it exceeds 9600 MiB (so "2c 10g 15g"); disk is // already GiB. func MachineSpecs(cpuTenths, memMB, diskGB int) string { - return FormatCPU(cpuTenths) + "c " + strconv.Itoa(memMB) + "m " + strconv.Itoa(diskGB) + "g" + mem := strconv.Itoa(memMB) + "m" + if memMB > 9600 { + mem = strconv.Itoa(int(math.Round(float64(memMB)/1024))) + "g" + } + return FormatCPU(cpuTenths) + "c " + mem + " " + strconv.Itoa(diskGB) + "g" } type UserGroup struct { diff --git a/src/internal/mgr/group_test.go b/src/internal/mgr/group_test.go index 30c52be..43c32bb 100644 --- a/src/internal/mgr/group_test.go +++ b/src/internal/mgr/group_test.go @@ -51,6 +51,10 @@ func TestMachineSpecs(t *testing.T) { {40, 8192, 40, "4c 8192m 40g"}, {5, 512, 10, "0.5c 512m 10g"}, {20, 1536, 20, "2c 1536m 20g"}, + {20, 9600, 20, "2c 9600m 20g"}, // boundary stays MiB + {20, 10000, 20, "2c 10g 20g"}, // 9.77 -> 10 + {20, 10240, 20, "2c 10g 20g"}, // exact GiB + {20, 11264, 20, "2c 11g 20g"}, // 11 GiB } { if got := MachineSpecs(test.cpu, test.mem, test.disk); got != test.want { t.Errorf("MachineSpecs(%d, %d, %d) = %q, want %q", test.cpu, test.mem, test.disk, got, test.want)