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

test(a08): add isolated installed WebView2 memory cycle harness

Davood Mehraban committed Nov 23, 2026 at 22:47 UTC 03de4637d1b4a25cec36b46694bc80f3f02decad
4 files changed +155 -7
.github/workflows/a08-installed-memory-stability.yml new
+75
@@ -0,0 +1,75 @@
1 +name: A08 installed Windows memory stability (reuse NSIS)
2 +on:
3 + workflow_dispatch:
4 + inputs:
5 + artifact_run_id:
6 + description: 'Native Windows workflow run holding candidate NSIS from this exact commit'
7 + required: true
8 + type: string
9 + source_sha:
10 + description: 'Exact 40-character commit SHA used to build the installer (not the workflow dispatch SHA)'
11 + required: true
12 + type: string
13 + expected_version:
14 + description: 'Candidate installer version from that run'
15 + required: true
16 + type: string
17 +permissions:
18 + contents: read
19 + actions: read
20 +jobs:
21 + targeted-native-a08:
22 + runs-on: windows-latest
23 + timeout-minutes: 35
24 + steps:
25 + # Checkout the separately reviewed QA harness; verify the immutable
26 + # binary-producing source SHA independently against its successful run.
27 + - uses: actions/checkout@v4
28 + with:
29 + ref: ${{ github.ref }}
30 + persist-credentials: false
31 + - uses: actions/setup-node@v4
32 + with:
33 + node-version: '22'
34 + - name: Verify artifact source SHA and workflow identity
35 + shell: pwsh
36 + env:
37 + GH_TOKEN: ${{ github.token }}
38 + SOURCE_RUN: ${{ inputs.artifact_run_id }}
39 + SOURCE_SHA: ${{ inputs.source_sha }}
40 + EXPECTED_VERSION: ${{ inputs.expected_version }}
41 + run: |
42 + if ($env:SOURCE_RUN -notmatch '^[0-9]+$') { throw 'Invalid source run ID' }
43 + if ($env:SOURCE_SHA -notmatch '^[a-fA-F0-9]{40}$') { throw 'Invalid source commit SHA' }
44 + if ((git rev-parse HEAD).Trim() -eq $env:SOURCE_SHA) { throw 'Stability harness must be a separately reviewed QA revision' }
45 + if ($env:EXPECTED_VERSION -notmatch '^\d+\.\d+\.\d+$') { throw 'Invalid candidate version' }
46 + $run=gh api "repos/$env:GITHUB_REPOSITORY/actions/runs/$env:SOURCE_RUN" | ConvertFrom-Json
47 + if ($run.head_sha -ne $env:SOURCE_SHA -or $run.status -ne 'completed' -or
48 + $run.conclusion -ne 'success' -or $run.event -notin @('pull_request','push','workflow_dispatch') -or
49 + $run.path -notmatch 'windows-vm-native-lab.yml') {
50 + throw 'Source must be a completed native lab run on exactly this commit'
51 + }
52 + Write-Host ("Verified candidate run "+$run.html_url+" SHA "+$run.head_sha)
53 + - name: Reuse already-built candidate NSIS
54 + uses: actions/download-artifact@v4
55 + with:
56 + run-id: ${{ inputs.artifact_run_id }}
57 + github-token: ${{ github.token }}
58 + name: phase-a-native-candidate-nsis
59 + path: test-installer
60 + - name: Run ten real installed WebView2 A08 memory cycles
61 + shell: pwsh
62 + env:
63 + EXPECTED_VERSION: ${{ inputs.expected_version }}
64 + run: |
65 + $files=@(Get-ChildItem test-installer -Recurse -Filter '*x64-setup.exe')
66 + if ($files.Count -ne 1) { throw 'Expected exactly one reused NSIS installer' }
67 + ./scripts/windows-vm-targeted-a08.ps1 -Installer $files[0].FullName -ExpectedVersion $env:EXPECTED_VERSION -Mode stability
68 + - name: Upload targeted native A08 evidence
69 + if: always()
70 + uses: actions/upload-artifact@v4
71 + with:
72 + name: a08-installed-memory-stability-evidence
73 + path: ${{ runner.temp }}/factor-a08-targeted-native/reports/*.json
74 + retention-days: 14
75 + if-no-files-found: warn
scripts/windows-vm-targeted-a08.ps1
+6 -3
@@ -1,7 +1,8 @@
1 # Disposable Windows runner: run only the installed native A08 benchmark using an existing NSIS artifact.
2 [CmdletBinding()]
3 param([Parameter(Mandatory=$true)][string]$Installer,
4 - [Parameter(Mandatory=$true)][string]$ExpectedVersion)
4 + [Parameter(Mandatory=$true)][string]$ExpectedVersion,
5 + [ValidateSet('benchmark','stability')][string]$Mode='benchmark')
6 $ErrorActionPreference='Stop'
7 if ($env:GITHUB_ACTIONS -ne 'true' -or $env:RUNNER_OS -ne 'Windows') {
8 throw 'Targeted native test is restricted to disposable Windows GitHub Actions runners'
@@ -24,13 +25,15 @@ try {
25 } finally { $proc.Dispose() }
26 $exe=@(Get-ChildItem $install -Recurse -File | Where-Object { $_.Name -in @('app.exe','Factor-easyPro.exe') })
27 if ($exe.Count -ne 1 -or $exe[0].Length -lt 300000) { throw 'Installed native executable not verified' }
27 -& node tests/windows-vm-installed-tauri-cdp.cjs $exe[0].FullName $profile benchmark $ExpectedVersion $report
28 +& node tests/windows-vm-installed-tauri-cdp.cjs $exe[0].FullName $profile $Mode $ExpectedVersion $report
29 if ($LASTEXITCODE -ne 0) { throw 'Installed WebView2 A08 benchmark failed' }
30 $result=Get-Content $report -Raw | ConvertFrom-Json
31 +if ($Mode -eq 'stability' -and ($result.nativeMemoryStability.status -ne 'PASSED' -or
32 + $result.nativeMemoryStability.cycles.Count -ne 10)) { throw 'Stability cycle acceptance incomplete' }
33 if ($result.status -ne 'PASSED' -or $result.installedNativeTauri -ne $true -or
34 $result.nativePerformance.products -ne 10000 -or
35 $result.nativePerformance.invoices -ne 50000 -or
36 $result.nativePerformance.companyInvoices -ne 50000) {
37 throw 'Targeted A08 acceptance incomplete'
38 }
36 -Write-Host 'Installed native A08 10k/50k benchmark PASSED'
39 +Write-Host ('Installed native A08 10k/50k ' + $Mode + ' PASSED')
tests/windows-vm-installed-tauri-cdp.cjs
+39 -4
@@ -11,10 +11,10 @@ const { verifyNativeOrigin } = require('./windows-vm-native-origin.cjs');
11
12 const [exe, profile, mode, expectedVersion, reportPath] = process.argv.slice(2);
13 assert.equal(process.platform, 'win32');
14 -assert.ok(['seed','upgrade','reopen','fresh','benchmark','crash-arm','crash-verify'].includes(mode), 'unknown lab mode');
14 +assert.ok(['seed','upgrade','reopen','fresh','benchmark','stability','crash-arm','crash-verify'].includes(mode), 'unknown lab mode');
15 assert.ok(fs.existsSync(exe), 'installed Windows executable missing');
16 fs.mkdirSync(profile, { recursive: true });
17 -const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : mode === 'reopen' ? 9374 : mode === 'benchmark' ? 9375 : mode === 'crash-arm' ? 9376 : mode === 'crash-verify' ? 9377 : 9373;
17 +const port = mode === 'seed' ? 9371 : mode === 'upgrade' ? 9372 : mode === 'reopen' ? 9374 : mode === 'benchmark' || mode === 'stability' ? 9375 : mode === 'crash-arm' ? 9376 : mode === 'crash-verify' ? 9377 : 9373;
18 const PASSWORD = 'VmOnly-Factor-83471!'; // Synthetic password, never printed.
19
20 const REG_POLICY = [
@@ -163,7 +163,7 @@ async function connect(url) {
163 assert.equal(ready.version, expectedVersion, 'candidate build runtime version mismatch');
164 }
165 const setup = ready.initialMode.includes('تعیین رمز');
166 - if (mode === 'seed' || mode === 'fresh' || mode === 'benchmark' || mode === 'crash-arm') {
166 + if (mode === 'seed' || mode === 'fresh' || mode === 'benchmark' || mode === 'stability' || mode === 'crash-arm') {
167 assert.equal(setup, true, 'a new native profile must prompt to set the administrator password');
168 } else {
169 assert.equal(setup, false, 'upgrade/reopen should preserve existing administrator credentials');
@@ -590,7 +590,7 @@ async function connect(url) {
590 });
591 }
592 }
593 - if (mode === 'benchmark') {
593 + if (mode === 'benchmark' || mode === 'stability') {
594 // A08 performance sample from the actually installed NSIS/Tauri/WebView2
595 // binary with a brand-new disposable profile, not Node fake-indexeddb.
596 // The separate profile prevents benchmark fixtures from affecting
@@ -639,6 +639,41 @@ async function connect(url) {
639 };
640 measured.jsHeapScope = 'renderer-js-heap-not-total-Windows-process-memory';
641 report.nativePerformance = measured;
642 + if (mode === 'stability') {
643 + const cycleCode = fs.readFileSync(
644 + path.join(__dirname, 'windows-vm-native-memory-stability-browser.js'), 'utf8');
645 + const cycles = [];
646 + const heap = async () => {
647 + const usage = await cdp.command('Runtime.getHeapUsage', {}, 30000);
648 + assert.ok(Number.isSafeInteger(usage.usedSize) && usage.usedSize >= 0);
649 + return { usedBytes: usage.usedSize, allocatedBytes: usage.totalSize };
650 + };
651 + let gcSupported = true;
652 + const collect = async () => {
653 + try { await cdp.command('HeapProfiler.collectGarbage', {}, 30000); }
654 + catch (_) { gcSupported = false; }
655 + };
656 + await collect();
657 + const baseline = await heap();
658 + for (let i = 0; i < 10; i++) {
659 + const result = await cdp.evaluate(cycleCode, 120000);
660 + assert.equal(result.products, 10000);
661 + assert.equal(result.invoices, 50000);
662 + assert.equal(result.companyInvoices, 50000);
663 + assert.equal(result.rounds.length, 1);
664 + const raw = await heap();
665 + if (gcSupported) await collect();
666 + const postGc = gcSupported ? await heap() : null;
667 + cycles.push({ cycle: i + 1, durationMs: result.rounds[0].durationMs,
668 + raw, postGc });
669 + }
670 + report.nativeMemoryStability = {
671 + status: 'PASSED', synthetic: true, cycles, baseline,
672 + gcSupported, heapScope: 'renderer-js-heap-not-Windows-working-set',
673 + note: 'Diagnostic series only; no leak verdict or SLA implied'
674 + };
675 + }
676 +
677 }
678 if (mode === 'fresh') {
679 // LAST operation: real installed WebView2 PDF engine, using production
tests/windows-vm-native-memory-stability-browser.js new
+35
@@ -0,0 +1,35 @@
1 +'use strict';
2 +const assert = require('node:assert/strict');
3 +const fs = require('node:fs');
4 +const path = require('node:path');
5 +const { spawn, execFileSync } = require('node:child_process');
6 +// This script is evaluated by CDP inside the installed Tauri/WebView2 renderer.
7 +// It does not seed data; the standard A08 benchmark must run first.
8 +(async () => {
9 + const db = FINORA.Storage;
10 + const company = await FINORA.Company.current();
11 + if (!company?.id || !globalThis.__TAURI_INTERNALS__?.invoke)
12 + throw Error('Installed native administrator required');
13 + const products = await db.count('products');
14 + const invoices = await db.count('invoices');
15 + if (products !== 10000 || invoices !== 50000)
16 + throw Error('Stability test requires exact synthetic A08 dataset');
17 + const rounds = [];
18 + for (let i = 0; i < 1; i++) {
19 + const start = performance.now();
20 + const rows = await db.getByCompany('invoices', company.id);
21 + if (rows.length !== 50000) throw Error('Company invoice count changed during stability cycle');
22 + await FINORA.Router.go('reports');
23 + window.ReportsView._switchTab('products');
24 + for (const page of [1, 50, 100]) {
25 + window.ReportsView._setProductsPage(page);
26 + const region = document.getElementById('reports-content');
27 + if (region?.querySelectorAll('tbody tr').length !== 100)
28 + throw Error('Stability pagination failed at page ' + page);
29 + }
30 + rounds.push({cycle: i + 1, durationMs: Math.round((performance.now()-start)*10)/10});
31 + if (await db.count('products') !== 10000 || await db.count('invoices') !== 50000)
32 + throw Error('Synthetic record counts changed during stability cycle');
33 + }
34 + return {rounds, products, invoices, companyInvoices: 50000, synthetic: true};
35 +})()