Files
magpie/internal/redact/export_test.go
T
yetone 5218119456 redact: every reply gets its values back, a turn that masked nothing too
yapechan123 (Discord) saw a table the model wrote come back as
{{PERSON_kb32hzkg}}、{{PERSON_iye66366}} and {{PERSON_isyrz5ih}}、
{{PERSON_j5kluh3x}}, all four in canonical form. Every way a placeholder
could come back unrestored was probed with those literal bytes, on each
protocol's stream split at every byte and at 1..7 runes, and whole:

- The gateway put no restoring writer on a reply when the request in
  hand masked nothing (redactedHits, redactedPromptHits returned early
  on n == 0). A vendor that holds the conversation (Codex's compacted
  history, a server-side session) answers with placeholders of earlier
  turns while the request carries no value, so they went back as
  written. Most likely the reporter's path. Now every reply on a masked
  route is read.
- Responses streams: each event's random "obfuscation" string could end
  like a placeholder start and take the stream's one held tail from its
  delta, so the placeholder after 、 stayed (4 of 140 text runs, 6 of
  tool args runs). The writer now holds a tail per string path and
  never for obfuscation or kept keys.
- Kept keys (name, type, data, status...) were never restored in a
  stream, so a Gemini functionCall args object {"name":"{{PERSON_…}}"}
  kept it. Every string is restored now but signatures, data: URLs and
  opaque blobs (sealedText).
- A whole body skipped restoring unless it held "{{", so a model's
  PERSON_kb32hzkg or {PERSON_kb32hzkg} stayed; heldIn looks for any held
  placeholder's hash.
- makeRoom let a random half of 200k values go though its comment said
  the oldest; now the least recently used half (touch on every mask and
  hit), so a value just masked is never the one let go.
- A binary reply (audio/, image/, video/, octet-stream, pdf, zip) goes
  through as it comes instead of being held.

Not fixed by design: values are in memory only (README's privacy
promise, TestNoValueOnDisk), so a placeholder from before a restart that
only the vendor still holds can't be restored. Masking switched off
later also restores nothing.

Tests (all red on d159314e3's code, green now, run on mote):
TestReporterTableRestoredOnEveryStream (responses-text 4, responses-tool
6 fails before), TestPlaceholdersRestoredWhereverTheySit,
TestFullValuesKeepTheNewest (499 of 1000 newest lost before),
TestBinaryReplyIsNotHeld, TestReplyToAnUnmaskedTurnIsRestored (gateway,
real stack: first turn masks an email, second masks nothing and the
fake vendor answers with the first turn's placeholder).

Run: gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... on mote: clean. The full go test -tags nogui
-timeout 45m ./... on mote, one step before this head, found a nil
masker in redactedPromptHits with masking off (image drawing:
TestAntigravityDrawingOutOfQuotaInsideTheReplyGoesOn, internal/cli's
image MCP); fixed here (m == nil returns as before). At this head
internal/redact and internal/gateway pass on Linux (wsl-run, 594s).
That run's other reds are outside this change: internal/gui
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll) and
TestColdTurnsTaken, internal/proc TestNoCommandBypassesProc
(internal/claudetui/child_unix.go uses os/exec). The full suite runs
again at the pushed head after the tag.
Not tried: a real Codex compaction round trip with a real account, and
the reporter's agent (unknown).
2026-10-31 11:23:53 +08:00

20 lines
546 B
Go

package redact
// ModelKinds is modelKinds, for the evaluation in package redact_test,
// which reads the real model through internal/pii (eval_test.go).
var ModelKinds = modelKinds
// Forget lets go of every value masked so far, so that what the
// evaluation scores is what its texts make masked, not what the tests
// before it masked and left known.
func Forget() {
mu.Lock()
values = map[string]string{}
used = map[string]uint64{}
shapes = map[string]string{}
scores = map[string]float64{}
reindexKnown()
mu.Unlock()
resetSent()
}