64 lines
2.9 KiB
Python
64 lines
2.9 KiB
Python
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
SCRIPT = ROOT / "scripts/reboot-recovery/agent99-stale-queue-quarantine.ps1"
|
|
|
|
|
|
def test_stale_queue_quarantine_is_exact_recoverable_and_receipted() -> None:
|
|
source = SCRIPT.read_text(encoding="utf-8")
|
|
|
|
assert '[ValidateSet("Check", "Apply")]' in source
|
|
assert "ExpectedQueueSha256" in source
|
|
assert "ExpectedMaintenanceSha256" in source
|
|
assert '"Global\\WoooAgent99StaleQueueMaintenanceV1"' in source
|
|
assert '"Global\\WoooAgent99ControlLoopMaintenanceV1"' in source
|
|
assert '"Global\\WoooAgent99RecoveryTransportV1"' in source
|
|
assert 'Get-ScheduledTask `' in source
|
|
assert '"Wooo-Agent99-Control-Loop"' in source
|
|
assert 'throw "control_loop_not_frozen"' in source
|
|
assert 'throw "active_control_or_recover_process"' in source
|
|
assert 'throw "recovery_lease_present"' in source
|
|
assert 'throw "recovery_mutex_active"' in source
|
|
assert '[string]$command.mode -ne "Recover"' in source
|
|
assert '[string]$command.source -ne "agent99-recovery-observer"' in source
|
|
assert "$command.controlledApply -isnot [bool]" in source
|
|
assert '"atomic_move_exact_queue_item_to_failed"' in source
|
|
assert "[IO.File]::Move($sourcePath, $destinationPath)" in source
|
|
assert "[IO.File]::Move($destinationPath, $sourcePath)" in source
|
|
assert '"verified_quarantined"' in source
|
|
assert '"failed_rolled_back"' in source
|
|
assert '"rollback_unverified"' in source
|
|
|
|
|
|
def test_stale_queue_quarantine_does_not_execute_or_delete_command() -> None:
|
|
source = SCRIPT.read_text(encoding="utf-8")
|
|
|
|
assert "commandExecuted = $false" in source
|
|
assert "deletePerformed = $false" in source
|
|
|
|
|
|
def test_invalid_untyped_maintenance_queue_quarantine_is_fail_closed() -> None:
|
|
source = SCRIPT.read_text(encoding="utf-8")
|
|
|
|
assert 'ValidateSet("StaleAutoRecover", "InvalidUntypedMaintenance")' in source
|
|
assert '"invalid-untyped-maintenance-$QueueFileName"' in source
|
|
assert 'source -ne "agent99-submit-request"' in source
|
|
assert 'reason -ne "operator_instruction"' in source
|
|
assert 'requestedBy -ne "Administrator"' in source
|
|
assert "$command.controlledApply" in source
|
|
assert "invalid_untyped_maintenance_queue_contract_mismatch" in source
|
|
assert "$createdAt -lt $maintenanceTimestamp" in source
|
|
assert 'quarantineClass = $QuarantineClass' in source
|
|
assert source.index("$maintenanceMutex.WaitOne(0)") < source.index(
|
|
"$writerMutex.WaitOne(0)"
|
|
)
|
|
assert 'recovery-transport-lease.json"\n ))' in source
|
|
assert "otherQueueMutationPerformed = $false" in source
|
|
assert "rawInstructionStored = $false" in source
|
|
assert "secretValueRead = $false" in source
|
|
assert "Remove-Item -LiteralPath $sourcePath" not in source
|
|
assert "Start-ScheduledTask" not in source
|
|
assert "Invoke-Expression" not in source
|
|
assert "& $command" not in source
|