/** * CLIContext Server Mode Tests * * Basic tests for persistent process functionality */ import { describe, expect, test } from 'bun:test'; import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { CLIContext } from './cli-context'; describe('CLIContext - Server Mode', () => { test('starts persistent process successfully', async () => { // Create temp directories for isolated test const dbPath = join(await mkdtemp(join(tmpdir(), 'cli-test-')), 'test.db'); const dataDir = await mkdtemp(join(tmpdir(), 'cli-test-data-')); const cli = await CLIContext.create('src/cli/index.ts', { CELILO_DB_PATH: dbPath, CELILO_DATA_DIR: dataDir, }); try { // If we get here, process started successfully expect(cli).toBeDefined(); // Try running a simple command const result = await cli.run('module list'); expect(result.exitCode).toBe(0); } finally { await cli.dispose(); // Cleanup await rm(dbPath, { force: true }); await rm(dataDir, { recursive: true, force: true }); } }, 15000); // 15 second timeout for this test test('reuses same process for multiple commands', async () => { const dbPath = join(await mkdtemp(join(tmpdir(), 'cli-test-')), 'test.db'); const dataDir = await mkdtemp(join(tmpdir(), 'cli-test-data-')); const cli = await CLIContext.create('src/cli/index.ts', { CELILO_DB_PATH: dbPath, CELILO_DATA_DIR: dataDir, }); try { // Run multiple commands - should reuse same process const result1 = await cli.run('module list'); expect(result1.exitCode).toBe(0); const result2 = await cli.run('module list'); expect(result2.exitCode).toBe(0); const result3 = await cli.run('module list'); expect(result3.exitCode).toBe(0); // All commands executed without spawning new processes } finally { await cli.dispose(); await rm(dbPath, { force: true }); await rm(dataDir, { recursive: true, force: true }); } }, 15000); });