fix(master-data): scope shadow env to audit diff steps
This commit is contained in:
parent
cfc3e5cc0e
commit
86df630894
@ -256,6 +256,7 @@ function auditSteps(outputDir, options = {}) {
|
||||
id: 'foundation-preflight',
|
||||
label: '结构变更前置预检',
|
||||
outputFile: path.join(outputDir, 'foundation-preflight.json'),
|
||||
usesShadowDatabase: true,
|
||||
args: [
|
||||
'scripts/preflight-database-foundation-change.js',
|
||||
'--output',
|
||||
@ -266,6 +267,7 @@ function auditSteps(outputDir, options = {}) {
|
||||
id: 'foundation-migrate-plan',
|
||||
label: '治理迁移执行计划',
|
||||
outputFile: path.join(outputDir, 'foundation-migrate-plan.json'),
|
||||
usesShadowDatabase: true,
|
||||
args: [
|
||||
'scripts/run-database-foundation-migrations.js',
|
||||
'--output',
|
||||
@ -432,16 +434,25 @@ function auditSteps(outputDir, options = {}) {
|
||||
return steps
|
||||
}
|
||||
|
||||
function environmentForAuditStep(step, env = process.env) {
|
||||
const stepEnv = { ...env }
|
||||
if (step?.usesShadowDatabase === true) return stepEnv
|
||||
|
||||
delete stepEnv.SHADOW_DATABASE_URL
|
||||
return stepEnv
|
||||
}
|
||||
|
||||
function readJsonFile(filePath) {
|
||||
if (!fs.existsSync(filePath)) return null
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
||||
}
|
||||
|
||||
function runAuditStep(step, env = process.env) {
|
||||
const stepEnv = environmentForAuditStep(step, env)
|
||||
const result = spawnSync(process.execPath, step.args, {
|
||||
cwd: ROOT_DIR,
|
||||
encoding: 'utf8',
|
||||
env: { ...process.env, ...env },
|
||||
env: { ...process.env, ...stepEnv },
|
||||
windowsHide: true,
|
||||
})
|
||||
const outputExists = fs.existsSync(step.outputFile)
|
||||
@ -1766,6 +1777,7 @@ module.exports = {
|
||||
countByField,
|
||||
createDockerShadowDatabase,
|
||||
defaultOutputDir,
|
||||
environmentForAuditStep,
|
||||
parseArgs,
|
||||
redactStepPreview,
|
||||
runAudit,
|
||||
|
||||
@ -26,6 +26,7 @@ const {
|
||||
countByField,
|
||||
countQualityDecisionPlaceholderFields,
|
||||
defaultOutputDir,
|
||||
environmentForAuditStep,
|
||||
parseArgs,
|
||||
timestampForDirectory,
|
||||
writeJsonReport,
|
||||
@ -205,6 +206,26 @@ describe('run-master-data-foundation-audit', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('only passes shadow database URLs to steps that need migration diff evidence', () => {
|
||||
const outputDir = path.resolve(__dirname, '../../.master-data-audits/example')
|
||||
const steps = auditSteps(outputDir)
|
||||
const readinessStep = steps.find((step) => step.id === 'readiness')
|
||||
const preflightStep = steps.find((step) => step.id === 'foundation-preflight')
|
||||
const migratePlanStep = steps.find((step) => step.id === 'foundation-migrate-plan')
|
||||
const env = {
|
||||
DATABASE_URL: 'postgresql://app:secret@localhost:5432/furniture_3d',
|
||||
SHADOW_DATABASE_URL: 'postgresql://shadow:secret@localhost:65436/furniture_3d_shadow',
|
||||
}
|
||||
|
||||
expect(preflightStep).toEqual(expect.objectContaining({ usesShadowDatabase: true }))
|
||||
expect(migratePlanStep).toEqual(expect.objectContaining({ usesShadowDatabase: true }))
|
||||
expect(environmentForAuditStep(readinessStep, env)).toEqual({
|
||||
DATABASE_URL: env.DATABASE_URL,
|
||||
})
|
||||
expect(environmentForAuditStep(preflightStep, env)).toEqual(env)
|
||||
expect(environmentForAuditStep(migratePlanStep, env)).toEqual(env)
|
||||
})
|
||||
|
||||
it('adds the sensitive cleanup template step only when explicitly requested', () => {
|
||||
const outputDir = path.resolve(__dirname, '../../.master-data-audits/example')
|
||||
const defaultSteps = auditSteps(outputDir)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user