Files
magpie/internal/gui/trace_test.go
T
yetone e698a688fd gui: Insights › Masking shows each request as sent, what was masked and how
What masking did moves out of Settings › Privacy into a page of its own
under Insights (plugins/redact: client.js, page.js, redact.css, i18n.js).
Privacy keeps how it is found and what to mask, with a "What was masked"
row that opens the page.

- The top card is Privacy's card, made shorter: the flow animation
  (agents → this computer → providers) with magpie's bird on the centre
  line and "magpie masks it on this computer" under it, so a screenshot
  says who masked it; the count and a 7-day bar. Nothing the list repeats.
- The list: one row per masked request, narrowed by kind, by who found it
  (rules or the local model), by agent or provider, or to held-back
  requests; or by value, each with how often it was put back.
- A request: the message as it went to the vendor beside the original,
  each mask marked, unchanged parts folded; picking a value lights every
  place it was masked; a held-back request offers "Mask it instead".
- Gateway's masked badge and ?view=masking&key=N (trace.go's mainView)
  open one request.
- Classes are msk-: library.css owns mk- (a first cut stacked the flow).
- Budgets lowered to the core's size after the move.
- Not shown: rule names and the local model's confidence; the records
  don't keep them.

Run on f5b1d36ff (rebased since onto 344d11484, which only raised the
budgets and changed a dialog's centring and two unrelated files):
- masking-records.test.cjs: 32/32, Chromium and WebKit, 5 languages,
  1100px and 640px (card, list, filters, detail, put back, held back,
  Gateway badge, deep link, Settings row, no scroll on click), with
  key-import and i18n-keys: 48/48.
- go test ./internal/maskrec ./internal/redact ./plugins/redact
  ./internal/gui ./internal/provider: ok. TestCoreScriptBudget and
  TestMainView ok; gofmt -l clean.
- Before the rebase, on 628e18987: go test ./... -timeout 45m, every
  package ok; GOOS=linux go vet -tags nogui ./... and GOOS=windows go
  vet ./... clean.
- Budgets lowered to the sizes at the pushed head (app.js 1,317,486,
  core 1,524,789), ~26KB under what f35c721c4 raised them to after
  ce5b23cdb's add-key spinner put the core over.

Broken by hand: the bird's href (#bird → #nobird) turns masking-records
red.

Not run at this head when pushed: internal/gateway, which main's newer
commits touched (run right after; the result goes on the release).
Not tried: the whole GUI suite (hours long, and another session's runs
held the machine), the real Linux (WebKitGTK) and Windows apps.
2026-10-24 19:45:03 +08:00

81 lines
2.8 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"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.
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"},
} {
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)
}
}
}