test(acceptance): reuse fixed customers and align native fulfillment flows

This commit is contained in:
2026-10-23 04:48:02 +08:00
parent b92f7fe991
commit 139f6b1932
51 changed files with 1076 additions and 228 deletions
+35 -1
View File
@@ -27,13 +27,17 @@ async function fixture(selector = ['--loading-plan-id', '2100000000000000001'],
const chunks = []
for await (const chunk of request) chunks.push(chunk)
const raw = Buffer.concat(chunks).toString()
const envelope = JSON.parse(raw)
const envelope = raw ? JSON.parse(raw) : {}
calls.push({ raw, authorization: request.headers.authorization, eventId: envelope.eventId, path: request.url })
const outcome = applied.has(envelope.eventId) ? 'DUPLICATE' : 'APPLIED'
applied.add(envelope.eventId)
const body = JSON.stringify({ code: '200', data: { eventId: invalidAck ? otherId : envelope.eventId,
payloadHash: envelope.payloadHash, outcome } })
response.writeHead(200, { 'Content-Type': 'application/json', 'X-Consumer-Evidence': 'actual-upstream' })
if (request.url === '/internal/lastleg/v1/order-workflow-facts' || request.method === 'GET') {
response.end(JSON.stringify({ code: '200', data: { method: request.method, raw, path: request.url } }))
return
}
response.end(body)
})
await new Promise(resolve => consumer.listen(0, '127.0.0.1', resolve))
@@ -70,6 +74,7 @@ async function fixture(selector = ['--loading-plan-id', '2100000000000000001'],
const dataUrl = `http://127.0.0.1:${ready.dataPort}${endpoint}`
const controlUrl = `http://127.0.0.1:${ready.controlPort}`
return { calls, applied, log, invalidAck: value => { invalidAck = value },
get: path => fetch(new URL(path, dataUrl), { headers: { Authorization: `Bearer ${secret}` } }),
send: async (envelope, path = endpoint) => {
const sent = JSON.stringify(envelope)
const response = await fetch(new URL(path, dataUrl), { method: 'POST', body: sent,
@@ -94,6 +99,35 @@ async function fixture(selector = ['--loading-plan-id', '2100000000000000001'],
}
}
test('loading fault preserves exact synchronous read requests and only injects the selected event', async t => {
const eventType = 'FirstLegLoadingPlanCompleted'
const runtime = await readFile(new URL('./test-event-fault-runtime.py', import.meta.url), 'utf8')
assert.ok(runtime.includes(`['--event-type', '${eventType}', '--loading-plan-id'`))
const proxy = await fixture(['--loading-plan-id', '2100000000000000001'], eventType, '/internal/lastleg/events')
t.after(() => proxy.stop())
await proxy.control('/mode', { mode: 'FAULT' })
const workflowPath = '/internal/lastleg/v1/order-workflow-facts'
const read = await proxy.send({ customerId: '101', orderIds: ['201'] }, workflowPath)
assert.equal(read.status, 200)
assert.equal(JSON.parse(read.raw).data.raw, read.sent)
const routePath = '/internal/lastleg/appointment-work/containers/301/route'
const route = await proxy.get(routePath)
assert.equal(route.status, 200)
assert.equal((await route.json()).data.path, routePath)
assert.ok(proxy.calls.every(call => call.authorization === `Bearer ${secret}`))
assert.equal((await (await proxy.control('/status')).json()).attempt, 0)
assert.equal((await proxy.send({}, '/internal/lastleg/v1/unknown')).status, 404)
assert.equal((await proxy.get('/internal/lastleg/appointment-work/containers/301/route?other=1')).status, 404)
assert.equal((await proxy.send({}, routePath)).status, 404)
assert.equal((await proxy.get('/internal/lastleg/events')).status, 404)
assert.equal(proxy.calls.length, 2)
assert.equal((await proxy.send({ ...event(), eventType })).status, 503)
const snapshot = await (await proxy.control('/status')).json()
assert.equal(snapshot.attempt, 1)
assert.equal(snapshot.records.length, 1)
assert.equal(snapshot.records[0].eventId, targetId)
})
test('fee fault preserves wallet endpoint bytes and auth without selecting its body', async t => {
const proxy = await fixture(['--fee-source-id', '2100000000000000001', '--source-version', '1'],
'BusinessFeeSourceChanged', '/internal/finance/v1/business-fee-source-events')