redact: more file names that read as addresses stay as written (willz on Discord)

willz (#feedback) asked to tell image names like image@2x.png apart from
emails. b855cfee9 (#3029) already leaves …@2x.png/.jpg/.webp/.pdf and
the other image extensions, for the rule and the local model. This
widens the same check (fileExt in realEmail, which modelTakes calls too)
to what it still masked:
- other files named so, whose extension is no domain either (IANA's list,
  checked 2026-10-21): strings@base.json, styles@2x.css, txt, csv, yaml,
  js/ts, fonts, office files, archives, audio;
- a scale before an extension that is a domain too: icon@2x.zip,
  intro@1.5x.mov, @2x.md, @2x.map (scaleExt). Without a scale,
  ops@files.zip and me@notes.md are addresses and still masked; .ai and
  .io never were file extensions here.
(@2x.mp4 and the like never matched: the rule's last label is letters
only.) There is no allow-list for redaction: Settings → Privacy has
words and rules to mask more, and per-kind switches, but email is part
of "Mask personal data" and can't be turned off on its own.

TestMoreFileNamesAreNoEmail: the names above unmasked, in Mask and in a
request's tool_result through MaskJSON, and a.b@acme-corp.com,
x@company.ai, dev@startup.io, me@notes.md, ops@files.zip,
jane@studio.mov, sales@2x.com, hi@png.dev still masked. Broken by hand:
with b855cfee9's list only it fails on strings@base.json, icon@2x.zip,
intro@1.5x.mov and the request; with zip/mov/md/ai taken as file
extensions whole it fails on x@company.ai, me@notes.md, ops@files.zip,
jane@studio.mov.

Run at this head (on origin/main d3db461bb), sandbox HOME:
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... clean; go build for darwin, linux (nogui)
  and windows ok (at 27a1f428c, the same change on 049040283).
- go test -timeout 45m ./...: 68 packages ok, exit 0 (load ~85-140);
  the same at 049040283. Rebased after onto origin/main 82fb0702f
  (six gateway-only commits, none in redact or its doc):
  go test ./internal/redact ok, go vet redact and gateway clean.
  An earlier run of this change at ba319a758 timed out internal/agent
  and internal/library at 45m (load ~25-77; #2544/#2723, #2853) and had
  TestMainWindowCorners/RightToLeft killed (#2645); alone, library
  (2207s), agent (-timeout 120m, 1887s) and those gui tests passed.
Not tried: a real agent request through a running magpie.
This commit is contained in:
yetone
2026-10-22 02:11:41 +08:00
parent b1a2eec2c1
commit b35e6a8b57
2 changed files with 110 additions and 1 deletions
+4 -1
View File
@@ -1147,7 +1147,10 @@ func (s *Server) models(w http.ResponseWriter, r *http.Request) {
data = append(data, videomakerObjects(r)...)
}
if r.Header.Get(provider.DecidersHeader) != "" {
deciders := keyAllowed(r, provider.Deciders())
// the decision models its own pickers offer: of a provider with
// picks (OpenRouter's twenty-odd), the picked ones, so another
// magpie lists what its Gateway page shows (GokoShiki on Discord)
deciders := keyAllowed(r, provider.OfferedDeciders(nil))
for i := range deciders {
deciders[i].Name = cmp.Or(deciders[i].Name, deciders[i].Model)
}
@@ -0,0 +1,106 @@
package gateway
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// A magpie added as a Remote magpie lists here what its user picked there,
// and no more (GokoShiki on Discord: 24 picked on the remote, 51 here, the
// extra ones OpenRouter's). The remote's list for another magpie carried
// every OpenRouter decision model, picked or not, so each one came here as
// a model of its own. A model a plugin serves there (the Grok
// subscription's) and an API provider's (DeepSeek's) come here as picked.
func TestRemoteMagpieListsThePicks(t *testing.T) {
// the remote magpie, under its own HOME
besideFake(t, "grok", http.NotFoundHandler())
var chat, decide []catalog.Model
for i := range 40 {
chat = append(chat, catalog.Model{ID: fmt.Sprintf("vendor/chat-%d", i)})
}
for i := range 27 {
decide = append(decide, catalog.Model{ID: fmt.Sprintf("vendor/dec-%d", i)})
}
const or = "https://openrouter.ai/api/v1"
for _, p := range []provider.Provider{
{ID: "openrouter", Name: "OpenRouter", Preset: "openrouter", Key: "k", Chat: or, Models: []string{"vendor/chat-1", "vendor/chat-2", "vendor/dec-3"}},
{ID: "deepseek", Name: "DeepSeek", Key: "k", Chat: "http://127.0.0.1:1/v1", Anthropic: "http://127.0.0.1:1/anthropic", Models: []string{"deepseek-chat"}},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
for id, ms := range map[string][]catalog.Model{"openrouter": chat, "openrouter.decisions": decide} {
if err := catalog.SaveLive(id, or, ms); err != nil {
t.Fatal(err)
}
}
if err := catalog.SaveLive("deepseek", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "deepseek-chat"}, {ID: "deepseek-reasoner"}}); err != nil {
t.Fatal(err)
}
// what the remote's Gateway page shows: each provider's picks
var picked []string
for _, p := range provider.All() {
for _, m := range p.Exposed() {
picked = append(picked, p.ID+"/"+m.ID)
}
}
slices.Sort(picked)
for _, want := range []string{"deepseek/deepseek-chat", "grok/fake-1", "openrouter/vendor/dec-3"} {
if !slices.Contains(picked, want) {
t.Fatalf("the remote's picks %v lack %s", picked, want)
}
}
// the list it gives another magpie, asked as one asks
req := httptest.NewRequest("GET", "/v1/models", nil)
req.Header.Set("User-Agent", "magpie")
for _, h := range []string{provider.DrawersHeader, provider.VideomakersHeader, provider.PricesHeader, provider.DecidersHeader} {
req.Header.Set(h, "1")
}
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("remote /v1/models: %d %s", rec.Code, rec.Body)
}
body := rec.Body.Bytes()
// this magpie, under a HOME of its own, adds the remote
fresh(t)
remote := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/models" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(body)
}))
t.Cleanup(remote.Close)
id, err := provider.Add(provider.Provider{ID: "office", Name: "Office", Preset: provider.RemoteMagpiePreset, Key: "k", Chat: remote.URL})
if err != nil {
t.Fatal(err)
}
office, _ := provider.Find(id)
if _, err := office.Fetch(context.Background()); err != nil {
t.Fatal(err)
}
office, _ = provider.Find(id)
var here []string
for _, m := range office.Exposed() {
here = append(here, m.ID)
}
slices.Sort(here)
if !slices.Equal(here, picked) {
var v struct{ Data []json.RawMessage }
json.Unmarshal(body, &v)
t.Fatalf("the remote picked %d: %v\nthis magpie lists %d: %v\n(the remote's list had %d entries)", len(picked), picked, len(here), here, len(v.Data))
}
}