Files
magpie/internal/gui/feedback_test.go
T
yetone 4519eea711 gui: Settings › About has Report a problem, which copies the details and opens the feedback post (River_WLan on X)
A user who hit a problem had to work out what to tell us. Settings ›
About now has a Report a problem row with an Open button: it copies a
short block to the clipboard (magpie version, OS name and version,
architecture, and whether this is the app or the browser page), says it
was copied, and opens the feedback post
https://x.com/magpie_router/status/2119861020978188499 so the user can
paste it in a reply. GET /api/feedback builds the block and the URL.

The block holds no account names, keys, paths, host or user names, and
nothing is put in a URL: the opened address has no query or fragment.
The TUI has no Community links, so it gets nothing here. The core script
budget is raised by 458 bytes for the row and its translations
(1,263,851 to 1,264,309 with the provider commit under it).

Run, on mica: new TestFeedbackBlockHoldsNoPrivateFacts (version, OS,
arch, surface; no home dir, host or USER; URL with no ? or #; macOS
version present; unknown surface becomes app) and about-report.test.cjs
(clipboard gets the block, /api/open gets the post URL with no
diagnostics), chromium and webkit, en zh zh-TW ja de, widths 1100 and
420, 40 of 40 with about-website; vet on darwin, windows and linux nogui
clean. Broken by hand: a "Home:" line added to the block turns the Go
test red. A loaded run of the About files plus gui-de/ja/zh-tw and the
i18n files had 40 reds in usage and picker files; the reachable ones
were run alone on origin/main 5e933e153 (see the provider commit under
this one: usage-hidden-way-back #6295 and usage-agents-hide #3414 are
red there; the rest pass alone).

Not tried: the Linux app (WebKitGTK) and Windows; the clipboard write in
the Wails webview rather than a browser.
2026-11-12 19:31:11 +08:00

50 lines
1.7 KiB
Go

package gui
import (
"encoding/json"
"net/http/httptest"
"os"
"runtime"
"strings"
"testing"
)
// Report a problem copies the version, the system, the architecture and
// where magpie is open, and nothing that names the user: no home folder,
// user name or host. The post it opens carries no part of it in its link
// (River_WLan on X).
func TestFeedbackBlockHoldsNoPrivateFacts(t *testing.T) {
sandboxHome(t)
rec := httptest.NewRecorder()
webPageHandler(t, webHost{}, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/api/feedback?surface=browser", nil))
var got struct{ Text, URL string }
if rec.Code != 200 || json.Unmarshal(rec.Body.Bytes(), &got) != nil {
t.Fatalf("feedback: %d %s", rec.Code, rec.Body)
}
for _, want := range []string{"magpie " + Version, "OS: ", "Arch: " + runtime.GOARCH, "Opened in: browser"} {
if !strings.Contains(got.Text, want) {
t.Errorf("block lacks %q:\n%s", want, got.Text)
}
}
if got.URL != FeedbackURL || strings.ContainsAny(got.URL, "?#") {
t.Errorf("post link %q carries something", got.URL)
}
home, _ := os.UserHomeDir()
host, _ := os.Hostname()
for _, secret := range []string{home, host, os.Getenv("USER"), os.Getenv("USERNAME")} {
if secret != "" && strings.Contains(got.Text, secret) {
t.Errorf("block holds %q:\n%s", secret, got.Text)
}
}
if strings.Contains(osVersion(), "\n") || osVersion() == "" {
t.Errorf("os version %q", osVersion())
}
if runtime.GOOS == "darwin" && !osVersionRE.MatchString(osVersion()) {
t.Errorf("macOS without its version, as a window launched from Finder has it: %q", osVersion())
}
// anything but browser is the app's window
if !strings.Contains(diagnostics("../x"), "Opened in: app") {
t.Error("an unknown surface is not the app")
}
}