#!/usr/bin/env node const fs = require('fs'); const os = require('os'); const path = require('path'); const { spawnSync } = require('child_process'); const { SOFTWARE_HEADER } = require('./export-proof-gap-software-form'); const root = path.resolve(__dirname, '..'); function main() { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tihao-proof-gap-form-')); const outputDir = path.join(tmp, 'form-latest'); const result = spawnSync(process.execPath, [ path.join(root, 'scripts', 'export-proof-gap-software-form.js'), '--output', outputDir, '--strict' ], { cwd: root, encoding: 'utf8' }); if (result.status !== 0) { process.stderr.write(result.stderr || result.stdout || ''); throw new Error('proof-gap software form export should pass'); } const csvPath = path.join(outputDir, 'tihao-proof-gap-software-form.csv'); const mdPath = path.join(outputDir, 'tihao-proof-gap-software-form.md'); const summaryPath = path.join(outputDir, 'tihao-proof-gap-software-form-summary.json'); assert(fs.existsSync(csvPath), 'csv should exist'); assert(fs.existsSync(mdPath), 'markdown should exist'); assert(fs.existsSync(summaryPath), 'summary should exist'); const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8')); const csv = fs.readFileSync(csvPath, 'utf8'); const md = fs.readFileSync(mdPath, 'utf8').replace(/^\uFEFF/, ''); const lines = csv.replace(/^\uFEFF/, '').split(/\r?\n/).filter(Boolean); assert(csv.charCodeAt(0) === 0xFEFF, 'csv should have UTF-8 BOM'); assert(summary.passed === true, 'summary should pass'); assert(summary.headerMatches === true, 'header should match software header'); assert(summary.rowWidthOk === true, 'all rows should have software header width'); assert(summary.rowCount === 5, 'row count should be 5'); assert(summary.duplicateIdCount === 0, 'duplicate ids should be 0'); assert(lines[0] === SOFTWARE_HEADER.join(','), 'csv header should match software header'); assert(lines.filter(line => /^GAP-\d{3},/.test(line)).length === 5, 'csv should include 5 GAP rows'); for (const title of summary.expectedTitles) { assert(csv.includes(title), `csv should include ${title}`); assert(md.includes(title), `markdown should include ${title}`); } assert(md.includes('最新提号补证表单'), 'markdown should be Chinese'); assert(md.includes('不能把 sample、smoke'), 'markdown should keep proof boundary'); assert(!/sk-[A-Za-z0-9_-]{10,}/.test(csv + md), 'form should not contain model token patterns'); assert(!/r:[A-Za-z0-9]{20,}/.test(csv + md), 'form should not contain Parse sessionToken patterns'); console.log(JSON.stringify({ ok: true, outputDir, rowCount: summary.rowCount, duplicateIdCount: summary.duplicateIdCount }, null, 2)); } function assert(condition, message) { if (!condition) throw new Error(message); } main();