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

test(A05): reject draft journal and duplicate fiscal closure in actual installed Windows UI

A05 real NSIS/Tauri/WebView2 AccountingView now refuses fiscal closure while a ledger draft exists, preserves state and audit, closes after synthetic draft resolution, and rejects repeated UI close without second period_closed event. Unit tests also verify concurrent close requests commit once. Quality CI #38960775857 (192 Node tests + Windows installer) and native Windows VM #38960775828 (11 scenarios, backup, 10 offline routes, RTL PDF, 60k IndexedDB and crash rollback) green. A05 remains accepted:false until independent treasury/accounting QA; no public release.

davoodmehraban89 committed Oct 16, 2026 at 23:52 UTC 245dacc572b24090ef0cc1bfb29733f1c67b4165
2 files changed +78
tests/a05-fiscal-close-gates.test.mjs
+32
@@ -61,3 +61,35 @@ test('A05: an open stocktake blocks period close without changing the period', a
61 await AccountingService.closePeriod(period.id);
62 await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
63 });
64 +
65 +test('A05: an unfinished journal blocks closing until the draft is removed', async () => {
66 + const { period } = await setup();
67 + const draftId = 'a05-unposted-ledger-draft';
68 + await StorageService.put('journal_entries', {
69 + id: draftId, companyId: 'a05', periodId: period.id,
70 + date: '1405/06/15', status: 'draft', sourceType: 'manual'
71 + });
72 + await assert.rejects(AccountingService.closePeriod(period.id), /اسناد پیش‌نویس/);
73 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, false);
74 + assert.equal((await AuditService.list()).filter(x => x.eventType === 'period_closed').length, 0);
75 + await StorageService.delete('journal_entries', draftId);
76 + await AccountingService.closePeriod(period.id);
77 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, true);
78 +});
79 +
80 +test('A05: simultaneous close commands commit only one period and one audit receipt', async () => {
81 + const { period } = await setup();
82 + const attempts = await Promise.allSettled([
83 + AccountingService.closePeriod(period.id),
84 + AccountingService.closePeriod(period.id)
85 + ]);
86 + assert.equal(attempts.filter(x => x.status === 'fulfilled').length, 1);
87 + assert.equal(attempts.filter(x => x.status === 'rejected').length, 1);
88 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, true);
89 + const events = (await AuditService.list()).filter(x =>
90 + x.eventType === 'period_closed' && x.sourceId === period.id);
91 + assert.equal(events.length, 1);
92 + await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
93 + assert.equal((await AuditService.list()).filter(x =>
94 + x.eventType === 'period_closed' && x.sourceId === period.id).length, 1);
95 +});
tests/windows-vm-native-functional-matrix.cjs
+46
@@ -602,6 +602,34 @@ async function fiscalCloseGuardrails() {
602 message.querySelector('.toast-close')?.click();
603 check(!document.querySelector('.toast-error'), 'Expected fiscal rejection toast remained');
604 await store.delete('stocktakes', stocktakeId);
605 +
606 + // A05: another real fiscal-close attempt must still be blocked while
607 + // there is an unfinished draft ledger in the same isolated period.
608 + const draftId = 'vm-a05-unposted-draft-journal';
609 + await store.put('journal_entries', {
610 + id: draftId, companyId: company.id, periodId: period.id,
611 + date: '1404/06/15', status: 'draft', sourceType: 'manual',
612 + description: 'VM-only pending draft prevents closure'
613 + });
614 + confirmClose();
615 + let draftToast = null;
616 + for (let i = 0; i < 60; i++) {
617 + draftToast = [...document.querySelectorAll('.toast-error')]
618 + .find(x => x.textContent.includes('اسناد پیش‌نویس'));
619 + if (draftToast) break;
620 + await wait(100);
621 + }
622 + check(draftToast, 'Native fiscal closure ignored the pending draft journal');
623 + check((await store.get('fiscal_periods', period.id))?.closed === false,
624 + 'Rejected draft-journal closure changed period state');
625 + check((await store.getAll('audit_events'))
626 + .filter(x => x.companyId === company.id &&
627 + x.eventType === 'period_closed').length === auditCount,
628 + 'Rejected draft-journal closure wrote a successful close audit');
629 + draftToast.querySelector('.toast-close')?.click();
630 + check(!document.querySelector('.toast-error'),
631 + 'Expected unposted-journal rejection toast remained visible');
632 + await store.delete('journal_entries', draftId);
633 confirmClose();
634 let closed = null;
635 for (let i = 0; i < 70; i++) {
@@ -617,12 +645,30 @@ async function fiscalCloseGuardrails() {
645 check(closureAudits.length === 1 &&
646 closureAudits[0].actorId === FINORA.Auth.current().id,
647 'Successful fiscal closure did not produce exactly one actor-scoped audit');
648 + // Already-closed periods must not be closed again via the actual confirmation
649 + // action, nor silently insert another period_closed audit receipt.
650 + confirmClose();
651 + let closedToast = null;
652 + for (let i = 0; i < 60; i++) {
653 + closedToast = [...document.querySelectorAll('.toast-error')]
654 + .find(x => x.textContent.includes('دوره مالی بسته است'));
655 + if (closedToast) break;
656 + await wait(100);
657 + }
658 + check(closedToast, 'Duplicate native close did not visibly reject');
659 + check((await store.getAll('audit_events'))
660 + .filter(x => x.companyId === company.id &&
661 + x.eventType === 'period_closed' && x.sourceId === period.id).length === 1,
662 + 'Duplicate fiscal close created a second audit receipt');
663 + closedToast.querySelector('.toast-close')?.click();
664 check(!document.querySelector('.toast-error') && !document.querySelector('.modal-backdrop'),
665 'Fiscal guardrail test left an unexpected UI error or modal');
666 return {
667 openStocktakeBlocked: true,
668 + draftJournalBlocked: true,
669 failedCloseRolledBack: true,
670 successfulCloseCommitted: true,
671 + duplicateCloseRejected: true,
672 singleAuditReceipt: true
673 };
674 }