完成单机TEST统一入口与可靠投递回归收尾
This commit is contained in:
@@ -1,49 +1,34 @@
|
||||
export const EVENT_BRIDGE_RECOVERY_FIXTURE = Object.freeze({
|
||||
customerCode: 'C10000000',
|
||||
eventId: 'b569c7f6-3493-4a0f-a944-dd42698f183b',
|
||||
initialOutboxStatus: 'PENDING',
|
||||
initialRetryCount: 62,
|
||||
failedTarget: '172.31.198.8:9313',
|
||||
currentOutboxStatus: 'PENDING',
|
||||
currentRetryCount: 81,
|
||||
currentFailureCode: 'A0401',
|
||||
currentFailureMessage: '内部服务令牌无效',
|
||||
currentRequestId: '200edca3-428e-446d-977a-ca98a84dd704',
|
||||
currentTraceId: 'e8e6d620c1cff40caa765e6968f89024',
|
||||
dockerDnsProven: true,
|
||||
// Pure evidence checks; no HTTP, SQL or historical incident data.
|
||||
export const TEST_DIRECT_DELIVERY_URLS = Object.freeze({
|
||||
LASTLEG_SERVICE_URL: 'http://lastleg-service:9303',
|
||||
FIRSTLEG_SERVICE_URL: 'http://firstleg:9202',
|
||||
FINANCE_SERVICE_URL: 'http://finance:9203',
|
||||
})
|
||||
|
||||
export const TEST_EVENT_BRIDGE_URLS = Object.freeze({
|
||||
LASTLEG_EVENT_BRIDGE_URL: 'http://event-bridge-overseas:9312',
|
||||
FIRSTLEG_EVENT_BRIDGE_URL: 'http://event-bridge-cn:9312',
|
||||
})
|
||||
|
||||
export const INTERNAL_TOKEN_COHORT_SERVICES = Object.freeze([
|
||||
'firstleg',
|
||||
'event-bridge-cn',
|
||||
'event-bridge-overseas',
|
||||
'lastleg-service',
|
||||
])
|
||||
|
||||
export function validTestEventBridgeEnvironment(values = {}) {
|
||||
return Object.entries(TEST_EVENT_BRIDGE_URLS)
|
||||
.every(([key, expected]) => values[key] === expected)
|
||||
&& Object.values(values).every((value) => !/^https?:\/\/(?:\d{1,3}\.){3}\d{1,3}(?::|\/|$)/.test(String(value)))
|
||||
export const INTERNAL_TOKEN_COHORT_SERVICES = Object.freeze(['firstleg', 'lastleg-service', 'finance'])
|
||||
export function validDirectDeliveryEnvironment(values = {}) {
|
||||
return Object.entries(TEST_DIRECT_DELIVERY_URLS).every(([key, url]) => values[key] === url)
|
||||
}
|
||||
|
||||
// Callers must provide only a non-secret fingerprint/revision marker, never the token value.
|
||||
// Only provide non-secret credential revision/fingerprints, never tokens.
|
||||
export function validInternalTokenCohort(fingerprints = {}) {
|
||||
const values = INTERNAL_TOKEN_COHORT_SERVICES.map((service) => fingerprints[service])
|
||||
return values.every((value) => typeof value === 'string' && value.length > 0)
|
||||
&& new Set(values).size === 1
|
||||
const values = INTERNAL_TOKEN_COHORT_SERVICES.map(service => fingerprints[service])
|
||||
return values.every(value => typeof value === 'string' && value.trim().length > 0) && new Set(values).size === 1
|
||||
}
|
||||
|
||||
export function recoveredEventBridgeFacts(facts = {}) {
|
||||
return facts.firstlegOutboxStatus === 'SENT'
|
||||
&& Number(facts.overseasBridgeEventCount) === 1
|
||||
&& Number(facts.lastlegInboxEventCount) === 1
|
||||
&& Number(facts.lastlegOrderCount) === 1
|
||||
&& Number(facts.cnBridgeDuplicateCount) === 0
|
||||
&& Number(facts.manualReplayCount) === 0
|
||||
&& Number(facts.sqlMutationCount) === 0
|
||||
export function validDirectDeliveryEvidence(facts = {}) {
|
||||
const attempts = facts.attempts
|
||||
if (!facts.marker || !facts.eventId || !facts.payloadHash || !Array.isArray(attempts) || attempts.length < 1) return false
|
||||
if (!Number.isInteger(facts.maxAttempts) || facts.maxAttempts < 1 || facts.sqlMutationCount !== 0) return false
|
||||
if (!attempts.every(a => a.eventId === facts.eventId && a.payloadHash === facts.payloadHash
|
||||
&& Number.isFinite(Date.parse(a.at)) && a.requestId && a.traceId)) return false
|
||||
const failures = attempts.filter(a => ['DNS_UNAVAILABLE','TOKEN_REJECTED','TIMEOUT'].includes(a.failure))
|
||||
if (failures.length === 0 || attempts.some(a => a.failure && a.outcome)) return false
|
||||
if (failures.some(a => a.failure === 'TOKEN_REJECTED') && facts.status !== 'DEAD'
|
||||
&& facts.authorizedDeadRetry !== true) return false
|
||||
const successful = attempts.filter(a => ['APPLIED','DUPLICATE','STALE'].includes(a.outcome))
|
||||
if (facts.status === 'DEAD') return successful.length === 0 && (failures.length === facts.maxAttempts
|
||||
|| (failures.length === 1 && failures[0].failure === 'TOKEN_REJECTED'))
|
||||
&& facts.automaticRetryScheduled === false
|
||||
// A read-only snapshot alone can never prove a duplicate delivery happened.
|
||||
return facts.status === 'SENT' && failures.length < facts.maxAttempts
|
||||
&& successful.some(a => a.outcome === 'APPLIED' && a.ackLost === true) && successful.some(a => a.outcome === 'DUPLICATE')
|
||||
&& facts.inboxEventCount === 1 && facts.businessEffectCount === 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user