import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; import {fileURLToPath} from 'node:url'; import {validateDevelopmentReferences} from '../payload/src/core/development-references.js'; const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'); const manifest=JSON.parse(fs.readFileSync(path.join(root,'deploy/industry-ui-files.json'))); const argv=process.argv.slice(2); if(argv.length&&!(argv.length===2&&argv[0]==='--origin'))throw Error('USAGE'); const origin=new URL(argv[1]||'https://kangshifu.fmode.cn'); if(!['https:','http:'].includes(origin.protocol)||origin.pathname!=='/'||origin.username||origin.password)throw Error('INVALID_ORIGIN'); const sha=b=>crypto.createHash('sha256').update(b).digest('hex'); const result={ok:false,release:manifest.release,checkedAt:new Date().toISOString(),origin:origin.origin,files:[],checks:[],productionWrites:0,paidCalls:0}; const check=(name,ok)=>result.checks.push({name,ok:!!ok}); try{ let data; for(const file of manifest.files){ const url=new URL(file.path,origin);url.searchParams.set('r15verify',String(Date.now())); const response=await fetch(url,{cache:'no-store',signal:AbortSignal.timeout(30000)}); const raw=Buffer.from(await response.arrayBuffer()),contentType=response.headers.get('content-type')||''; const normalizedSha256=sha(Buffer.from(raw.toString('utf8').replaceAll('\r\n','\n'))); const matches=response.ok&&contentType.includes(file.path.endsWith('.json')?'application/json':'javascript')&&normalizedSha256===file.sha256; result.files.push({path:file.path,status:response.status,bytes:raw.length,sha256:sha(raw),normalizedSha256,contentType,matches}); if(file.path.endsWith('.json')&&matches)data=validateDevelopmentReferences(JSON.parse(raw)); } check('six-public-files-match',result.files.length===6&&result.files.every(r=>r.matches)); check('verified-research-publication',data?.records.length===58&&data.sources.length===14); const home=await fetch(new URL('index.html',origin),{cache:'no-store',signal:AbortSignal.timeout(30000)}); result.homepageSha256=sha(Buffer.from(await home.arrayBuffer()));check('homepage-unchanged',home.ok&&result.homepageSha256===manifest.homepageSha256); const response=await fetch(new URL('api/library',origin),{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({op:'summary'}),signal:AbortSignal.timeout(30000)}); const summary=await response.json();result.generation=summary.generation;result.counts=summary.counts; check('VOC-library-read-only',response.ok&&summary.ok&&summary.readOnly===true&&summary.databaseWrites===0); check('reference-generation-matches-library',data?.libraryGeneration===summary.generation); check('product-review-price-counts-preserved',summary.counts?.products===4674&&summary.counts.reviews===3454&&summary.counts.prices===4172); result.ok=result.checks.every(r=>r.ok); }catch(e){result.error='PUBLIC_VERIFICATION_FAILED';} console.log(JSON.stringify(result,null,2));if(!result.ok)process.exitCode=1;