Option2 무결성 강화: integrity index 추가, 인덱스 정렬/교차 검증, referencedAt 매트릭스, README 문서화 (TDD)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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<n;i++) a[i]=i&0xff; return a }
|
||||
|
||||
type IndexShape = { images: string[]; fonts: string[]; other: string[] }
|
||||
|
||||
describe('assets.index.json ↔ assets.json consistency', () => {
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user