Files
magpie/internal/gui/plugins_github_why_test.go
yetone 63c0c354af gui: Discover is quieter: one unofficial mark, one button style, a reason in your language
Kiko03O1 on X asked for a better-looking Plugins › Discover page
("ui 设计能不能好看点"). Five things on it said one thing twice or said
it raw:

- A GitHub card had an "Unofficial" chip. A GitHub card is only ever
  drawn in the 非官方插件 · GitHub section, so the chip repeated the
  section's head on every card. It is gone from the card; the plugin's
  page keeps its full warning.
- Sign in on a card and on an Installed row is tinted like Install,
  not filled. It stays filled only in the plugin's sheet, so each level
  of action has one look.
- The GitHub line said Go's English in the middle of a zh page ("no
  answer in 8s"). internal/plugin's GitHub read now wraps its timeout in
  ErrNoAnswer; /api/plugins/github passes `why`: "slow" for that or any
  timeout, "limited" for GitHub's rate limit (ghtoken.Limited), and the page says "GitHub 响应超时" (zh, zh-TW, ja, de); the raw
  error is the line's hover. The line is smaller and muted, and Retry
  takes the accent colour.
- The second filter row's All had a count. It always equalled
  Installed + Not installed and the first row's picked count, so
  "全部 · N" showed twice side by side. It has no count now.
- Found on the way, same page: the filter box's placeholder was cut off
  in en at 1280/1100/980 and in de at every width but 420. It fits at
  every width now; the filter bar wraps where it did.

Looked at and left alone: the 8px inset on the borderless Signed in,
and the monospace version numbers.

plugins.js nets -25 bytes (the Unofficial chip's code went), so the
core script budget is unchanged: TestCoreScriptBudget passes at the
pushed head with no raise.

What was run, at this change on origin/main 4b9694c34, and again after
the last rebase onto 0df6a3aba: TestCoreScriptBudget, TestTaggedWhyKind,
gofmt, and the four changed GUI files with i18n-keys in both engines
(80 of 80):
- Red without the change: with the old assets, the four changed GUI
  files (plugin-github, plugin-github-wait, plugin-github-filter,
  plugin-market) went 37 red in Chromium; plugin-market expected the
  tinted colour and got the filled one. TestTaggedWhyKind doesn't
  compile without the change.
- Changed and nearby GUI files (those four, i18n-keys,
  plugin-check-github-limit, plugin-kinds-discover, plugin-page), both
  engines: 124 of 124 pass.
- gofmt clean. go vet clean on darwin, linux (-tags nogui) and windows;
  all three build. go test internal/gui and internal/plugin: plugin ok;
  gui ok on its own, one red in the package run,
  TestMainWindowCorners/macOS_15_SDK killed at its 40s deadline at load
  ~85 (#2645), which passes alone.
- The whole GUI suite (858 files, both engines, concurrency 3) was
  started at 628e18987 and ended early when the disk filled (ENOSPC):
  ~350 files ran, 3108 passed. Its five reds from before the disk
  filled are off the Plugins page, pass alone, and are filed:
  agent-models (#3468), cli-update (#3473), context-picks (#3483),
  deprecated-subscriptions (#3484). The rest failed launching a browser
  with ENOSPC.
- Rerun after space was freed, at d7ad3f2a3 plus this change: every
  library-* file, every plugin-* file, login-import, menu-input-scroll,
  mobile-web, name-suffix-saved and i18n-keys (94 files, both engines):
  1414 of 1426 pass. The 12 reds are all red on an origin/main
  118486258 worktree too, and filed: library-mcp-health-wsl ja (#3350),
  menu-input-scroll (#3402, 0 of 4 on main), plugin-card-update webkit
  (#3079, 0-1 of 3 on main over three runs, same Update-button wait),
  plugin-github chromium de 440 scrolled 1px (#3218, 18 of 18 alone).
- The two files after name-suffix-saved outside plugin-* that open the
  Plugins page, settings-tabs-stick and title-bar-tools, both engines:
  42 of 42 pass.
- Not run: the other ~440 GUI files after name-suffix-saved, and
  go test ./... .

Screenshots, before and after, zh dark and en light, were checked by
eye at 1280.
2026-10-24 22:31:59 +08:00

53 lines
2.3 KiB
Go

package gui
import (
"context"
"errors"
"fmt"
"net"
"net/url"
"testing"
"time"
"github.com/yetone/magpie/internal/ghtoken"
"github.com/yetone/magpie/internal/plugin"
)
// The Plugins page says why GitHub's list isn't whole in the reader's
// language when magpie knows the kind of why, rather than Go's English in
// the middle of the page (the Kiko03O1 reply on X: "no answer in 8s"
// under 非官方插件 · GitHub). Each kind as the errors arrive: wrapped in
// TaggedMissing, in a url.Error, or as they are.
func TestTaggedWhyKind(t *testing.T) {
timeout := &url.Error{Op: "Get", URL: "https://raw.githubusercontent.com/a/b/main/package.json", Err: &net.OpError{Op: "dial", Net: "tcp", Err: timeoutErr{}}}
refused := &url.Error{Op: "Get", URL: "http://127.0.0.1:1/raw", Err: &net.OpError{Op: "dial", Net: "tcp", Err: errors.New("connect: connection refused")}}
for _, c := range []struct {
name string
err error
want string
}{
{"the page stopped waiting", &plugin.TaggedMissing{Missing: 7, Why: fmt.Errorf("%w in %s", plugin.ErrNoAnswer, 8*time.Second)}, "slow"},
{"a read past its deadline", &plugin.TaggedMissing{Missing: 2, Why: &url.Error{Op: "Get", URL: "https://raw.githubusercontent.com/x", Err: context.DeadlineExceeded}}, "slow"},
{"a dial that timed out", &plugin.TaggedMissing{Missing: 1, Why: timeout}, "slow"},
{"the search past its deadline", fmt.Errorf("search: %w", context.DeadlineExceeded), "slow"},
{"GitHub's rate limit", ghtoken.Limited{Until: time.Now().Add(time.Hour)}, "limited"},
{"GitHub's rate limit, missing", &plugin.TaggedMissing{Missing: 3, Why: ghtoken.Limited{Token: true}}, "limited"},
{"refused: said as it is", &plugin.TaggedMissing{Missing: 12, Why: refused}, ""},
{"anything else", errors.New("GitHub's search: 502 Bad Gateway"), ""},
} {
if got := taggedWhyKind(c.err); got != c.want {
t.Errorf("%s: %q, want %q (%v)", c.name, got, c.want, c.err)
}
}
// the error as it came is still what the line's hover says
if e := fmt.Errorf("%w in %s", plugin.ErrNoAnswer, 8*time.Second); e.Error() != "no answer in 8s" {
t.Errorf("hover: %q", e)
}
}
type timeoutErr struct{}
func (timeoutErr) Error() string { return "i/o timeout" }
func (timeoutErr) Timeout() bool { return true }
func (timeoutErr) Temporary() bool { return true }