Files
foil-cap-theories/verify.js
2026-06-30 11:09:38 +03:00

68 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
const JSZip = require('jszip');
const base = __dirname;
const pptxPath = path.join(base, 'prezentaciya-vampiricheskoe-tenevoe-pravitelstvo.pptx');
const pdfPath = path.join(base, 'prezentaciya-vampiricheskoe-tenevoe-pravitelstvo.pdf');
const reportPath = path.join(base, 'doklad.md');
const handoutPath = path.join(base, 'razdatochnyj-material.md');
function assert(cond, msg) {
if (!cond) throw new Error(msg);
}
async function main() {
execFileSync('node', ['generate_presentation.js'], { cwd: base, stdio: 'inherit' });
assert(fs.existsSync(reportPath), 'Доклад не найден');
assert(fs.existsSync(handoutPath), 'Раздаточный материал не найден');
assert(fs.existsSync(pptxPath), 'PPTX не найден');
const report = fs.readFileSync(reportPath, 'utf8');
const handout = fs.readFileSync(handoutPath, 'utf8');
assert(report.includes('Sanguis Noctis Virus'), 'В докладе отсутствует ключевой термин');
assert(report.includes('Экономика качественной крови'), 'В докладе нет раздела о качественной крови');
assert(report.includes('Почему искусственная кровь им не подходит'), 'В докладе нет раздела про искусственную кровь');
assert(handout.includes('Тайный рынок доноров'), 'В раздатке нет блока про тайный рынок доноров');
const pptxBuf = fs.readFileSync(pptxPath);
const zip = await JSZip.loadAsync(pptxBuf);
const slideFiles = Object.keys(zip.files)
.filter((n) => /^ppt\/slides\/slide\d+\.xml$/.test(n))
.sort((a, b) => Number(a.match(/slide(\d+)/)[1]) - Number(b.match(/slide(\d+)/)[1]));
assert(slideFiles.length === 15, `Ожидалось 15 слайдов, получено ${slideFiles.length}`);
const firstSlide = await zip.files[slideFiles[0]].async('string');
const middleSlide = await zip.files[slideFiles[7]].async('string');
const lastSlide = await zip.files[slideFiles[slideFiles.length - 1]].async('string');
assert(firstSlide.includes('Пищевая цепочка:'), 'На первом слайде нет заголовка');
assert(middleSlide.includes('Экономика качественной крови'), 'Нет слайда про экономику качественной крови');
assert(lastSlide.includes('Вывод'), 'На последнем слайде нет слайда с выводом');
try {
execFileSync('soffice', ['--headless', '--convert-to', 'pdf', '--outdir', base, pptxPath], {
cwd: base,
stdio: 'pipe'
});
} catch (err) {
throw new Error(`Не удалось сконвертировать PPTX в PDF: ${err.message}`);
}
assert(fs.existsSync(pdfPath), 'PDF не был создан');
assert(fs.statSync(pdfPath).size > 20000, 'PDF подозрительно мал');
console.log('Verification OK');
console.log(`- report bytes: ${fs.statSync(reportPath).size}`);
console.log(`- handout bytes: ${fs.statSync(handoutPath).size}`);
console.log(`- pptx bytes: ${fs.statSync(pptxPath).size}`);
console.log(`- pdf bytes: ${fs.statSync(pdfPath).size}`);
console.log(`- slides: ${slideFiles.length}`);
}
main().catch((err) => {
console.error(err.stack || err.message || String(err));
process.exit(1);
});