import test from 'brittle'
import { nextRetryDelay, RETRY_MS } from '../lib/host/retry-policy.js'
test('backs off, then holds — it never gives up', (t) => {
t.is(nextRetryDelay(0), 15_000)
t.is(nextRetryDelay(1), 30_000)
t.is(nextRetryDelay(4), 300_000)
// ⚠ A phone that gave up for good would need a manual restart to ever update again — the exact
// state this exists to end. Capped, never exhausted.
t.is(nextRetryDelay(50), 300_000)
t.is(nextRetryDelay(5000), RETRY_MS[RETRY_MS.length - 1])
})
test('a nonsense attempt count does not produce a nonsense delay', (t) => {
for (const bad of [-1, NaN, undefined, null, 'x', Infinity]) {
const d = nextRetryDelay(bad)
t.ok(RETRY_MS.includes(d), String(bad) + ' → a real step (' + d + ')')
}
})
test('every step is long enough to be recovering, not spinning', (t) => {
// The failure being recovered from is a 120s timeout; a tight retry would hold a swarm open
// against a DHT that is not answering and spend the battery doing it.
t.ok(RETRY_MS.every((ms) => ms >= 15_000))
t.ok(RETRY_MS.every((ms, i, a) => i === 0 || ms > a[i - 1]), 'monotonic')
})