Files
magpie/internal/redact/thingname_test.go
T
yetone 4e7661adce redact: an app's one-word name the model took for a person's goes as written
Reported by ylorn. on Discord (11-06): choosing apps in Alma, a question
about one app was answered with another's facts. Privacy Filter took the
apps' names (Cicada, Mimi, Phosphor, Parakeet, Muesli) for people's: in a
bare list of them, alone, and in the Markdown list of apps the assistant
answered with (probed on the real model: ~0.99 each). The follow-up
questions ("How about Mimi?", "Phosphor vs Parakeet") it did not flag, so
they went as written while the history held the names as placeholders;
Phosphor and Parakeet (8 bytes) then became known values and were masked
everywhere. The vendor could not tell which placeholder was which app.

Restore was not the cause: placeholders are a keyed hash of kind and value,
one per value, and restore maps each back to its own value in any case
(TestManyNamesRestoreEachToItself, a guard: it passes on the old code too).

personFits now lets one ASCII word go when what is around it says a thing
and nothing says a person (thingNamed, internal/redact/thingname.go): a
person's word beside it (my colleague, Hi, Mr, said, told) masks; a thing's
word beside it (using, switched to, the ... app, vs, apps like, 这个软件)
lets go; else its sentence decides (he/she/relations/greetings/said mask;
app/macOS/subscription/vs/软件 let go); else a list item among items that
speak of apps, or a text of capitalized names only, lets go.

