优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { AcceptanceRun } from './admin-test-env-acceptance.mjs'
|
||||
import { AcceptanceRun, transportFailureDetails } from './admin-test-env-acceptance.mjs'
|
||||
|
||||
function runContext() {
|
||||
return new AcceptanceRun({ gateway: 'http://acceptance.invalid', overseasGateway: 'http://overseas.invalid' })
|
||||
@@ -32,14 +32,29 @@ test('mutating HTTP requests never retry an ambiguous network failure', async ()
|
||||
let attempts = 0
|
||||
globalThis.fetch = async () => {
|
||||
attempts += 1
|
||||
throw new TypeError('fetch failed')
|
||||
throw new TypeError('fetch failed', { cause: Object.assign(new Error('private host and token'), { code: 'ECONNRESET', syscall: 'read' }) })
|
||||
}
|
||||
try {
|
||||
const response = await runContext().request('POST', '/api/orders', { value: 1 })
|
||||
assert.equal(attempts, 1)
|
||||
assert.equal(response.http, 0)
|
||||
assert.equal(response.raw, 'fetch failed')
|
||||
assert.equal(response.transportError.causes[1].code, 'ECONNRESET')
|
||||
const run = runContext(); run.options.quiet = true
|
||||
run.addStep('orders', 'conflict request', response, false)
|
||||
assert.deepEqual(run.steps[0].transportError, response.transportError)
|
||||
assert.ok(!JSON.stringify(run.steps).includes('private host and token'))
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch
|
||||
}
|
||||
})
|
||||
|
||||
test('transport diagnostics retain nested connection codes without addresses or exception messages', () => {
|
||||
const cause = Object.assign(new Error('secret endpoint'), { code: 'ETIMEDOUT', address: 'private', syscall: 'connect' })
|
||||
const error = new TypeError('fetch failed', { cause: new AggregateError([cause]) })
|
||||
cause.cause = error
|
||||
const result = transportFailureDetails(error)
|
||||
assert.equal(result.causes.length, 3)
|
||||
assert.equal(result.causes[2].code, 'ETIMEDOUT')
|
||||
assert.doesNotMatch(JSON.stringify(result), /secret|private|endpoint/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user