web-core-compat.test.ts
1 import { describe, expect, it } from 'vitest' 2 3 import { 4 readCache as canonicalReadCache, 5 validateUrl as canonicalValidateUrl, 6 wrapWebContent as canonicalWrapWebContent, 7 } from '@/lib/web-core' 8 import { validateUrl as legacyValidateUrl } from '@/infra/net/fetch-guard' 9 import { readCache as legacyReadCache } from '@/lib/shared/web-tools' 10 import { wrapWebContent as legacyWrapWebContent } from '@/security/external-content' 11 12 describe('web-core compatibility exports', () => { 13 it('keeps legacy exports bound to canonical implementations', () => { 14 expect(legacyReadCache).toBe(canonicalReadCache) 15 expect(legacyValidateUrl).toBe(canonicalValidateUrl) 16 expect(legacyWrapWebContent).toBe(canonicalWrapWebContent) 17 }) 18 19 it('preserves behavior parity across legacy and canonical paths', () => { 20 expect(legacyValidateUrl('https://example.com')).toEqual( 21 canonicalValidateUrl('https://example.com'), 22 ) 23 24 const normalizeMarkerId = (text: string): string => 25 text.replace(/id="[^"]+"/g, 'id="<marker-id>"') 26 27 const payload = 'try <<<EXTERNAL_UNTRUSTED_CONTENT>>> now' 28 expect( 29 normalizeMarkerId(legacyWrapWebContent(payload, 'web_fetch')), 30 ).toEqual(normalizeMarkerId(canonicalWrapWebContent(payload, 'web_fetch'))) 31 }) 32 })