@davoodmehraban89 / Factor-easy / commits / 2f0a0d4
Fork 0

سامانه صدور فاکتور و حسابداری

Gate bounded restore and integration inputs

davoodmehraban89 committed Sep 29, 2026 at 22:35 UTC 2f0a0d425d3022f6f915b17d987f3e91069cd215
1 file changed +2 -1
scripts/phase5-behavior-check.mjs
+2 -1
@@ -9,8 +9,9 @@ eq(D.convert(10,600000),6000000,'fx conversion');
9 D.validateMovement({kind:'transfer',productId:'P1',warehouseId:'W1',toWarehouseId:'W2',qty:1});
10 let rejected=false;try{D.validateMovement({kind:'transfer',productId:'P1',warehouseId:'W1',toWarehouseId:'W1',qty:1})}catch{rejected=true}if(!rejected)throw new Error('same-warehouse transfer accepted');
11 D.validateRestore({formatVersion:5,warehouses:[]},['warehouses']);rejected=false;try{D.validateRestore({evil:[]},['warehouses'])}catch{rejected=true}if(!rejected)throw new Error('unknown restore collection accepted');
12 -const app=fs.readFileSync('js/phase5-enterprise.js','utf8');for(const x of ['p5PostMovement','p5SaveCount','p5RunDepreciation','p5SaveRate','p5SaveCostCenter','p5PreviewRestore','p5QueueEvent','status:\'posted\''])if(!app.includes(x))throw new Error('Phase5 application invariant missing '+x);
12 +const app=fs.readFileSync('js/phase5-enterprise.js','utf8');for(const x of ['p5PostMovement','p5SaveCount','p5RunDepreciation','p5SaveRate','p5SaveCostCenter','p5PreviewRestore','p5QueueEvent','p5ValidateIntegrationEndpoint','20*1024*1024','status:\'posted\''])if(!app.includes(x))throw new Error('Phase5 application invariant missing '+x);
13 const intCtx={URL};vm.createContext(intCtx);vm.runInContext(app,intCtx);if(vm.runInContext("p5ValidateIntegrationEndpoint('https://hooks.example.com/events')",intCtx)!=='https://hooks.example.com/events')throw new Error('valid HTTPS integration endpoint rejected');for(const bad of ['http://hooks.example.com','https://user:pass@hooks.example.com','https://localhost/hook','https://192.168.1.20/hook']){let blocked=false;try{intCtx.bad=bad;vm.runInContext("p5ValidateIntegrationEndpoint(bad)",intCtx)}catch{blocked=true}if(!blocked)throw new Error('unsafe integration endpoint accepted: '+bad)}
14 +const backup=fs.readFileSync('js/backup.js','utf8');if(!backup.includes('20*1024*1024'))throw new Error('backup import size bound missing');
15 console.log('Phase 5 behavioral/domain scenarios passed.');
16 const syncSrc=fs.readFileSync('js/sync.js','utf8');const syncCtx={console,currentUser:{id:'u1'},COLLS:[],neutralize:x=>JSON.parse(JSON.stringify(x)),safeId:(id,p)=>String(id||p),window:{addEventListener:()=>{}},document:{getElementById:()=>null,addEventListener:()=>{},visibilityState:'visible'},setTimeout:()=>0,clearTimeout:()=>{},localStorage:{getItem:()=>null,setItem:()=>{}},confirm:()=>true,alert:()=>{},refreshAllSurfaces:()=>{},requireWrite:()=>true};vm.createContext(syncCtx);vm.runInContext(syncSrc,syncCtx);
17 vm.runInContext("datastore.products.push({id:'P1',ownerUserId:'u1',name:'Before'});datastore.journalVouchers.push({id:'JV1',ownerUserId:'u1',status:'posted'});datastore.journalLines.push({id:'JL1',ownerUserId:'u1',voucherId:'JV1',debit:100,credit:0});",syncCtx);