Skip to content

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

2.5 KB
Raw Blame
package redact

import (
	"strings"
	"testing"
)

// What follows the @ of a decorator or a module's attribute (pytest.fixture)
// ends in a word no registry has, and an agent's own files (AGENTS.md)
// end in .md: neither was an address, and both were masked (ydzh on
// Discord). Addresses on real domains, a company's own (.local, .corp)
// and the .md of a domain that isn't such a file are still masked.
func TestEmailNeedsAMailDomain(t *testing.T) {
	o := Options{Secrets: true, Personal: true}
	for _, s := range []string{
		"[email protected]", "follow [email protected]", "see [email protected] and [email protected]",
		"[email protected]", "[email protected]", "[email protected]",
		"[email protected]", "[email protected]",
	} {
		in := "look at " + s + " now"
		if out, n := Mask(in, o); n != 0 || out != in {
			t.Errorf("%q: %d masked: %q", s, n, out)
		}
	}
	for _, s := range []string{
		"[email protected]", "[email protected]", "[email protected]", "[email protected]",
		"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]",
	} {
		in := "mail " + s + " today"
		if out, n := Mask(in, o); n != 1 || strings.Contains(out, s) {
			t.Errorf("%q: %d masked: %q", s, n, out)
		}
	}
	f := &fakeModel{values: map[string]string{"[email protected]": "private_email", "[email protected]": "private_email"}}
	for _, s := range []string{"[email protected]", "[email protected]"} {
		if out, n := Mask(s, Options{Personal: true, Model: f.find}); n != 0 {
			t.Errorf("model's %q: %d masked: %q", s, n, out)
		}
	}
}

// An address that ends a sentence is masked: the dot after it was a
// bound character, so "The user's email address is [email protected]." (Claude
// Code's own line in every request) and "write to me at [email protected]."
// went to the vendor as written, the rules masking nothing. A dot that
// makes the address part of a longer name still keeps it as it is.
func TestEmailBeforeAFullStop(t *testing.T) {
	o := Options{Secrets: true, Personal: true}
	for _, in := range []string{
		"The user's email address is [email protected]. Use it only to identify the user.",
		"The user's email address is [email protected].",
		"write to me at [email protected].",
		"ask [email protected]... she knows",
		`{"text":"mail [email protected].\nthanks"}`,
	} {
		if out, n := Mask(in, o); n != 1 || strings.Contains(out, "@") {
			t.Errorf("%q: %d masked: %q", in, n, out)
		}
	}
	for _, in := range []string{
		"[email protected] is a version",
		"[email protected]_y",
	} {
		if out, n := Mask(in, o); n != 0 {
			t.Errorf("%q: %d masked: %q", in, n, out)
		}
	}
}