-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfirmation_request_selftest.ps1
More file actions
64 lines (59 loc) · 2.53 KB
/
Copy pathconfirmation_request_selftest.ps1
File metadata and controls
64 lines (59 loc) · 2.53 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
param(
[string]$Root = '',
[switch]$Help
)
$ErrorActionPreference = 'Stop'
if ($Help) {
Write-Host 'Usage: .\confirmation_request_selftest.ps1 [-Root <path>]'
Write-Host 'Validates v5.3.2 ConfirmationRequest generation.'
exit 0
}
$Resolver = Join-Path $PSScriptRoot 'scripts\Resolve-DesktopVisualRoot.ps1'
$Root = & $Resolver -Root $Root -StartPath $PSScriptRoot
$WinAgent = Join-Path $Root 'bin\winagent.exe'
$ArtifactDir = Join-Path $Root 'artifacts\dev5.3.2'
$Report = Join-Path $ArtifactDir 'confirmation_request_selftest_report.md'
New-Item -ItemType Directory -Force -Path $ArtifactDir | Out-Null
$output = & $WinAgent confirmation-request-create `
--action 'send email' `
--risk-level high `
--summary 'Review mock email before send.' `
--target-window 'Local Mail Mock' `
--screenshot 'artifacts/dev5.3.2/screenshots/pre_send_review.bmp' `
--files 'artifacts/dev5.3.2/mock_attachment.txt' `
--destination 'qa@example.invalid' `
--timeout-ms 30000 `
--allowed-responses 'confirm,reject'
if ($LASTEXITCODE -ne 0) {
throw "confirmation-request-create failed. Output: $output"
}
$json = $output | ConvertFrom-Json
if (-not $json.ok) { throw 'confirmation-request-create returned ok=false.' }
foreach ($field in @('action', 'risk_level', 'summary', 'target_window', 'screenshot', 'involved_files', 'destination', 'timeout_ms', 'allowed_responses', 'audit_id', 'request_json', 'report_md')) {
if ($null -eq $json.data.$field) { throw "ConfirmationRequest missing $field" }
}
if ($json.data.risk_level -ne 'high') { throw 'Expected risk_level high.' }
if ($json.data.allowed_responses -notcontains 'confirm') { throw 'allowed_responses missing confirm.' }
if ($json.data.allowed_responses -notcontains 'reject') { throw 'allowed_responses missing reject.' }
foreach ($path in @($json.data.request_json, $json.data.report_md)) {
$full = Join-Path $Root $path
if (-not (Test-Path -LiteralPath $full)) { throw "Expected artifact missing: $full" }
}
Get-Content -LiteralPath (Join-Path $Root $json.data.request_json) -Raw | ConvertFrom-Json | Out-Null
$lines = @(
'# v5.3.2 Confirmation Request Selftest Report',
'',
'- Result: PASS',
"- Timestamp: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
"- Request JSON: $($json.data.request_json)",
"- Report MD: $($json.data.report_md)",
'',
'## Output',
'',
'```json',
$output,
'```'
)
$lines | Set-Content -LiteralPath $Report -Encoding UTF8
Write-Host 'PASS: v5.3.2 ConfirmationRequest selftest'
Write-Host "Report: $Report"