// @vitest-environment jsdom import { afterEach, describe, expect, it } from 'vitest'; import { hasIncludeAnnotation, hasRedactAnnotation, heuristicRedactKind, } from '../heuristics'; afterEach(() => { document.body.innerHTML = ''; }); function el(html: string): HTMLElement { document.body.innerHTML = html; return document.body.firstElementChild as HTMLElement; } describe('heuristicRedactKind', () => { it('flags a password input', () => { expect(heuristicRedactKind(el(''))).toBe( 'password', ); }); it('flags fields named like secrets', () => { expect(heuristicRedactKind(el(''))).toBe( 'sensitive-name', ); expect(heuristicRedactKind(el(''))).toBe( 'sensitive-name', ); expect(heuristicRedactKind(el(''))).toBe( 'sensitive-name', ); }); it('flags sensitive autocomplete values', () => { expect( heuristicRedactKind(el('')), ).toBe('autocomplete'); expect( heuristicRedactKind(el('')), ).toBe('autocomplete'); }); it('does not flag a normal text field', () => { expect(heuristicRedactKind(el(''))).toBeNull(); expect(heuristicRedactKind(el(''))).toBeNull(); }); }); describe('hasRedactAnnotation', () => { it('detects data-ai-redact on the element', () => { expect(hasRedactAnnotation(el('
'))).toBe(true); }); it('detects data-ai-redact on an ancestor', () => { document.body.innerHTML = `