mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 22:41:40 +09:00
fix(retry): stop callbacks after attempts are exhausted
Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
This commit is contained in:
2 files changed
+21
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { withRetry } from '../v3/@claude-flow/cli/src/production/retry.ts';
|
||||
test('retry callbacks and history describe only actual retries', async () => {
|
||||
for (const maxAttempts of [1, 3]) {
|
||||
let calls = 0; const callbacks = [];
|
||||
const result = await withRetry(async () => { calls++; throw new Error('failure'); }, { maxAttempts, initialDelayMs: 0, jitter: 0, shouldRetry: () => true, onRetry: (_, attempt) => callbacks.push(attempt) });
|
||||
assert.equal(calls, maxAttempts);
|
||||
assert.equal(result.success, false);
|
||||
assert.equal(result.retryHistory.length, maxAttempts - 1);
|
||||
assert.deepEqual(callbacks, Array.from({ length: maxAttempts - 1 }, (_, i) => i + 1));
|
||||
}
|
||||
});
|
||||
test('successful retry preserves prior retry history', async () => {
|
||||
let calls = 0;
|
||||
const result = await withRetry(async () => { if (++calls === 1) throw new Error('transient'); return 42; }, { initialDelayMs: 0, jitter: 0, shouldRetry: () => true });
|
||||
assert.equal(result.result, 42); assert.equal(result.retryHistory.length, 1);
|
||||
});
|
||||
@@ -129,6 +129,9 @@ function shouldRetryError(
|
||||
attempt: number,
|
||||
config: RetryConfig
|
||||
): boolean {
|
||||
// Exhaustion always takes precedence over custom retry policies.
|
||||
if (attempt >= config.maxAttempts) return false;
|
||||
|
||||
// Check custom retry function
|
||||
if (config.shouldRetry) {
|
||||
return config.shouldRetry(error, attempt);
|
||||
|
||||
Reference in new issue
Block a user