#!/usr/bin/env node const fs = require('fs'); const os = require('os'); const path = require('path'); const { spawnSync } = require('child_process'); const { HISTORY_HEADER, REVIEW_HEADER } = require('./create-data-intake-pack'); const root = path.resolve(__dirname, '..'); function main() { const output = fs.mkdtempSync(path.join(os.tmpdir(), 'tihao-data-intake-')); const result = spawnSync(process.execPath, [ path.join(root, 'scripts', 'create-data-intake-pack.js'), '--output', output ], { cwd: root, encoding: 'utf8' }); if (result.status !== 0) { process.stderr.write(result.stderr || result.stdout || ''); throw new Error('create-data-intake-pack failed'); } const historyCsv = path.join(output, 'history-data-template.csv'); const reviewCsv = path.join(output, 'manual-review-template.csv'); const readme = path.join(output, 'README.md'); assert(fs.existsSync(historyCsv), 'history template should exist'); assert(fs.existsSync(reviewCsv), 'review template should exist'); assert(fs.existsSync(readme), 'README should exist'); assert(readHeader(historyCsv) === HISTORY_HEADER.join(','), 'history template header should match history:from-csv fields'); assert(readHeader(reviewCsv) === REVIEW_HEADER.join(','), 'review template header should match review/customer-effect fields'); const allText = [historyCsv, reviewCsv, readme].map(file => fs.readFileSync(file, 'utf8')).join('\n'); assert(!/(sk-[A-Za-z0-9_-]{20,}|r:[A-Za-z0-9]{20,}|Authorization\s*[:=]\s*Bearer)/i.test(allText), 'data intake pack should not contain secrets'); assert(allText.includes('客户选择'), 'templates should include customer decision field'); assert(allText.includes('历史人工补号量基线'), 'templates should include historical manual supplement baseline'); assert(allText.includes('本轮人工补号量'), 'templates should include current manual supplement count'); assert(allText.includes('字段填写验收表'), 'README should include field checklist'); assert(allText.includes('常见退回原因'), 'README should explain common rejection reasons'); assert(allText.includes('npm run intake:readiness'), 'README should tell business to run intake readiness first'); assert(allText.includes('客户拒绝样本必须填写'), 'README should explain rejection reason requirement'); assert(fs.readFileSync(readme, 'utf8').includes('才能宣称客户效果证明完成'), 'README should preserve proof boundary'); console.log(JSON.stringify({ ok: true, output, files: 3 }, null, 2)); } function readHeader(file) { return fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '').split(/\r?\n/)[0]; } function assert(condition, message) { if (!condition) throw new Error(message); } main();