import {mkdir,writeFile,readFile,copyFile} from 'node:fs/promises'; import {resolve,dirname} from 'node:path'; import {createHash} from 'node:crypto'; import {PDFDocument,StandardFonts,rgb} from 'pdf-lib'; const out=resolve(process.argv[2]??'file-comparison-output'); const save=async(name,data)=>{const path=resolve(out,name);await mkdir(dirname(path),{recursive:true});await writeFile(path,data,{flag:'wx'});}; const csvA='item,qty,unit_price,total\nAdapter,12,15000,180000\n'; const csvB='item,qty,unit_price,total\nAdapter,15,15000,225000\n'; await save('original/quote.csv',csvA); await save('renamed/quote-final.csv',csvA); await save('revised/quote.csv',csvB); await save('extension-only/quote.pdf',csvA); async function makePdf(qty,total,revision){ const doc=await PDFDocument.create(); doc.setTitle('Sample quote '+revision);doc.setSubject('Fictional sample: qty='+qty+'; total='+total);doc.setAuthor('ToffeeLab');doc.setCreationDate(new Date('2026-11-22T00:00:00Z'));doc.setModificationDate(new Date('2026-11-22T00:00:00Z')); const page=doc.addPage([595,420]); const font=await doc.embedFont(StandardFonts.Helvetica); const bold=await doc.embedFont(StandardFonts.HelveticaBold); page.drawRectangle({x:0,y:0,width:595,height:420,color:rgb(.96,.97,.99)}); const text=(s,x,y,size=14,strong=false)=>page.drawText(s,{x,y,size,font:strong?bold:font,color:rgb(.12,.17,.25)}); text('SAMPLE QUOTE',36,362,26,true);text('FICTIONAL DATA - NOT A TRANSACTION',36,332,10);text('Revision '+revision,36,290,18,true); text('Item',36,242,12,true);text('Quantity',260,242,12,true);text('Unit price (KRW)',355,242,12,true); page.drawLine({start:{x:36,y:228},end:{x:559,y:228},thickness:1,color:rgb(.7,.75,.8)}); text('Adapter',36,200);text(String(qty),260,200);text('15,000',355,200); text('Total (KRW)',36,140,18,true);text(total.toLocaleString('en-US'),355,140,24,true); text('Created for the ToffeeLab file comparison, 2026-11-22.',36,60,10); return doc.save({useObjectStreams:false}); } await save('exported/quote.pdf',await makePdf(12,180000,'A')); await save('copied-attachment/quote.pdf',await readFile(resolve(out,'exported/quote.pdf'))); await save('current/quote.pdf',await makePdf(15,225000,'B')); const names=['original/quote.csv','renamed/quote-final.csv','revised/quote.csv','extension-only/quote.pdf','exported/quote.pdf','copied-attachment/quote.pdf','current/quote.pdf']; const records=[]; for(const name of names){const b=await readFile(resolve(out,name));let pdfPages=null;try{pdfPages=(await PDFDocument.load(b)).getPageCount();}catch{} records.push({path:name,bytes:b.length,sha256:createHash('sha256').update(b).digest('hex'),firstBytesHex:b.subarray(0,8).toString('hex'),pdfPages});} const by=name=>records.find(r=>r.path===name); const assertions={renamingKeepsBytes:by(names[0]).sha256===by(names[1]).sha256,sameSizeDifferentContent:by(names[0]).bytes===by(names[2]).bytes&&by(names[0]).sha256!==by(names[2]).sha256,extensionOnlyIsNotPdf:by(names[3]).pdfPages===null,exportIsPdf:by(names[4]).pdfPages===1,copiedAttachmentRetainsRevisionA:by(names[4]).sha256===by(names[5]).sha256&&by(names[5]).sha256!==by(names[6]).sha256}; if(!Object.values(assertions).every(Boolean))throw new Error('Unexpected comparison result'); const report={observedAt:new Date().toISOString(),editorialDate:'2026-11-22',environment:{node:process.version,platform:process.platform,pdfLib:'1.17.1'},scope:'Generated fictional files and local byte copies. No Gmail delivery, Drive account or recipient device was tested.',records,assertions}; await save('observations.json',JSON.stringify(report,null,2)+'\n'); await save('README.txt','ToffeeLab fictional file samples, 2026-11-22.\nCSV files use UTF-8. Amounts are illustrative KRW values, not a real quote.\nThe extension-only/quote.pdf file is deliberately CSV text with a PDF name; it is not a PDF.\nexported/quote.pdf and copied-attachment/quote.pdf are Revision A. current/quote.pdf is Revision B.\nRead observations.json for byte lengths, full SHA-256 values and parser checks.\nNo live email or cloud service was tested.\n'); console.log(JSON.stringify(report));