4616308402
Used by Stop-hook before JSONL write. 6 Vitest cases including idempotence and recursive object sanitization. Per Pravila §16.2 + ADR-011 + spec §5.4. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { sanitize } from './observer-pii-filter.mjs';
|
|
|
|
describe('observer-pii-filter sanitize', () => {
|
|
it('masks Russian phone numbers', () => {
|
|
const input = 'Контакт: +79991234567 — позвонить';
|
|
expect(sanitize(input)).toBe('Контакт: +7XXXXXXXXXX — позвонить');
|
|
});
|
|
|
|
it('masks email addresses', () => {
|
|
const input = 'Mail: kpd9363@gmail.com';
|
|
expect(sanitize(input)).toBe('Mail: ***@***');
|
|
});
|
|
|
|
it('masks Sentry-style tokens', () => {
|
|
const input = 'token sntrys_abc123def456ghi789';
|
|
expect(sanitize(input)).toContain('[REDACTED');
|
|
expect(sanitize(input)).not.toContain('sntrys_abc123def456ghi789');
|
|
});
|
|
|
|
it('is idempotent on already-sanitized strings', () => {
|
|
const sanitized = 'Контакт: +7XXXXXXXXXX, ***@***';
|
|
expect(sanitize(sanitized)).toBe(sanitized);
|
|
});
|
|
|
|
it('handles empty string', () => {
|
|
expect(sanitize('')).toBe('');
|
|
});
|
|
|
|
it('handles object input by sanitizing string fields recursively', () => {
|
|
const input = { task_id: 'x', note: 'call +79991234567' };
|
|
const out = sanitize(input);
|
|
expect(out.note).toBe('call +7XXXXXXXXXX');
|
|
expect(out.task_id).toBe('x');
|
|
});
|
|
});
|