feat: verifyIntegrity CLI 래퍼 추가 및 문서화 (TDD)
- verify.cli.ts/verify.cli.test.ts 추가 - README 사용법/종료코드/CI 가이드 문서화 - 전체 테스트 그린 유지
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { verifyCli } from '@/lib/exporter/verify.cli'
|
||||
|
||||
// helpers to build base64 from string
|
||||
function b64(s: string) {
|
||||
if (typeof Buffer !== 'undefined') return Buffer.from(s, 'utf-8').toString('base64')
|
||||
throw new Error('Buffer not available')
|
||||
}
|
||||
|
||||
describe('verify.cli', () => {
|
||||
const EMPTY_SHA256_B64 = '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='
|
||||
|
||||
it('returns 0 and logs summary when ok', async () => {
|
||||
// empty entries integrity index; bundleHash = sha256("") in base64
|
||||
const extras = {
|
||||
'assets.integrity.index.json': b64(JSON.stringify({ entries: [], bundleHash: 'sha256-' + EMPTY_SHA256_B64 }))
|
||||
}
|
||||
const assets = {}
|
||||
const extrasJson = JSON.stringify(extras)
|
||||
const assetsJson = JSON.stringify(assets)
|
||||
|
||||
const paths: Record<string, string> = {
|
||||
'/tmp/extras.ok.json': extrasJson,
|
||||
'/tmp/assets.ok.json': assetsJson,
|
||||
}
|
||||
const logs: string[] = []
|
||||
const readText = async (p: string) => {
|
||||
const v = paths[p]
|
||||
if (v == null) throw new Error('no such file: ' + p)
|
||||
return v
|
||||
}
|
||||
const code = await verifyCli(['--extras', '/tmp/extras.ok.json', '--assets', '/tmp/assets.ok.json'], readText, (s: string) => logs.push(s))
|
||||
expect(code).toBe(0)
|
||||
expect(logs.join('\n')).toMatch(/"ok": true/)
|
||||
expect(logs.join('\n')).toMatch(/"total": 0/)
|
||||
})
|
||||
|
||||
it('returns 1 and logs errors when invalid JSON', async () => {
|
||||
const paths: Record<string, string> = {
|
||||
'/tmp/extras.bad.json': JSON.stringify({ 'assets.integrity.index.json': 'not-base64' }),
|
||||
'/tmp/assets.empty.json': JSON.stringify({}),
|
||||
}
|
||||
const logs: string[] = []
|
||||
const readText = async (p: string) => {
|
||||
const v = paths[p]
|
||||
if (v == null) throw new Error('no such file: ' + p)
|
||||
return v
|
||||
}
|
||||
const code = await verifyCli(['--extras', '/tmp/extras.bad.json', '--assets', '/tmp/assets.empty.json'], readText, (s: string) => logs.push(s))
|
||||
expect(code).toBe(1)
|
||||
expect(logs.join('\n')).toMatch(/"ok": false/)
|
||||
expect(logs.join('\n')).toMatch(/Invalid assets\.integrity\.index\.json JSON|Missing assets\.integrity\.index\.json/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user