Spaces:
Running
Running
| import { describe, expect, it } from 'vitest'; | |
| import releaseManifest from '../../public/manifest/models.json'; | |
| import { EngineClientError } from '../engine'; | |
| import { | |
| DEFAULT_CONTEXT_SIZE, | |
| DEFAULT_MAX_TOKENS, | |
| DEFAULT_MODEL_ID, | |
| modelArchitectureLabel, | |
| publishBackendReport, | |
| reconcileCompletionTokens, | |
| reconcileTotalTokens, | |
| reportsModelWeightProgress, | |
| requiresModelReload, | |
| } from './App'; | |
| function engineError(code: string): EngineClientError { | |
| return new EngineClientError({ code, message: code }); | |
| } | |
| describe('App model invalidation policy', () => { | |
| it.each([ | |
| 'WEBGPU_DEVICE_LOST', | |
| 'ENGINE_WORKER_FAILED', | |
| 'MODEL_NOT_LOADED', | |
| ])('requires an explicit reload after %s', (code) => { | |
| expect(requiresModelReload(engineError(code))).toBe(true); | |
| }); | |
| it('keeps an otherwise healthy loaded model after a responsive abort', () => { | |
| expect(requiresModelReload(engineError('ABORTED'))).toBe(false); | |
| }); | |
| }); | |
| describe('App release defaults', () => { | |
| it('opens on the flagship tier required by the product contract', () => { | |
| expect(DEFAULT_MODEL_ID).toBe('bonsai-27b'); | |
| }); | |
| it('shows manifest architecture instead of invented model aliases', () => { | |
| expect(modelArchitectureLabel('qwen3')).toBe('Qwen3 dense'); | |
| expect(modelArchitectureLabel('qwen35')).toBe('Qwen3.5 hybrid'); | |
| }); | |
| it('uses one 4K ceiling for context allocation and completion requests', () => { | |
| expect(DEFAULT_CONTEXT_SIZE).toBe(4096); | |
| expect(DEFAULT_MAX_TOKENS).toBe(4096); | |
| expect(DEFAULT_CONTEXT_SIZE).toBe(DEFAULT_MAX_TOKENS); | |
| expect(releaseManifest.models.find((model) => model.id === '27b')?.defaultContext) | |
| .toBe(DEFAULT_CONTEXT_SIZE); | |
| }); | |
| }); | |
| describe('App model-load progress', () => { | |
| it('does not turn pinned manifest metadata reads into model-weight download state', () => { | |
| expect(reportsModelWeightProgress('manifest')).toBe(false); | |
| expect(reportsModelWeightProgress('download')).toBe(true); | |
| expect(reportsModelWeightProgress('load')).toBe(true); | |
| }); | |
| }); | |
| describe('App streamed completion telemetry', () => { | |
| it('uses observed stream events when final engine usage is incomplete', () => { | |
| expect(reconcileCompletionTokens(5, 64)).toBe(64); | |
| }); | |
| it('keeps the engine count when one stream event contains multiple tokens', () => { | |
| expect(reconcileCompletionTokens(12, 8)).toBe(12); | |
| }); | |
| it('fails closed to the observed count for invalid engine usage', () => { | |
| expect(reconcileCompletionTokens(Number.NaN, 7)).toBe(7); | |
| }); | |
| it('keeps context usage consistent with a reconciled completion count', () => { | |
| expect(reconcileTotalTokens(5, 5, 64)).toBe(69); | |
| expect(reconcileTotalTokens(80, 5, 64)).toBe(80); | |
| }); | |
| }); | |
| describe('App backend diagnostics', () => { | |
| it('publishes the complete backend report for the browser gate without rendering it', () => { | |
| const report = { | |
| backends: ['WebGPU'], | |
| nGraphSplits: 1, | |
| opsOnCpu: 0, | |
| layersGpu: { offloaded: 65, total: 65 }, | |
| flashAttention: false, | |
| cacheTypeK: 'f16', | |
| cacheTypeV: 'f16', | |
| webgpuKvBufferBytes: 1024, | |
| webgpuTrace: ['@@WEBGPU_TRACE@@completion_end id=1 steps=65 error=0'], | |
| }; | |
| publishBackendReport(report); | |
| expect(globalThis.__bonsaiBackendReport).toEqual(report); | |
| delete globalThis.__bonsaiBackendReport; | |
| }); | |
| }); | |