import test from 'node:test' import assert from 'node:assert/strict' import { replayCompletedCommand } from './phase3-loading-finalize.mjs' test('completed-command replay retries one connection failure and keeps its diagnostic', async () => { const failure = { http: 0, raw: 'fetch failed' } const success = { http: 200, body: { code: '200' } } const responses = [failure, success] const diagnostics = [] let calls = 0 assert.equal(await replayCompletedCommand(async () => { calls++; return responses.shift() }, r => diagnostics.push(r)), success) assert.equal(calls, 2) assert.deepEqual(diagnostics, [failure]) }) test('business failures are never retried; a second connection failure remains failure', async () => { for (const response of [{ http: 200, body: { code: 'A0409' } }, { http: 503 }, { http: 0 }]) { let calls = 0 const result = await replayCompletedCommand(async () => { calls++; return response }, () => {}) assert.equal(result, response) assert.equal(calls, response.http === 0 ? 2 : 1) } })