Files
baiyue-firstleg/scripts/phase4-overseas-acceptance-entry-contract.test.mjs
T

183 lines
10 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { AcceptanceRun, parseArguments, validateExecutionOptions } from './admin-test-env-acceptance.mjs'
const source = readFileSync(resolve('scripts/admin-test-env-acceptance.mjs'), 'utf8')
test('phase-four HTTP acceptance modules are registered in the Admin acceptance entry', () => {
for (const module of [
'phase4-overseas-warehouse',
'phase4-overseas-pda',
'phase4-overseas-pda-operations',
'phase4-overseas-inbound-operations',
'phase4-overseas-client-services',
'phase4-overseas-dispatch',
'phase4-cross-region-events',
'phase4-overseas-business',
'phase4-overseas-master-data',
'phase4-carrier-nodes',
'phase4-overseas-wallet-and-pallet-cost',
]) {
assert.match(source, new RegExp(`CONFIGURED_MODULES\\s*=\\s*\\[[^\\]]*'${module}'`, 's'))
}
})
test('wallet and destuff cost closure expands the fresh merchant and completed overseas PDA chain', () => {
const modules = parseArguments(['--modules', 'phase4-overseas-wallet-and-pallet-cost']).modules
for (const prerequisite of ['merchant-qualification-fixture', 'phase3-loading-finalize',
'phase4-overseas-pda', 'phase4-overseas-pda-operations', 'phase4-overseas-business']) {
assert.ok(modules.indexOf(prerequisite) >= 0
&& modules.indexOf(prerequisite) < modules.indexOf('phase4-overseas-wallet-and-pallet-cost'))
}
})
test('overseas inbound commands, client services and dispatch follow completed PDA receiving', () => {
for (const consumer of ['phase4-overseas-inbound-operations', 'phase4-overseas-client-services',
'phase4-overseas-dispatch']) {
const modules = parseArguments(['--modules', consumer]).modules
for (const prerequisite of ['merchant-qualification-fixture', 'phase3-loading',
'phase3-loading-finalize', 'phase4-overseas-pda', 'phase4-overseas-pda-operations']) {
assert.ok(modules.indexOf(prerequisite) >= 0
&& modules.indexOf(prerequisite) < modules.indexOf(consumer))
}
}
})
test('entry uses one TEST gateway and rejects retired regional options', () => {
const options = parseArguments(['--gateway', 'http://localhost:9000/', '--modules', 'phase4-overseas-warehouse'])
assert.equal(options.gateway, 'http://localhost:9000')
assert.equal(options.environment, 'test')
assert.throws(() => parseArguments(['--overseas-gateway', 'http://localhost:9300']), /one TEST gateway/)
assert.throws(() => parseArguments(['--environment', 'cn']), /TEST|test/)
assert.doesNotMatch(source, /async requestOverseas|this\.overseasToken|overseasAccessToken/)
assert.match(source, /this\.refreshToken = login\.refreshToken/)
assert.match(source, /system后新admin统一Token只读探针可用/)
})
test('overseas business keeps its marker-scoped customer fixture with reusable credentials configured', () => {
const previousUsername = process.env.MERCHANT_TEST_USERNAME
const previousPassword = process.env.MERCHANT_TEST_PASSWORD
process.env.MERCHANT_TEST_USERNAME = 'reusable-client'
process.env.MERCHANT_TEST_PASSWORD = 'reusable-password'
try {
const modules = parseArguments(['--modules', 'phase4-overseas-business']).modules
assert.ok(modules.includes('merchant-qualification-fixture'))
assert.ok(modules.indexOf('merchant-qualification-fixture') < modules.indexOf('phase4-overseas-business'))
} finally {
if (previousUsername === undefined) delete process.env.MERCHANT_TEST_USERNAME
else process.env.MERCHANT_TEST_USERNAME = previousUsername
if (previousPassword === undefined) delete process.env.MERCHANT_TEST_PASSWORD
else process.env.MERCHANT_TEST_PASSWORD = previousPassword
}
})
test('a fixed origin route does not require randomized order fixtures', () => {
const options = parseArguments(['--origin-warehouse-name', '东莞仓', '--modules', 'phase4-overseas-pda'])
assert.equal(options.originWarehouseName, '东莞仓')
assert.equal(options.routeMode, 'fixed')
assert.equal(options.orderProfileMode, 'fixed')
assert.match(source, /else if \(this\.options\.originWarehouseName \|\| this\.options\.channelName \|\| this\.options\.channelCode\)/)
assert.match(source, /this\.context\.waitSplitRoute = \{[\s\S]*randomize: false/)
assert.match(source, /this\.context\.allowAnyExistingPallet = true/)
})
test('unified-session refresh replaces the whole session only after a complete response', async () => {
const run = new AcceptanceRun({ gateway: 'http://localhost:9000',
username: 'contract-user', password: 'contract-password', modules: [], output: '' })
Object.assign(run, { token: 'old-access', refreshToken: 'old-refresh', expiresAt: 1 })
run.request = async (method, path, body, token) => {
assert.equal(method, 'POST'); assert.equal(path, '/api/auth/refresh')
assert.deepEqual(body, { refreshToken: 'old-refresh' }); assert.equal(token, '')
return { method, path, http: 200, body: { code: '200', data: {
accessToken: 'new-access', refreshToken: 'new-refresh',
expiresIn: 900,
} }, requestId: 'refresh-request', traceId: 'refresh-trace' }
}
assert.equal(await run.refreshSession('contract'), true)
assert.equal(run.token, 'new-access')
assert.equal(run.refreshToken, 'new-refresh')
assert.ok(run.expiresAt > Date.now())
const frozen = { token: run.token, refreshToken: run.refreshToken,
expiresAt: run.expiresAt }
run.request = async (method, path) => ({ method, path, http: 200,
body: { code: '200', data: { accessToken: 'partial-only' } },
requestId: 'partial-request', traceId: 'partial-trace' })
assert.equal(await run.refreshSession('incomplete-contract'), false)
assert.deepEqual({ token: run.token, refreshToken: run.refreshToken,
expiresAt: run.expiresAt }, frozen)
})
test('entry has no built-in environment address or password and requires explicit execution options', () => {
assert.doesNotMatch(source, /8\.163\.|ChangeMe123|DEFAULT_PASSWORD|DEFAULT_GATEWAY/)
assert.throws(() => validateExecutionOptions(parseArguments(['--modules', 'phase4-overseas-pda'])),
/缺少必填执行参数/)
const options = parseArguments([
'--gateway', 'http://localhost:9000',
'--username', 'contract-user', '--password', 'contract-password', '--modules', 'phase4-overseas-pda',
'--pda-username', 'contract-picker', '--pda-password', 'contract-picker-password',
])
assert.equal(validateExecutionOptions(options), options)
})
test('loading dependency chains require PDA credentials before making any HTTP requests', () => {
for (const module of ['phase3-loading', 'phase3-container-loading', 'phase5-overseas-fulfillment']) {
const options = parseArguments(['--gateway', 'http://localhost:9000',
'--username', 'admin', '--password', 'fixture',
'--modules', module])
options.pdaUsername = ''
options.pdaPassword = ''
assert.throws(() => validateExecutionOptions(options), /PDA 作业员凭据/)
options.pdaUsername = 'picker'
assert.throws(() => validateExecutionOptions(options), /PDA 作业员凭据/)
options.pdaPassword = 'fixture'
assert.equal(validateExecutionOptions(options), options)
}
})
test('core coverage gaps fail closed while device and external-provider gaps remain report-only', () => {
const run = new AcceptanceRun({ gateway: 'http://localhost:9000',
username: 'contract-user', password: 'contract-password', modules: [], output: '' })
run.addCoverageGap('phase4', 'core', 'fixture', 'missing fixture', 'fixture')
assert.equal(run.steps.at(-1)?.passed, false)
assert.equal(run.steps.at(-1)?.deploymentBlocker, true)
const stepCount = run.steps.length
run.addCoverageGap('phase3', 'device', 'Android', 'manual device validation', 'device')
run.addCoverageGap('phase3', 'provider', 'captcha', 'external captcha', 'external-third-party')
run.addCoverageGap('phase3', 'device', 'Android', 'manual device validation', 'device')
run.addCoverageGap('phase3', 'provider', 'captcha', 'external captcha', 'external-third-party')
assert.equal(run.steps.length, stepCount)
assert.equal(run.coverageGaps.length, 3)
})
test('PDA entry expands the real phase-three producer chain and builds an FBA/OVERSEAS/second-container matrix', () => {
const modules = parseArguments(['--modules', 'phase4-overseas-pda']).modules
for (const prerequisite of ['merchant-qualification-fixture', 'phase3-loading', 'phase3-pda-convergence',
'phase3-evidence-gate', 'phase3-loading-finalize']) {
assert.ok(modules.indexOf(prerequisite) >= 0 && modules.indexOf(prerequisite) < modules.indexOf('phase4-overseas-pda'))
}
assert.match(source, /async ensurePhase4PdaProducerMatrix\(\)/)
assert.match(source, /runPhase4ProducerVariant\('DROPSHIP-PRIMARY', 'FBA', 'ONE_CLICK_DROPSHIP', true\)/)
assert.match(source, /runPhase4ProducerVariant\('OVERSEAS-PRIMARY', 'OVERSEAS', 'ONE_CLICK_DROPSHIP', true\)/)
assert.match(source, /runPhase4ProducerVariant\('FBA-STANDARD', 'FBA', 'STANDARD', true\)/)
assert.match(source, /runPhase4ProducerVariant\('FBA-OPERATIONS', 'FBA', 'STANDARD', true\)/)
assert.match(source, /-P4-FBA-STANDARD\(\?:-R\\d\+\)\?:/)
assert.match(source, /runPhase4ProducerVariant\('SECONDARY', 'FBA', 'STANDARD', false\)/)
assert.match(source, /runUntilPickupReady\(this\)/)
const variant = source.slice(source.indexOf('async runPhase4ProducerVariant'), source.indexOf('async ensurePhase4PdaProducerMatrix'))
assert.match(variant, /this\.phase4ProducerAttempts\.get\(label\)/)
assert.match(variant, /attempt === 1 \? '' : `-R\$\{attempt\}`/)
assert.ok(variant.indexOf('ensureInitialCalculated') < variant.indexOf('phase3-loading-phase4-'))
assert.match(variant, /fulfillmentType === 'ONE_CLICK_DROPSHIP'/)
assert.doesNotMatch(variant, /inboundFees\.run\(this\)/)
assert.ok(variant.indexOf('phase3-outbound-dispatch-phase4-') < variant.indexOf('phase3-container-documents-phase4-'))
assert.ok(variant.indexOf('phase3-container-documents-phase4-') < variant.indexOf('phase3-carrier-schedule-queries-phase4-'))
assert.match(source, /\['phase3-container-documents', \['phase3-outbound-dispatch'\]\]/)
assert.doesNotMatch(source, /\['phase3-outbound-dispatch', \['phase3-container-documents'/)
assert.match(source, /carrierScheduleQueryId/)
assert.match(source, /readyForPhase4Pda === true/)
assert.equal(modules.indexOf('phase4-overseas-pda-operations'), modules.indexOf('phase4-overseas-pda') + 1)
})