UNPKG

claude-flow

Version:

Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration

98 lines 3.86 kB
/** * Smoke tests for python_exec — ADR-133-PR4 * * Run with: * cd v3/@claude-flow/cli * npx tsx src/benchmarks/gaia-tools/python_exec.smoke.ts * * Expects python3 to be installed and on PATH. * * Refs: ADR-133, #2156 */ import { createPythonExecTool } from './python_exec.js'; async function runTest(name, fn) { try { await fn(); return { name, passed: true, message: 'OK' }; } catch (e) { return { name, passed: false, message: String(e) }; } } function assert(condition, msg) { if (!condition) throw new Error(`Assertion failed: ${msg}`); } // --------------------------------------------------------------------------- // Tests // --------------------------------------------------------------------------- const tool = createPythonExecTool(); const tests = [ runTest('Test 1: basic arithmetic — print(2+2)', async () => { const out = await tool.execute({ code: 'print(2+2)' }); assert(out.includes('4'), `Expected stdout to contain "4", got:\n${out}`); assert(out.includes('exit_code: 0'), `Expected exit_code 0, got:\n${out}`); }), runTest('Test 2: large computation — sum(range(1000000))', async () => { const out = await tool.execute({ code: 'print(sum(range(1000000)))' }); assert(out.includes('499999500000'), `Expected "499999500000", got:\n${out}`); assert(out.includes('exit_code: 0'), `Expected exit_code 0, got:\n${out}`); }), runTest('Test 3: stdlib import — math.sqrt(144)', async () => { const out = await tool.execute({ code: 'import math; print(math.sqrt(144))', }); assert(out.includes('12.0'), `Expected "12.0", got:\n${out}`); assert(out.includes('exit_code: 0'), `Expected exit_code 0, got:\n${out}`); }), runTest('Test 4: timeout — infinite loop with 2s limit', async () => { const start = Date.now(); const out = await tool.execute({ code: 'while True: pass', timeout_seconds: 2, }); const elapsed = Date.now() - start; assert(elapsed < 6_000, `Timeout should have fired within ~2s, took ${elapsed}ms`); const hasTimedOut = out.includes('timed out') || out.includes('exit_code: 124') || // SIGKILL on some platforms gives exit code -9 or 137 out.includes('exit_code: -9') || out.includes('exit_code: 137'); assert(hasTimedOut, `Expected timeout signal, got:\n${out}`); }), runTest('Test 5: syntax error — exit_code != 0, stderr contains SyntaxError', async () => { const out = await tool.execute({ code: 'x = (' }); assert(out.includes('SyntaxError'), `Expected SyntaxError in output, got:\n${out}`); const hasNonZeroExit = !out.includes('exit_code: 0') || out.includes('stderr:'); assert(hasNonZeroExit, `Expected non-zero exit code or stderr for syntax error, got:\n${out}`); }), ]; // --------------------------------------------------------------------------- // Runner // --------------------------------------------------------------------------- async function main() { console.log('python_exec smoke tests — ADR-133-PR4\n'); const results = await Promise.all(tests); let passed = 0; let failed = 0; for (const r of results) { const icon = r.passed ? 'PASS' : 'FAIL'; console.log(`[${icon}] ${r.name}`); if (!r.passed) { console.log(` ${r.message}`); } if (r.passed) passed++; else failed++; } console.log(`\nResults: ${passed}/${results.length} passed`); if (failed > 0) { process.exit(1); } } main().catch((e) => { console.error('Fatal:', e); process.exit(1); }); //# sourceMappingURL=python_exec.smoke.js.map