A value let go from the request view's menu (Never mask) went as written
in the conversation's earlier turns too, so the prompt the vendor had
cached no longer matched and the whole conversation was read again at
full price. Now a text sent masked on a route keeps that value masked,
with the same placeholder, while magpie remembers the text; new texts
(the next turn, another conversation) send it as written. It holds for
values added in Settings too.
allowkept.go remembers a maphash of (route, text) and of the value,
never the value, in two generations of 2^17 like sentSpans' memo. Only a
request with a route (Options.sent and Route) keeps it; a search's query
or an embedding's input has the value as written at once. Keeping a
value masked is the safe side: a collision masks a value the user let
go, and a text no longer remembered (after a restart) sends it as
written, as before. The menu's message now says earlier messages stay
masked so the cache holds (en, zh, zh-TW, ja, de). The request view's
inline Never mask was already there (yew_fence on Discord).
Run (mote refused SSH for ~30 min at load ~125, so on the Linux box):
- wsl-run go test ./internal/redact/ ./internal/masking/ ./plugins/redact/
ok, at the pushed head b9d1f00a5 too.
- wsl-run go test -run "Mask|Redact|Allow|Sent" ./internal/gateway/ and
-tags nogui ./internal/gui/: ok.
- go vet: GOOS=windows (redact, gui), GOOS=darwin (redact), linux -tags
nogui (redact, gui): ok. gofmt -l clean.
- node --test mask-value-menu, i18n-keys, i18n-en-no-cjk (chromium and
webkit, every language): ok. masking-records: the same reds as fresh
origin/main b35867730 (24 there, 23 here), filed as #5830, commented.
Broken by hand: apply without the maskedBefore check makes
TestAllowKeepsSentTextMasked red (the earlier turn goes as written).
Not tried: a real Anthropic request reading the cache across the
change; macOS (mote down); the full suite.
52 lines
2.1 KiB
Go
52 lines
2.1 KiB
Go
package redact
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Never mask holds from the next text on (NicoleS76448271 on X): a
|
|
// conversation's earlier turns, sent masked, go masked again with the
|
|
// same placeholder, so the vendor's cache of them still matches, and the
|
|
// turn after the value was let go has it as written. Another route, or a
|
|
// request with none, has it as written at once.
|
|
func TestAllowKeepsSentTextMasked(t *testing.T) {
|
|
resetSent()
|
|
t.Cleanup(resetSent)
|
|
const mail = "nicole.ops@kelvarn.io"
|
|
o := Options{Secrets: true, Personal: true, Route: "anthropic"}
|
|
turn1 := `{"role":"user","content":"mail ` + mail + ` the report"}`
|
|
body1 := `{"messages":[` + turn1 + `]}`
|
|
first, _ := MaskJSON([]byte(body1), o)
|
|
if strings.Contains(string(first), mail) {
|
|
t.Fatalf("not masked before it was let go: %s", first)
|
|
}
|
|
sent1 := strings.TrimSuffix(strings.TrimPrefix(string(first), `{"messages":[`), `]}`)
|
|
|
|
o.Allow = []string{"Nicole.Ops@kelvarn.io"}
|
|
turn2 := `{"role":"user","content":"and cc ` + mail + ` too"}`
|
|
second, _ := MaskJSON([]byte(`{"messages":[`+turn1+`,{"role":"assistant","content":"ok"},`+turn2+`]}`), o)
|
|
if !strings.HasPrefix(string(second), `{"messages":[`+sent1+`,`) {
|
|
t.Fatalf("the turn sent before changed, the cache misses:\nbefore %s\nnow %s", first, second)
|
|
}
|
|
if !strings.Contains(string(second), `"and cc `+mail+` too"`) {
|
|
t.Fatalf("the turn after Never mask isn't as written: %s", second)
|
|
}
|
|
|
|
// another route never had it: as written there
|
|
other := o
|
|
other.Route = "openai"
|
|
if out, _ := MaskJSON([]byte(body1), other); !strings.Contains(string(out), mail) {
|
|
t.Fatalf("masked on a route it never went: %s", out)
|
|
}
|
|
// nor does a request with no route keep it (a search's query)
|
|
if out, _ := Mask("mail "+mail+" the report", Options{Secrets: true, Personal: true, Allow: o.Allow}); !strings.Contains(out, mail) {
|
|
t.Fatalf("masked with no route: %q", out)
|
|
}
|
|
// taken off Never mask, it is masked again everywhere
|
|
o.Allow = nil
|
|
if out, _ := MaskJSON([]byte(`{"messages":[`+turn2+`]}`), o); strings.Contains(string(out), mail) {
|
|
t.Fatalf("masked no more after leaving Never mask: %s", out)
|
|
}
|
|
}
|