فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(a02): parse-only gate for all A02 PowerShell helpers with malformed negative control
davoodmehraban89 committed
Oct 30, 2026 at 22:32 UTC
33e511c76b0207dc77f04e3a422fae69ccddbab9
1 file changed
+46
scripts/a02-powershell-parse-gate.ps1
new
+46
@@ -0,0 +1,46 @@
1
+#requires -Version 5.1
2
+<#
3
+A02: parser-only guard against accidentally committing malformed PowerShell.
4
+This gate NEVER executes migration scripts, SQL, ZIP input or owner data.
5
+#>
6
+[CmdletBinding()]
7
+param()
8
+Set-StrictMode -Version Latest
9
+$ErrorActionPreference='Stop'
10
+try {
11
+ $root=[IO.Path]::GetFullPath($PSScriptRoot)
12
+ $scripts=@(Get-ChildItem -LiteralPath $root -Filter 'a02-*.ps1' -File)
13
+ if($scripts.Count -lt 7 -or $scripts.Count -gt 30){
14
+ throw 'A02_POWERSHELL_SCRIPT_SET_UNEXPECTED'
15
+ }
16
+ foreach($scriptFile in $scripts){
17
+ $tokens=$null
18
+ $errors=$null
19
+ $null=[System.Management.Automation.Language.Parser]::ParseFile(
20
+ $scriptFile.FullName,[ref]$tokens,[ref]$errors)
21
+ if($null -ne $errors -and @($errors).Count -gt 0){
22
+ # Do not print original source lines, path, or diagnostics: future
23
+ # operator scripts could accidentally contain sensitive strings.
24
+ throw 'A02_POWERSHELL_SCRIPT_PARSE_FAILED'
25
+ }
26
+ }
27
+ $tokens=$null
28
+ $errors=$null
29
+ $null=[System.Management.Automation.Language.Parser]::ParseInput(
30
+ 'try { Write-Output "broken" ',[ref]$tokens,[ref]$errors)
31
+ if($null -eq $errors -or @($errors).Count -eq 0){
32
+ throw 'A02_POWERSHELL_PARSER_NEGATIVE_CONTROL_FAILED'
33
+ }
34
+ [pscustomobject]@{
35
+ status='a02-all-powershell-parser-gates-passed'
36
+ checkedScripts=$scripts.Count
37
+ malformedSyntheticScriptRejected=$true
38
+ scriptsExecuted=$false
39
+ ownerBackupUsed=$false
40
+ sqlConnected=$false
41
+ canImport=$false
42
+ } | ConvertTo-Json -Compress
43
+}catch{
44
+ Write-Error 'A02_POWERSHELL_PARSE_GATE_FAILED'
45
+ exit 2
46
+}