Files
baiyue-firstleg/scripts/overseas-deployment-contract.test.mjs

54 lines
3.6 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync, existsSync, readdirSync } from 'node:fs'
import test from 'node:test'
const read = p => readFileSync(new URL('../' + p, import.meta.url), 'utf8').replaceAll('\r\n','\n')
const exists = p => existsSync(new URL('../' + p, import.meta.url))
test('TEST has one complete Compose, namespace, session and no retired deployment entry', () => {
const compose=read('deploy/docker-compose.yml')
for(const service of ['gateway','auth','iam','firstleg','finance','order','warehouse','file','print','integration-service','lastleg-service','warehouse-overseas-service','audit-service']) assert.match(compose,new RegExp('^ '+service+':','m'))
assert.doesNotMatch(compose,/event-bridge|gateway-overseas|OVERSEAS_REDIS|OVERSEAS_NACOS|OVERSEAS_JWT|JWT_SECRET|test-cn|test-overseas/)
assert.match(compose,/SPRING_PROFILES_ACTIVE: \$\{DEPLOY_ENV:-test\}/)
assert.match(compose,/NACOS_NAMESPACE: \$\{NACOS_NAMESPACE:\?actual environment namespace ID required\}/)
assert.match(compose,/REDIS_DATABASE: \$\{REDIS_DATABASE:-0\}/)
assert.match(compose,/SPRING_DATA_REDIS_USERNAME: \$\{REDIS_USERNAME:-default\}/)
assert.match(compose,/JWT_JWKS_URI: http:\/\/auth:9100\/api\/auth\/\.well-known\/jwks.json/)
assert.equal([...compose.matchAll(/^ ports:/gm)].length,1)
assert.equal([...compose.matchAll(/^ JWT_RSA_JWK_SET:/gm)].length,1)
assert.equal([...compose.matchAll(/^ EVENT_OPERATIONS_TOKEN:/gm)].length,3)
assert.match(compose,/LASTLEG_SERVICE_URL: http:\/\/lastleg-service:9303/)
assert.match(compose,/FIRSTLEG_SERVICE_URL: http:\/\/firstleg:9202/)
assert.match(compose,/FINANCE_SERVICE_URL: http:\/\/finance:9203/)
assert.match(compose,/FILE_UPLOADS_HOST_DIR/)
assert.match(compose,/ROCKETMQ_NAME_SERVER/)
for(const p of ['deploy/docker-compose.overseas.yml','deploy/scripts/deploy-blue-green-service.sh','deploy/scripts/deploy-development-service.sh']) assert.equal(exists(p),false,p)
})
test('every retained application imports TEST configuration with explicit namespace and no SQL auto init',()=>{
const services=[...read('deploy/service-map.yml').matchAll(/^ ([a-z][a-z-]+):/gm)].map(m=>m[1])
for(const service of services){
const app=read(`${service}/src/main/resources/application.yml`)
assert.match(app,/nacos:baiyue-common.yml\?group=\$\{NACOS_GROUP:BAIYUE\}/)
assert.match(app,/\$\{NACOS_NAMESPACE\}/)
assert.doesNotMatch(app,/optional:nacos|NACOS_NAMESPACE:public|mode: always|EVENT_BRIDGE|JWT_SECRET|REDIS_PORT:6380/)
}
const common=read('config/nacos/test/baiyue-common.yml')
assert.match(common,/jwt-mode: jwks/)
assert.match(common,/session-mode: redis/)
assert.match(common,/session-validation-uri: \$\{AUTH_SESSION_VALIDATION_URL:http:\/\/auth:9100\/internal\/auth\/accounts\/sessions\/validate\}/)
assert.match(read('deploy/scripts/deploy-built-service.sh'),/Missing HEALTHCHECK; deployment failed/)
})
test('Jenkins retains the unified topology across TEST and gray; Nacos import stays explicit',()=>{
for(const p of ['Jenkinsfile','Jenkinsfile.service']){
const s=read(p)
assert.doesNotMatch(s,/EVENT_BRIDGE|gateway-overseas|event-bridge-service|return 'development'|java-dev/)
assert.doesNotMatch(s,/maven.test.skip/)
}
assert.match(read('Jenkinsfile.service'),/node\('java-test'\)/)
assert.match(read('Jenkinsfile.service'),/ALLOW_SAME_CONTRACT_ROLLBACK', defaultValue: false/)
const publisher=read('scripts/publish-nacos-config.ps1')
assert.match(publisher,/ValidateSet\('test'\)/)
assert.match(publisher,/config\/nacos\/test/)
assert.match(publisher,/\[switch\]\$DryRun/)
assert.match(publisher,/accessToken/)
})