Settings › Privacy's masked words (脱敏词) were matched as written:
Nightjar masked "Nightjar" and let NIGHTJAR and nightjar go to the
vendor. A new row under them, "Masked words in any case", makes each word
match in any capitals (Unicode simple folding, so МОСКВА matches Москва
too), with no rule to write. It is off by default and for every existing
user: settings.json without redactWordsAnyCase reads false, and a page
from before it that saves without the field keeps what was set
(api.go, as noAutoDownload). Each match goes as {{TERM_…}} and comes
back as it was written in the request. Translated in zh, zh-TW, ja, de.
redact.Options.WordsAnyCase; settings.RedactWordsAnyCase
(redactWordsAnyCase) reaches it through internal/masking; prefsKeep
sends it on every Settings save.
Tests, each red when its part is broken by hand:
- TestWordsAnyCase (internal/redact): with the any-case branch skipped,
FAIL "any case: \"NIGHTJAR\" still in …" and NIGHTJAR left in a request.
- TestCountTokensRedacted/words_any_case (internal/gateway): with
masking.go not passing the setting, FAIL "system, message and tool
description must be masked: …NIGHTJAR…"; words_as_written holds that
the default leaves NIGHTJAR alone.
- TestSettingsRedactWordsAnyCaseKept (internal/gui): with the
not-sent guard removed, FAIL "after {…no field…}: any case false".
- redact-words-any-case.test.cjs: 20 of 20 (Chromium and WebKit, en,
zh, zh-TW, ja, de, 1100 and 640px). With the old app.js it times out
waiting for #redactWordsAnyCaseRow; with only prefsKeep's field
removed, WebKit fails "a later save keeps it".
Not tried: a real vendor request with the switch on; the gateway test checks the body that goes out.
Rebased over b00c82acf (#1977's Warn/Block and Never mask list):
masking.go and settings.go keep its Actions and Allow beside
WordsAnyCase; redact, settings and provider ran ok after it.
Run for this batch of seven commits (devin, routing zh, qoder, masked words
any case, Long conversations, Claude subagents, user-select), in a worktree,
sandbox HOME, never against live configs:
- At e352cc823 (tree ea497c9f5, on origin/main 7dd965ed2): go test
-timeout 45m ./... with pipefail, tee'd: 68 packages ok, exit 0, no
ENOSPC. gofmt -l clean; go vet ./... for darwin, GOOS=linux -tags nogui
and GOOS=windows: clean.
- The whole GUI suite at e352cc823 (node --test --test-concurrency=3
internal/gui/tests/*.test.cjs, Chromium and WebKit, every language):
11725 tests, 11679 pass, 46 fail, none ENOSPC. Each red file run alone at
both 7dd965ed2 and e352cc823 gives the same counts on both, so none is
from this batch: usage-agents-hide 5/16 (#2276), usage-ledger 28/34
(#3104), usage-fold, quota-count-wrap, quota-name-translated (#2399),
usage-checkin 26/28 (#2549), plugin-github 14/18 (#3218), s3-sync 3/4
(#2448), modal-morph (#3179), fonts (filed as #3227, 1 in 9 alone on
main). tray-usages (#2453), plugin-card-update (#3079) and
proto-menu-overflow (filed as #3229) were red only under the full run
and pass alone on both.
- Rebased onto origin/main 4a87c4476 (only Zed's mover min changed), tree
8944b5dbb: go test ./internal/provider ./internal/gui (TestCoreScriptBudget
and the app.js budget) ./internal/redact ./internal/settings
./internal/agent: all five ok; gofmt -l clean.
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package redact
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A masked word matches in any case only when the user asked for it
|
|
// (ZoeCats on Discord): off, the default, it is matched as written, as
|
|
// before; on, NIGHTJAR and nightjar go as placeholders too, and each comes
|
|
// back as it was written.
|
|
func TestWordsAnyCase(t *testing.T) {
|
|
in := "Nightjar, NIGHTJAR and nightjar; МОСКВА is Москва. A nightjars' night."
|
|
for _, c := range []struct {
|
|
name string
|
|
anyCase bool
|
|
count int
|
|
gone []string
|
|
kept []string
|
|
}{
|
|
{"as written", false, 1, []string{"Nightjar,"}, []string{"NIGHTJAR", "nightjar;", "МОСКВА", "nightjars'"}},
|
|
{"any case", true, 6, []string{"Nightjar", "NIGHTJAR", "nightjar", "МОСКВА", "Москва"}, []string{"A ", "s' night."}},
|
|
} {
|
|
o := Options{Words: []string{"Nightjar", " москва "}, WordsAnyCase: c.anyCase}
|
|
out, n := Mask(in, o)
|
|
if n != c.count {
|
|
t.Errorf("%s: %d masked, want %d: %q", c.name, n, c.count, out)
|
|
}
|
|
for _, g := range c.gone {
|
|
if strings.Contains(unmarked(out), g) {
|
|
t.Errorf("%s: %q still in %q", c.name, g, out)
|
|
}
|
|
}
|
|
for _, k := range c.kept {
|
|
if !strings.Contains(out, k) {
|
|
t.Errorf("%s: %q gone from %q", c.name, k, out)
|
|
}
|
|
}
|
|
if back := Restore(out, false); back != in {
|
|
t.Errorf("%s: round trip %q → %q", c.name, out, back)
|
|
}
|
|
// and in a request body, as the gateway masks it
|
|
body, _ := MaskJSON([]byte(`{"messages":[{"role":"user","content":"ship NIGHTJAR"}]}`), o)
|
|
if hid := !strings.Contains(string(body), "NIGHTJAR"); hid != c.anyCase {
|
|
t.Errorf("%s: NIGHTJAR in a request masked=%v: %s", c.name, hid, body)
|
|
}
|
|
}
|
|
}
|