Files
magpie/internal/proc/browser_test.go
T
yetone b319657301 gui: a sign-in whose browser didn't open says why and shows its link, and Windows names rundll32 by its path (#2043)
xiaobaifly7: on Windows, signing in to Cloudflare's MCP server (and any
sign-in) opened no browser, and the window said to finish in the
browser until the sign-in timed out. Wails' Browser.OpenURL starts
rundll32 by its bare name, which Go looks up with PATHEXT's extensions;
a PATHEXT without .EXE (WSL passes one on as ".CPL") finds nothing, and
host.OpenURL dropped the error.

- proc.OpenBrowser starts %SystemRoot%\System32\rundll32.exe by its
  path (open / xdg-open / termux-open-url elsewhere) and returns the
  launcher's error. host.OpenURL falls back to it when Wails' fails, and
  the CLI's account sign-in uses it.
- Windows.OpenURL returns the error. /api/signin, the plugin sign-in and
  /api/library/mcp-signin answer it as openError; /api/open fails with
  it, so Open again says why.
- The sign-in card shows "magpie couldn't open your browser: {error}.
  Open the sign-in link below in a browser yourself." where it said
  magpie opened the page, with the link already shown below; the MCP
  editor shows the error with the link and a copy button. Translated
  (zh, zh-TW, ja, de).
- Open again matched its sign-in by identity, so a poll that put a fresh
  copy of the same sign-in in place kept the old error after a
  successful retry; it now matches by id.

Run:
- TestBrowserNamesRundll32ByItsPath, TestMCPSignInSaysTheBrowserDidntOpen
  and the /api/open and /api/signin tests in signin_open_2043_test.go.
  Broken by hand: the bare name back in browserCommand fails the first;
  openError returning "" fails the gui tests.
- On the Windows box (amd64, cmd with PATHEXT=.CPL): exec.Command
  ("rundll32", ...).Start() gave `exec: "rundll32": executable file not
  found in %PATH%`; proc.OpenBrowser started it (nil). The proc test
  binary's TestBrowserNamesRundll32ByItsPath passed there.
- signin-browser-down.test.cjs (new): the card's text, the link, no
  sideways overflow, Open again failing then succeeding, and the MCP
  editor's error and link, in Chromium and WebKit at 1100 and 420 in
  every language: 20/20. The related sign-in GUI tests: 451/452, the
  one a signin-proxy flake also on main (fixed in its own commit).
- gofmt -l clean; go vet darwin, linux -tags nogui, windows; GOOS=linux
  and windows builds; go test -tags nogui ./internal/gui/
  ./internal/proc/ ./internal/cli/.

Not tried: the real Wails app on Windows under PATHEXT=.CPL (the
fallback path is exercised only through proc.OpenBrowser), WSL itself,
the reporter's machine. Not covered: internal/tui/sessions.go and
internal/provider/install.go start `powershell` by its bare name, which
would miss the same way under such a PATHEXT.
2026-10-14 08:36:07 +08:00

30 lines
1.1 KiB
Go

package proc
import (
"path/filepath"
"testing"
)
// Windows' rundll32 is named by its path in the system folder: by its bare
// name a PATHEXT without .EXE (WSL passed one on as ".CPL") found nothing,
// and the sign-in's page never opened (#2043, xiaobaifly7).
func TestBrowserNamesRundll32ByItsPath(t *testing.T) {
url := "https://mcp.cloudflare.com/authorize?state=a&b=c"
name, args := browserCommand("windows", `C:\WINDOWS`, url)
if want := filepath.Join(`C:\WINDOWS`, "System32", "rundll32.exe"); name != want {
t.Fatalf("launcher %q, want %q", name, want)
}
if len(args) != 2 || args[0] != "url.dll,FileProtocolHandler" || args[1] != url {
t.Fatalf("args %q", args)
}
// no SystemRoot to go by: the bare name, as before
if name, _ := browserCommand("windows", "", url); name != "rundll32" {
t.Fatalf("without SystemRoot: %q", name)
}
for goos, want := range map[string]string{"darwin": "open", "linux": "xdg-open", "android": "termux-open-url"} {
if name, args := browserCommand(goos, "", url); name != want || len(args) != 1 || args[0] != url {
t.Errorf("%s: %q %q", goos, name, args)
}
}
}