Files
baiyue-firstleg/scripts/controller-pipeline-contract.test.mjs
T

54 lines
2.8 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const pipeline = (await readFile(new URL('../Jenkinsfile', import.meta.url), 'utf8'))
.replaceAll('\r\n', '\n')
test('coordinator releases its builder while waiting for downstream jobs', () => {
assert.match(pipeline, /pipeline \{[\s\S]*?agent none/)
assert.match(pipeline, /stage\('确定构建范围'\) \{[\s\S]*?agent \{ label 'java-builder' \}/)
assert.match(pipeline, /agent \{ label 'java-builder' \}/)
assert.doesNotMatch(pipeline, /agent any/)
assert.doesNotMatch(pipeline, /cleanWs\(/)
assert.doesNotMatch(pipeline, /^\s*(?:&&|\|\|)/m)
})
test('coordinator runs selected tests once before parallel service packaging', () => {
const gateIndex = pipeline.indexOf("stage('统一 Maven 测试门禁')")
const dispatchIndex = pipeline.indexOf("stage('并行调度独立服务 Job')")
assert.ok(gateIndex >= 0, 'unified test gate must exist')
assert.ok(dispatchIndex > gateIndex, 'unified tests must finish before downstream dispatch')
assert.match(pipeline, /-pl \$\{selectedModules\} -am test/)
assert.match(pipeline, /booleanParam\(name: 'SKIP_TESTS', value: true\)/)
assert.doesNotMatch(pipeline, /TESTED_COMMIT/)
})
test('AUTO detects database migrations without expanding them to all services', () => {
assert.match(pipeline, /def databaseMigrationPaths = \['deploy\/sql\/'\]/)
assert.match(pipeline, /!databaseMigration && commonPaths\.any/)
assert.match(pipeline, /env\.DATABASE_CHANGE_DETECTED = databaseChanged \? 'true' : 'false'/)
})
test('database-only changes are reported as a separate migration action', () => {
assert.match(pipeline, /仅数据库迁移变更 \| 需单独审核执行/)
assert.match(pipeline, /统一 SQL 须独立审核并执行/)
})
test('coordinator cannot initialize test databases', () => {
assert.doesNotMatch(pipeline, /INITIALIZE_TEST_DATABASE/)
assert.doesNotMatch(pipeline, /initialize-test-databases\.sh/)
assert.doesNotMatch(pipeline, /测试数据库初始化/)
})
test('coordinator defaults event bridge deployments to both non-production regions', () => {
assert.match(pipeline, /choice\(name: 'EVENT_BRIDGE_REGION', choices: \['BOTH', 'CN', 'OVERSEAS'\]/)
assert.match(pipeline, /\['BOTH', 'SELECT', 'CN', 'OVERSEAS'\]\.contains\(bridgeRegion\)/)
assert.match(pipeline, /兼容旧 Jenkins 参数 SELECT:本次按 BOTH/)
assert.match(pipeline, /事件桥 BOTH 仅支持开发或测试环境/)
assert.match(pipeline, /String downstreamImageTag = deployBothBridges[\s\S]*?\? "\$\{env\.IMAGE_TAG\}-both"/)
assert.match(pipeline, /String downstreamBridgeRegion = deployBothBridges[\s\S]*?\? 'CN'/)
assert.match(pipeline, /string\(name: 'EVENT_BRIDGE_REGION', value: downstreamBridgeRegion\)/)
})