import { describe, expect, it } from 'vitest'; import { findManifestModel, orderedShardUrls, parseModelManifestV2, type ModelTierId, } from './manifest'; const REVISION = '0123456789abcdef0123456789abcdef01234567'; const SHA = 'a'.repeat(64); function rawModel(id: ModelTierId) { const is27b = id === '27b'; const files = is27b ? [ { path: '27b/Bonsai-00001-of-00002.gguf', bytes: 60, sha256: SHA }, { path: '27b/Bonsai-00002-of-00002.gguf', bytes: 40, sha256: SHA }, ] : [{ path: `${id}/Bonsai.gguf`, bytes: 100, sha256: SHA }]; return { id, displayName: `Bonsai ${id}`, architecture: is27b ? 'qwen35' : 'qwen3', source: { repo: 'prism-ml/Bonsai', revision: REVISION, file: 'Bonsai.gguf', bytes: 100, sha256: SHA, }, files, downloadBytes: 100, contextLength: 32768, defaultContext: 4096, cpuFallback: !is27b, largestTensorBytes: 64, requiredLimits: { maxStorageBufferBindingSize: 64 }, chatTemplate: { bytes: 10, sha256: SHA, markers: { think: true, toolCall: true, toolResponse: true }, }, hybridDimensions: {}, nextNTensorCount: 0, runtimePolicy: { flashAttention: false, tokenEmbeddingOnWebGPU: true, requireSingleWebGPUGraph: is27b, }, }; } function rawManifest() { return { schemaVersion: 2, repository: { id: 'WaveCut/Bonsai-web-GGUF', revision: REVISION }, models: (['1_7b', '4b', '8b', '27b'] as const).map(rawModel), }; } describe('model manifest v2', () => { it('preserves explicit shard order and derives commit-pinned URLs', () => { const manifest = parseModelManifestV2(rawManifest()); const model = findManifestModel(manifest, '27b'); expect(orderedShardUrls(manifest, model)).toEqual([ `https://huggingface.co/WaveCut/Bonsai-web-GGUF/resolve/${REVISION}/27b/Bonsai-00001-of-00002.gguf`, `https://huggingface.co/WaveCut/Bonsai-web-GGUF/resolve/${REVISION}/27b/Bonsai-00002-of-00002.gguf`, ]); }); it('rejects out-of-order shards', () => { const value = rawManifest(); const model = value.models.find((candidate) => candidate.id === '27b')!; model.files.reverse(); expect(() => parseModelManifestV2(value)).toThrow(/out of order/); }); it('rejects an unpinned repository when a shard has no explicit URL', () => { const manifest = parseModelManifestV2(rawManifest()); manifest.repository.revision = null; expect(() => orderedShardUrls(manifest, findManifestModel(manifest, '1_7b'))).toThrow( /repository\.revision is required/, ); }); });