Files
baiyue-firstleg/scripts/client-import-template-test-env.mjs
T

26 lines
2.0 KiB
JavaScript

import { spawn } from 'node:child_process'
import { resolve, dirname } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { executionOptions } from './client-workbench-test-env.mjs'
export async function execute(args = process.argv.slice(2), execArgs = process.execArgv, env = process.env) {
if (!args.length || args.length === 1 && args[0] === '--plan') return { plan: true, businessWrites: false,
checks: ['full warehouse catalog', 'channel union', 'own customer addresses', 'named dropdown ranges', '50 input rows'],
required: 'Explicit TEST profile, new run-id, and --python=<bundled workspace Python>' }
if (args.length !== 4 || !args[3].startsWith('--python=')) throw new Error('Explicit bundled Python required')
const options = executionOptions(args.slice(0, 3), execArgs, env)
const python = resolve(args[3].slice(9))
if (!python.replaceAll('\\', '/').endsWith('/codex-primary-runtime/dependencies/python/python.exe')) throw new Error('Use bundled workspace Python')
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const config = { environment: 'TEST', base: options.base, username: env.CHONGCHONG_MERCHANT_USERNAME,
password: env.CHONGCHONG_MERCHANT_PASSWORD, runId: options.runId }
const child = spawn(python, [resolve(root, 'scripts/client-import-template-inspect.py')], { cwd: root, windowsHide: true, stdio: ['pipe', 'inherit', 'inherit'] })
child.stdin.end(JSON.stringify(config))
const code = await new Promise((accept, reject) => { child.on('error', reject); child.on('close', accept) })
return { success: code === 0, report: resolve(root, 'reports', `client-template-${options.runId}`, 'report.json') }
}
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
execute().then(result => { console.log(JSON.stringify(result)); if (result.success === false) process.exitCode = 1 })
.catch(() => { console.error('Template audit did not start. Check explicit TEST profile, runtime and new run-id.'); process.exitCode = 1 })
}