Trade-off, by design: a single first name alone, or a first name in a
sentence that speaks of an app with nothing of a person ("Mimi uses the
app daily"), goes as written. A full name (John Smith), a Chinese name
(张伟), and a first name beside a relation, a greeting, said or a pronoun
are masked as before.

Run (mote, worktree at 84ad780b6 + this):
- go test ./internal/redact/... ./internal/pii/... ./internal/masking/...
  ./internal/otlp/... ./internal/sessions/... ./internal/settings/... ok
- go test -run 'Mask|Redact|Privacy|Person|Known' ./internal/gateway
  ./internal/gui ok
- TestMaskEval re-recorded with both real models (MAGPIE_EVAL_CACHE);
  only the 12 new cases' recordings are added, old entries kept as they
  were (mote's re-record drifted 4 AstrLink and 2 Privacy Filter entries
  by score; not taken in). New cases app-names, app-alone, app-markdown
  (real Privacy Filter flags), app-compare/vs/list/using/zh (model finds
  none; guard), app-and-person, app-and-full-name, app-and-zh-name,
  greeting (person controls).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet ./internal/redact ok.

Broken by hand:
- the personFits hook off: TestAppNamesNotPersons red 9/9,
  TestPersonBesideAppStillMasked red on the 3 apps, TestMaskEval red on
  app-names (5), app-alone, app-markdown (3) with the real recordings.
- thingNamed always true: TestPersonBesideAppStillMasked red on Mimi (x2),
  Laura, Daniel.

Not tried: a real Alma chat through the gateway with the model on; Windows
and Linux runs (pure Go string code, vetted for both); the full suite runs
after the push.
2026-11-06 09:28:25 +08:00

116 lines
4.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package redact
import (
"strings"
"testing"
)
// The apps ylorn. was choosing among (Discord, 11-06) are no one's names:
// in a list of them, alone, and in the Markdown list of apps the vendor
// answered with, each goes as written though the model took it for a
// person's. Privacy Filter flagged exactly these texts (zz probe, 11-06).
func TestAppNamesNotPersons(t *testing.T) {
apps := []string{"Cicada", "Mimi", "Phosphor", "Parakeet", "Muesli"}
f := &fakeModel{values: map[string]string{}}
for _, v := range apps {
f.values[v] = "private_person"
}
for _, s := range []string{
"Cicada, Mimi, Phosphor, Parakeet, Muesli",
"Muesli",
"Cicada and Mimi",
"1. **Cicada** – a minimal note-taking app with Markdown.\n2. **Mimi** – a voice memo app with AI summaries.\n3. **Phosphor** – an RSS reader.\n4. **Parakeet** – a podcast player for macOS.\n5. **Muesli** – a meal planner.",
"Which is better for notes on my Mac, Cicada or Mimi?",
"I switched to Muesli last week; Parakeet crashes too often.",
"I'm using Phosphor now, and Cicada vs Mimi is still open.",
"Apps like Muesli are hard to find.",
"Parakeet 这个软件很好用,Cicada 和 Mimi 呢?",
} {
out, _ := Mask(s, Options{Personal: true, Model: f.find})
if out != s {
t.Errorf("an app's name masked:\n in: %q\nout: %q", s, out)
}
}
}
// A person's name beside an app's is masked as before: a full name, a
// first name with a relation, a greeting or said beside it, a first name
// in a sentence of a person's doings, and a Chinese name.
func TestPersonBesideAppStillMasked(t *testing.T) {
f := &fakeModel{values: map[string]string{
"Mimi": "private_person", "Phosphor": "private_person", "John Smith": "private_person",
"Cicada": "private_person", "Daniel": "private_person", "Laura": "private_person",
"张伟": "private_person", "Parakeet": "private_person",
}}
for _, c := range []struct {
s string
mask, keep []string
}{
{"My colleague Mimi said the Phosphor app is great; she uses it every day.", []string{"Mimi"}, []string{"Phosphor"}},
{"John Smith asked me to install Cicada on his Mac.", []string{"John Smith"}, []string{"Cicada"}},
{"张伟说 Parakeet 这个软件很好用,让我也装一个。", []string{"张伟"}, []string{"Parakeet"}},
{"Hi Mimi, thanks for the notes from Tuesday's call. Can you send them to Laura as well?", []string{"Mimi", "Laura"}, nil},
{"Mimi will review the draft tomorrow and send it to Daniel.", []string{"Mimi", "Daniel"}, nil},
{"Mimi", nil, nil}, // alone it says nothing whose: let go, by design
} {
out, _ := Mask(c.s, Options{Personal: true, Model: f.find})
for _, v := range c.mask {
if strings.Contains(out, v) {
t.Errorf("%q went as written:\n in: %q\nout: %q", v, c.s, out)
}
}
for _, v := range c.keep {
if !strings.Contains(out, v) {
t.Errorf("%q masked:\n in: %q\nout: %q", v, c.s, out)
}
}
if back := Restore(out, false); back != c.s {
t.Errorf("round trip: %q", back)
}
}
}
// Several one-word names masked across a chat's turns come back each as
// itself, however the reply orders and splits their placeholders: restore
// never gives one name's placeholder another's value. ylorn.'s mix-up was
// not a swap here; it was the names masked in one turn and as written in
// the next (thingname.go).
func TestManyNamesRestoreEachToItself(t *testing.T) {
names := []string{"Rosalind", "Mimi", "Torvald", "Ines", "Bartholomew", "Yuki", "Odile", "Kofi"}
f := &fakeModel{values: map[string]string{}}
for _, v := range names {
f.values[v] = "private_person"
}
ph := map[string]string{}
for i, v := range names {
turn := "Hi " + v + ", my colleague " + names[(i+1)%len(names)] + " said she would call."
out, _ := Mask(turn, Options{Personal: true, Model: f.find})
if strings.Contains(out, v) {
t.Fatalf("%q not masked: %q", v, out)
}
for _, p := range placeholderRe.FindAllString(out, -1) {
back := Restore(p, false)
if old, ok := ph[back]; ok && !strings.EqualFold(old, p) {
t.Fatalf("%q masked as %s and %s", back, old, p)
}
ph[back] = p
}
}
if len(ph) != len(names) {
t.Fatalf("%d placeholders for %d names: %v", len(ph), len(names), ph)
}
// a reply naming them in reverse and in another case
var reply, want strings.Builder
for i := len(names) - 1; i >= 0; i-- {
p := ph[names[i]]
if i%2 == 0 {
p = strings.ToLower(p)
}
reply.WriteString(p + " (" + names[i][:1] + "); ")
want.WriteString(names[i] + " (" + names[i][:1] + "); ")
}
if got := Restore(reply.String(), false); got != want.String() {
t.Fatalf("restored\n got %q\nwant %q", got, want.String())
}
}