فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(windows-vm): install real signed-by-checksum v2.0.3 then upgrade NSIS and verify WebView2 persistence
davoodmehraban89 committed
Oct 16, 2026 at 17:58 UTC
cc7afb1516044747e5411a4412820f886364b54c
1 file changed
+125
scripts/windows-vm-native-lab.ps1
new
+125
@@ -0,0 +1,125 @@
1
+# PowerShell 7. Disposable Windows GitHub Actions laboratory.
2
+# Exercises REAL NSIS binaries: released v2.0.3 -> locally built candidate,
3
+# and fresh candidate. No installed user data or public publishing.
4
+[CmdletBinding()]
5
+param(
6
+ [Parameter(Mandatory=$true)][string]$CandidateInstaller,
7
+ [Parameter(Mandatory=$true)][string]$CandidateVersion,
8
+ [string]$OldVersion = '2.0.3'
9
+)
10
+$ErrorActionPreference = 'Stop'
11
+$ProgressPreference = 'SilentlyContinue'
12
+if (-not $env:GITHUB_ACTIONS -or $env:RUNNER_OS -ne 'Windows') {
13
+ throw 'This test must run only on a disposable Windows GitHub Actions runner'
14
+}
15
+$lab = Join-Path $env:RUNNER_TEMP 'factor-easypro-native-vm-lab'
16
+$reportDir = Join-Path $lab 'reports'
17
+New-Item -ItemType Directory -Force -Path $reportDir | Out-Null
18
+$summary = [ordered]@{
19
+ lab='real-Windows-NSIS-WebView2'
20
+ oldVersion=$OldVersion
21
+ candidateVersion=$CandidateVersion
22
+ install='not-run'
23
+ upgrade='not-run'
24
+ freshInstall='not-run'
25
+ nativeGUI='not-run'
26
+ status='FAILED'
27
+}
28
+function Verify-Installer([string]$file) {
29
+ if (!(Test-Path -LiteralPath $file)) { throw "Installer does not exist: $file" }
30
+ $size = (Get-Item -LiteralPath $file).Length
31
+ if ($size -lt 500000) { throw "Installer size suspicious: $size" }
32
+ return (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash
33
+}
34
+function Install-NSIS([string]$installer,[string]$directory) {
35
+ # NSIS /D=path MUST be the final argument. The VM path has no spaces.
36
+ if ($directory.Contains(' ')) { throw 'Use a disposable NSIS test path without spaces' }
37
+ New-Item -ItemType Directory -Force -Path $directory | Out-Null
38
+ $args = @('/S',("/D=" + $directory))
39
+ Write-Output ("Installing " + (Split-Path $installer -Leaf) + ' to ' + $directory)
40
+ $process = Start-Process -FilePath $installer -ArgumentList $args -PassThru
41
+ try {
42
+ if (-not $process.WaitForExit(150000)) {
43
+ $process.Kill()
44
+ throw 'NSIS silent installation timed out'
45
+ }
46
+ if ($process.ExitCode -ne 0) { throw "NSIS installer exited $($process.ExitCode)" }
47
+ } finally { $process.Dispose() }
48
+ $candidate = Get-ChildItem -LiteralPath $directory -Recurse -File -ErrorAction SilentlyContinue |
49
+ Where-Object { $_.Name -eq 'Factor-easyPro.exe' } | Select-Object -First 1
50
+ if (-not $candidate) { throw "Installed Factor-easyPro.exe not found in $directory" }
51
+ if ($candidate.Length -lt 300000) { throw 'Installed executable suspiciously small' }
52
+ return $candidate.FullName
53
+}
54
+function Run-Native([string]$exe,[string]$profile,[string]$mode,[string]$version) {
55
+ $report = Join-Path $reportDir ($mode + '-native-result.json')
56
+ & node 'tests/windows-vm-installed-tauri-cdp.cjs' $exe $profile $mode $version $report
57
+ if ($LASTEXITCODE -ne 0) { throw "Installed native application $mode test failed (exit $LASTEXITCODE)" }
58
+ $result = Get-Content $report -Raw | ConvertFrom-Json
59
+ if ($result.status -ne 'PASSED' -or $result.installedNativeTauri -ne $true) {
60
+ throw "Native $mode test did not verify real Tauri WebView2"
61
+ }
62
+ return $result
63
+}
64
+function Cleanup-Installed([string]$folder) {
65
+ $uninstaller = Get-ChildItem -LiteralPath $folder -Recurse -File -ErrorAction SilentlyContinue |
66
+ Where-Object { $_.Name -match 'uninstall.*\.exe$' } | Select-Object -First 1
67
+ if (-not $uninstaller) {
68
+ Write-Warning "NSIS uninstaller not found in disposable folder $folder"
69
+ return
70
+ }
71
+ $proc = Start-Process -FilePath $uninstaller.FullName -ArgumentList '/S' -PassThru
72
+ try {
73
+ if (!$proc.WaitForExit(90000)) { $proc.Kill(); throw 'Uninstaller timed out' }
74
+ if ($proc.ExitCode -ne 0) { throw "Uninstaller failed with $($proc.ExitCode)" }
75
+ } finally { $proc.Dispose() }
76
+}
77
+try {
78
+ $newSha = Verify-Installer $CandidateInstaller
79
+ $previous = Join-Path $lab ('Factor-easyPro_' + $OldVersion + '_x64-setup.exe')
80
+ $checksum = Join-Path $lab 'v2.0.3-SHA256SUMS.txt'
81
+ $releaseBase = 'https://github.com/davoodmehraban89/Factor-easyPro/releases/download/v' + $OldVersion + '/'
82
+ Invoke-WebRequest -Uri ($releaseBase + (Split-Path $previous -Leaf)) -OutFile $previous
83
+ Invoke-WebRequest -Uri ($releaseBase + 'SHA256SUMS.txt') -OutFile $checksum
84
+ $checksumText = Get-Content $checksum -Raw
85
+ $found = [regex]::Match($checksumText,'(?i)([0-9a-f]{64})\s+\*?Factor-easyPro_' +
86
+ [regex]::Escape($OldVersion) + '_x64-setup.exe')
87
+ if (-not $found.Success) { throw 'Previous public installer checksum not found' }
88
+ $oldSha = Verify-Installer $previous
89
+ if ($found.Groups[1].Value.ToUpperInvariant() -ne $oldSha.ToUpperInvariant()) {
90
+ throw 'Previous public installer SHA256 verification FAILED'
91
+ }
92
+ if ($oldSha -eq $newSha) { throw 'Previous and candidate installers are byte-identical' }
93
+ Write-Output "Verified signed-by-checksum public release artifact v$OldVersion"
94
+
95
+ $upgradeDir = Join-Path $lab 'installed-upgrade'
96
+ $upgradeData = Join-Path $lab 'webview2-upgrade-profile'
97
+ $oldExe = Install-NSIS $previous $upgradeDir
98
+ $summary.install = 'public-v' + $OldVersion + '-nsis-installed'
99
+ $seed = Run-Native $oldExe $upgradeData 'seed' $OldVersion
100
+ $summary.nativeGUI = 'old-native-CDP-connected'
101
+
102
+ $newExe = Install-NSIS $CandidateInstaller $upgradeDir
103
+ $summary.upgrade = 'nsis-in-place-upgrade-installed'
104
+ $verified = Run-Native $newExe $upgradeData 'upgrade' $CandidateVersion
105
+ $summary.upgrade = $verified.persistence
106
+ $summary.nativeGUI = 'real-native-WebView2-validated'
107
+
108
+ $freshDir = Join-Path $lab 'installed-fresh'
109
+ $freshData = Join-Path $lab 'webview2-fresh-profile'
110
+ $freshExe = Install-NSIS $CandidateInstaller $freshDir
111
+ $freshResult = Run-Native $freshExe $freshData 'fresh' $CandidateVersion
112
+ $summary.freshInstall = $freshResult.indexedDb
113
+ $summary.status = 'PASSED'
114
+ Write-Output 'Verified fresh installation, NSIS in-place upgrade, retained v6 records, native login and Windows DPAPI'
115
+ Cleanup-Installed $freshDir
116
+ Cleanup-Installed $upgradeDir
117
+} catch {
118
+ $summary.failure = $_.Exception.Message
119
+ Write-Error $_.Exception.Message
120
+ throw
121
+} finally {
122
+ New-Item -ItemType Directory -Force -Path $reportDir | Out-Null
123
+ $summary | ConvertTo-Json -Depth 5 | Set-Content -Path (Join-Path $reportDir 'lab-summary.json') -Encoding utf8
124
+ $summary | ConvertTo-Json -Depth 5 | Write-Output
125
+}