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

test(A08): add genuine Tauri WebView2 10k/50k synthetic fixture timings

davoodmehraban89 committed Oct 16, 2026 at 22:21 UTC f8af973013ecc8e4af0fade77bff22a3f6c89509
1 file changed +78
tests/windows-vm-native-performance-browser.js new
+78
@@ -0,0 +1,78 @@
1 +(async () => {
2 + // A08 measured in the real installed Tauri/WebView2 IndexedDB with a fresh
3 + // disposable Windows profile. Synthetic *unposted* records only.
4 + const db = FINORA.Storage;
5 + const company = await FINORA.Company.current();
6 + const user = FINORA.Auth.current();
7 + if (!company?.id || !user?.id || !FINORA.Auth.isAdmin() ||
8 + !globalThis.__TAURI_INTERNALS__?.invoke) {
9 + throw Error('Native A08 benchmark needs an installed desktop administrator');
10 + }
11 + const productCount = 10000;
12 + const invoiceCount = 50000;
13 + const t = fn => performance.now();
14 + const duration = async work => {
15 + const start = performance.now();
16 + const value = await work();
17 + return { ms: Math.round((performance.now() - start) * 100) / 100, value };
18 + };
19 + const batchWrite = async (name, count, generator) => {
20 + const start = performance.now();
21 + for (let i = 0; i < count; i += 200) {
22 + const batch = Array.from({ length: Math.min(200, count - i) },
23 + (_, offset) => generator(i + offset));
24 + await db.transaction(name, async tx => {
25 + await Promise.all(batch.map(item => tx.putRaw(name, item)));
26 + });
27 + }
28 + return Math.round((performance.now() - start) * 100) / 100;
29 + };
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
40 + }));
41 + const actualProducts = await db.count('products');
42 + const actualInvoices = await db.count('invoices');
43 + if (actualProducts !== productCount || actualInvoices !== invoiceCount) {
44 + throw Error('Installed WebView2 seed count differs from requested A08 scale');
45 + }
46 + const samples = [];
47 + for (let i = 0; i < 10; i++) {
48 + const x = await duration(() => db.getByCompany('invoices', company.id));
49 + if (x.value.length !== invoiceCount) {
50 + throw Error('Installed WebView2 company invoice filter dropped records');
51 + }
52 + samples.push(x.ms);
53 + }
54 + samples.sort((a, b) => a - b);
55 + const exported = await duration(() => db.exportAll());
56 + const snap = exported.value;
57 + if (snap.version !== 7 || snap.data.products.length !== productCount ||
58 + snap.data.invoices.length !== invoiceCount ||
59 + snap.data.users.some(x => x.pwHash || x.pwSalt || x.pass)) {
60 + throw Error('A08 native performance snapshot is incomplete or has credentials');
61 + }
62 + const safe = x => Math.round(x * 100) / 100;
63 + return {
64 + environment: 'installed-Tauri-WebView2-IndexedDB',
65 + products: productCount, invoices: invoiceCount,
66 + companyInvoices: invoiceCount, companiesMeasured: 1,
67 + unpostedSyntheticFixture: true,
68 + timingsMs: {
69 + seedProducts: productMs, seedInvoices: invoiceMs,
70 + companyInvoiceReadP50: samples[4],
71 + companyInvoiceReadP95: samples[9],
72 + snapshotExport: exported.ms
73 + },
74 + measuredAt: new Date().toISOString(),
75 + // No user/customer names, passwords, data payload or signing secrets.
76 + note: 'Disposable native WebView2 sample; not a customer SLA, printer test or disk crash benchmark'
77 + };
78 +})()
\ No newline at end of file