Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

2.8 KB
Raw Blame
package redact

import (
	"strings"
	"testing"
)

// An image a Mac saved at twice its size is named like an address
// (…@2x.jpg), and was masked as one, so Pi could no longer read the file
// (#3029, the reporter's path). A file's name stays; an address beside it
// is still masked.
func TestFileNameIsNoEmail(t *testing.T) {
	o := Options{Secrets: true, Personal: true}
	for _, s := range []string{
		"/Users/vdxz/Pictures/[email protected]",
		"read assets/[email protected] and [email protected]",
		"open ~/Desktop/[email protected]",
	} {
		if out, n := Mask(s, o); n != 0 || out != s {
			t.Errorf("%q masked: %q", s, out)
		}
	}
	s := `{"role":"user","content":"look at /Users/vdxz/Pictures/[email protected] and mail [email protected]"}`
	out, n := MaskJSON([]byte(s), o)
	if n != 1 || !strings.Contains(string(out), "[email protected]") || strings.Contains(string(out), "[email protected]") {
		t.Fatalf("%d masked: %s", n, out)
	}

	// nor does the local model's EMAIL take one
	f := &fakeModel{values: map[string]string{"[email protected]": "private_email"}}
	if out, n := Mask("/Users/vdxz/Pictures/[email protected]", Options{Personal: true, Model: f.find}); n != 0 {
		t.Fatalf("model's: %d masked: %q", n, out)
	}
}

// Image names as apps ship them (willz on Discord: [email protected]), other
// files named so ([email protected]), and a scale before an extension that is a
// domain too ([email protected]) are no address either. An address on a real
// domain still is: .ai, .io, and .zip, .mov and .md with no scale.
func TestMoreFileNamesAreNoEmail(t *testing.T) {
	o := Options{Secrets: true, Personal: true}
	for _, s := range []string{
		"[email protected]", "Default@2x~iphone.png", "[email protected]", "[email protected]",
		"[email protected]", "Assets/[email protected]", "[email protected]",
		"[email protected]", "[email protected]", "[email protected]", "[email protected]",
		`"src": "img/[email protected]"`, "![shot](./docs/[email protected])",
	} {
		in := "see " + s + " here"
		if out, n := Mask(in, o); out != in || n != 0 {
			t.Errorf("%q: %d masked: %q", s, n, out)
		}
	}
	// as a request carries them: a tool's result listing an asset folder
	body := `{"messages":[{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_01","content":"[email protected]\[email protected]\[email protected]\nowner: [email protected]"}]}]}`
	got, n := MaskJSON([]byte(body), o)
	if n != 1 || !strings.Contains(string(got), `[email protected]\[email protected]\[email protected]\nowner: {{EMAIL_`) {
		t.Errorf("request: %d masked: %s", n, got)
	}
	for _, s := range []string{
		"[email protected]", "[email protected]", "[email protected]", "[email protected]",
		"[email protected]", "[email protected]", "[email protected]", "[email protected]",
	} {
		in := "mail " + s + " now"
		if out, n := Mask(in, o); n != 1 || strings.Contains(unmarked(out), s) {
			t.Errorf("%q: %d masked: %q", s, n, out)
		}
	}
}