فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A04): force-kill native Windows restore mid-transaction and verify atomic restart
Extend actual Windows NSIS/Tauri/WebView2 VM lab with 50000 synthetic contact importAll writes. On 20+ staged IndexedDB requests kill real installed Windows app tree with taskkill /T /F. Reopen same profile/installer and assert existing login survives with zero partial restored rows. This is process-crash, not physical power loss or arbitrary customer backup approval. PR Quality #38956382672 and full Windows Native #38956382667 success; synthetic crash evidence artifact #12071096362. A04 remains release-blocked pending independent real-world backup and power-loss QA.
davoodmehraban89 committed
Oct 16, 2026 at 23:16 UTC
dc8dc43416d8e7d53c52030bb8c01621107efc48
4 files changed
+92
-3
.github/workflows/windows-vm-native-lab.yml
+1
@@ -15,6 +15,7 @@ on:
15
- 'tests/windows-vm-native-functional-matrix.cjs'
16
- 'tests/windows-vm-encrypted-company-backup-browser.js'
17
- 'tests/windows-vm-native-print-pdf-browser.js'
18
+ - 'tests/windows-vm-native-crash-import-browser.js'
19
- 'tests/windows-vm-native-performance-browser.js'
20
- 'scripts/windows-vm-native-lab.ps1'
21
- 'scripts/windows-vm-set-candidate.cjs'
scripts/windows-vm-native-lab.ps1
+11
@@ -151,6 +151,17 @@ try {
151
$nativePerformance = Run-Native $freshExe $performanceData 'benchmark' $CandidateVersion
152
$summary.nativePerformance = $nativePerformance.nativePerformance
153
154
+ # A04 destructive fault injection is strictly confined to a disposable
155
+ # Windows VM profile. Abruptly kill the native app during genuine importAll,
156
+ # reopen SAME persistent profile and check not one staged row committed.
157
+ $crashData = Join-Path $lab 'webview2-crash-restore-profile'
158
+ $armed = Run-Native $freshExe $crashData 'crash-arm' $CandidateVersion
159
+ if (!$armed.crashInjected.realWindowsProcessKilled) {
160
+ throw 'Native restore process was not genuinely force-terminated'
161
+ }
162
+ $crashVerified = Run-Native $freshExe $crashData 'crash-verify' $CandidateVersion
163
+ $summary.crashRestoreRollback = $crashVerified.crashRollback
164
+
165
$summary.status = 'PASSED'
166
Write-Output 'Verified fresh installation, NSIS in-place upgrade, retained v6 records, native login and Windows DPAPI'
167
Cleanup-Installed $freshDir
tests/windows-vm-installed-tauri-cdp.cjs
+37
-3
@@ -11,10 +11,10 @@ const { verifyNativeOrigin } = require('./windows-vm-native-origin.cjs');
11
12
const [exe, profile, mode, expectedVersion, reportPath] = process.argv.slice(2);
13
assert.equal(process.platform, 'win32');
14
-assert.ok(['seed','upgrade','reopen','fresh','benchmark'].includes(mode), 'unknown lab mode');
14
+assert.ok(['seed','upgrade','reopen','fresh','benchmark','crash-arm','crash-verify'].includes(mode), 'unknown lab mode');
15
assert.ok(fs.existsSync(exe), 'installed Windows executable missing');
16
fs.mkdirSync(profile, { recursive: true });
17
-const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : mode === 'reopen' ? 9374 : mode === 'benchmark' ? 9375 : 9373;
17
+const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : mode === 'reopen' ? 9374 : mode === 'benchmark' ? 9375 : mode === 'crash-arm' ? 9376 : mode === 'crash-verify' ? 9377 : 9373;
18
const PASSWORD = 'VmOnly-Factor-83471!'; // Synthetic password, never printed.
19
20
const REG_POLICY = [
@@ -143,7 +143,7 @@ async function connect(url) {
143
assert.equal(ready.version, expectedVersion, 'candidate build runtime version mismatch');
144
}
145
const setup = ready.initialMode.includes('تعیین رمز');
146
- if (mode === 'seed' || mode === 'fresh' || mode === 'benchmark') {
146
+ if (mode === 'seed' || mode === 'fresh' || mode === 'benchmark' || mode === 'crash-arm') {
147
assert.equal(setup, true, 'a new native profile must prompt to set the administrator password');
148
} else {
149
assert.equal(setup, false, 'upgrade/reopen should preserve existing administrator credentials');
@@ -158,6 +158,40 @@ async function connect(url) {
158
), 65000);
159
report.login = setup ? 'first-run-admin-setup-passed' : 'existing-admin-password-passed';
160
161
+ if (mode === 'crash-arm') {
162
+ const source = fs.readFileSync(
163
+ path.join(__dirname, 'windows-vm-native-crash-import-browser.js'), 'utf8');
164
+ const armed = await cdp.evaluate(source, 90000);
165
+ assert.equal(armed.scenario, 'real-StorageService.importAll-mid-write');
166
+ assert.equal(armed.armed, true);
167
+ assert.equal(armed.committed, false);
168
+ assert.ok(armed.staged >= 20 && armed.staged < armed.total,
169
+ 'A04 restore must be actively staging before process termination');
170
+ // Kill the *real Windows native process tree*, including WebView2, not
171
+ // just abort an IndexedDB request or throw a JS exception.
172
+ assert.ok(proc?.pid, 'Real native process PID missing for crash test');
173
+ execFileSync('taskkill.exe', ['/PID', String(proc.pid), '/T', '/F'],
174
+ { stdio: 'ignore', timeout: 30000 });
175
+ report.crashInjected = { realWindowsProcessKilled: true,
176
+ restoreInProgress: true, stagedBeforeCrash: armed.staged };
177
+ report.status = 'PASSED';
178
+ return;
179
+ }
180
+ if (mode === 'crash-verify') {
181
+ const result = await cdp.evaluate(`(async () => {
182
+ const rows=(await FINORA.Storage.getAll('contacts'))
183
+ .filter(x=>typeof x.id==='string' && x.id.startsWith('vm-a04-crash-contact-'));
184
+ return { partialRows: rows.length,
185
+ dbVersion: (await FINORA.Storage.init()).version,
186
+ signedIn: !document.getElementById('finoraAuthOverlay') };
187
+ })()`, 60000);
188
+ assert.deepEqual(result, { partialRows: 0, dbVersion: 7, signedIn: true },
189
+ 'Forced termination left partial restored contacts or lost login');
190
+ report.crashRollback = 'killed-real-installed-Windows-WebView2-during-importAll-no-partial-rows-on-restart';
191
+ report.status = 'PASSED';
192
+ return;
193
+ }
194
+
195
if (mode === 'seed') {
196
const seeded = await cdp.evaluate('(async()=>{' +
197
'const S=FINORA.Storage;' +
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