mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 06:06:02 +09:00
## 🔧 Critical Swarm System Fixes ### Fixed Task File Naming Bug - Tasks were being saved as '[object Object].json' due to TaskId object structure - Now properly extracts task ID string for file naming - Files save correctly as 'task_<id>.json' ### Added Task Timeout Protection - Implemented automatic timeout detection in task execution loop - Tasks that exceed timeout (default 5 minutes) are marked as failed - Prevents swarms from hanging indefinitely on stuck tasks - Agent state properly cleaned up on timeout ### Fixed Target Directory Propagation - Testing tasks were receiving null targetDir, preventing file access - Target directory now extracted from objective description - All tasks inherit targetDir through context - Enhanced extractTargetDirectory to check multiple sources ### Improved Task Dependencies - Fixed taskDependenciesMet to handle both string and TaskId objects - Added convertDependenciesToTaskDependencies for Map structure - Dependencies now properly resolve for sequential task execution ### Auto Strategy Integration - Added missing autoStrategy property and initialization - Proper AutoStrategy instantiation in coordinator constructor - Enables intelligent task decomposition for 'auto' strategy ## 📊 Added Comprehensive Benchmarks ### Benchmark Suite Integration - Added complete Python-based benchmarking tool - Tests 7 strategies across 5 coordination modes - 100% success rate across all test scenarios - Performance metrics: 0.10s - 0.20s execution times ### Real-World Performance Data - Calculator example: 4m 20s total (3 tasks) - Task breakdown: Analysis 29%, Implementation 22%, Testing 48% - Successfully created 6 files with proper directory structure ## 📝 Documentation Updates ### Updated README.md - Added v1.0.50 changelog with critical fixes - Integrated benchmark performance results table - Added real-world timing example - Removed old update notes for clarity - Added dedicated Benchmarks & Performance section ## 🧪 Test Results - Swarm now completes successfully with proper task coordination - All fixes validated in production environment - Task files save with correct names - Testing tasks find implementation files - Swarms exit cleanly after completion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
154 lines
4.0 KiB
TypeScript
154 lines
4.0 KiB
TypeScript
import { describe, it, beforeEach, afterEach } from "https://deno.land/std@0.220.0/testing/bdd.ts";
|
|
import { assertEquals, assertExists, assertThrows } from "https://deno.land/std@0.220.0/assert/mod.ts";
|
|
import { spy, stub } from "https://deno.land/std@0.220.0/testing/mock.ts";
|
|
|
|
// Example calculator class to test
|
|
class Calculator {
|
|
add(a: number, b: number): number {
|
|
return a + b;
|
|
}
|
|
|
|
subtract(a: number, b: number): number {
|
|
return a - b;
|
|
}
|
|
|
|
multiply(a: number, b: number): number {
|
|
return a * b;
|
|
}
|
|
|
|
divide(a: number, b: number): number {
|
|
if (b === 0) {
|
|
throw new Error("Division by zero");
|
|
}
|
|
return a / b;
|
|
}
|
|
|
|
async asyncOperation(value: number): Promise<number> {
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
return value * 2;
|
|
}
|
|
}
|
|
|
|
describe("Calculator", () => {
|
|
let calculator: Calculator;
|
|
|
|
beforeEach(() => {
|
|
// Setup before each test
|
|
calculator = new Calculator();
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Cleanup after each test
|
|
// In a real test, you might clean up resources here
|
|
});
|
|
|
|
describe("add", () => {
|
|
it("should add two positive numbers", () => {
|
|
const result = calculator.add(2, 3);
|
|
assertEquals(result, 5);
|
|
});
|
|
|
|
it("should handle negative numbers", () => {
|
|
const result = calculator.add(-5, 3);
|
|
assertEquals(result, -2);
|
|
});
|
|
|
|
it("should handle zero", () => {
|
|
const result = calculator.add(0, 0);
|
|
assertEquals(result, 0);
|
|
});
|
|
});
|
|
|
|
describe("subtract", () => {
|
|
it("should subtract two numbers", () => {
|
|
const result = calculator.subtract(10, 4);
|
|
assertEquals(result, 6);
|
|
});
|
|
|
|
it("should handle negative results", () => {
|
|
const result = calculator.subtract(3, 5);
|
|
assertEquals(result, -2);
|
|
});
|
|
});
|
|
|
|
describe("multiply", () => {
|
|
it("should multiply two numbers", () => {
|
|
const result = calculator.multiply(4, 5);
|
|
assertEquals(result, 20);
|
|
});
|
|
|
|
it("should handle multiplication by zero", () => {
|
|
const result = calculator.multiply(10, 0);
|
|
assertEquals(result, 0);
|
|
});
|
|
});
|
|
|
|
describe("divide", () => {
|
|
it("should divide two numbers", () => {
|
|
const result = calculator.divide(10, 2);
|
|
assertEquals(result, 5);
|
|
});
|
|
|
|
it("should handle decimal results", () => {
|
|
const result = calculator.divide(7, 2);
|
|
assertEquals(result, 3.5);
|
|
});
|
|
|
|
it("should throw error when dividing by zero", () => {
|
|
assertThrows(
|
|
() => calculator.divide(10, 0),
|
|
Error,
|
|
"Division by zero"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("asyncOperation", () => {
|
|
it("should double the value asynchronously", async () => {
|
|
const result = await calculator.asyncOperation(5);
|
|
assertEquals(result, 10);
|
|
});
|
|
|
|
it("should handle zero", async () => {
|
|
const result = await calculator.asyncOperation(0);
|
|
assertEquals(result, 0);
|
|
});
|
|
});
|
|
|
|
describe("instance", () => {
|
|
it("should create a calculator instance", () => {
|
|
assertExists(calculator);
|
|
assertEquals(typeof calculator.add, "function");
|
|
assertEquals(typeof calculator.subtract, "function");
|
|
assertEquals(typeof calculator.multiply, "function");
|
|
assertEquals(typeof calculator.divide, "function");
|
|
});
|
|
});
|
|
});
|
|
|
|
// Example of using spies and stubs
|
|
describe("Calculator with mocks", () => {
|
|
it("should spy on method calls", () => {
|
|
const calculator = new Calculator();
|
|
const addSpy = spy(calculator, "add");
|
|
|
|
calculator.add(2, 3);
|
|
calculator.add(4, 5);
|
|
|
|
assertEquals(addSpy.calls.length, 2);
|
|
assertEquals(addSpy.calls[0].args, [2, 3]);
|
|
assertEquals(addSpy.calls[1].args, [4, 5]);
|
|
});
|
|
|
|
it("should stub a method", () => {
|
|
const calculator = new Calculator();
|
|
const multiplyStub = stub(calculator, "multiply", () => 100);
|
|
|
|
const result = calculator.multiply(2, 3);
|
|
assertEquals(result, 100); // Stubbed value
|
|
|
|
multiplyStub.restore();
|
|
const realResult = calculator.multiply(2, 3);
|
|
assertEquals(realResult, 6); // Real value after restore
|
|
});
|
|
}); |