فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A04): verify real installed Windows backup recovery across NSIS upgrade
* test(A04): restore real v2.0.3 full backup after native Windows NSIS upgrade * test(A04): verify rollback on tampered audit restore and durability after native app restart * test(A04): persist old-version backup across actual Windows upgrade and second native launch * docs(A04): define actual old-version backup recovery, rollback and restart acceptance boundaries * test(A04): distinguish empty migrated history from intentionally persisted audit event on restart
davoodmehraban89 committed
Oct 16, 2026 at 18:54 UTC
7cfd942609bbae9b8be753cda00f1d952284545e
3 files changed
+119
-7
docs/A04_NATIVE_WINDOWS_BACKUP_RECOVERY_LAB_FA.md
new
+23
@@ -0,0 +1,23 @@
1
+# آزمایشگاه بازیابی نسخه قدیمی در ویندوز مجازی — A04
2
+
3
+این آزمایش پس از ساخت نسخه کاندید **فقط داخل GitHub Actions ویندوز** اجرا میشود و از نصبکننده عمومی اصلی `v2.0.3` برای تهیه یک snapshot واقعی سازگار با schema=6 استفاده میکند.
4
+
5
+## سناریوی عملی
6
+
7
+1. نصب واقعی NSIS نسخه عمومی `2.0.3` در مسیر موقت، راهاندازی `app.exe` بومی با WebView2 و تعیین رمز مدیر آزمایشی.
8
+2. ساخت کالای ساختگی و پیشفاکتور ساختگی در IndexedDB نسخه ۶؛ استخراج `StorageService.exportAll()` نسخه قدیمی، تأیید حذف credentialها و نگهداری snapshot فقط در پروفایل آزمایشی روی ماشین مجازی.
9
+3. ارتقای واقعی همان مسیر نصب به نسخه کاندید (بدون ایجاد GitHub Release)، ورود با همان رمز، تأیید حفظ کالا/فاکتور و مهاجرت نسخه پایگاه داده به ۷.
10
+4. حذف عمدی **فقط دو رکورد آزمایشی**، بازیابی آنها با `StorageService.importAll` از snapshot تولیدشده در نسخه قبلی، بررسی مبالغ و نام محصول.
11
+5. ردکردن snapshot با شناسه برنامه غیرمعتبر بدون اثر جانبی.
12
+6. ایجاد رویداد حسابرسی ساختگی و آزمایش تراکنش برگشت اتمی در صورت تلاش برای بازنویسی رویداد قطعی؛ رکورد کالای تزریقشده نباید باقی بماند.
13
+7. بستن برنامه، اجرای مجدد `app.exe` با پروفایل سابق، بررسی ماندگاری اطلاعات و ردپای حسابرسی؛ سپس نصب تازه در پروفایل جداگانه و تست بومی DPAPI.
14
+8. ثبت گزارشهای JSON بدون داده مشتری، نام واقعی، رمز یا کلید خصوصی در artifact سیروزه.
15
+
16
+## محدودیت اعتبار
17
+
18
+- این آزمایش، بازیابی **snapshot کامل سازگار با نسخه ۶** را کنترل میکند، نه لزوماً فرمت رمزگذاریشده `.fbackup` شرکت یا فایل تاریخی یک مشتری واقعی.
19
+- دادههای حسابداری این آزمایش ساختگی و بسیار کوچکاند؛ تست دفتر کل، صحت مالی مستقل، چاپ RTL چندصفحهای، قطع برق و فرایند بازیابی مشتری همچنان گیتهای جداگانهاند.
20
+- مقدار `v2.0.4` صرفاً نسخه موقت CI برای آزمایش ارتقا است؛ بهمعنی انتشار نسخه 2.0.4 نیست.
21
+- موفقیت این آزمایش تنها بخشی از شواهد A04/A07 است؛ وضعیت `docs/PHASE_A_RELEASE_ACCEPTANCE.json` بدون تأیید مستقل تغییر نمیکند.
22
+
23
+اجرای workflow: [Phase A Windows VM Native Installer and Upgrade Lab](../.github/workflows/windows-vm-native-lab.yml).
scripts/windows-vm-native-lab.ps1
+6
@@ -131,6 +131,12 @@ try {
131
$verified = Run-Native $newExe $upgradeData 'upgrade' $CandidateVersion
132
$summary.upgrade = $verified.persistence
133
$summary.nativeGUI = 'real-native-WebView2-validated'
134
+ $summary.backupRecovery = $verified.backupRecovery
135
+ $summary.atomicTamperRollback = $verified.immutableRestoreRollback
136
+ # Reopen the real installed executable with the SAME Windows WebView2
137
+ # profile after the restore and rollback tests. This proves disk durability.
138
+ $reopened = Run-Native $newExe $upgradeData 'reopen' $CandidateVersion
139
+ $summary.restartPersistence = $reopened.persistence
140
141
$freshDir = Join-Path $lab 'installed-fresh'
142
$freshData = Join-Path $lab 'webview2-fresh-profile'
tests/windows-vm-installed-tauri-cdp.cjs
+90
-7
@@ -10,10 +10,10 @@ const verifyNativeFunctionalMatrix = require('./windows-vm-native-functional-mat
10
11
const [exe, profile, mode, expectedVersion, reportPath] = process.argv.slice(2);
12
assert.equal(process.platform, 'win32');
13
-assert.ok(['seed','upgrade','fresh'].includes(mode), 'unknown lab mode');
13
+assert.ok(['seed','upgrade','reopen','fresh'].includes(mode), 'unknown lab mode');
14
assert.ok(fs.existsSync(exe), 'installed Windows executable missing');
15
fs.mkdirSync(profile, { recursive: true });
16
-const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : 9373;
16
+const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : mode === 'reopen' ? 9374 : 9373;
17
const PASSWORD = 'VmOnly-Factor-83471!'; // Synthetic password, never printed.
18
19
const REG_POLICY = [
@@ -145,7 +145,7 @@ async function connect(url) {
145
if (mode === 'seed' || mode === 'fresh') {
146
assert.equal(setup, true, 'a new native profile must prompt to set the administrator password');
147
} else {
148
- assert.equal(setup, false, 'upgrade should preserve existing administrator credentials');
148
+ assert.equal(setup, false, 'upgrade/reopen should preserve existing administrator credentials');
149
}
150
await cdp.evaluate('(() => {' +
151
'document.getElementById("faUser").value="مدیر";' +
@@ -163,13 +163,28 @@ async function connect(url) {
163
'await S.put("products",{id:"vm-upgrade-product",companyId:"company_default",name:"Synthetic VM product",sellPrice:123456});' +
164
'await S.put("invoices",{id:"vm-upgrade-draft",companyId:"company_default",kind:"sale",isPreInvoice:true,financePosted:false,grandTotal:987654,paidAmount:0,remaining:987654});' +
165
'const db=await S.init();' +
166
- 'return {version:db.version,products:(await S.getAll("products")).length,amount:(await S.get("invoices","vm-upgrade-draft")).grandTotal};' +
166
+ // Real v2.0.3 backup format: all stores, v6 schema, credentials excluded.
167
+ // Keep a synthetic backup only in the disposable Windows profile so the
168
+ // upgraded app can test restoring the OLD version without cloud artifacts.
169
+ 'const snapshot=await S.exportAll();' +
170
+ 'await S.put("settings",{id:"vm-legacy-backup",companyId:"company_default",payload:snapshot});' +
171
+ 'return {version:db.version,products:(await S.getAll("products")).length,amount:(await S.get("invoices","vm-upgrade-draft")).grandTotal,' +
172
+ 'backupVersion:snapshot.version,backupApp:snapshot.app,' +
173
+ 'backupContainsProduct:snapshot.data.products.some(p=>p.id==="vm-upgrade-product"),' +
174
+ 'backupContainsInvoice:snapshot.data.invoices.some(i=>i.id==="vm-upgrade-draft"),' +
175
+ 'backupCredentialsExcluded:!snapshot.data.users.some(u=>"pwHash" in u||"pwSalt" in u)};' +
176
'})()');
177
assert.equal(seeded.version, 6, 'old release should have IndexedDB v6');
178
assert.equal(seeded.amount, 987654);
179
+ assert.equal(seeded.backupVersion, 6);
180
+ assert.equal(seeded.backupApp, 'Factor-easyPro');
181
+ assert.equal(seeded.backupContainsProduct, true);
182
+ assert.equal(seeded.backupContainsInvoice, true);
183
+ assert.equal(seeded.backupCredentialsExcluded, true);
184
+ report.legacyBackup = 'real-v2.0.3-snapshot-saved-in-test-profile';
185
report.indexedDb = 'v6-written';
186
report.persistence = 'synthetic-legacy-fixtures-created';
172
- } else if (mode === 'upgrade') {
187
+ } else if (mode === 'upgrade' || mode === 'reopen') {
188
const restored = await cdp.evaluate('(async()=>{' +
189
'const S=FINORA.Storage, db=await S.init();' +
190
'const product=await S.get("products","vm-upgrade-product");' +
@@ -180,10 +195,78 @@ async function connect(url) {
195
assert.equal(restored.version, 7);
196
assert.equal(restored.product, 'Synthetic VM product');
197
assert.equal(restored.amount, 987654);
183
- assert.equal(restored.audits, 0, 'migration must not manufacture historical audit events');
198
+ assert.equal(restored.audits, mode === 'upgrade' ? 0 : 1,
199
+ 'migration must not fabricate history; an explicitly created event must persist after restart');
200
assert.equal(restored.corrections, true);
185
- report.indexedDb = 'real-WebView2-v6-to-v7-passed';
201
+ report.indexedDb = mode === 'upgrade' ?
202
+ 'real-WebView2-v6-to-v7-passed' : 'persisted-real-WebView2-v7-on-restart';
203
report.persistence = 'product-invoice-and-login-survived-upgrade';
204
+ if (mode === 'upgrade') {
205
+ // Exercise the actual importer in the INSTALLED Tauri WebView2 process.
206
+ // Intentionally delete only the synthetic draft and product, restore an
207
+ // older real v6 snapshot, verify both records, and assert a corrupted
208
+ // snapshot cannot produce partial writes.
209
+ const recovery = await cdp.evaluate('(async()=>{' +
210
+ 'const S=FINORA.Storage;' +
211
+ 'const snapshot=(await S.get("settings","vm-legacy-backup"))?.payload;' +
212
+ 'if(!snapshot || snapshot.version!==6) throw Error("v2.0.3 backup not persisted");' +
213
+ 'await S.delete("products","vm-upgrade-product");' +
214
+ 'await S.delete("invoices","vm-upgrade-draft");' +
215
+ 'const emptyBefore=!(await S.get("products","vm-upgrade-product"))&&!(await S.get("invoices","vm-upgrade-draft"));' +
216
+ 'await S.importAll(snapshot);' +
217
+ 'const p=await S.get("products","vm-upgrade-product");' +
218
+ 'const i=await S.get("invoices","vm-upgrade-draft");' +
219
+ 'const tampered=structuredClone(snapshot);' +
220
+ 'tampered.data.products.push({...p,id:"vm-would-rollback"});' +
221
+ 'tampered.data.invoices.push({...i,grandTotal:1});' +
222
+ 'let blocked=false;' +
223
+ 'try {await S.importAll({...tampered,app:"foreign-finance"});}catch(e){blocked=true;}' +
224
+ 'return {emptyBefore,restoredProduct:p?.name,restoredInvoice:i?.grandTotal,' +
225
+ 'blockedBadApp:blocked,afterBadApp:(await S.get("products","vm-would-rollback"))??null,' +
226
+ 'databaseVersion:(await S.init()).version};' +
227
+ '})()');
228
+ assert.deepEqual(recovery, {
229
+ emptyBefore:true,restoredProduct:'Synthetic VM product',
230
+ restoredInvoice:987654,blockedBadApp:true,afterBadApp:null,
231
+ databaseVersion:7
232
+ });
233
+ report.backupRecovery = 'actual-v2.0.3-v6-snapshot-restored-on-installed-v7';
234
+ report.invalidBackup = 'foreign-app-rejected-no-writes';
235
+
236
+ const immutable = await cdp.evaluate('(async()=>{' +
237
+ 'const S=FINORA.Storage;' +
238
+ 'const audit={id:"vm-audit-immutable",companyId:"company_default",' +
239
+ 'commandKey:"company_default:vm-native-test",eventType:"journal_posted",' +
240
+ 'actorId:"user_admin",sourceId:"vm-upgrade-draft",safeSummary:{lineCount:2}};' +
241
+ 'await S.put("audit_events",audit);' +
242
+ 'const stored=await S.get("audit_events",audit.id);' +
243
+ 'let refused=false;' +
244
+ 'try {await S.importAll({app:"Factor-easyPro",version:7,data:{' +
245
+ 'products:[{id:"vm-should-roll-back",companyId:"company_default",name:"No partial writes"}],' +
246
+ 'audit_events:[{...stored,eventType:"period_closed"}]}});}' +
247
+ 'catch(e){refused=true;}' +
248
+ 'return {refused,product:(await S.get("products","vm-should-roll-back"))??null,' +
249
+ 'auditType:(await S.get("audit_events",audit.id)).eventType};' +
250
+ '})()');
251
+ assert.deepEqual(immutable, {
252
+ refused:true,product:null,auditType:'journal_posted'
253
+ });
254
+ report.immutableRestoreRollback = 'full-restore-transaction-rolled-back-on-audit-conflict';
255
+ }
256
+ if (mode === 'reopen') {
257
+ const persisted = await cdp.evaluate('(async()=>{' +
258
+ 'const S=FINORA.Storage;' +
259
+ 'const audit=await S.get("audit_events","vm-audit-immutable");' +
260
+ 'return {product:(await S.get("products","vm-upgrade-product"))?.name,' +
261
+ 'invoice:(await S.get("invoices","vm-upgrade-draft"))?.grandTotal,' +
262
+ 'auditType:audit?.eventType,dbVersion:(await S.init()).version};' +
263
+ '})()');
264
+ assert.deepEqual(persisted, {
265
+ product:'Synthetic VM product', invoice:987654,
266
+ auditType:'journal_posted', dbVersion:7
267
+ });
268
+ report.persistence = 'v6-backup-recovery-and-audit-survived-real-native-restart';
269
+ }
270
} else {
271
const fresh = await cdp.evaluate('(async()=>{' +
272
'const S=FINORA.Storage, db=await S.init();' +