Files
magpie/internal/gui/trace_test.go
T
JoeyWu-tech ef9cd2fd6c gui: the tray panel's More in Plugins opens the window on Discover (#3579)
yetone (#3579): in the tray panel, the add sheet's More in Plugins, and
its search's "look for a plugin", asked the window for Plugins with no
more than the view's name (window/main?view=plugins). The window opened
on the tab of Plugins kept from before, Installed or Built-in, with
nothing looked for. 894ec960 made both open Discover in the window
itself; this is the panel's half.

The panel now asks for view=plugins&q=, with what its add sheet looked
for, empty when nothing was. More in Plugins sends the sheet's search,
lowercased, when it shows beside one (a search naming a subscription a
plugin serves, kiro say), and look for a plugin sends the search that
found nothing. mainView passes q on for Plugins whenever it is there,
empty too, since its being there is what says Discover; a q with a
control character (a newline, a tab) or over 100 code points goes on
empty. The window
opened on that address does what its own More in Plugins does
(pluginQuery): Discover, looking for q. start.js does it when the
window's first show() is done, so after show() has sent a window with a
plugin's update waiting to Installed, as the window's own More in
Plugins calls pluginQuery after show() too. It does it once: syncURL,
which show() calls, now takes q out of the address, so a reload, or the
window opened on Plugins again without a q, shows the tab kept, as
before. In the same window Plugins stays on Discover until another tab
is picked, as after the window's own More in Plugins. The GUI tests'
README describes the new half.

The deprecation note's Review in Plugins (several deprecated
subscriptions signed in) goes through openPlugins too, so from the
panel it now opens Discover as well, as it has in the window since
894ec960. openPlugins is the only sender of window/main?view=plugins.

plugins.js is not changed. app.js grows 94 bytes and start.js 182; with
the previous commit the core's scripts are 3 bytes under main's,
1,527,969 of 1,528,076, and app.js is 1,309,997 of 1,310,460.

