Files
mini-openclaw/scripts/reset_aliyun_demo.ps1
T
2026-09-28 16:34:10 +08:00

74 lines
2.9 KiB
PowerShell

[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High")]
param(
[string]$BaseUrl = "http://8.163.107.248:3200",
[string]$AccessToken = "",
[switch]$CheckOnly,
[string]$Confirmation = ""
)
$ErrorActionPreference = "Stop"
$apiRoot = $BaseUrl.TrimEnd("/") + "/api/risk-agent/project-assistant"
$headers = @{ Accept = "application/json" }
if ($AccessToken) {
$headers.Authorization = "Bearer $AccessToken"
} else {
$headers["X-Xingbang-Demo-Role"] = "admin"
}
function Get-DemoState {
$response = Invoke-RestMethod -Method Get -Uri "$apiRoot/projects" -Headers $headers -TimeoutSec 20
return @($response.projects | Where-Object { $_.id -in @("DEMO-A", "DEMO-B", "DEMO-C") } | Sort-Object id)
}
function Show-DemoState([string]$Title, $Projects) {
Write-Host ""
Write-Host $Title -ForegroundColor Cyan
$Projects | Select-Object id, customer, stage, workflow_state, revision, data_revision, open_findings, next_action | Format-Table -AutoSize
}
$before = Get-DemoState
if ($before.Count -ne 3) {
throw "Demo projects are incomplete: expected DEMO-A, DEMO-B and DEMO-C; received $($before.Count)."
}
Show-DemoState "Current Alibaba Cloud demo state" $before
if ($CheckOnly) {
Write-Host "Read-only check completed. No data was changed." -ForegroundColor Green
exit 0
}
Write-Warning "This restores DEMO-A, DEMO-B and DEMO-C facts, materials, runs, findings, reports and review decisions to the built-in baseline."
Write-Warning "Formal projects and published cards, skills, rules and templates are not reset. Demo audit and timing events return to the baseline and the prior state is archived."
if (-not $Confirmation) {
$Confirmation = Read-Host "Type RESET-DEMO-A-B-C to continue"
}
if ($Confirmation -ne "RESET-DEMO-A-B-C") {
throw "Confirmation text did not match. No reset was performed."
}
$target = "$apiRoot/demo/reset"
if (-not $PSCmdlet.ShouldProcess($target, "Reset the three demo projects")) {
Write-Host "Cancelled. No data was changed."
exit 0
}
$result = Invoke-RestMethod -Method Post -Uri $target -Headers ($headers + @{ "Content-Type" = "application/json" }) -Body (@{ confirmation = $Confirmation } | ConvertTo-Json -Compress) -TimeoutSec 30
if ($result.status -ne "reset" -or $result.projects -ne 3) {
throw "The server did not return the expected reset response: $($result | ConvertTo-Json -Compress)"
}
$after = Get-DemoState
Show-DemoState "Demo state after reset" $after
$expected = @{
"DEMO-A" = "report_ready"
"DEMO-B" = "supplementing"
"DEMO-C" = "under_review"
}
$unexpected = @($after | Where-Object { $expected[$_.id] -ne $_.workflow_state })
if ($unexpected.Count) {
throw "The reset API succeeded, but the project state does not match the baseline. Stop and investigate before the demo."
}
Write-Host "Reset completed. Refresh the browser. DEMO-B should be supplementing and retain the four demo risk conditions." -ForegroundColor Green