فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A04): verify late-stage company backup restore rolls back all writes in native Windows

Verified transactional rollback after a staged synthetic contact and posted invoice fail late ledger reference validation in the real NSIS-installed Tauri WebView2. No false audit receipt, existing records untouched, UI errors explicitly checked. Both required workflows passed: PR Quality #38945374362 and native Windows NSIS/WebView2 #38945374347. A04 remains acceptance-gated.

davoodmehraban89 committed Oct 16, 2026 at 21:48 UTC a038959e231f2a5b40e5d2487acb851ae94bf070
2 files changed +64
tests/windows-vm-encrypted-company-backup-browser.js
+63
@@ -164,11 +164,74 @@
164 if (!audits.length) {
165 throw Error('Company restore did not create a corresponding audit event');
166 }
167 + // A04 late-validation rollback: the first contact and a fake posted sale
168 + // are staged INSIDE the same real IndexedDB transaction. Validation of the
169 + // nonexistent posted journal must abort the entire transaction, including
170 + // the earlier contact write and any audit receipt.
171 + const rollbackContactId = 'vm-only-late-rollback-contact';
172 + const rollbackInvoiceId = 'vm-only-late-rollback-invoice';
173 + const auditCountBeforeLateRollback = (await store.getAll('audit_events')).length;
174 + const corruptFinancialSnapshot = {
175 + app: 'Factor-easyPro',
176 + scope: 'company',
177 + schemaVersion: 7,
178 + companyId: company.id,
179 + data: {
180 + contacts: [{
181 + id: rollbackContactId,
182 + companyId: company.id,
183 + ownerUserId: actor.id,
184 + name: 'VM-ONLY aborted restore record'
185 + }],
186 + invoices: [{
187 + id: rollbackInvoiceId,
188 + companyId: company.id,
189 + kind: 'sale',
190 + financePosted: true,
191 + journalId: 'vm-only-nonexistent-posted-journal',
192 + grandTotal: 1000
193 + }]
194 + }
195 + };
196 + restoreFile(JSON.stringify(corruptFinancialSnapshot));
197 + await window.SettingsView.restoreBackup();
198 + if (await store.get('contacts', rollbackContactId) ||
199 + await store.get('invoices', rollbackInvoiceId)) {
200 + throw Error('Late ledger validation failed to roll back all staged rows');
201 + }
202 + if ((await store.getAll('audit_events')).length !== auditCountBeforeLateRollback) {
203 + throw Error('Aborted restore incorrectly committed an audit receipt');
204 + }
205 + if ((await store.get('contacts', contactId))?.name !== synthetic) {
206 + throw Error('Aborted restore modified an existing recovered contact');
207 + }
208 + const validationMessage = 'ارجاع دفتر کل سند مالی بازیابی‌شده نامعتبر است';
209 + if (capturedErrors.length !== 3 ||
210 + !capturedErrors[2].includes(validationMessage)) {
211 + throw Error('Late validation failure was not exposed through Settings UI');
212 + }
213 + const rollbackToasts = [...document.querySelectorAll('.toast-error')];
214 + if (rollbackToasts.length !== 1 ||
215 + !rollbackToasts[0].textContent.includes(validationMessage)) {
216 + throw Error('Late validation did not show exactly one expected error');
217 + }
218 + const rollbackDismiss = rollbackToasts[0].querySelector('.toast-close');
219 + if (!rollbackDismiss) throw Error('Late validation error cannot be dismissed');
220 + rollbackDismiss.click();
221 + if (document.querySelector('.toast-error') || !document.getElementById('restoreFile')) {
222 + throw Error('Late rollback left an unexpected error or closed its form');
223 + }
224 + FINORA.Modal.close();
225 + if (document.querySelector('.modal-backdrop')) {
226 + throw Error('Aborted restore form remained open');
227 + }
228 +
229 return {
230 encryptedEnvelope: true,
231 filenameSuffix: '.fbackup',
232 wrongPasswordRejected: true,
233 tamperedCiphertextRejectedWithoutWrites: true,
234 + lateFinancialValidationRolledBack: true,
235 sameCompanyRestore: true,
236 restoredContact: true,
237 restoreAudited: true,
tests/windows-vm-installed-tauri-cdp.cjs
+1
@@ -308,6 +308,7 @@ async function connect(url) {
308 filenameSuffix: '.fbackup',
309 wrongPasswordRejected: true,
310 tamperedCiphertextRejectedWithoutWrites: true,
311 + lateFinancialValidationRolledBack: true,
312 sameCompanyRestore: true,
313 restoredContact: true,
314 restoreAudited: true,