Files
magpie/internal/gui/traycolumns_darwin_test.go
T
yetone c5cb1c0588 gui: the tray's logo is 16pt, as large as other apps' menu bar icons
qingnianxiaozhe on X: magpie's A\ in the menu bar looked a size smaller
than another app's A\ beside it. magpie fitted each logo to a 14pt box,
so the A\ (about 1.37:1) drew 14x10pt. Claude.app's menu bar template
(TrayIconTemplate@2x.png, 48x48 px) has 32x32 px of ink, a 16pt glyph,
and in the reporter's screenshot the other A\ is 32x22 px against
magpie's 28x20 px at 2x. mpLogo is now 16; the letter in a ring (a logo
that can't be read) grows with it. The two 10pt rows of percentages are
unchanged and still fit the 22pt bar.

Tests: the logo boxes in the tray tests follow the 16pt box (offsets 28
-> 32, 34 -> 38 px at 2x); TestTrayImageLogoSizes now wants 27-33 px of
a 32 px box.

Run on mote (macOS 27.2):
- go test ./internal/gui -run Tray -count=1 -v: ok.
- Broken by hand (mpLogo back to 14): TestTrayImageLogoSizes FAILs
  ("alma spans 24 px of a 32 px box", codex/zcode/workbuddy 26 px) and
  TestTrayImagePlain FAILs ("238 px with logos, 182 without").
- Rendered by the real drawing code (trayImagePNG, 22pt bar at 2x)
  next to Claude.app's own template icon: the A\ is 28 px wide before
  and 32x24 px of ink after, as wide as Claude's 32 px spark; the
  percentages are the same text at the same size. The before/after
  strips are kept outside the repo (tray-toolbar-scratch/before and
  after/strip-{light,dark}.png).
Suite and checks, on mote at aa31e737c8d271455865615fafdf512e09073663 (this commit and its pair, the
tray logo size / the toolbar menu):
- go test -count=1 -timeout 45m ./... in a sandbox HOME, caches pinned:
  exit 0, 103 packages ok, none FAIL (internal/gateway 1633s,
  internal/agent 949s, internal/provider 470s, internal/gui 295s).
- gofmt -l internal/gui: nothing. go vet ./..., GOOS=linux go vet -tags
  nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: all ok.
- No GUI asset changed, so the Playwright suite wasn't run.
After a rebase onto 42c43c002 (Antigravity sessions, internal/gui
sessions reads; no file in common), at the pushed head:
go vet, GOOS=windows and GOOS=linux -tags nogui go vet of ./internal/gui/...
and go test -count=1 ./internal/gui/...: ok.
Then rebased onto f7e0f68ca (Codex instructions, internal/provider
only), not run again.

Not tried: a screen screenshot of the real menu bar (no Screen
Recording permission over ssh on mote; the image is the one the app
hands NSStatusItem); the reporter's notch Mac, where the bar is 24pt.
2026-11-18 16:08:15 +08:00

84 lines
3.2 KiB
Go

package gui
import (
"bytes"
"image"
"image/png"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// A card with four windows draws, through AppKit, two columns of two
// stacked rows (jen_celeus on X), in light and dark: as high as a card
// with two, up to about twice as wide, with a gap of no ink between its
// columns; with three, the third alone on the top line of its column.
func TestTrayImageColumns(t *testing.T) {
bird, err := os.ReadFile("tray.png")
if err != nil {
t.Fatal(err)
}
now := time.Date(2026, 11, 15, 3, 0, 0, 0, time.UTC)
q := antigravityPools()
four, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, nil)
var kinds []string
for _, w := range withTrayKinds([]provider.SubscriptionQuota{q})[0].Windows {
kinds = append(kinds, w.TrayKind)
}
two, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, map[string][]string{"antigravity": {kinds[1], kinds[3]}})
three, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, map[string][]string{"antigravity": {kinds[1], kinds[3], kinds[0]}})
if len(four[0].Rows) != 4 || len(two[0].Rows) != 2 || len(three[0].Rows) != 3 {
t.Fatalf("rows %q %q %q", four[0].Rows, two[0].Rows, three[0].Rows)
}
out := os.Getenv("MAGPIE_TRAY_PREVIEW")
for _, dark := range []bool{false, true} {
_, w0, _ := trayImagePNG(nil, bird, 22, 2, dark, false)
_, w2, _ := trayImagePNG(two, bird, 22, 2, dark, false)
b, w4, h := trayImagePNG(four, bird, 22, 2, dark, false)
img, err := png.Decode(bytes.NewReader(b))
if err != nil || h != 44 {
t.Fatalf("dark %v: %v, %dx%d", dark, err, w4, h)
}
// the digits after the logo (16pt and 3pt, at 2x)
digits2, digits4 := w2-w0-38, w4-w0-38
if digits4 < digits2+30 || digits4 > digits2*2+20 {
t.Errorf("dark %v: four windows' digits are %d px wide, two's %d", dark, digits4, digits2)
}
left := image.Rect(w0+38, 0, w0+38+digits4/2-6, h)
right := image.Rect(w0+38+digits4/2+6, 0, w4, h)
if l, r := inkBands(img, left, dark), inkBands(img, right, dark); l != 2 || r != 2 {
t.Errorf("dark %v: the columns draw %d and %d lines, want 2 and 2", dark, l, r)
}
// a gap of no ink between the columns
gap := false
for x := w0 + 38 + digits4/4; x < w4-digits4/4; x++ {
if inkIn(img, image.Rect(x, 0, x+1, h), dark) == 0 {
gap = true
break
}
}
if !gap {
t.Errorf("dark %v: no gap between the columns", dark)
}
b3, w3, _ := trayImagePNG(three, bird, 22, 2, dark, false)
img3, _ := png.Decode(bytes.NewReader(b3))
top := inkIn(img3, image.Rect(w3-10, 0, w3, h/2), dark)
bottom := inkIn(img3, image.Rect(w3-10, h/2+2, w3, h), dark)
if top < 20 || bottom != 0 {
t.Errorf("dark %v: the third window's column: %d px of ink on top, %d below", dark, top, bottom)
}
if out != "" {
for name, cs := range map[string][]trayCell{"two": two, "three": three, "four": four, "plain": trayPlain(four)} {
bg, _, _ := trayImagePNG(cs, bird, 22, 2, dark, true)
f := filepath.Join(out, "tray-columns-"+name+map[bool]string{false: "-light.png", true: "-dark.png"}[dark])
if err := os.WriteFile(f, bg, 0o644); err != nil {
t.Fatal(err)
}
}
}
}
}