fix(lab): release T-014 process handles before cleanup [T-014]
Harness governance / validate (push) Has been cancelled

This commit is contained in:
QiuSW
2026-08-08 10:45:23 +08:00
parent 707ca8e508
commit c3cfaff614
2 changed files with 26 additions and 4 deletions
+24 -4
View File
@@ -146,6 +146,29 @@ function Stop-AllManagedProcesses($Items) {
if ($remaining.Count -gt 0) {
Write-Warning "managed processes did not exit within the shared cleanup deadline: $($remaining.Count)"
}
foreach ($item in $processes) {
if ($item.Process.HasExited) {
$item.Stdout.Wait(2000) | Out-Null
$item.Stderr.Wait(2000) | Out-Null
$item.Process.Dispose()
}
}
}
function Remove-SessionDirectory([string]$Path) {
Get-ChildItem -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue |
ForEach-Object { $_.Attributes = 'Normal' }
(Get-Item -LiteralPath $Path -Force).Attributes = 'Directory'
$deleteWatch = [Diagnostics.Stopwatch]::StartNew()
while (Test-Path -LiteralPath $Path) {
try {
Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction Stop
}
catch {
if ($deleteWatch.Elapsed.TotalSeconds -ge 10) { throw }
Start-Sleep -Milliseconds 200
}
}
}
function Assert-Alive($Managed) {
@@ -920,10 +943,7 @@ finally {
throw 'refusing to clean an unexpected T-014 session path'
}
if (Test-Path -LiteralPath $resolvedSession) {
Get-ChildItem -LiteralPath $resolvedSession -Recurse -Force -ErrorAction SilentlyContinue |
ForEach-Object { $_.Attributes = 'Normal' }
(Get-Item -LiteralPath $resolvedSession -Force).Attributes = 'Directory'
Remove-Item -LiteralPath $resolvedSession -Recurse -Force
Remove-SessionDirectory $resolvedSession
}
}
else {
+2
View File
@@ -46,6 +46,8 @@ class SenseCapacityContractTests(unittest.TestCase):
self.assertIn("the existing PostgreSQL listener on port 5432 changed", self.script)
self.assertNotRegex(self.script, r"Invoke-Checked \$script:pgCtl .* 'start'")
self.assertIn("$cleanupWatch.Elapsed.TotalSeconds -lt 10", self.script)
self.assertIn("$item.Process.Dispose()", self.script)
self.assertIn("$deleteWatch.Elapsed.TotalSeconds -ge 10", self.script)
def test_runtime_secrets_and_sensitive_inventory_are_not_reported(self):
self.assertIn("New-SecretToken", self.script)