Not changed: the window's own More in Plugins, and every other page the
panel opens the window on. mainView takes the view's own value
unchecked, so a q inside it skips mainFind (#3846); q goes no further
than Plugins' search field and its npm search, as typed there.

What was run (tree 7dce6444, on origin/main 56602426, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, the Go tests at umask 077:
- plugins-more-discover (Node 22.22.1, Playwright 1.58.2), its panel and
  window halves new, in English and Chinese, 5 times in Chromium and 5
  in WebKit: 3 of 3 pass each time. The panel, on a first use (where it
  shows the add sheet), asks for ?view=plugins&q= from More in Plugins
  and ?view=plugins&q=fake%20co%26x from "look for a plugin" after a
  search for "fake co&x" found nothing. The window, at what mainView
  makes of those (?view=plugins&q=fake+co%26x, and &q=) with Installed
  the tab kept, shows Discover with the search in its field, and its
  address keeps no q, so a reload shows Installed. With a plugin's
  update waiting (the test holds start.js until the update's answer is
  sent; WebKit has it by the first show(), Chromium not always, see the
  breaks), Plugins opened without a q shows Installed, and the window
  the panel opened shows Discover.
- TestMainView's new cases: Plugins with no q, an empty q, a word,
  "fake co&x", Chinese with &view=settings in it, a newline, a tab, 100
  and 101 characters, 100 and 101 Chinese characters, and Settings with
  a q. TestMainURL's: "智谱 glm" reads back from the window's address as
  it was sent. With TestCoreScriptBudget, -count=50: 150 of 150 pass.
- Broken by hand, each red in plugins-more-discover:
  - the panel asking for view=plugins alone, as on main: 0 of 3 in
    each engine, at the panel's asks (?view=plugins for
    ?view=plugins&q= and for ?view=plugins&q=fake%20co%26x);
  - start.js not looking for q, as on main: 0 of 3 in each engine, the
    window the panel opened on Installed (已安装 in Chinese) for
    Discover;
  - Discover asked as start.js loads, before show(): WebKit 0 of 3 in
    each of 5 runs, en and zh at "the window the panel opened, an
    update waiting", Installed for Discover; Chromium red there in 2
    of the 5 (en in both, zh in one). 25e1d038's record, its window
    half in plugins.js, had Chromium red in 4 runs of 4 (en every run,
    zh in 2);
  - q left in the address (syncURL's q.delete taken out): 0 of 3 in
    each engine, the address after the window opened still
    ?view=plugins&q=fake+co%26x for ?view=plugins.
- Every GUI file that reaches Plugins, the panel's add sheet or the
  window the panel opens (the same 53 as 25e1d038's record, by a grep
  for view=plugins, window/main, more-plugins, pluginQuery, pluginTab,
  lookFor, look for a plugin, show("plugins") and #view-plugins), and
  i18n-keys, each alone in both engines: 94 of 108 runs green. The
  other 14 are red at 56602426 too, alone, and none is in what this
  changes. Playwright here is 1.58.2, older than the 1.62.1 the GUI
  tests' README names, so some of these may be red with this
  Chromium or WebKit only; those with no issue named have none yet:
  - builtins, WebKit: Plugins › Built-in, the Observability switch's
    click times out; the stuck Plugins head intercepts the pointer.
  - i18n-keys, run twice (it needs no browser): "a plugin's words are
    its own", for plugins/routing/i18n.js's "masking…" (#4053).
  - mobile-web, both engines: its "desktop matches origin/main" cases
    compare with BASE_REF, origin/main by default, as git has it at
    the run, which had moved on from 56602426 (the Gateway page's
    screenshots differ). A copy with BASE_REF set to 56602426 passes
    15 of 15 in each engine.
  - modal-centred-late, WebKit: 820px and 560px, the dialog reaches its
    README's height with fewer than 3 frames between
    ([407,575,676,674,672] and [407,466,519,520,520,520]).
  - plugin-card-update, WebKit: en and zh, the wait for the Update
    button times out, in 4 runs of 4; at 56602426 the same in 3 runs
    of 4, and zh alone in the other (#3079 has en).
  - plugin-github, WebKit: de 440, a click moves #view-plugins from 73
    to 135 (#3218 has the same check red in Chromium, by 1px).
  - plugin-github-wait, Chromium: de 440, a press on Try again
    moves #view-plugins by 2.
  - plugin-release, WebKit: en and zh read the line with a trailing
    newline ("Serves Zed\n").
  - settings-lines-wrap, both engines: de 440px, a row's line is cut
    short, Usage's in Chromium and General's in WebKit.
  - title-bar-tools: in Chromium, de, the wait for the Plugins head
    times out; in WebKit, all five languages, here and at 56602426:
    zh, zh-TW, ja and en for page errors from the fetches a reload cut
    off (/api/agents/cli, /api/agents/install, /api/update and
    /api/whatsnew; #2740 has /api/providers'), and de for that same
    wait.
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  vet for windows, go build -tags nogui for linux and darwin and go
  build for windows: exit 0 each. go vet and go build without the tag
  on linux: exit 1 (no libsoup-3.0 or gio-unix-2.0 here).
- go test -tags nogui -count=1 -timeout 45m ./... (Bun 1.4.2, log
  kept; 8m41s, load 40 at its start): 72 packages ok, and 12 tests red
  in 5 packages, none of them this commit's tests or what they cover
  (internal/gui's are its gateway tests): agent TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath (#3141);
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram
  (umask 077, #3640); gateway TestPluginToldWhereTheAgentWorks
  (the /tmp/.git of #3675); gui TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649).

The rest is what was run for 25e1d038, at tree ffc1adb1 on origin/main
02cbdf5b, the same Go code, tests and README (its window half was in
plugins.js, where this one's is in start.js; not this tree):
- Broken by hand in the Go, each red in the Go tests named:
  - mainView passing no q: TestMainURL, and TestMainView's every
    Plugins case with a q;
  - mainView passing any q: TestMainView's newline, tab, 101
    characters and 101 Chinese characters;
  - mainFind as ^.{0,100}$: TestMainView's tab;
  - mainFind counting bytes too: TestMainView's 100 Chinese characters.

Not tried: the real app's tray panel and window, on macOS, Windows or
Linux.

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00

96 lines
3.9 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/gateway"
)
// The tray panel's Routing tab opens the window's Routing page on the
// request clicked: the id goes along, and nothing else does. Its More in
// Plugins opens Plugins on Discover, q even empty, with what the panel
// looked for when that is a line of text (#3579).
func TestMainView(t *testing.T) {
for _, c := range []struct {
q url.Values
want string
}{
{url.Values{}, ""},
{url.Values{"view": {"settings"}}, "settings"},
{url.Values{"view": {"routing"}}, "routing"},
{url.Values{"view": {"routing"}, "req": {"42"}}, "routing&req=42"},
{url.Values{"view": {"settings"}, "req": {"42"}}, "settings"},
{url.Values{"view": {"routing"}, "req": {"42&view=x"}}, "routing"},
{url.Values{"view": {"routing"}, "req": {"-1"}}, "routing"},
{url.Values{"view": {"masking"}, "key": {"1730000000123"}}, "masking&key=1730000000123"},
{url.Values{"view": {"masking"}, "key": {"7&view=settings"}}, "masking"},
{url.Values{"view": {"settings"}, "key": {"7"}}, "settings"},
{url.Values{"view": {"usage"}}, "usage"},
{url.Values{"view": {"usage"}, "tab": {"requests"}, "provider": {"codex"}}, "usage&tab=requests&provider=codex"},
{url.Values{"view": {"usage"}, "tab": {"requests"}, "agent": {"claude-desktop"}, "provider": {"relay team"}}, "usage&tab=requests&provider=relay+team&agent=claude-desktop"},
{url.Values{"view": {"usage"}, "tab": {"other"}, "provider": {"x&view=settings"}}, "usage"},
{url.Values{"view": {"settings"}, "provider": {"codex"}}, "settings"},
{url.Values{"view": {"plugins"}}, "plugins"},
{url.Values{"view": {"plugins"}, "q": {""}}, "plugins&q="},
{url.Values{"view": {"plugins"}, "q": {"kiro"}}, "plugins&q=kiro"},
{url.Values{"view": {"plugins"}, "q": {"fake co&x"}}, "plugins&q=fake+co%26x"},
{url.Values{"view": {"plugins"}, "q": {"智谱 glm&view=settings"}}, "plugins&q=%E6%99%BA%E8%B0%B1+glm%26view%3Dsettings"},
{url.Values{"view": {"plugins"}, "q": {"a\nb"}}, "plugins&q="},
{url.Values{"view": {"plugins"}, "q": {strings.Repeat("x", 100)}}, "plugins&q=" + strings.Repeat("x", 100)},
{url.Values{"view": {"plugins"}, "q": {strings.Repeat("x", 101)}}, "plugins&q="},
{url.Values{"view": {"plugins"}, "q": {"a\tb"}}, "plugins&q="},
{url.Values{"view": {"plugins"}, "q": {strings.Repeat("智", 100)}}, "plugins&q=" + strings.Repeat("%E6%99%BA", 100)},
{url.Values{"view": {"plugins"}, "q": {strings.Repeat("智", 101)}}, "plugins&q="},
{url.Values{"view": {"settings"}, "q": {"kiro"}}, "settings"},
} {
if got := mainView(c.q); got != c.want {
t.Errorf("%v: %q, want %q", c.q, got, c.want)
}
}
}
func TestRouteLookup(t *testing.T) {
sandboxHome(t)
old := served.Swap(nil)
t.Cleanup(func() { served.Store(old) })
if err := os.MkdirAll(gateway.HistoryDir(), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(gateway.HistoryDir(), "2026-09-30.jsonl"), []byte(`{"id":123,"model":"wanted","done":true}`+"\n"), 0o600); err != nil {
t.Fatal(err)
}
mux := http.NewServeMux()
traceRoutes(mux)
for _, c := range []struct {
id string
code int
}{{"123", 200}, {"124", 404}, {"", 400}, {"-1", 400}, {"../123", 400}} {
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/gateway/route?id="+url.QueryEscape(c.id)+"&day=2026-09-30", nil))
if w.Code != c.code {
t.Fatalf("id %q: %d %s", c.id, w.Code, w.Body)
}
if c.code == 200 {
var route gateway.Route
if err := json.Unmarshal(w.Body.Bytes(), &route); err != nil || route.ID != 123 || route.Model != "wanted" {
t.Fatalf("route: %+v, %v", route, err)
}
}
}
for _, day := range []string{"", "../2026-09-30", "2026-02-30"} {
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/gateway/route?id=123&day="+url.QueryEscape(day), nil))
if w.Code != 400 {
t.Fatalf("invalid day %q: %d", day, w.Code)
}
}
}