Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

2.5 KB
Raw Blame
import type { StarterModel, StarterModelBundle } from '@features/models/core/types';

import { describe, expect, it } from 'vitest';

import type { StarterInstallSource } from './starterModelInstallSources';

import { getStarterBundleInstallSources, getStarterModelInstallSources } from './starterModelInstallSources';

const model = (source: string, overrides: Partial<StarterModel> = {}): StarterModel => ({
  base: 'sdxl',
  description: source,
  is_installed: false,
  name: source,
  source,
  type: 'main',
  ...overrides,
});

const sourcesOf = (entries: StarterInstallSource[]): string[] => entries.map((entry) => entry.source);

describe('starter model install sources', () => {
  it('queues uninstalled dependencies before the model', () => {
    const sources = getStarterModelInstallSources(
      model('main', { dependencies: [model('vae'), model('encoder', { is_installed: true })] })
    );

    expect(sourcesOf(sources)).toEqual(['vae', 'main']);
  });

  it('registers each entry with its own curated config', () => {
    const sources = getStarterModelInstallSources(
      model('main', {
        base: 'flux',
        source_urls: ['https://example.com/main'],
        dependencies: [model('vae', { base: 'sdxl', type: 'vae', source_urls: ['https://example.com/vae'] })],
      })
    );

    expect(sources).toEqual([
      {
        config: {
          base: 'sdxl',
          description: 'vae',
          name: 'vae',
          source_urls: ['https://example.com/vae'],
          type: 'vae',
        },
        source: 'vae',
      },
      {
        config: {
          base: 'flux',
          description: 'main',
          name: 'main',
          source_urls: ['https://example.com/main'],
          type: 'main',
        },
        source: 'main',
      },
    ]);
  });

  it('skips dependency sources already visible in the opened bundle', () => {
    const sources = getStarterModelInstallSources(model('main', { dependencies: [model('vae'), model('encoder')] }), {
      dependencySourcesToSkip: new Set(['vae']),
    });

    expect(sourcesOf(sources)).toEqual(['encoder', 'main']);
  });

  it('deduplicates sources across bundle models', () => {
    const bundle: StarterModelBundle = {
      models: [
        model('main-a', { dependencies: [model('shared-vae')] }),
        model('main-b', { dependencies: [model('shared-vae')] }),
      ],
      name: 'Bundle',
    };

    expect(sourcesOf(getStarterBundleInstallSources(bundle))).toEqual(['shared-vae', 'main-a', 'main-b']);
  });
});