Files
SGF/scripts/geography-demo-assets.mjs
2026-11-04 09:37:20 +02:00

3 lines
1.9 KiB
JavaScript

import fs from 'node:fs';import path from 'node:path';import assert from 'node:assert/strict';import crypto from 'node:crypto';import {spawnSync} from 'node:child_process';
const tag=process.argv[2];assert(/^[a-f0-9]{12}$/.test(tag??''));const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=path.join(run.root,'private/receipt-composition-'+tag),s=JSON.parse(fs.readFileSync(path.join(root,'state.json'))),out=path.join(root,'geography-demo-assets.json');assert(s.suppliers&&!fs.existsSync(out));if(!fs.existsSync(path.join(root,'geography-build.log'))){const result=spawnSync(process.execPath,['node_modules/vite/bin/vite.js','build','--outDir',path.join(s.app,'public/build')],{cwd:process.cwd(),encoding:'utf8',windowsHide:true,timeout:180000});fs.writeFileSync(path.join(root,'geography-build.log'),result.stdout+'\n'+result.stderr);assert.equal(result.status,0,'private build');}else assert(fs.readFileSync(path.join(root,'geography-build.log'),'utf8').includes('built in'),'prior build succeeded');const manifest=JSON.parse(fs.readFileSync(path.join(s.app,'public/build/manifest.json'))),files=Object.values(manifest).flatMap(v=>[v.file,...(v.css??[])]),checks=['private frontend build succeeds'];for(const file of files){const bytes=fs.readFileSync(path.join(s.app,'public/build',file)),r=await fetch('http://127.0.0.1:8069/build/'+file);assert.equal(r.status,200);assert.equal(crypto.createHash('sha256').update(Buffer.from(await r.arrayBuffer())).digest('hex'),crypto.createHash('sha256').update(bytes).digest('hex'));}checks.push('served built assets match private build');const r=await fetch('http://127.0.0.1:8069/geography-workspace.mjs');assert.equal(r.status,200);checks.push('geography module is served through private static whitelist');fs.writeFileSync(out,JSON.stringify({passed:true,checks,assets:files,visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length}));