Files
baiyue-firstleg/scripts/phase4-overseas-acceptance-entry-contract.test.mjs
T
2026-08-24 19:58:35 +08:00

71 lines
3.6 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-cross-region-events',
'phase4-overseas-business',
'phase4-overseas-master-data',
'phase4-carrier-nodes',
]) {
assert.match(source, new RegExp(`CONFIGURED_MODULES\\s*=\\s*\\[[^\\]]*'${module}'`, 's'))
}
})
test('entry accepts a separate overseas Gateway without exposing token state', () => {
const options = parseArguments([
'--gateway', 'http://localhost:9000/',
'--overseas-gateway', 'http://localhost:9300/',
'--modules', 'phase4-overseas-warehouse',
])
assert.equal(options.gateway, 'http://localhost:9000')
assert.equal(options.overseasGateway, 'http://localhost:9300')
assert.match(source, /this\.overseasToken = login\.overseasAccessToken \|\| ''/)
assert.match(source, /async requestOverseas\(/)
assert.match(source, /async requestOverseasBinary\(/)
assert.match(source, /async requestOverseasMultipart\(/)
assert.match(source, /forbiddenValues = \[this\.options\.password, this\.token, this\.overseasToken\]/)
})
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', '--overseas-gateway', 'http://localhost:9300',
'--username', 'contract-user', '--password', 'contract-password', '--modules', 'phase4-overseas-pda',
])
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', overseasGateway: 'http://localhost:9300',
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')
assert.equal(run.steps.length, stepCount)
})
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\('OVERSEAS-PRIMARY', 'OVERSEAS'\)/)
assert.match(source, /runPhase4ProducerVariant\('SECONDARY', 'FBA'\)/)
assert.match(source, /readyForPhase4Pda === true/)
})