← Back to Kontasks
retry.ts tests
Display the 20 tests for retry utility with exponential backoff and circuit breaker
Output
🧪 shared/tests/retry.test.ts
20 tests covering withRetry, withRetryResult, CircuitBreaker, and withCircuitBreaker (312 lines)
withRetry Tests (8)
| ✓ | succeeds on first attempt |
| ✓ | retries on network error and succeeds |
| ✓ | gives up after max retries |
| ✓ | does not retry non-network errors |
| ✓ | calls onRetry callback |
| ✓ | uses exponential backoff |
| ✓ | respects max delay |
| ✓ | custom shouldRetry function |
withRetryResult Tests (2)
| ✓ | returns success result |
| ✓ | returns failure result after max retries |
CircuitBreaker Tests (5)
| ✓ | starts closed |
| ✓ | opens after threshold failures |
| ✓ | success resets failure count |
| ✓ | resets after timeout |
| ✓ | getState returns current state |
withCircuitBreaker Tests (5)
| ✓ | executes when circuit closed |
| ✓ | throws when circuit open |
| ✓ | returns fallback when circuit open |
| ✓ | records success |
| ✓ | records failure |
Key Test Patterns
// Verify exponential backoff delays assertEquals(delays[0], 100); // 100 * 2^0 assertEquals(delays[1], 200); // 100 * 2^1 assertEquals(delays[2], 400); // 100 * 2^2 // Circuit breaker auto-reset const breaker = new CircuitBreaker(2, 50); // 50ms reset breaker.recordFailure(); breaker.recordFailure(); assertEquals(breaker.isCircuitOpen(), true); await sleep(60); assertEquals(breaker.isCircuitOpen(), false);
Quick Actions
Original Request
No layout configured
Details
Type
General
Status
Completed
Scope
vibetools
Tags
sharedutilitiestests
Created
4 Jan 2026, 11:45 am
Updated
4 Jan 2026, 11:45 am
Created By
claude
Raw Data
{
"id": "dd51ae7d-749c-4ef1-9db7-70edc93e8ae1",
"type": "general",
"status": "completed",
"title": "retry.ts tests",
"description": "Display the 20 tests for retry utility with exponential backoff and circuit breaker",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:'Consolas','Monaco',monospace;\">\n<h2 style=\"font-family:sans-serif;color:#fff;margin:0 0 16px 0;\">🧪 shared/tests/retry.test.ts</h2>\n<p style=\"font-family:sans-serif;color:#9ca3af;margin:0 0 16px 0;\">20 tests covering withRetry, withRetryResult, CircuitBreaker, and withCircuitBreaker (312 lines)</p>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#98c379;margin:0 0 12px 0;font-family:sans-serif;\">withRetry Tests (8)</h3>\n<table style=\"width:100%;border-collapse:collapse;font-size:0.85rem;\">\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">succeeds on first attempt</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">retries on network error and succeeds</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">gives up after max retries</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">does not retry non-network errors</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">calls onRetry callback</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">uses exponential backoff</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">respects max delay</td></tr>\n<tr><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">custom shouldRetry function</td></tr>\n</table>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#61afef;margin:0 0 12px 0;font-family:sans-serif;\">withRetryResult Tests (2)</h3>\n<table style=\"width:100%;border-collapse:collapse;font-size:0.85rem;\">\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">returns success result</td></tr>\n<tr><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">returns failure result after max retries</td></tr>\n</table>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c678dd;margin:0 0 12px 0;font-family:sans-serif;\">CircuitBreaker Tests (5)</h3>\n<table style=\"width:100%;border-collapse:collapse;font-size:0.85rem;\">\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">starts closed</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">opens after threshold failures</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">success resets failure count</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">resets after timeout</td></tr>\n<tr><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">getState returns current state</td></tr>\n</table>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#56b6c2;margin:0 0 12px 0;font-family:sans-serif;\">withCircuitBreaker Tests (5)</h3>\n<table style=\"width:100%;border-collapse:collapse;font-size:0.85rem;\">\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">executes when circuit closed</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">throws when circuit open</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">returns fallback when circuit open</td></tr>\n<tr style=\"border-bottom:1px solid #444;\"><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">records success</td></tr>\n<tr><td style=\"padding:6px 0;color:#e5c07b;\">✓</td><td style=\"padding:6px;\">records failure</td></tr>\n</table>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;\">\n<h3 style=\"color:#98c379;margin:0 0 12px 0;font-family:sans-serif;\">Key Test Patterns</h3>\n<pre style=\"margin:0;line-height:1.6;overflow-x:auto;\"><span style=\"color:#7f848e;\">// Verify exponential backoff delays</span>\n<span style=\"color:#61afef;\">assertEquals</span>(delays[<span style=\"color:#d19a66;\">0</span>], <span style=\"color:#d19a66;\">100</span>); <span style=\"color:#7f848e;\">// 100 * 2^0</span>\n<span style=\"color:#61afef;\">assertEquals</span>(delays[<span style=\"color:#d19a66;\">1</span>], <span style=\"color:#d19a66;\">200</span>); <span style=\"color:#7f848e;\">// 100 * 2^1</span>\n<span style=\"color:#61afef;\">assertEquals</span>(delays[<span style=\"color:#d19a66;\">2</span>], <span style=\"color:#d19a66;\">400</span>); <span style=\"color:#7f848e;\">// 100 * 2^2</span>\n\n<span style=\"color:#7f848e;\">// Circuit breaker auto-reset</span>\n<span style=\"color:#c678dd;\">const</span> breaker = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">CircuitBreaker</span>(<span style=\"color:#d19a66;\">2</span>, <span style=\"color:#d19a66;\">50</span>); <span style=\"color:#7f848e;\">// 50ms reset</span>\nbreaker.<span style=\"color:#61afef;\">recordFailure</span>();\nbreaker.<span style=\"color:#61afef;\">recordFailure</span>();\n<span style=\"color:#61afef;\">assertEquals</span>(breaker.<span style=\"color:#61afef;\">isCircuitOpen</span>(), <span style=\"color:#d19a66;\">true</span>);\n<span style=\"color:#c678dd;\">await</span> <span style=\"color:#61afef;\">sleep</span>(<span style=\"color:#d19a66;\">60</span>);\n<span style=\"color:#61afef;\">assertEquals</span>(breaker.<span style=\"color:#61afef;\">isCircuitOpen</span>(), <span style=\"color:#d19a66;\">false</span>);</pre>\n</div>\n</div>",
"requestedAt": "2026-01-04T00:00:00.000Z",
"requestId": "7bc5d0e7-6073-47db-896d-6ed25a0f9e12",
"choices": [
{
"label": "Run tests",
"value": "Run the shared retry tests",
"primary": true
},
{
"label": "View retry.ts",
"value": "Show me retry.ts in shared"
},
{
"label": "All shared tests",
"value": "Run all shared utility tests"
}
]
},
"createdBy": "claude",
"createdAt": "2026-01-04T01:45:20.689Z",
"updatedAt": "2026-01-04T01:45:20.977Z",
"requestId": "7bc5d0e7-6073-47db-896d-6ed25a0f9e12",
"scope": "vibetools",
"tags": [
"shared",
"utilities",
"tests"
],
"targetUser": "claude"
}