Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

4.8 KB
Raw Blame
import { beforeEach, describe, expect, it } from 'vitest';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { awaitEnabled } from '../test/enabledBarrier.js';
import { lastEventSource } from '../test/mockEventSource';

import {
  loadVideoGenPage,
  renderVideoGenPage,
  resetVideoGenMockState,
  state,
  videoGenModel,
  videoGenModelContext,
  videoGenStatus,
  videoGenTermsGate,
} from '../test/videoGenPageMocks.jsx';

const TERMS_ONE = 'minimax-h3-license-v1';
const TERMS_TWO = 'minimax-h3-license-v2';
const H3_ONE = videoGenModel('h3-one', { termsGate: videoGenTermsGate(TERMS_ONE) });
const H3_TWO = videoGenModel('h3-two', { termsGate: videoGenTermsGate(TERMS_TWO) });

await loadVideoGenPage();

const prompt = () => screen.getByLabelText('Prompt');
const generate = () => screen.getByRole('button', { name: /^Generate$/ });
const enqueue = () => screen.getByRole('button', { name: /Add to queue/ });

describe('VideoGen MiniMax H3 orchestration', () => {
  beforeEach(() => {
    localStorage.clear();
    resetVideoGenMockState();
    state.modelStatuses = {
      [H3_ONE.id]: { id: H3_ONE.id, repo: H3_ONE.repo, cached: true, sizeBytes: 100 },
      [H3_TWO.id]: { id: H3_TWO.id, repo: H3_TWO.repo, cached: true, sizeBytes: 100 },
    };
    state.generateVideo.mockResolvedValue({ jobId: 'job-1' });
    state.repair.mockResolvedValue({ ok: true });
    state.getVideoGenStatus.mockResolvedValue(videoGenStatus([H3_ONE, H3_TWO]));
    state.getVideoGenModelContext.mockResolvedValue(videoGenModelContext([H3_ONE, H3_TWO]));
  });

  it('lets H3 generate and queue with no eligibility checkbox', async () => {
    await renderVideoGenPage();

    await waitFor(() => expect(screen.getByLabelText('Model')).toHaveValue(H3_ONE.id));
    expect(screen.queryByRole('checkbox', { name: /I am eligible/ })).toBeNull();
    expect(screen.queryByText(/eligibility and terms/i)).toBeNull();
    fireEvent.change(prompt(), { target: { value: 'a fox watches the rain' } });

    await awaitEnabled(enqueue);
    fireEvent.click(enqueue());
    await waitFor(() => expect(state.generateVideo).toHaveBeenCalledWith(expect.objectContaining({
      modelId: H3_ONE.id,
    })));
    expect(state.generateVideo.mock.calls[0][0]).not.toHaveProperty('termsAcceptance');

    await act(async () => {
      fireEvent.submit(prompt().closest('form'));
    });
    await waitFor(() => expect(state.generateVideo).toHaveBeenCalledWith(expect.objectContaining({
      modelId: H3_ONE.id,
    })));
    expect(state.generateVideo.mock.calls[0][0]).not.toHaveProperty('termsAcceptance');

    // Finish the render so the page returns to idle and Generate is offered again.
    await waitFor(() => expect(lastEventSource()).toBeTruthy());
    await act(async () => { lastEventSource().emit({ type: 'complete', result: { filename: 'example.mp4' } }); });

    fireEvent.change(screen.getByLabelText('Model'), { target: { value: H3_TWO.id } });
    await waitFor(() => expect(screen.getByLabelText('Model')).toHaveValue(H3_TWO.id));
    expect(generate()).toBeEnabled();
    expect(enqueue()).toBeEnabled();
    expect(screen.queryByRole('checkbox', { name: /I am eligible/ })).toBeNull();
  });

  it('offers download without an eligibility acknowledgement', async () => {
    state.modelStatuses[H3_ONE.id] = { id: H3_ONE.id, repo: H3_ONE.repo, cached: false, sizeBytes: 0 };
    await renderVideoGenPage();

    const download = await screen.findByRole('button', { name: /Download/ });
    expect(download).toBeEnabled();
    fireEvent.click(download);
    expect(state.start).toHaveBeenCalledWith(H3_ONE.id);
  });

  it('offers integrity repair without an eligibility acknowledgement', async () => {
    state.modelStatuses[H3_ONE.id] = {
      id: H3_ONE.id,
      repo: H3_ONE.repo,
      cached: true,
      sizeBytes: 100,
      integrity: { status: 'bad', badFiles: [{ name: 'model.safetensors' }] },
    };
    await renderVideoGenPage();

    const repair = await screen.findByRole('button', { name: /Repair model/ });
    expect(repair).toBeEnabled();
    fireEvent.click(repair);
    expect(state.repair).toHaveBeenCalledWith(H3_ONE.id);
  });

  it('refreshes the model capability payload after runtime setup completes', async () => {
    await renderVideoGenPage();
    await waitFor(() => expect(screen.getByLabelText('Model')).toHaveValue(H3_ONE.id));
    const beforeStatus = state.getVideoGenStatus.mock.calls.length;
    const beforeContext = state.getVideoGenModelContext.mock.calls.length;

    await act(async () => { await state.runtimeInstallComplete(); });

    // The install moves BOTH halves: the hardware decoration on the model list
    // and the python health the connectivity banner reads.
    await waitFor(() => expect(state.getVideoGenModelContext).toHaveBeenCalledTimes(beforeContext + 1));
    expect(state.getVideoGenStatus).toHaveBeenCalledTimes(beforeStatus + 1);
  });
});