فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A04): instrument real native importAll mid-write before force-kill
davoodmehraban89 committed
Oct 16, 2026 at 23:07 UTC
f282893d0ca2dcb60a16bb761c58520359e6792a
1 file changed
+43
tests/windows-vm-native-crash-import-browser.js
new
+43
@@ -0,0 +1,43 @@
1
+(async () => {
2
+ const check=(value,message)=>{if(!value)throw Error(message);};
3
+ check(!!globalThis.__TAURI_INTERNALS__?.invoke,
4
+ 'Crash restore must run in real installed native WebView2');
5
+ const store=FINORA.Storage;
6
+ const company=await FINORA.Company.current();
7
+ check(company?.id && FINORA.Auth.isAdmin(),
8
+ 'A04 crash test needs an authenticated synthetic administrator');
9
+ const total=50000;
10
+ const rows=Array.from({length:total},(_,i)=>({
11
+ id:'vm-a04-crash-contact-'+i,companyId:company.id,
12
+ name:'VM ONLY interrupted restore '+i,ownerUserId:FINORA.Auth.current().id
13
+ }));
14
+ const nativeTransaction=store.transaction.bind(store);
15
+ const state={staged:0,armed:false,committed:false,error:null};
16
+ globalThis.__VM_A04_CRASH=state;
17
+ // Observe actual importAll -> StorageService.transaction -> tx.putRaw.
18
+ // This does not introduce a fake implementation or modify app source.
19
+ store.transaction=(stores,fn,mode)=>nativeTransaction(stores,async tx=>{
20
+ const proxy={
21
+ ...tx,
22
+ putRaw:async (name,item)=>{
23
+ const result=await tx.putRaw(name,item);
24
+ if(name==='contacts'){
25
+ state.staged++;
26
+ if(state.staged===20)state.armed=true;
27
+ }
28
+ return result;
29
+ }
30
+ };
31
+ return fn(proxy);
32
+ },mode);
33
+ store.importAll({app:'Factor-easyPro',version:7,data:{contacts:rows}})
34
+ .then(()=>{state.committed=true;},e=>{state.error=String(e);});
35
+ const deadline=Date.now()+60000;
36
+ while(!state.armed && !state.error && Date.now()<deadline){
37
+ await new Promise(resolve=>setTimeout(resolve,10));
38
+ }
39
+ check(state.armed && !state.committed && !state.error,
40
+ 'Real restore did not reach a safely observable mid-transaction stage');
41
+ return {armed:true,staged:state.staged,committed:false,total,
42
+ scenario:'real-StorageService.importAll-mid-write'};
43
+})()
\ No newline at end of file