mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 06:06:02 +09:00
## Fixes ### Configuration Issues (fixes #276) - Move mcpServers from ~/.claude/settings.json to project-scoped .mcp.json - Add enabledMcpjsonServers to settings.json for proper MCP authorization - Move features and performance settings to claude-flow.config.json - Fix Claude Code startup errors and enable MCP server functionality ### Process Management (fixes #277) - Add proper child process lifecycle management - Implement graceful shutdown handlers for SIGINT/SIGTERM - Handle TTY input (Ctrl+D) for clean exit - Prevent zombie/defunct processes ### Cleanup - Remove alpha-50 directory (outdated release artifacts) - Fix broken test files - Update package.json version - Improve test compatibility ## Breaking Changes - Configuration files now in different locations: - MCP servers: .mcp.json (project root) - Claude Flow settings: claude-flow.config.json (project root) - Claude Code settings: ~/.claude/settings.json (cleaned up) ## Migration Users should run 'claude-flow init --force' after updating to regenerate proper configuration files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
350 lines
9.6 KiB
Plaintext
350 lines
9.6 KiB
Plaintext
/**
|
|
* Integration tests for Claude-Flow CLI
|
|
*/
|
|
|
|
import { jest } from '@jest/globals';
|
|
import { spawn } from 'child_process';
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const rootDir = path.resolve(__dirname, '../../../');
|
|
const cliPath = path.join(rootDir, 'claude-flow');
|
|
|
|
describe('CLI Integration Tests', () => {
|
|
let testDir;
|
|
|
|
beforeEach(async () => {
|
|
// Create temporary test directory
|
|
testDir = path.join(__dirname, `test-${Date.now()}`);
|
|
await fs.ensureDir(testDir);
|
|
process.chdir(testDir);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
// Cleanup test directory
|
|
if (testDir && await fs.pathExists(testDir)) {
|
|
await fs.remove(testDir);
|
|
}
|
|
});
|
|
|
|
describe('CLI Commands', () => {
|
|
test('should show help when no arguments', (done) => {
|
|
const child = spawn(cliPath, ['--help'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' }
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(stdout).toContain('Claude-Flow');
|
|
expect(stdout).toContain('USAGE:');
|
|
expect(stdout).toContain('claude-flow <command> [options]');
|
|
done();
|
|
});
|
|
}, 10000);
|
|
|
|
test('should show version', (done) => {
|
|
const child = spawn(cliPath, ['--version'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' }
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(stdout.trim()).toBe('v2.0.0-alpha.54');
|
|
expect(code).toBe(0);
|
|
done();
|
|
});
|
|
}, 10000);
|
|
|
|
test('should handle unknown command', (done) => {
|
|
const child = spawn(cliPath, [, 'unknown-command'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' }
|
|
});
|
|
|
|
let stderr = '';
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(stderr).toContain('Unknown command: unknown-command');
|
|
expect(code).toBe(1);
|
|
done();
|
|
});
|
|
}, 10000);
|
|
});
|
|
|
|
describe('Init Command', () => {
|
|
test('should initialize basic setup', (done) => {
|
|
const child = spawn(cliPath, [, 'init', '--minimal'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
child.on('close', async (code) => {
|
|
try {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('Claude-Flow initialized');
|
|
|
|
// Check if .claude directory was created
|
|
const claudeDir = path.join(testDir, '.claude');
|
|
expect(await fs.pathExists(claudeDir)).toBe(true);
|
|
|
|
done();
|
|
} catch (error) {
|
|
done(error);
|
|
}
|
|
});
|
|
}, 15000);
|
|
|
|
test('should initialize with SPARC setup', (done) => {
|
|
const child = spawn(cliPath, [, 'init', '--sparc'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
child.on('close', async (code) => {
|
|
try {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('SPARC development environment');
|
|
|
|
// Check for SPARC files
|
|
const sparcFiles = [
|
|
path.join(testDir, '.roomodes'),
|
|
path.join(testDir, 'CLAUDE.md'),
|
|
path.join(testDir, '.claude', 'commands'),
|
|
];
|
|
|
|
for (const file of sparcFiles) {
|
|
expect(await fs.pathExists(file)).toBe(true);
|
|
}
|
|
|
|
done();
|
|
} catch (error) {
|
|
done(error);
|
|
}
|
|
});
|
|
}, 20000);
|
|
});
|
|
|
|
describe('Memory Command', () => {
|
|
beforeEach(async () => {
|
|
// Initialize basic setup first
|
|
await new Promise((resolve) => {
|
|
const child = spawn(cliPath, [, 'init', '--minimal'], {
|
|
stdio: 'ignore',
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
child.on('close', resolve);
|
|
});
|
|
});
|
|
|
|
test('should store and retrieve memory', (done) => {
|
|
// First store a memory
|
|
const storeChild = spawn(cliPath, [, 'memory', 'store', 'test-key', 'test-value'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
storeChild.on('close', (code) => {
|
|
expect(code).toBe(0);
|
|
|
|
// Then retrieve it
|
|
const retrieveChild = spawn(cliPath, [, 'memory', 'retrieve', 'test-key'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
retrieveChild.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
retrieveChild.on('close', (code) => {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('test-value');
|
|
done();
|
|
});
|
|
});
|
|
}, 15000);
|
|
|
|
test('should list memory entries', (done) => {
|
|
// Store some memories first
|
|
const store1 = spawn(cliPath, [, 'memory', 'store', 'key1', 'value1'], {
|
|
stdio: 'ignore',
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
store1.on('close', () => {
|
|
const store2 = spawn(cliPath, [, 'memory', 'store', 'key2', 'value2'], {
|
|
stdio: 'ignore',
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
store2.on('close', () => {
|
|
// List memories
|
|
const listChild = spawn(cliPath, [, 'memory', 'list'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
listChild.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
listChild.on('close', (code) => {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('key1');
|
|
expect(stdout).toContain('key2');
|
|
expect(stdout).toContain('Memory Entries (2)');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
}, 20000);
|
|
});
|
|
|
|
describe('Agent Command', () => {
|
|
beforeEach(async () => {
|
|
// Initialize and start a swarm first
|
|
await new Promise((resolve) => {
|
|
const child = spawn(cliPath, [, 'init', '--minimal'], {
|
|
stdio: 'ignore',
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
child.on('close', resolve);
|
|
});
|
|
});
|
|
|
|
test('should list available agent types', (done) => {
|
|
const child = spawn(cliPath, [, 'agent', 'list'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('Available Agent Types');
|
|
expect(stdout).toContain('researcher');
|
|
expect(stdout).toContain('coder');
|
|
expect(stdout).toContain('analyst');
|
|
done();
|
|
});
|
|
}, 10000);
|
|
});
|
|
|
|
describe('Error Handling', () => {
|
|
test('should handle commands without initialization', (done) => {
|
|
const child = spawn(cliPath, [, 'agent', 'status'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stderr = '';
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(code).toBe(1);
|
|
expect(stderr).toContain('Claude-Flow not initialized');
|
|
done();
|
|
});
|
|
}, 10000);
|
|
|
|
test('should handle insufficient arguments', (done) => {
|
|
const child = spawn(cliPath, [, 'memory', 'store'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stderr = '';
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
expect(code).toBe(1);
|
|
expect(stderr).toContain('Missing required');
|
|
done();
|
|
});
|
|
}, 10000);
|
|
});
|
|
|
|
describe('Configuration', () => {
|
|
test('should handle configuration files', async () => {
|
|
// Create a test config file
|
|
const configPath = path.join(testDir, 'claude-flow.json');
|
|
const config = {
|
|
version: '2.0.0',
|
|
features: {
|
|
swarm: true,
|
|
memory: true,
|
|
github: false
|
|
}
|
|
};
|
|
|
|
await fs.writeJson(configPath, config);
|
|
|
|
const child = spawn(cliPath, [, 'config', 'show'], {
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
cwd: testDir
|
|
});
|
|
|
|
let stdout = '';
|
|
child.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
await new Promise((resolve) => {
|
|
child.on('close', (code) => {
|
|
expect(code).toBe(0);
|
|
expect(stdout).toContain('Configuration');
|
|
resolve();
|
|
});
|
|
});
|
|
}, 10000);
|
|
});
|
|
}); |