import { describe, it, expect } from 'vitest' import { AssetManager } from '@/lib/assets/assetManager' import { buildAssetsMetadata, type AssetMetaItem } from '@/lib/exporter/assets.meta' function u8(n: number): Uint8Array { const arr = new Uint8Array(n) for (let i = 0; i < n; i++) arr[i] = (i * 17) & 0xff return arr } describe('referencedAt is populated when rewriteUrl is used', () => { it('marks originalName as referenced via local:', async () => { const am = new AssetManager({ maxBytes: 1024 * 1024, allowedExts: ['png'] }) await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(16) }) // use rewriteUrl to simulate page referencing the local asset const rewritten = am.rewriteUrl('local:hero.png') expect(rewritten).toMatch(/assets\//) const metaBytes = buildAssetsMetadata(am) const obj = JSON.parse(new TextDecoder().decode(metaBytes)) as { assets: AssetMetaItem[] } expect(obj.assets.length).toBe(1) const a = obj.assets[0] expect(Array.isArray(a.referencedAt)).toBe(true) expect(a.referencedAt).toContain('local:hero.png') }) })