Files
SGF/scripts/workshop-stock-closure-ui-check.mjs
2026-11-02 20:29:34 +02:00

31 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import crypto from 'node:crypto';
import React from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import {createServer} from 'vite';
const server=await createServer({configFile:false,server:{middlewareMode:true,watch:null},appType:'custom',optimizeDeps:{noDiscovery:true}});
try {
const {WorkshopStockClosureImpact,WorkshopStockImpact}=await server.ssrLoadModule('/resources/js/WorkshopStockWorkspace.jsx');
for(const action of ['withdraw','reject']){
const html=renderToStaticMarkup(React.createElement(WorkshopStockClosureImpact,{action}));
assert(html.includes(action==='withdraw'?'retirada':'recusada'));
assert(html.includes('Efeito físico: 0'));
assert(html.includes('nenhuma origem será associada ou libertada'));
assert(html.includes('nova conferência'));
}
const impact={physical_before:'5000',physical_after:'8000',quantity_milli:'0',return_quantity_milli:'3000',mode:'return_existing_delivery',existing_movement_id:42,unallocated_before:'3000',unallocated_after:'0',stock_item_id:1,warehouse_id:11,source_version:1};
const html=renderToStaticMarkup(React.createElement(WorkshopStockImpact,{impact}));
assert(html.includes('5,000 → 8,000'));assert(html.includes('Entrada por devolução: 3,000'));
const source=await fs.readFile('resources/js/WorkshopStockWorkspace.jsx','utf8');
assert(source.includes('Prévia arquivada, não executada.'));
assert(source.includes('state_version:p.state_version,source_hash:p.source_hash'));
assert(source.includes('p.can_withdraw&&can(\'workshop_stock.prepare\',unit)'));
assert(source.includes('p.can_review&&can(\'workshop_stock.confirm\',unit)'));
assert(source.includes('if(n===generation.current)'));
const report={kind:'static_closure_impact_render_and_source_guards',closure_zero_effect_visible:true,archival_and_new_review_visible:true,existing_return_impact_preserved:true,version_and_hash_sent:true,independent_action_visibility_guards:true,context_generation_guards:true,source_sha256:crypto.createHash('sha256').update(source).digest('hex'),backend_requests:0,browser_interactions_tested:false,visual_review:false};
await fs.writeFile('docs/proofs/workshop-stock-closure-ui-20261102.json',JSON.stringify(report,null,2)+'\n');
console.log(JSON.stringify(report));
} finally {await server.close();}