File size: 2,368 Bytes
6c62075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import type { ModelLoadProgress, ModelShardProgress } from '../../lib/contracts';
import { ComposerActivity, describeLoadProgress, overallLoadProgress } from './ComposerActivity';

function shard(index: number, state: ModelShardProgress['state']): ModelShardProgress {
  return {
    index,
    path: `shard-${index + 1}.gguf`,
    loadedBytes: state === 'queued' ? 0 : 100,
    verifiedBytes: state === 'complete' || state === 'cached' ? 100 : 0,
    totalBytes: 100,
    state,
  };
}

function progress(overrides: Partial<ModelLoadProgress> = {}): ModelLoadProgress {
  return {
    modelId: 'bonsai-27b',
    modelLabel: 'Bonsai 27B',
    stage: 'download',
    stageProgress: 0.5,
    downloadedBytes: 400,
    totalBytes: 800,
    residentBytes: 0,
    nativeStage: null,
    shards: [
      shard(0, 'complete'),
      shard(1, 'downloading'),
      ...Array.from({ length: 6 }, (_, index) => shard(index + 2, 'queued')),
    ],
    ...overrides,
  };
}

describe('ComposerActivity', () => {
  it('combines the load pipeline into one weighted overall progress value', () => {
    expect(overallLoadProgress(progress())).toBeCloseTo(0.39625);
    expect(overallLoadProgress(progress({ stage: 'cache', stageProgress: 0.2 }))).toBeCloseTo(0.39625);
    expect(overallLoadProgress(progress({ stage: 'load', stageProgress: 0.5 }))).toBeCloseTo(0.95);
    expect(overallLoadProgress(progress({ stage: 'ready' }))).toBe(1);
  });

  it('annotates the active shard and total ready shard count', () => {
    expect(describeLoadProgress(progress())).toEqual({
      label: 'Downloading shard 2 of 8',
      detail: '1 of 8 shards ready · 400 B / 800 B',
    });
  });

  it('renders exactly one progressbar during load and disappears afterwards', () => {
    const loading = renderToStaticMarkup(
      <ComposerActivity modelId="bonsai-27b" streamState="loading" progress={progress()} />,
    );
    expect(loading.match(/role="progressbar"/g)).toHaveLength(1);
    expect(loading).not.toContain('Model transfer');
    expect(loading).not.toContain('Load pipeline');

    const ready = renderToStaticMarkup(
      <ComposerActivity modelId="bonsai-27b" streamState="complete" progress={progress({ stage: 'ready' })} />,
    );
    expect(ready).toBe('');
  });
});