Files
baiyue-firstleg/scripts/admin-test-env-modules/completed-command-replay-contract.test.mjs
T
2026-09-20 20:40:21 +08:00

23 lines
1.0 KiB
JavaScript

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)
}
})