-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-process-catalog-parser.ps1
More file actions
76 lines (63 loc) · 2.47 KB
/
test-process-catalog-parser.ps1
File metadata and controls
76 lines (63 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
param(
[string]$CatalogPath = (Join-Path $PSScriptRoot "..\data\catalog\processes.catalog.json"),
[string]$Configuration = "Debug"
)
$solutionRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
$projectPath = Join-Path $solutionRoot "src\TidyWindow.Core\TidyWindow.Core.csproj"
$assemblyPath = Join-Path $solutionRoot "src\TidyWindow.Core\bin\$Configuration\net8.0\TidyWindow.Core.dll"
if (-not (Test-Path $CatalogPath)) {
throw "Catalog file not found: $CatalogPath"
}
if (-not (Test-Path $assemblyPath)) {
Write-Host "Building TidyWindow.Core in $Configuration..." -ForegroundColor Cyan
dotnet build $projectPath -c $Configuration | Out-Host
if (-not (Test-Path $assemblyPath)) {
throw "Failed to locate compiled assembly at $assemblyPath"
}
}
Add-Type -Path $assemblyPath
$parser = [TidyWindow.Core.Processes.ProcessCatalogParser]::new($CatalogPath)
$snapshot = $parser.LoadSnapshot()
$expectedBackslashIdentifiers = @(
'\\microsoft\\windows\\edgeupdate\\microsoftedgeupdatetaskmachinecore',
'\\microsoft\\windows\\rds\\*'
)
$missing = @()
foreach ($identifier in $expectedBackslashIdentifiers) {
$found = $snapshot.Entries | Where-Object { $_.Identifier -eq $identifier }
if (-not $found) {
$missing += $identifier
}
}
if ($missing.Count -gt 0) {
throw "Parser did not surface expected identifiers: $($missing -join ', ')"
}
Write-Host ("Parsed {0} catalog entries from {1}" -f $snapshot.Entries.Count, $CatalogPath) -ForegroundColor Green
Write-Host "Verified double-backslash identifiers from the catalog." -ForegroundColor Green
$fixturePath = Join-Path ([System.IO.Path]::GetTempPath()) "TidyWindow_CatalogFixture.json"
$fixtureJson = @"
{
"entries": [
{
"identifier": "\\microsoft\\windows\\fixture",
"displayName": "\\Microsoft\\Windows\\Fixture",
"categoryKey": "M",
"recommendedAction": "AutoStop",
"risk": "Safe"
}
// Parser should accept this comment
]
}
"@
$fixtureJson | Set-Content -Path $fixturePath -Encoding UTF8
try {
$fixtureParser = [TidyWindow.Core.Processes.ProcessCatalogParser]::new($fixturePath)
$fixtureSnapshot = $fixtureParser.LoadSnapshot()
if ($fixtureSnapshot.Entries.Count -ne 1) {
throw "Fixture catalog did not parse correctly."
}
Write-Host "Fixture JSON with // comments parsed successfully." -ForegroundColor Green
}
finally {
Remove-Item -Path $fixturePath -ErrorAction SilentlyContinue
}