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.7 KB
Raw Blame
/**
 * Test for migration 152 — add the OpenCode Ollama TUI provider to existing
 * installs. Picked up by server/vitest.config.js's `../scripts/**\/*.test.js`
 * glob.
 *
 * The shell shared by all six provider-seed migrations (read → guard → add
 * missing ids → conditional write) is asserted once against
 * `makeProviderSeedMigration` in _lib.test.js; what stays here is this
 * migration's own frozen payload.
 */
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';

import migration from './152-opencode-ollama-tui-provider.js';

const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));

describe('migration 152 — OpenCode Ollama TUI provider', () => {
  let rootDir;
  let providersPath;

  beforeEach(() => {
    rootDir = mkdtempSync(join(tmpdir(), 'migration-152-'));
    mkdirSync(join(rootDir, 'data'), { recursive: true });
    providersPath = join(rootDir, 'data/providers.json');
  });

  afterEach(() => {
    rmSync(rootDir, { recursive: true, force: true });
  });

  it('adds the OpenCode Ollama TUI provider to an existing install', async () => {
    writeJson(providersPath, {
      activeProvider: 'claude-code',
      providers: {
        'claude-code': { id: 'claude-code', type: 'cli', command: 'claude' },
        'opencode-ollama': { id: 'opencode-ollama', type: 'cli', command: 'opencode' },
      },
    });

    await migration.up({ rootDir });

    const out = readJson(providersPath);
    const tui = out.providers['opencode-ollama-tui'];
    expect(tui.type).toBe('tui');
    expect(tui.command).toBe('opencode');
    expect(tui.args).toEqual([]);
    expect(tui.ollamaBacked).toBe(true);
    expect(tui.enabled).toBe(false);
    expect(tui.tuiPromptDelayMs).toBe(2500);
    expect(tui.tuiIdleTimeoutMs).toBe(180000);
    // unrelated providers + active provider untouched
    expect(out.providers['claude-code']).toBeDefined();
    expect(out.providers['opencode-ollama']).toBeDefined();
    expect(out.activeProvider).toBe('claude-code');
  });

  it('declares a valid inline OpenCode config pointing at the local Ollama daemon', async () => {
    writeJson(providersPath, { providers: {} });

    await migration.up({ rootDir });

    const out = readJson(providersPath);
    const cfg = JSON.parse(out.providers['opencode-ollama-tui'].envVars.OPENCODE_CONFIG_CONTENT);
    expect(cfg.permission).toBe('allow');
    expect(cfg.provider.ollama.npm).toBe('@ai-sdk/openai-compatible');
    expect(cfg.provider.ollama.options.baseURL).toBe('http://localhost:11434/v1');
  });
});