|
| 1 | +import { describe, it, expect, beforeAll } from "vitest"; |
| 2 | +import { PII } from "@elizaos/core"; |
| 3 | + |
| 4 | +describe.skip("PII redaction", () => { |
| 5 | + let pii: PII; |
| 6 | + |
| 7 | + beforeAll(async () => { |
| 8 | + process.env.PII_MODEL_ID = process.env.PII_MODEL_ID || "jammmmmm/pii"; |
| 9 | + process.env.PII_AGGREGATION_STRATEGY = |
| 10 | + process.env.PII_AGGREGATION_STRATEGY || "simple"; |
| 11 | + process.env.PII_DEBUG = "true"; |
| 12 | + pii = await PII.create(); |
| 13 | + }, 120_000); |
| 14 | + |
| 15 | + async function expectRedacted(input: string, mustNotContain: string[]) { |
| 16 | + const result = await pii.redact(input); |
| 17 | + expect(result).not.toBeNull(); |
| 18 | + if (!result) return; |
| 19 | + expect(result.entities.length).toBeGreaterThan(0); |
| 20 | + for (const s of mustNotContain) { |
| 21 | + expect(result.redactedText).not.toContain(s); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + it("redacts email addresses", async () => { |
| 26 | + const input = "Contact me at alice.smith@example.org for details."; |
| 27 | + await expectRedacted(input, ["alice.smith", "example.org"]); |
| 28 | + }, 120_000); |
| 29 | + |
| 30 | + it("redacts names", async () => { |
| 31 | + const input = "My name is John Doe."; |
| 32 | + await expectRedacted(input, ["John", "Doe"]); |
| 33 | + }, 120_000); |
| 34 | + |
| 35 | + it("redacts phone numbers", async () => { |
| 36 | + const input = "Call me at +1 (415) 555-2671 tomorrow."; |
| 37 | + await expectRedacted(input, ["415", "555-2671"]); |
| 38 | + }, 120_000); |
| 39 | + |
| 40 | + it("redacts crypto wallet addresses (BTC)", async () => { |
| 41 | + const input = |
| 42 | + "Donate BTC to bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080"; |
| 43 | + await expectRedacted(input, [ |
| 44 | + "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080", |
| 45 | + ]); |
| 46 | + }, 120_000); |
| 47 | + |
| 48 | + it("redacts crypto wallet addresses (ETH)", async () => { |
| 49 | + const input = |
| 50 | + "Send ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e please."; |
| 51 | + await expectRedacted(input, [ |
| 52 | + "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", |
| 53 | + ]); |
| 54 | + }, 120_000); |
| 55 | + |
| 56 | + it("redacts private keys (hex)", async () => { |
| 57 | + const key = |
| 58 | + "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce036f8e6f2b59e6fc9b8a7"; |
| 59 | + const input = `Never share your private key: ${key}`; |
| 60 | + await expectRedacted(input, [key]); |
| 61 | + }, 120_000); |
| 62 | + |
| 63 | + it("redacts home addresses", async () => { |
| 64 | + const input = |
| 65 | + "Ship it to 1600 Amphitheatre Parkway, Mountain View, CA 94043."; |
| 66 | + await expectRedacted(input, ["1600 Amphitheatre", "94043"]); |
| 67 | + }, 120_000); |
| 68 | +}); |
0 commit comments