Files
Assistant/tests/topology_equivalence/verify-remote.ps1
2026-08-16 15:22:49 +03:00

82 lines
4.4 KiB
PowerShell

param([string]$DockerContext = "docker-prod")
$ErrorActionPreference = "Stop"
function Post-Json([string]$container, [string]$url, [object]$body) {
$json = $body | ConvertTo-Json -Depth 8 -Compress
$local = New-TemporaryFile
$remote = "/tmp/domovoy-$([guid]::NewGuid().ToString('N')).json"
try {
[IO.File]::WriteAllText($local, $json, [Text.UTF8Encoding]::new($false))
docker --context $DockerContext cp $local "${container}:$remote" | Out-Null
docker --context $DockerContext exec $container wget -qO- --header "Content-Type: application/json" --post-file $remote $url
if ($LASTEXITCODE -ne 0) { throw "POST $url failed" }
} finally {
docker --context $DockerContext exec --user root $container rm -f $remote 2>$null
Remove-Item -LiteralPath $local -Force
}
}
function Expect-PostStatus([string]$container, [string]$url, [object]$body, [int]$status) {
$json = $body | ConvertTo-Json -Depth 8 -Compress
$local = New-TemporaryFile
$remote = "/tmp/domovoy-$([guid]::NewGuid().ToString('N')).json"
try {
[IO.File]::WriteAllText($local, $json, [Text.UTF8Encoding]::new($false))
docker --context $DockerContext cp $local "${container}:$remote" | Out-Null
$previous = $ErrorActionPreference
$ErrorActionPreference = "Continue"
$response = (docker --context $DockerContext exec $container wget -S -O /dev/null --header "Content-Type: application/json" --post-file $remote $url 2>&1) -join "`n"
$ErrorActionPreference = $previous
if (-not $response.Contains("$status")) { throw "POST $url did not return $status" }
} finally {
docker --context $DockerContext exec --user root $container rm -f $remote 2>$null
Remove-Item -LiteralPath $local -Force
}
}
$suffix = [guid]::NewGuid().ToString("N")
$scope = "domovoy-global-scope"
$goal = "goal-$suffix"
$task = "task-$suffix"
$session = "session-$suffix"
$workspace = "workspace-$suffix"
Post-Json assistant-core-runtime-1 http://localhost:8080/v1/focus-bindings @{
ID="focus-$suffix"; ActorID="domovoy-creator-actor"; SessionID=$session; Workspace=$workspace
ProjectID="project-$suffix"; GoalID=$goal; ScopeID=$scope; Active=$true
} | Out-Null
Post-Json assistant-core-runtime-1 http://localhost:8080/v1/tasks @{
TaskID=$task; GoalID=$goal; ScopeID=$scope; Revision=1
} | Out-Null
$wrongCommit = @{ SessionID=$session; Workspace=$workspace; Target=@{TaskID=$task;GoalID="wrong-$goal";ScopeID=$scope;Revision=1} }
Expect-PostStatus assistant-core-runtime-1 http://localhost:8080/v1/focus-task-commits $wrongCommit 409
$rightCommit = @{ SessionID=$session; Workspace=$workspace; Target=@{TaskID=$task;GoalID=$goal;ScopeID=$scope;Revision=1} }
$commitResult = Post-Json assistant-core-runtime-1 http://localhost:8080/v1/focus-task-commits $rightCommit
if (($commitResult | ConvertFrom-Json).Revision -ne 2) { throw "remote task revision did not advance" }
$prospectiveID = "prospective-$suffix"
Post-Json assistant-continuity-runtime-1 http://localhost:8081/v1/prospective-items @{
ID=$prospectiveID; CommitmentID="commitment-$suffix"; OwnerPrincipalID="domovoy-creator-principal"
ScopeID=$scope; GoalID=$goal; TriggerAtUnixMillis=1800000000000; State="ARMED"; Revision=1
} | Out-Null
docker --context $DockerContext restart assistant-continuity-runtime-1 | Out-Null
for ($attempt=0; $attempt -lt 15; $attempt++) {
$restored = docker --context $DockerContext exec assistant-continuity-runtime-1 wget -qO- "http://localhost:8081/v1/prospective-items/$prospectiveID" 2>$null
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 2
}
if ($LASTEXITCODE -ne 0 -or $restored -notmatch $prospectiveID) { throw "prospective item did not survive restart" }
$intent = "intent-$suffix"
$authorized = "authorized-$suffix"
Post-Json assistant-commit-runtime-1 http://localhost:8082/v1/authorized-actions @{
Proposal=@{IntentID=$intent;ActorID="domovoy-creator-actor";CapabilityID="test-executor";Target=@{TaskID=$task;GoalID=$goal;ScopeID=$scope;Revision=2};Operation="test-idempotent-effect"}
AuthorizedID=$authorized;GrantID="domovoy-creator-grant";PrincipalID="domovoy-creator-principal"
} | Out-Null
Post-Json assistant-commit-runtime-1 http://localhost:8082/v1/action-attempts @{
ID="attempt-$suffix";AuthorizedID=$authorized;IntentID=$intent;State="UNKNOWN_OUTCOME"
} | Out-Null
Write-Output "WS-004 remote topology verification: PASS"