فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): exercise native installed history-clear failure and rollback
davoodmehraban89 committed
Oct 16, 2026 at 23:32 UTC
e6215181d81af9ba95f5c3fc82a04fc397053d4c
1 file changed
+43
tests/windows-vm-native-functional-matrix.cjs
+43
@@ -440,6 +440,48 @@ async function nativePurchaseReturnGuardrails() {
440
overReturnRejectedAtomically:true };
441
}
442
443
+async function nativeHistoryClearFailClosed() {
444
+ const check = (value, message) => { if (!value) throw Error(message); };
445
+ const store = FINORA.Storage;
446
+ const company = await FINORA.Company.current();
447
+ check(company?.id && FINORA.Auth.isAdmin(),
448
+ 'History protection must run in installed VM with synthetic administrator');
449
+ const preserved = {};
450
+ for (const name of ['audit_events', 'document_corrections']) {
451
+ const history = (await store.getAll(name))
452
+ .filter(row => row.companyId === company.id);
453
+ check(history.length > 0, 'Native immutable history prerequisite missing: ' + name);
454
+ preserved[name] = history.map(row => JSON.stringify(row)).sort();
455
+ const sentinel = 'vm-a03-aborted-clear-' + name;
456
+ let rejected = false;
457
+ try {
458
+ await store.transaction(['contacts', name], async tx => {
459
+ await tx.putRaw('contacts', {
460
+ id: sentinel, companyId: company.id,
461
+ name: 'VM ONLY must roll back before history clear'
462
+ });
463
+ await tx.clear(name);
464
+ });
465
+ } catch (error) {
466
+ rejected = String(error).includes('پاکسازی مستقیم');
467
+ }
468
+ check(rejected, 'Installed IndexedDB accepted a bulk history clear: ' + name);
469
+ check(!(await store.get('contacts', sentinel)),
470
+ 'Rejected native history-clear transaction committed earlier writes');
471
+ const after = (await store.getAll(name))
472
+ .filter(row => row.companyId === company.id)
473
+ .map(row => JSON.stringify(row)).sort();
474
+ check(JSON.stringify(after) === JSON.stringify(preserved[name]),
475
+ 'Failed clear mutated immutable history: ' + name);
476
+ }
477
+ check(!document.querySelector('.toast-error'),
478
+ 'Native history protection left unrelated UI error');
479
+ return { immutableAuditClearRejected: true,
480
+ immutableCorrectionClearRejected: true,
481
+ bothTransactionsRolledBack: true,
482
+ historyUnchanged: true };
483
+}
484
+
485
async function nativeBackupRestore() {
486
const check = (value, message) => { if (!value) throw Error(message); };
487
const S = FINORA.Storage;
@@ -657,6 +699,7 @@ module.exports = async function nativeFunctionalMatrix(cdp) {
699
['partial-sale-and-inventory', saleInvoice],
700
['sale-return-immutable-stock-and-ledger', nativeSaleReturnGuardrails],
701
['purchase-return-and-stock-guardrails', nativePurchaseReturnGuardrails],
702
+ ['append-only-history-bulk-clear-protection', nativeHistoryClearFailClosed],
703
['backup-and-atomic-rejection', nativeBackupRestore],
704
['rtl-invoice-print-settings', invoicePrintLayout],
705
['fiscal-close-atomic-guardrails', fiscalCloseGuardrails],