import { describe, it, expect } from 'vitest' import { AssetManager } from '@/lib/assets/assetManager' import { buildAssetsIndex } from '@/lib/exporter/assets.index' import { buildAssetsMetadata } from '@/lib/exporter/assets.meta' function u8(n: number): Uint8Array { const a = new Uint8Array(n); for (let i=0;i { it.each([ { mode: 'flat' as const }, { mode: 'grouped' as const }, ])('ensures index paths exist in assets.json zipPath with correct group ($mode)', async ({ mode }) => { const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png','woff2','txt','jpg'], pathStrategy: mode }) await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) }) await am.add({ name: 'thumb.jpg', type: 'image/jpeg', bytes: u8(11) }) await am.add({ name: 'main.woff2', type: 'font/woff2', bytes: u8(12) }) await am.add({ name: 'readme.txt', type: 'text/plain', bytes: u8(1) }) const indexBytes = buildAssetsIndex(am) const metaBytes = buildAssetsMetadata(am) const index = JSON.parse(new TextDecoder().decode(indexBytes)) as IndexShape const meta = JSON.parse(new TextDecoder().decode(metaBytes)) as { assets: Array<{ zipPath: string; group: 'images'|'fonts'|'other' }> } const metaByPath = new Map(meta.assets.map(a => [a.zipPath, a.group])) for (const p of index.images) { expect(metaByPath.has(p)).toBe(true) expect(metaByPath.get(p)).toBe('images') } for (const p of index.fonts) { expect(metaByPath.has(p)).toBe(true) expect(metaByPath.get(p)).toBe('fonts') } for (const p of index.other) { expect(metaByPath.has(p)).toBe(true) expect(metaByPath.get(p)).toBe('other') } // Optional: ensure no extra paths exist in meta that are missing in index groups const indexSet = new Set([...index.images, ...index.fonts, ...index.other]) for (const a of meta.assets) { expect(indexSet.has(a.zipPath)).toBe(true) } }) })