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

test(A08): measure installed reports and encrypted 60k-record backup

davoodmehraban89 committed Oct 31, 2026 at 21:59 UTC 711edd2da9255faacb26b50eb1a198c2fa7b6f8a
5 files changed +160 -11
docs/PHASE_A_EXIT_RUNBOOK_FA.md
+1 -1
@@ -23,7 +23,7 @@
23 | A05 | بستن دوره بدون سند نیمه‌تمام، توقف هنگام انبارگردانی باز، تسویه کامل خزانه، Audit یکتا و آزمون هم‌زمانی | آزمون‌های واحد وجود دارند؛ سناریوهای بیشتر خزانه و ارزیابی مستقل مالی باقی‌اند |
24 | A06 | کلید عمومی معتبر ناشر تجاری در محصول، صدور امضای امن خارج از برنامه، انقضا/تمدید، حدود کاربر/شرکت و انتقال trial بدون قفل داده | آزمون ECDSA با کلید ساختگی موفقیت الگوریتم را نشان می‌دهد، نه صدور/کلید معتبر تولیدی. کلید خصوصی هرگز نباید در GitHub، فایل کاربر، لاگ یا گفتگو قرار گیرد |
25 | A07 | نصب/ارتقا/حذف واقعی NSIS، آزمون عملکرد آفلاین، چاپ RTL چندصفحه‌ای در چاپگر فیزیکی، نصب روی محیط نماینده مشتری | نصب و ارتقا و مرور ده مسیر در VM تأیید شده‌اند؛ چاپ واقعی و محیط فیزیکی مستقل هنوز بازند |
26 -| A08 | داده ساختگی ۱۰هزار کالا و ۵۰هزار فاکتور، اندازه‌گیری p50/p95، مصرف حافظه، گزارش/بکاپ و بازیابی خرابی | benchmark ویندوز Node/fake-indexeddb فقط baseline مصنوعی است؛ سنجش نصب واقعی و خرابی فیزیکی/بلندمدت با این نتیجه جایگزین نمی‌شوند |
26 +| A08 | داده ساختگی ۱۰هزار کالا و ۵۰هزار فاکتور، اندازه‌گیری p50/p95، مصرف حافظه، گزارش/بکاپ و بازیابی خرابی | آزمون نصب واقعی Tauri/WebView2 اکنون خواندن ۵۰هزار فاکتور، p50/p95، heap رندرر، چهار تب گزارش، خروجی رمزگذاری‌شده ۵۰هزار فاکتور/۱۰هزار کالا و kill واقعی فرایند هنگام restore را می‌سنجد؛ SLA مشتری، RSS کل ویندوز، قطع برق فیزیکی و soak بلندمدت همچنان خارج از این شاهدند |
27 | INDEPENDENT_QA | حسابدار مستقل مجموعه نماینده را با دفاتر، مانده‌ها، بازپرداخت و خزانه تطبیق و تأیید کند | هنوز سند پذیرش مستقل وجود ندارد |
28 | DATA_BACKUP | پیش از ارتقای کاربر، فایل رمزگذاری‌شده واقعی با اجازه صریح اخذ، جدا نگهداری و در کپی آزمایشی restore شود | فایل مصنوعی VM جایگزین مجوز و آزمون فایل مشتری واقعی نیست |
29
scripts/windows-vm-native-lab.ps1
+21
@@ -218,6 +218,22 @@ try {
218 [long]$heap.afterAllocated -lt [long]$heap.afterUsed) {
219 throw 'Installed native WebView2 60k workload has no valid JS heap evidence'
220 }
221 + $reportTabs = $nativePerformance.nativePerformance.reportTabs
222 + foreach ($tab in @('pl','sales','products','customers')) {
223 + if (!$reportTabs.$tab -or [int]$reportTabs.$tab.htmlCharacters -lt 200) {
224 + throw "A08 installed report tab evidence is missing: $tab"
225 + }
226 + }
227 + $encryptedBackup = $nativePerformance.nativePerformance.encryptedBackup
228 + if (!$encryptedBackup -or [int]$encryptedBackup.products -ne 10000 -or
229 + [int]$encryptedBackup.invoices -ne 50000 -or
230 + [int]$encryptedBackup.schemaVersion -ne 7 -or
231 + $encryptedBackup.filenameSuffix -ne '.fbackup' -or
232 + $encryptedBackup.companyScoped -ne $true -or
233 + $encryptedBackup.credentialsExcluded -ne $true -or
234 + [long]$encryptedBackup.bytes -lt 100000) {
235 + throw 'A08 installed encrypted company backup did not include the complete synthetic scale'
236 + }
237 $summary.integratedCoverage = [ordered]@{
238 installedFinancialScenarios = $mandatory.Count
239 offlineRoutes = 10
@@ -226,10 +242,15 @@ try {
242 benchmarkInvoices = 50000
243 nativeJsHeapAfterUsedBytes = [long]$heap.afterUsed
244 nativeJsHeapScope = 'renderer-only'
245 + reportsRendered = 4
246 + reportsReloadMs = [double]$nativePerformance.nativePerformance.timingsMs.reportsReload
247 + encryptedBackupBytes = [long]$encryptedBackup.bytes
248 + encryptedBackupMs = [double]$encryptedBackup.durationMs
249 crashRestoreRowsRemaining = 0
250 independentHumanQA = 'not-covered'
251 customerBackup = 'not-covered'
252 physicalPrinter = 'not-covered'
253 + physicalPowerLoss = 'not-tested'
254 }
255 $summary.status = 'PASSED'
256 Write-Output 'Verified fresh installation, NSIS in-place upgrade, retained v6 records, native login and Windows DPAPI'
tests/windows-vm-installed-tauri-cdp.cjs
+15 -1
@@ -605,7 +605,21 @@ async function connect(url) {
605 assert.ok(measured.timingsMs.seedProducts >= 0 &&
606 measured.timingsMs.seedInvoices >= 0 &&
607 measured.timingsMs.companyInvoiceReadP95 >= 0 &&
608 - measured.timingsMs.snapshotExport >= 0);
608 + measured.timingsMs.snapshotExport >= 0 &&
609 + measured.timingsMs.reportsReload >= 0 &&
610 + measured.timingsMs.encryptedBackup >= 0);
611 + for (const tab of ['pl','sales','products','customers']) {
612 + assert.ok(measured.reportTabs?.[tab]?.htmlCharacters >= 200,
613 + 'A08 installed report tab was not rendered: ' + tab);
614 + }
615 + assert.equal(measured.encryptedBackup?.schemaVersion, 7);
616 + assert.equal(measured.encryptedBackup?.products, 10000);
617 + assert.equal(measured.encryptedBackup?.invoices, 50000);
618 + assert.equal(measured.encryptedBackup?.filenameSuffix, '.fbackup');
619 + assert.equal(measured.encryptedBackup?.companyScoped, true);
620 + assert.equal(measured.encryptedBackup?.credentialsExcluded, true);
621 + assert.ok(measured.encryptedBackup?.bytes > 100000,
622 + 'A08 large encrypted backup is suspiciously small');
623 const validHeap = item =>
624 Number.isSafeInteger(item?.usedSize) && item.usedSize >= 0 &&
625 Number.isSafeInteger(item?.totalSize) && item.totalSize >= item.usedSize;
tests/windows-vm-native-performance-browser.js
+98 -9
@@ -30,14 +30,27 @@
30 const productMs = await batchWrite('products', productCount, i => ({
31 id: 'vm-a08-product-' + i, companyId: company.id, ownerUserId: user.id,
32 name: 'VM synthetic item ' + i, code: 'VM-A08-' + i,
33 - sellPrice: 1000 + i, trackInventory: false
34 - }));
35 - const invoiceMs = await batchWrite('invoices', invoiceCount, i => ({
36 - id: 'vm-a08-invoice-' + i, companyId: company.id, ownerUserId: user.id,
37 - number: String(i + 1), date: '1405/07/18', kind: 'sale',
38 - isPreInvoice: true, financePosted: false,
39 - grandTotal: 100000 + i, paidAmount: 0, remaining: 100000 + i
33 + buyPrice: 500 + (i % 500), sellPrice: 1000 + (i % 1000), trackInventory: false
34 }));
35 + await db.put('contacts', {
36 + id: 'vm-a08-contact', companyId: company.id, ownerUserId: user.id,
37 + name: 'VM synthetic benchmark customer'
38 + });
39 + const invoiceMs = await batchWrite('invoices', invoiceCount, i => {
40 + const productIndex = i % productCount;
41 + const price = 1000 + (productIndex % 1000);
42 + const productId = 'vm-a08-product-' + productIndex;
43 + return {
44 + id: 'vm-a08-invoice-' + i, companyId: company.id, ownerUserId: user.id,
45 + number: String(i + 1), date: '1405/07/18', kind: 'sale',
46 + contactId: 'vm-a08-contact', contactName: 'VM synthetic benchmark customer',
47 + isPreInvoice: false, financePosted: false,
48 + subtotal: price, totalDiscount: 0, vatAmount: 0,
49 + grandTotal: price, paidAmount: 0, remaining: price,
50 + items: [{ productId, productName: 'VM synthetic item ' + productIndex,
51 + qty: 1, price, lineSubtotal: price, discount: 0, lineTotal: price }]
52 + };
53 + });
54 const actualProducts = await db.count('products');
55 const actualInvoices = await db.count('invoices');
56 if (actualProducts !== productCount || actualInvoices !== invoiceCount) {
@@ -52,6 +65,27 @@
65 samples.push(x.ms);
66 }
67 samples.sort((a, b) => a - b);
68 + // Exercise the actual installed reports route with the same 50k invoice
69 + // population. The report fixture remains unposted and synthetic.
70 + const reportStart = performance.now();
71 + await FINORA.Router.go('reports');
72 + const reportsReloadMs = Math.round((performance.now() - reportStart) * 100) / 100;
73 + const reportTabs = {};
74 + for (const tab of ['pl','sales','products','customers']) {
75 + const start = performance.now();
76 + window.ReportsView._switchTab(tab);
77 + const region = document.getElementById('reports-content');
78 + const rendered = region?.textContent?.trim() || '';
79 + const htmlLength = region?.innerHTML?.length || 0;
80 + if (rendered.length < 40 || htmlLength < 200)
81 + throw Error('Installed report tab rendered no usable result: ' + tab);
82 + reportTabs[tab] = {
83 + renderMs: Math.round((performance.now() - start) * 100) / 100,
84 + textCharacters: rendered.length,
85 + htmlCharacters: htmlLength,
86 + tableRows: region.querySelectorAll('tbody tr').length
87 + };
88 + }
89 const exported = await duration(() => db.exportAll());
90 const snap = exported.value;
91 if (snap.version !== 7 || snap.data.products.length !== productCount ||
@@ -59,7 +93,58 @@
93 snap.data.users.some(x => x.pwHash || x.pwSalt || x.pass)) {
94 throw Error('A08 native performance snapshot is incomplete or has credentials');
95 }
62 - const safe = x => Math.round(x * 100) / 100;
96 + // Measure a real encrypted .fbackup download through SettingsView using
97 + // only the disposable synthetic company. Decrypt the captured blob in-memory
98 + // to verify scale and schema without writing a file or exposing its contents.
99 + const original = {
100 + prompt: window.prompt, create: URL.createObjectURL, revoke: URL.revokeObjectURL,
101 + anchorClick: HTMLAnchorElement.prototype.click
102 + };
103 + let backupBlob = null, backupFilename = '';
104 + const passphrase = 'VM-ONLY-A08-ENCRYPTED-BACKUP-PASSPHRASE';
105 + let encryptedBackupMs = 0;
106 + let backupSummary;
107 + try {
108 + window.prompt = () => passphrase;
109 + URL.createObjectURL = blob => { backupBlob = blob; return 'blob:vm-a08-encrypted-backup'; };
110 + URL.revokeObjectURL = () => {};
111 + HTMLAnchorElement.prototype.click = function () { backupFilename = this.download; };
112 + await FINORA.Router.go('settings');
113 + const backupStart = performance.now();
114 + await window.SettingsView.downloadBackup();
115 + encryptedBackupMs = Math.round((performance.now() - backupStart) * 100) / 100;
116 + if (!(backupBlob instanceof Blob) || !backupFilename.endsWith('.fbackup'))
117 + throw Error('Installed SettingsView did not create a real encrypted .fbackup blob');
118 + const envelope = JSON.parse(await backupBlob.text());
119 + if (envelope.format !== 'finora-encrypted-backup-v1' ||
120 + !envelope.salt || !envelope.iv || !envelope.ciphertext)
121 + throw Error('Installed SettingsView returned an invalid encrypted backup envelope');
122 + const fromB64 = value => Uint8Array.from(atob(value), c => c.charCodeAt(0));
123 + const material = await crypto.subtle.importKey('raw', new TextEncoder().encode(passphrase),
124 + 'PBKDF2', false, ['deriveKey']);
125 + const key = await crypto.subtle.deriveKey({ name: 'PBKDF2', salt: fromB64(envelope.salt),
126 + iterations: 600000, hash: 'SHA-256' }, material,
127 + { name: 'AES-GCM', length: 256 }, false, ['decrypt']);
128 + const clear = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: fromB64(envelope.iv) },
129 + key, fromB64(envelope.ciphertext));
130 + const backup = JSON.parse(new TextDecoder().decode(clear));
131 + if (backup.schemaVersion !== 7 || backup.scope !== 'company' ||
132 + backup.data.products.length !== productCount ||
133 + backup.data.invoices.length !== invoiceCount ||
134 + (backup.data.users || []).length !== 0)
135 + throw Error('Large encrypted backup failed schema, company-scope or record-count verification');
136 + backupSummary = {
137 + durationMs: encryptedBackupMs, bytes: backupBlob.size,
138 + filenameSuffix: '.fbackup', schemaVersion: backup.schemaVersion,
139 + products: backup.data.products.length, invoices: backup.data.invoices.length,
140 + companyScoped: true, credentialsExcluded: true
141 + };
142 + } finally {
143 + window.prompt = original.prompt;
144 + URL.createObjectURL = original.create;
145 + URL.revokeObjectURL = original.revoke;
146 + HTMLAnchorElement.prototype.click = original.anchorClick;
147 + }
148 return {
149 environment: 'installed-Tauri-WebView2-IndexedDB',
150 products: productCount, invoices: invoiceCount,
@@ -69,8 +154,12 @@
154 seedProducts: productMs, seedInvoices: invoiceMs,
155 companyInvoiceReadP50: samples[4],
156 companyInvoiceReadP95: samples[9],
72 - snapshotExport: exported.ms
157 + snapshotExport: exported.ms,
158 + reportsReload: reportsReloadMs,
159 + encryptedBackup: encryptedBackupMs
160 },
161 + reportTabs,
162 + encryptedBackup: backupSummary,
163 measuredAt: new Date().toISOString(),
164 // No user/customer names, passwords, data payload or signing secrets.
165 note: 'Disposable native WebView2 sample; not a customer SLA, printer test or disk crash benchmark'
tests/windows-vm-native-performance-contract.test.cjs new
+25
@@ -0,0 +1,25 @@
1 +'use strict';
2 +const test=require('node:test');
3 +const assert=require('node:assert/strict');
4 +const fs=require('node:fs');
5 +
6 +test('A08 native benchmark measures installed report tabs and encrypted full-scale backup',()=>{
7 + const source=fs.readFileSync(new URL('../tests/windows-vm-native-performance-browser.js',import.meta.url),'utf8');
8 + assert.match(source,/await FINORA\.Router\.go\('reports'\)/);
9 + assert.match(source,/window\.ReportsView\._switchTab\(tab\)/);
10 + assert.match(source,/window\.SettingsView\.downloadBackup\(\)/);
11 + assert.match(source,/crypto\.subtle\.decrypt/);
12 + assert.match(source,/backup\.data\.products\.length !== productCount/);
13 + assert.match(source,/backup\.data\.invoices\.length !== invoiceCount/);
14 + assert.match(source,/iterations: 600000/);
15 +});
16 +
17 +test('A08 installed VM runner rejects incomplete report or encrypted-backup measurements',()=>{
18 + const source=fs.readFileSync(new URL('../tests/windows-vm-installed-tauri-cdp.cjs',import.meta.url),'utf8');
19 + assert.match(source,/measured\.reportTabs\?\.\[tab\]\?\.htmlCharacters >= 200/);
20 + assert.match(source,/measured\.encryptedBackup\?\.products, 10000/);
21 + assert.match(source,/measured\.encryptedBackup\?\.invoices, 50000/);
22 + const lab=fs.readFileSync(new URL('../scripts/windows-vm-native-lab.ps1',import.meta.url),'utf8');
23 + assert.match(lab,/\$encryptedBackup\.bytes -lt 100000/);
24 + assert.match(lab,/reportsRendered = 4/);
25 +});