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

2.0 KB
Raw Blame
import { afterEach, expect, it } from 'vitest';
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'os';
import { join } from 'path';
import migration from './388-nim-comparison-coverage.js';

let rootDir;
afterEach(async () => { if (rootDir) await rm(rootDir, { recursive: true, force: true }); });
it('upgrades an existing catalog without losing researched evidence and fails closed on future versions', async () => {
  rootDir = await mkdtemp(join(tmpdir(), 'portos-nim-seed-'));
  await mkdir(join(rootDir, 'data'));
  await mkdir(join(rootDir, 'data.reference'));
  const seed = JSON.parse(await readFile(new URL('../../data.reference/model-comparison.json', import.meta.url), 'utf8'));
  await writeFile(join(rootDir, 'data.reference/model-comparison.json'), JSON.stringify(seed));
  expect(await migration.up({ rootDir })).toEqual({ added: 0 });
  const nim = seed.observations.filter(row => row.provider === 'NVIDIA NIM');
  expect(nim).toHaveLength(2);
  expect(nim.map(row => row.model).sort()).toEqual(['google/gemma-4-31b-it', 'poolside/laguna-xs-2.1']);
  expect(nim.every(row => row.quality === null && row.tokensPerSecond === null && row.inputPerMillion.value === 0)).toBe(true);
  const researched = { ...nim[0], notes: 'Example locally researched evidence' };
  const prior = { schemaVersion: 1, observations: [seed.observations[0], researched] };
  const path = join(rootDir, 'data/model-comparison.json');
  await writeFile(path, JSON.stringify(prior));
  expect(await migration.up({ rootDir })).toEqual({ added: 1 });
  const result = JSON.parse(await readFile(path, 'utf8'));
  expect(result.observations.slice(0, 2)).toEqual(prior.observations);
  expect(await migration.up({ rootDir })).toEqual({ added: 0 });
  const future = JSON.stringify({ ...prior, schemaVersion: 99 });
  await writeFile(path, future);
  await expect(migration.up({ rootDir })).rejects.toThrow();
  expect(await readFile(path, 'utf8')).toBe(future);
});