@trillboards/edge-sdk 0.2.245 → 0.2.253
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy/detector/bench/detect_frames.py +88 -0
- package/deploy/detector/bench/openvino_parity.py +152 -0
- package/deploy/detector/pyproject.toml +10 -1
- package/deploy/detector/tests/test_actor_tracking.py +168 -0
- package/deploy/detector/tests/test_actor_tracking_wire.py +22 -0
- package/deploy/detector/tests/test_loader.py +25 -0
- package/deploy/detector/tests/test_openvino_engines.py +251 -0
- package/deploy/detector/tests/test_registry.py +53 -0
- package/deploy/detector/tests/test_server.py +43 -0
- package/deploy/detector/tests/test_version_stamp.py +17 -4
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/actor_tracking.py +139 -2
- package/deploy/detector/trillboards_detector/cli.py +5 -0
- package/deploy/detector/trillboards_detector/detections.py +5 -0
- package/deploy/detector/trillboards_detector/execution.py +386 -0
- package/deploy/detector/trillboards_detector/loader.py +40 -1
- package/deploy/detector/trillboards_detector/registry.py +33 -1
- package/deploy/detector/trillboards_detector/server.py +43 -1
- package/deploy/detector/trillboards_detector/session.py +81 -3
- package/deploy/detector/trillboards_detector/track_records.py +113 -0
- package/deploy/windows/build-windows.ps1 +1 -0
- package/deploy/windows/ci/test-detector-looks-field.ps1 +15 -3
- package/deploy/windows/ci/test-detector-reinstall.ps1 +645 -0
- package/deploy/windows/ci/test-rollout-proofs.ps1 +3 -2
- package/deploy/windows/ensure-detector.ps1 +255 -0
- package/deploy/windows/install-update.ps1 +4 -3
- package/deploy/windows/setup-detector.ps1 +122 -29
- package/deploy/windows/stop-existing.ps1 +1 -0
- package/deploy/windows/trillboards-edge.cmd +10 -22
- package/dist/ActorTracking.d.ts +38 -0
- package/dist/ActorTracking.d.ts.map +1 -1
- package/dist/ActorTracking.js +40 -0
- package/dist/ActorTracking.js.map +1 -1
- package/dist/AlertClips.d.ts +4 -2
- package/dist/AlertClips.d.ts.map +1 -1
- package/dist/AlertClips.js +24 -9
- package/dist/AlertClips.js.map +1 -1
- package/dist/CloudSensingManager.d.ts +9 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +52 -4
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/ConnectorStatusClient.d.ts +8 -0
- package/dist/ConnectorStatusClient.d.ts.map +1 -1
- package/dist/ConnectorStatusClient.js +3 -0
- package/dist/ConnectorStatusClient.js.map +1 -1
- package/dist/DurableVlmCandidateSpool.d.ts +11 -0
- package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
- package/dist/DurableVlmCandidateSpool.js +31 -2
- package/dist/DurableVlmCandidateSpool.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/FrameGroupingShadow.d.ts +57 -0
- package/dist/FrameGroupingShadow.d.ts.map +1 -1
- package/dist/FrameGroupingShadow.js +123 -5
- package/dist/FrameGroupingShadow.js.map +1 -1
- package/dist/LocalDetectorClient.d.ts +44 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +88 -4
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/LocalVideoBuffer.d.ts +14 -2
- package/dist/LocalVideoBuffer.d.ts.map +1 -1
- package/dist/LocalVideoBuffer.js +23 -3
- package/dist/LocalVideoBuffer.js.map +1 -1
- package/dist/NativeReadiness.d.ts +21 -2
- package/dist/NativeReadiness.d.ts.map +1 -1
- package/dist/NativeReadiness.js +25 -6
- package/dist/NativeReadiness.js.map +1 -1
- package/dist/OrderedReviewClient.d.ts +3 -0
- package/dist/OrderedReviewClient.d.ts.map +1 -1
- package/dist/OrderedReviewClient.js +3 -0
- package/dist/OrderedReviewClient.js.map +1 -1
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +3 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/TemporalReviewClient.d.ts +3 -0
- package/dist/TemporalReviewClient.d.ts.map +1 -1
- package/dist/TemporalReviewClient.js +3 -0
- package/dist/TemporalReviewClient.js.map +1 -1
- package/dist/VideoSegmentUploader.d.ts +14 -7
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +34 -38
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/VlmCandidateBuffer.d.ts +13 -0
- package/dist/VlmCandidateBuffer.d.ts.map +1 -1
- package/dist/VlmCandidateBuffer.js.map +1 -1
- package/dist/autoSense.d.ts +4 -0
- package/dist/autoSense.d.ts.map +1 -1
- package/dist/autoSense.js +7 -0
- package/dist/autoSense.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/connectorUpdate.d.ts +18 -9
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +66 -3
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/connectorUpdateApply.d.ts +20 -1
- package/dist/connectorUpdateApply.d.ts.map +1 -1
- package/dist/connectorUpdateApply.js +55 -1
- package/dist/connectorUpdateApply.js.map +1 -1
- package/dist/connectorUpdateApplyMac.d.ts +3 -1
- package/dist/connectorUpdateApplyMac.d.ts.map +1 -1
- package/dist/connectorUpdateApplyMac.js +6 -0
- package/dist/connectorUpdateApplyMac.js.map +1 -1
- package/dist/continuousReview.d.ts +6 -2
- package/dist/continuousReview.d.ts.map +1 -1
- package/dist/continuousReview.js.map +1 -1
- package/dist/detectorBackendRelay.d.ts +24 -0
- package/dist/detectorBackendRelay.d.ts.map +1 -0
- package/dist/detectorBackendRelay.js +70 -0
- package/dist/detectorBackendRelay.js.map +1 -0
- package/dist/detectorEndpointState.d.ts +30 -0
- package/dist/detectorEndpointState.d.ts.map +1 -0
- package/dist/detectorEndpointState.js +125 -0
- package/dist/detectorEndpointState.js.map +1 -0
- package/dist/detectorLauncher.d.ts +23 -0
- package/dist/detectorLauncher.d.ts.map +1 -0
- package/dist/detectorLauncher.js +94 -0
- package/dist/detectorLauncher.js.map +1 -0
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +72 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +280 -31
- package/dist/localSensing.js.map +1 -1
- package/dist/pipelineSwitches.d.ts +59 -0
- package/dist/pipelineSwitches.d.ts.map +1 -0
- package/dist/pipelineSwitches.js +240 -0
- package/dist/pipelineSwitches.js.map +1 -0
- package/package.json +4 -4
- package/retained/ProfileAuthorityClient.cjs +4 -0
- package/retained/RetainedCaptureClient.cjs +41 -2
- package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
- package/retained/__tests__/look-reuse.test.cjs +167 -0
- package/retained/manager.cjs +28 -2
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
<#
|
|
2
|
+
test-detector-reinstall.ps1 -- the detector reinstall a connector update runs
|
|
3
|
+
(install-update.ps1 Update-DetectorTask -> setup-detector.ps1), against a
|
|
4
|
+
detector that is SERVING, on a real Windows runner with real uv.
|
|
5
|
+
|
|
6
|
+
Why: `uv tool install --force` deletes the old venv and executable after it
|
|
7
|
+
resolves and before it downloads. Run with the service stopped, a WAN drop
|
|
8
|
+
during the download left a store PC with no detector at all (found from code
|
|
9
|
+
before the 0.2.246 install, 2026-11-17). setup-detector.ps1 now trial-installs
|
|
10
|
+
into a throwaway tool directory while the old service keeps serving, and only
|
|
11
|
+
then stops it and replaces it offline, from uv's cache.
|
|
12
|
+
|
|
13
|
+
The old detector is installed the way production 0.2.245 left it ([cpu], its
|
|
14
|
+
own version) and serves /health 200 on a stand-in ONNX with the shipped
|
|
15
|
+
RF-DETR Medium signature (the real artifact is behind presigned URLs).
|
|
16
|
+
|
|
17
|
+
(a) index unreachable: a cold uv cache and a dead proxy. Both trial rungs
|
|
18
|
+
fail; the old detector's process, executable and version are unchanged
|
|
19
|
+
and /health answers 200 from the same loaded model throughout.
|
|
20
|
+
(b) network cut right after the trial: a cold uv cache, uv's traffic through
|
|
21
|
+
a logging proxy that refuses every connection from the moment the
|
|
22
|
+
"trial install passed" line is written. The replacement must complete,
|
|
23
|
+
the proxy must see no connection attempt after the cut, and the old
|
|
24
|
+
detector must have answered 200 through the whole trial.
|
|
25
|
+
(c) the detector's down time inside (b): the old process's last /health 200
|
|
26
|
+
to the new process's first.
|
|
27
|
+
|
|
28
|
+
Then the connector launcher's check of that detector (ensure-detector.ps1,
|
|
29
|
+
run under Windows PowerShell 5.1 as the launcher runs it; the provisioner
|
|
30
|
+
is a stub that only records that it ran, except where noted):
|
|
31
|
+
(d) a busy detector: /health answers 503 after 4 s. Through 0.2.252 the
|
|
32
|
+
launcher's 2 s curl re-provisioned exactly this. `answered`, no setup.
|
|
33
|
+
(e) the task registered and enabled, its process stopped: `started_task`,
|
|
34
|
+
the detector answers within 60 s from a new process, no setup.
|
|
35
|
+
(f) the task registered but unable to start (its executable renamed):
|
|
36
|
+
`reprovision_still_refused` after the start wait, setup ran.
|
|
37
|
+
(g) the task unregistered: `reprovision_task_missing`, setup ran.
|
|
38
|
+
(h) the provisioner running (its per-user mutex held): left alone,
|
|
39
|
+
`provisioning_in_progress`, no setup.
|
|
40
|
+
(i) a listener that never answers: three timeouts, never refused, left
|
|
41
|
+
alone (`no_answer_left_alone`), no setup.
|
|
42
|
+
#>
|
|
43
|
+
[CmdletBinding()]
|
|
44
|
+
param()
|
|
45
|
+
|
|
46
|
+
$ErrorActionPreference = 'Stop'
|
|
47
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
48
|
+
|
|
49
|
+
$deploy = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
|
50
|
+
$detectorSource = (Resolve-Path (Join-Path $deploy '..\detector')).Path
|
|
51
|
+
$root = Join-Path $env:LOCALAPPDATA ('detector-reinstall-proof-' + [Guid]::NewGuid().ToString('N').Substring(0, 8))
|
|
52
|
+
$evidence = Join-Path $root 'evidence'
|
|
53
|
+
New-Item -ItemType Directory -Force -Path $evidence | Out-Null
|
|
54
|
+
if ($env:GITHUB_OUTPUT) { "artifact_path=$evidence" | Add-Content -LiteralPath $env:GITHUB_OUTPUT }
|
|
55
|
+
$setupLog = Join-Path $env:LOCALAPPDATA 'Trillboards\logs\detector-setup.log'
|
|
56
|
+
$healthUrl = 'http://127.0.0.1:9380/health'
|
|
57
|
+
$localBin = Join-Path $env:USERPROFILE '.local\bin'
|
|
58
|
+
$detectorExe = Join-Path $localBin 'trillboards-detector.exe'
|
|
59
|
+
$receipt = [ordered]@{ version = 1; startedAtUtc = [DateTimeOffset]::UtcNow.ToString('o'); passed = $false; cases = [ordered]@{} }
|
|
60
|
+
|
|
61
|
+
function Write-Receipt {
|
|
62
|
+
$receipt | ConvertTo-Json -Depth 12 | Set-Content -LiteralPath (Join-Path $evidence 'receipt.json') -Encoding utf8
|
|
63
|
+
}
|
|
64
|
+
function Write-Utf8NoBom([string]$Path, [string]$Text) {
|
|
65
|
+
[IO.File]::WriteAllText($Path, $Text, (New-Object Text.UTF8Encoding $false))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function Copy-DetectorSource([string]$Destination, [string]$Version) {
|
|
69
|
+
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
|
70
|
+
& robocopy $detectorSource $Destination /E /XD tests bench __pycache__ .venv /NFL /NDL /NJH /NJS /NP | Out-Null
|
|
71
|
+
if ($LASTEXITCODE -ge 8) { throw "robocopy of the detector source failed ($LASTEXITCODE)" }
|
|
72
|
+
$global:LASTEXITCODE = 0
|
|
73
|
+
if ($Version) {
|
|
74
|
+
$pyproject = Join-Path $Destination 'pyproject.toml'
|
|
75
|
+
$text = [IO.File]::ReadAllText($pyproject)
|
|
76
|
+
$text = [Text.RegularExpressions.Regex]::Replace($text, '(?m)^version = "[^"]+"', ('version = "' + $Version + '"'))
|
|
77
|
+
Write-Utf8NoBom $pyproject $text
|
|
78
|
+
$versionPy = Join-Path $Destination 'trillboards_detector\_version.py'
|
|
79
|
+
$text = [IO.File]::ReadAllText($versionPy)
|
|
80
|
+
$text = [Text.RegularExpressions.Regex]::Replace($text, '(?m)^VERSION = "[^"]+"', ('VERSION = "' + $Version + '"'))
|
|
81
|
+
Write-Utf8NoBom $versionPy $text
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Read-PackageVersion([string]$SourceDir) {
|
|
86
|
+
foreach ($line in [IO.File]::ReadAllLines((Join-Path $SourceDir 'pyproject.toml'))) {
|
|
87
|
+
if ($line -match '^\s*version\s*=\s*"([^"]+)"\s*$') { return $Matches[1] }
|
|
88
|
+
}
|
|
89
|
+
throw "no version in $SourceDir"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function Get-InstalledVersion {
|
|
93
|
+
if (-not (Test-Path -LiteralPath $detectorExe)) { return $null }
|
|
94
|
+
$out = & $detectorExe --version 2>$null
|
|
95
|
+
if ($LASTEXITCODE -ne 0 -or -not $out) { $global:LASTEXITCODE = 0; return $null }
|
|
96
|
+
return ([string]$out).Trim().Split(' ')[-1]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function Get-HealthCode {
|
|
100
|
+
try {
|
|
101
|
+
$response = Invoke-WebRequest -Uri $healthUrl -NoProxy -SkipHttpErrorCheck -TimeoutSec 3
|
|
102
|
+
return [int]$response.StatusCode
|
|
103
|
+
} catch { return 0 }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function Wait-HealthCode([int]$Code, [int]$Seconds) {
|
|
107
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
108
|
+
while ($watch.Elapsed.TotalSeconds -lt $Seconds) {
|
|
109
|
+
if ((Get-HealthCode) -eq $Code) { return $watch.Elapsed.TotalSeconds }
|
|
110
|
+
Start-Sleep -Milliseconds 250
|
|
111
|
+
}
|
|
112
|
+
throw "/health did not answer $Code within $Seconds s (last: $(Get-HealthCode))"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Get-ListenerPid {
|
|
116
|
+
$listener = @(Get-NetTCPConnection -LocalPort 9380 -State Listen -ErrorAction SilentlyContinue)
|
|
117
|
+
if (-not $listener.Count) { return $null }
|
|
118
|
+
return [int]$listener[0].OwningProcess
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function Get-LogLength {
|
|
122
|
+
if (-not (Test-Path -LiteralPath $setupLog)) { return 0 }
|
|
123
|
+
return (Get-Item -LiteralPath $setupLog).Length
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function Read-NewLogText([long]$Offset) {
|
|
127
|
+
if (-not (Test-Path -LiteralPath $setupLog)) { return '' }
|
|
128
|
+
$stream = [IO.File]::Open($setupLog, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
129
|
+
try {
|
|
130
|
+
$null = $stream.Seek($Offset, [IO.SeekOrigin]::Begin)
|
|
131
|
+
return (New-Object IO.StreamReader($stream)).ReadToEnd()
|
|
132
|
+
} finally { $stream.Dispose() }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# /health every 100 ms, in its own process, until the stop file appears. Each
|
|
136
|
+
# sample keeps the model's loaded_at, which identifies the serving process: a
|
|
137
|
+
# slow answer is not mistaken for the swap, and a 200 from a restarted process
|
|
138
|
+
# is not mistaken for the old one.
|
|
139
|
+
function Start-HealthPoller([string]$Samples, [string]$StopFile) {
|
|
140
|
+
Start-Job -ArgumentList $healthUrl, $Samples, $StopFile -ScriptBlock {
|
|
141
|
+
param($url, $samples, $stop)
|
|
142
|
+
while (-not (Test-Path -LiteralPath $stop)) {
|
|
143
|
+
$code = 0; $loadedAt = ''
|
|
144
|
+
try {
|
|
145
|
+
$response = Invoke-WebRequest -Uri $url -NoProxy -SkipHttpErrorCheck -TimeoutSec 3
|
|
146
|
+
$code = [int]$response.StatusCode
|
|
147
|
+
if ([string]$response.Content -match '"loaded_at":\s*([0-9.]+)') { $loadedAt = $Matches[1] }
|
|
148
|
+
} catch { $code = 0 }
|
|
149
|
+
Add-Content -LiteralPath $samples -Value ('{0},{1},{2}' -f [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds(), $code, $loadedAt)
|
|
150
|
+
Start-Sleep -Milliseconds 100
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function Stop-HealthPoller($Job, [string]$StopFile) {
|
|
156
|
+
New-Item -ItemType File -Force -Path $StopFile | Out-Null
|
|
157
|
+
$null = Wait-Job $Job -Timeout 30
|
|
158
|
+
Remove-Job $Job -Force
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function Read-HealthSamples([string]$Samples) {
|
|
162
|
+
@(Get-Content -LiteralPath $Samples | ForEach-Object {
|
|
163
|
+
$parts = $_.Split(',')
|
|
164
|
+
[pscustomobject]@{ atMs = [long]$parts[0]; code = [int]$parts[1]; loadedAt = $parts[2] }
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# Runs setup-detector.ps1 the way install-update.ps1 does (Windows PowerShell),
|
|
169
|
+
# with the given environment overrides, and returns what it appended to its log.
|
|
170
|
+
function Invoke-SetupDetector([string]$SourceDir, [hashtable]$Environment) {
|
|
171
|
+
$saved = @{}
|
|
172
|
+
foreach ($name in $Environment.Keys) {
|
|
173
|
+
$saved[$name] = [Environment]::GetEnvironmentVariable($name, 'Process')
|
|
174
|
+
[Environment]::SetEnvironmentVariable($name, $Environment[$name], 'Process')
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
$offset = Get-LogLength
|
|
178
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
179
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $deploy 'setup-detector.ps1') -SourcePath $SourceDir | Out-Host
|
|
180
|
+
$exit = $LASTEXITCODE
|
|
181
|
+
$global:LASTEXITCODE = 0
|
|
182
|
+
return [pscustomobject]@{ exit = $exit; seconds = [math]::Round($watch.Elapsed.TotalSeconds, 1); log = (Read-NewLogText $offset) }
|
|
183
|
+
} finally {
|
|
184
|
+
foreach ($name in $saved.Keys) { [Environment]::SetEnvironmentVariable($name, $saved[$name], 'Process') }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
$pythonProxy = @'
|
|
189
|
+
import os, socket, sys, threading, time
|
|
190
|
+
|
|
191
|
+
port, log_path, cut_path = int(sys.argv[1]), sys.argv[2], sys.argv[3]
|
|
192
|
+
lock = threading.Lock()
|
|
193
|
+
|
|
194
|
+
def log(line):
|
|
195
|
+
with lock, open(log_path, "a", encoding="utf-8") as f:
|
|
196
|
+
f.write("%d %s\n" % (int(time.time() * 1000), line))
|
|
197
|
+
|
|
198
|
+
def pipe(src, dst):
|
|
199
|
+
try:
|
|
200
|
+
while True:
|
|
201
|
+
data = src.recv(65536)
|
|
202
|
+
if not data:
|
|
203
|
+
break
|
|
204
|
+
dst.sendall(data)
|
|
205
|
+
except OSError:
|
|
206
|
+
pass
|
|
207
|
+
finally:
|
|
208
|
+
for s in (src, dst):
|
|
209
|
+
try:
|
|
210
|
+
s.shutdown(socket.SHUT_RDWR)
|
|
211
|
+
except OSError:
|
|
212
|
+
pass
|
|
213
|
+
|
|
214
|
+
def handle(client):
|
|
215
|
+
try:
|
|
216
|
+
head = b""
|
|
217
|
+
while b"\r\n\r\n" not in head:
|
|
218
|
+
chunk = client.recv(4096)
|
|
219
|
+
if not chunk:
|
|
220
|
+
client.close()
|
|
221
|
+
return
|
|
222
|
+
head += chunk
|
|
223
|
+
method, target = head.split(b"\r\n", 1)[0].decode("latin1").split(" ")[:2]
|
|
224
|
+
if os.path.exists(cut_path):
|
|
225
|
+
log("REFUSED %s %s" % (method, target))
|
|
226
|
+
client.sendall(b"HTTP/1.1 503 Service Unavailable\r\nContent-Length: 0\r\n\r\n")
|
|
227
|
+
client.close()
|
|
228
|
+
return
|
|
229
|
+
if method != "CONNECT":
|
|
230
|
+
log("REJECTED %s %s" % (method, target))
|
|
231
|
+
client.sendall(b"HTTP/1.1 405 Method Not Allowed\r\nContent-Length: 0\r\n\r\n")
|
|
232
|
+
client.close()
|
|
233
|
+
return
|
|
234
|
+
host, port_text = target.rsplit(":", 1)
|
|
235
|
+
upstream = socket.create_connection((host, int(port_text)), timeout=30)
|
|
236
|
+
upstream.settimeout(None)
|
|
237
|
+
log("CONNECT %s" % target)
|
|
238
|
+
client.sendall(b"HTTP/1.1 200 Connection Established\r\n\r\n")
|
|
239
|
+
threading.Thread(target=pipe, args=(upstream, client), daemon=True).start()
|
|
240
|
+
pipe(client, upstream)
|
|
241
|
+
except Exception as error:
|
|
242
|
+
log("ERROR %r" % (error,))
|
|
243
|
+
try:
|
|
244
|
+
client.close()
|
|
245
|
+
except OSError:
|
|
246
|
+
pass
|
|
247
|
+
|
|
248
|
+
server = socket.socket()
|
|
249
|
+
server.bind(("127.0.0.1", port))
|
|
250
|
+
server.listen(128)
|
|
251
|
+
log("LISTENING %d" % port)
|
|
252
|
+
while True:
|
|
253
|
+
connection, _ = server.accept()
|
|
254
|
+
threading.Thread(target=handle, args=(connection,), daemon=True).start()
|
|
255
|
+
'@
|
|
256
|
+
|
|
257
|
+
$pythonStandIn = @'
|
|
258
|
+
import sys
|
|
259
|
+
import onnx
|
|
260
|
+
from onnx import TensorProto, helper
|
|
261
|
+
|
|
262
|
+
# The shipped RF-DETR Medium export's signature (input [1,3,576,576], dets
|
|
263
|
+
# [1,300,4], labels [1,300,91]); every output constant, so the service's load
|
|
264
|
+
# probe completes and nothing is ever detected.
|
|
265
|
+
shape_dets = helper.make_tensor("shape_dets", TensorProto.INT64, [3], [1, 300, 4])
|
|
266
|
+
shape_labels = helper.make_tensor("shape_labels", TensorProto.INT64, [3], [1, 300, 91])
|
|
267
|
+
nodes = [
|
|
268
|
+
helper.make_node("ConstantOfShape", ["shape_dets"], ["dets"],
|
|
269
|
+
value=helper.make_tensor("zero", TensorProto.FLOAT, [1], [0.0])),
|
|
270
|
+
helper.make_node("ConstantOfShape", ["shape_labels"], ["labels"],
|
|
271
|
+
value=helper.make_tensor("low", TensorProto.FLOAT, [1], [-20.0])),
|
|
272
|
+
]
|
|
273
|
+
graph = helper.make_graph(
|
|
274
|
+
nodes, "rfdetr_medium_stand_in",
|
|
275
|
+
[helper.make_tensor_value_info("input", TensorProto.FLOAT, [1, 3, 576, 576])],
|
|
276
|
+
[helper.make_tensor_value_info("dets", TensorProto.FLOAT, [1, 300, 4]),
|
|
277
|
+
helper.make_tensor_value_info("labels", TensorProto.FLOAT, [1, 300, 91])],
|
|
278
|
+
initializer=[shape_dets, shape_labels])
|
|
279
|
+
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)])
|
|
280
|
+
model.ir_version = 8
|
|
281
|
+
onnx.checker.check_model(model)
|
|
282
|
+
for path in sys.argv[1:]:
|
|
283
|
+
onnx.save(model, path)
|
|
284
|
+
'@
|
|
285
|
+
|
|
286
|
+
$proxyProcess = $null
|
|
287
|
+
try {
|
|
288
|
+
$processor = @(Get-CimInstance Win32_Processor | Select-Object -First 1)
|
|
289
|
+
$receipt.runner = [ordered]@{ cpu = [string]$processor[0].Name; manufacturer = [string]$processor[0].Manufacturer
|
|
290
|
+
openVinoExpected = ([string]$processor[0].Manufacturer -match 'GenuineIntel') }
|
|
291
|
+
|
|
292
|
+
# --- uv, the way setup-detector.ps1 gets it --------------------------------
|
|
293
|
+
$env:PATH = "$localBin;$env:LOCALAPPDATA\uv\bin;$env:PATH"
|
|
294
|
+
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
|
|
295
|
+
# In its own process, exactly as setup-detector.ps1 runs it. Piped into
|
|
296
|
+
# Invoke-Expression here, the installer ran in THIS scope and replaced
|
|
297
|
+
# $receipt with its own install receipt (first runner without uv, 2026-11-17).
|
|
298
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'irm https://astral.sh/uv/install.ps1 | iex' | Out-Host
|
|
299
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing uv failed' }
|
|
300
|
+
$env:PATH = "$localBin;$env:LOCALAPPDATA\uv\bin;$env:PATH"
|
|
301
|
+
}
|
|
302
|
+
$uv = (Get-Command uv).Source
|
|
303
|
+
$receipt.uv = ((& $uv --version) | Out-String).Trim()
|
|
304
|
+
|
|
305
|
+
# --- two copies of the detector package: the field's and this release's ----
|
|
306
|
+
$oldSource = Join-Path $root 'detector-old'
|
|
307
|
+
$newSource = Join-Path $root 'detector-new'
|
|
308
|
+
Copy-DetectorSource $oldSource '0.2.0+src.000000000000'
|
|
309
|
+
Copy-DetectorSource $newSource $null
|
|
310
|
+
$oldVersion = Read-PackageVersion $oldSource
|
|
311
|
+
$newVersion = Read-PackageVersion $newSource
|
|
312
|
+
$receipt.oldVersion = $oldVersion; $receipt.newVersion = $newVersion
|
|
313
|
+
if ($oldVersion -eq $newVersion) { throw 'the old and new detector versions must differ' }
|
|
314
|
+
|
|
315
|
+
# --- the old detector, installed the way 0.2.245 left it --------------------
|
|
316
|
+
& $uv tool install --python 3.12 --managed-python --force --refresh-package trillboards-detector ($oldSource + '[cpu]') | Out-Host
|
|
317
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing the old detector failed' }
|
|
318
|
+
|
|
319
|
+
# --- a Python for the stand-in model and the proxy, beside the tool --------
|
|
320
|
+
$helperEnv = Join-Path $root 'helper-venv'
|
|
321
|
+
& $uv venv $helperEnv --python 3.12 --managed-python | Out-Host
|
|
322
|
+
if ($LASTEXITCODE -ne 0) { throw 'creating the helper venv failed' }
|
|
323
|
+
$py = Join-Path $helperEnv 'Scripts\python.exe'
|
|
324
|
+
& $uv pip install --python $py onnx | Out-Host
|
|
325
|
+
if ($LASTEXITCODE -ne 0) { throw 'installing onnx into the helper venv failed' }
|
|
326
|
+
|
|
327
|
+
# --- the stand-in model, where the service looks for the real one ----------
|
|
328
|
+
# trillboards_detector/modelpath.py: HOME, else USERPROFILE, then
|
|
329
|
+
# .trillboards\models\rfdetr_medium\model.onnx. The task does not inherit this
|
|
330
|
+
# job's environment, so every HOME it could see gets a copy.
|
|
331
|
+
$homes = @($env:USERPROFILE, $env:HOME, [Environment]::GetEnvironmentVariable('HOME', 'User'),
|
|
332
|
+
[Environment]::GetEnvironmentVariable('HOME', 'Machine')) | Where-Object { $_ } | Select-Object -Unique
|
|
333
|
+
$modelPaths = @(foreach ($h in $homes) {
|
|
334
|
+
$dir = Join-Path $h '.trillboards\models\rfdetr_medium'
|
|
335
|
+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
336
|
+
Join-Path $dir 'model.onnx'
|
|
337
|
+
})
|
|
338
|
+
$standInScript = Join-Path $root 'stand_in.py'
|
|
339
|
+
Write-Utf8NoBom $standInScript $pythonStandIn
|
|
340
|
+
& $py -I $standInScript @modelPaths
|
|
341
|
+
if ($LASTEXITCODE -ne 0) { throw 'building the stand-in model failed' }
|
|
342
|
+
$receipt.modelPaths = $modelPaths
|
|
343
|
+
|
|
344
|
+
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $deploy 'register-detector-task.ps1') -DetectorPath $detectorExe -Port 9380 | Out-Host
|
|
345
|
+
if ($LASTEXITCODE -ne 0) { throw 'registering the old detector task failed' }
|
|
346
|
+
$receipt.oldReadySeconds = [math]::Round((Wait-HealthCode 200 180), 1)
|
|
347
|
+
if ((Get-InstalledVersion) -ne $oldVersion) { throw "the old detector reports $(Get-InstalledVersion), expected $oldVersion" }
|
|
348
|
+
Write-Receipt
|
|
349
|
+
|
|
350
|
+
$noProxy = '127.0.0.1,localhost'
|
|
351
|
+
|
|
352
|
+
# --- (a) index unreachable --------------------------------------------------
|
|
353
|
+
$case = [ordered]@{ name = 'index unreachable: cold uv cache, dead proxy' }
|
|
354
|
+
$receipt.cases.a = $case
|
|
355
|
+
$pidBefore = Get-ListenerPid
|
|
356
|
+
$hashBefore = (Get-FileHash -LiteralPath $detectorExe -Algorithm SHA256).Hash
|
|
357
|
+
$samples = Join-Path $evidence 'health-a.csv'
|
|
358
|
+
$poller = Start-HealthPoller $samples (Join-Path $root 'stop-a')
|
|
359
|
+
Start-Sleep -Seconds 2
|
|
360
|
+
$dead = 'http://127.0.0.1:9'
|
|
361
|
+
$run = Invoke-SetupDetector $newSource @{
|
|
362
|
+
UV_CACHE_DIR = (Join-Path $root 'uv-cache-a'); HTTPS_PROXY = $dead; HTTP_PROXY = $dead; ALL_PROXY = $dead; NO_PROXY = $noProxy }
|
|
363
|
+
Start-Sleep -Seconds 2
|
|
364
|
+
Stop-HealthPoller $poller (Join-Path $root 'stop-a')
|
|
365
|
+
Set-Content -LiteralPath (Join-Path $evidence 'setup-a.log') -Value $run.log -Encoding utf8
|
|
366
|
+
$health = Read-HealthSamples $samples
|
|
367
|
+
$case.setupExit = $run.exit; $case.setupSeconds = $run.seconds
|
|
368
|
+
$case.healthSamples = $health.Count
|
|
369
|
+
$case.healthNot200 = @($health | Where-Object { $_.code -ne 200 }).Count
|
|
370
|
+
$case.servingModelsSeen = @($health | ForEach-Object { $_.loadedAt } | Select-Object -Unique).Count
|
|
371
|
+
$case.pidBefore = $pidBefore; $case.pidAfter = Get-ListenerPid
|
|
372
|
+
$case.versionAfter = Get-InstalledVersion
|
|
373
|
+
$case.exeUnchanged = ((Test-Path -LiteralPath $detectorExe) -and (Get-FileHash -LiteralPath $detectorExe -Algorithm SHA256).Hash -eq $hashBefore)
|
|
374
|
+
$case.trialRefused = $run.log.Contains('the running detector was not touched and keeps serving')
|
|
375
|
+
$case.wentOnToReplace = $run.log.Contains('installing/repairing trillboards-detector')
|
|
376
|
+
$case.openVinoRetried = $run.log.Contains('retrying the same detector with ONNX Runtime only')
|
|
377
|
+
Write-Receipt
|
|
378
|
+
if ($run.exit -ne 0) { throw "(a) setup-detector exited $($run.exit)" }
|
|
379
|
+
if (-not $case.trialRefused) { throw '(a) the trial install did not report the refusal' }
|
|
380
|
+
if ($case.wentOnToReplace) { throw '(a) setup-detector went on to replace the detector' }
|
|
381
|
+
if ($receipt.runner.openVinoExpected -and -not $case.openVinoRetried) { throw '(a) the trial did not retry without OpenVINO' }
|
|
382
|
+
if ($case.healthSamples -lt 20) { throw "(a) only $($case.healthSamples) /health samples" }
|
|
383
|
+
if ($case.healthNot200 -ne 0) { throw "(a) /health answered other than 200 $($case.healthNot200) time(s)" }
|
|
384
|
+
if ($case.servingModelsSeen -ne 1) { throw "(a) /health was answered by $($case.servingModelsSeen) different model loads" }
|
|
385
|
+
if ($case.pidAfter -ne $pidBefore) { throw "(a) the detector process changed: $pidBefore -> $($case.pidAfter)" }
|
|
386
|
+
if (-not $case.exeUnchanged) { throw '(a) the detector executable changed or disappeared' }
|
|
387
|
+
if ($case.versionAfter -ne $oldVersion) { throw "(a) the detector reports $($case.versionAfter), expected $oldVersion" }
|
|
388
|
+
$case.passed = $true
|
|
389
|
+
Write-Receipt
|
|
390
|
+
|
|
391
|
+
# --- (b) network cut right after the trial, and (c) the down time ----------
|
|
392
|
+
$case = [ordered]@{ name = 'network cut after the trial install: cold uv cache, cuttable proxy' }
|
|
393
|
+
$receipt.cases.b = $case
|
|
394
|
+
$proxyScript = Join-Path $root 'proxy.py'
|
|
395
|
+
Write-Utf8NoBom $proxyScript $pythonProxy
|
|
396
|
+
$proxyLog = Join-Path $evidence 'proxy-b.log'
|
|
397
|
+
$cut = Join-Path $root 'cut-b'
|
|
398
|
+
$proxyPort = 18765
|
|
399
|
+
$proxyProcess = Start-Process -FilePath $py -ArgumentList @('-I', $proxyScript, $proxyPort, $proxyLog, $cut) -PassThru -WindowStyle Hidden
|
|
400
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
401
|
+
while (-not ((Test-Path -LiteralPath $proxyLog) -and (Get-Content -LiteralPath $proxyLog -Raw) -match 'LISTENING')) {
|
|
402
|
+
if ($watch.Elapsed.TotalSeconds -gt 20) { throw 'the proxy did not start' }
|
|
403
|
+
Start-Sleep -Milliseconds 200
|
|
404
|
+
}
|
|
405
|
+
$samples = Join-Path $evidence 'health-b.csv'
|
|
406
|
+
$poller = Start-HealthPoller $samples (Join-Path $root 'stop-b')
|
|
407
|
+
# The cut: the instant setup-detector logs that the trial passed.
|
|
408
|
+
$cutter = Start-Job -ArgumentList $setupLog, (Get-LogLength), $cut -ScriptBlock {
|
|
409
|
+
param($log, $offset, $cutFile)
|
|
410
|
+
$deadline = (Get-Date).AddMinutes(20)
|
|
411
|
+
while ((Get-Date) -lt $deadline) {
|
|
412
|
+
if (Test-Path -LiteralPath $log) {
|
|
413
|
+
$stream = [IO.File]::Open($log, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
414
|
+
try { $null = $stream.Seek($offset, [IO.SeekOrigin]::Begin); $text = (New-Object IO.StreamReader($stream)).ReadToEnd() }
|
|
415
|
+
finally { $stream.Dispose() }
|
|
416
|
+
if ($text.Contains('trial install passed')) {
|
|
417
|
+
Set-Content -LiteralPath $cutFile -Value ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
|
|
418
|
+
return
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
Start-Sleep -Milliseconds 25
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
Start-Sleep -Seconds 2
|
|
425
|
+
$via = "http://127.0.0.1:$proxyPort"
|
|
426
|
+
$run = Invoke-SetupDetector $newSource @{
|
|
427
|
+
UV_CACHE_DIR = (Join-Path $root 'uv-cache-b'); HTTPS_PROXY = $via; HTTP_PROXY = $via; ALL_PROXY = $null; NO_PROXY = $noProxy }
|
|
428
|
+
$null = Wait-HealthCode 200 120
|
|
429
|
+
Start-Sleep -Seconds 2
|
|
430
|
+
Stop-HealthPoller $poller (Join-Path $root 'stop-b')
|
|
431
|
+
$null = Wait-Job $cutter -Timeout 5; Remove-Job $cutter -Force
|
|
432
|
+
Set-Content -LiteralPath (Join-Path $evidence 'setup-b.log') -Value $run.log -Encoding utf8
|
|
433
|
+
$case.setupExit = $run.exit; $case.setupSeconds = $run.seconds
|
|
434
|
+
if (-not (Test-Path -LiteralPath $cut)) { throw '(b) the trial install never reported passing' }
|
|
435
|
+
$cutAtMs = [long]((Get-Content -LiteralPath $cut -Raw).Trim())
|
|
436
|
+
$proxyLines = @(Get-Content -LiteralPath $proxyLog | Where-Object { $_ -match '^\d+ (CONNECT|REFUSED|REJECTED|ERROR) ' })
|
|
437
|
+
$after = @($proxyLines | Where-Object { [long]($_.Split(' ')[0]) -gt $cutAtMs })
|
|
438
|
+
$case.connectionsBeforeCut = @($proxyLines | Where-Object { [long]($_.Split(' ')[0]) -le $cutAtMs -and $_ -match ' CONNECT ' }).Count
|
|
439
|
+
$case.attemptsAfterCut = $after.Count
|
|
440
|
+
$case.attemptsAfterCutLines = @($after | Select-Object -First 20)
|
|
441
|
+
$health = Read-HealthSamples $samples
|
|
442
|
+
$oldLoad = ($health | Where-Object { $_.code -eq 200 } | Select-Object -First 1).loadedAt
|
|
443
|
+
$beforeCut = @($health | Where-Object { $_.atMs -le $cutAtMs })
|
|
444
|
+
$case.healthSamplesThroughTrial = $beforeCut.Count
|
|
445
|
+
$case.trialNotServedByOld = @($beforeCut | Where-Object { $_.code -ne 200 -or $_.loadedAt -ne $oldLoad }).Count
|
|
446
|
+
$lastOld200 = $health | Where-Object { $_.code -eq 200 -and $_.loadedAt -eq $oldLoad } | Select-Object -Last 1
|
|
447
|
+
$firstNew200 = $health | Where-Object { $_.code -eq 200 -and $_.loadedAt -ne $oldLoad } | Select-Object -First 1
|
|
448
|
+
$firstNewAnswer = if ($lastOld200) { $health | Where-Object { $_.atMs -gt $lastOld200.atMs -and $_.code -ne 0 -and $_.loadedAt -ne $oldLoad } | Select-Object -First 1 } else { $null }
|
|
449
|
+
$case.oldServedUntilMsAfterCut = if ($lastOld200) { $lastOld200.atMs - $cutAtMs } else { $null }
|
|
450
|
+
$case.versionAfter = Get-InstalledVersion
|
|
451
|
+
$case.trialSeconds = if ($run.log -match 'trial install passed in ([0-9.]+) s with \[([^\]]+)\]') { [double]$Matches[1] } else { $null }
|
|
452
|
+
$case.extras = if ($run.log -match 'trial install passed in [0-9.]+ s with \[([^\]]+)\]') { $Matches[1] } else { $null }
|
|
453
|
+
$case.answeredAfterInstall = ($run.log -match 'detector is READY|detector is running and AWAITING ITS MODEL')
|
|
454
|
+
$receipt.cases.c = [ordered]@{
|
|
455
|
+
name = 'detector down time inside (b): the old process''s last /health 200 to the new process''s first'
|
|
456
|
+
downMs = if ($firstNew200 -and $lastOld200) { $firstNew200.atMs - $lastOld200.atMs } else { $null }
|
|
457
|
+
downToFirstAnswerMs = if ($firstNewAnswer -and $lastOld200) { $firstNewAnswer.atMs - $lastOld200.atMs } else { $null }
|
|
458
|
+
firstAnswerTo200Ms = if ($firstNew200 -and $firstNewAnswer) { $firstNew200.atMs - $firstNewAnswer.atMs } else { $null }
|
|
459
|
+
model = 'stand-in ONNX with the RF-DETR Medium signature; the shipped ~128 MB artifact adds its own load to this'
|
|
460
|
+
}
|
|
461
|
+
Write-Receipt
|
|
462
|
+
if ($run.exit -ne 0) { throw "(b) setup-detector exited $($run.exit)" }
|
|
463
|
+
if ($case.connectionsBeforeCut -lt 1) { throw '(b) the trial install never used the network, so the cut proves nothing' }
|
|
464
|
+
if ($case.attemptsAfterCut -ne 0) { throw "(b) $($case.attemptsAfterCut) connection attempt(s) after the cut" }
|
|
465
|
+
if ($case.healthSamplesThroughTrial -lt 20) { throw "(b) only $($case.healthSamplesThroughTrial) /health samples through the trial" }
|
|
466
|
+
if ($case.trialNotServedByOld -ne 0) { throw "(b) the old detector did not answer 200 through the trial ($($case.trialNotServedByOld) sample(s))" }
|
|
467
|
+
if (-not $lastOld200) { throw '(b) the old detector never answered' }
|
|
468
|
+
if ($case.versionAfter -ne $newVersion) { throw "(b) the detector reports $($case.versionAfter), expected $newVersion" }
|
|
469
|
+
if (-not $case.answeredAfterInstall) { throw '(b) setup-detector did not see the new detector answer' }
|
|
470
|
+
if ($null -eq $receipt.cases.c.downMs) { throw '(c) the new detector never answered 200' }
|
|
471
|
+
$case.passed = $true
|
|
472
|
+
$receipt.cases.c.passed = $true
|
|
473
|
+
Write-Receipt
|
|
474
|
+
|
|
475
|
+
# --- (d)-(i) the launcher's detector check ---------------------------------
|
|
476
|
+
$ensure = Join-Path $deploy 'ensure-detector.ps1'
|
|
477
|
+
$parseErrors = $null
|
|
478
|
+
[Management.Automation.Language.Parser]::ParseFile($ensure, [ref]$null, [ref]$parseErrors) | Out-Null
|
|
479
|
+
if ($parseErrors) { throw ('ensure-detector.ps1 does not parse: ' + (@($parseErrors | ForEach-Object { $_.Message }) -join '; ')) }
|
|
480
|
+
$setupMarker = Join-Path $root 'setup-stub-ran.txt'
|
|
481
|
+
$setupStub = Join-Path $root 'setup-stub.ps1'
|
|
482
|
+
Write-Utf8NoBom $setupStub ("Add-Content -LiteralPath '" + $setupMarker.Replace("'", "''") + "' -Value ([DateTimeOffset]::UtcNow.ToString('o'))`r`nexit 0`r`n")
|
|
483
|
+
$decisionFile = Join-Path $root 'detector-launcher.json'
|
|
484
|
+
$slowServer = Join-Path $root 'slow_health.py'
|
|
485
|
+
Write-Utf8NoBom $slowServer @'
|
|
486
|
+
import sys, time
|
|
487
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
488
|
+
port, delay, status = int(sys.argv[1]), float(sys.argv[2]), int(sys.argv[3])
|
|
489
|
+
class Handler(BaseHTTPRequestHandler):
|
|
490
|
+
def do_GET(self):
|
|
491
|
+
time.sleep(delay)
|
|
492
|
+
body = b'{"state":"loading"}'
|
|
493
|
+
self.send_response(status)
|
|
494
|
+
self.send_header("Content-Type", "application/json")
|
|
495
|
+
self.send_header("Content-Length", str(len(body)))
|
|
496
|
+
self.end_headers()
|
|
497
|
+
self.wfile.write(body)
|
|
498
|
+
def log_message(self, *args):
|
|
499
|
+
pass
|
|
500
|
+
ThreadingHTTPServer(("127.0.0.1", port), Handler).serve_forever()
|
|
501
|
+
'@
|
|
502
|
+
|
|
503
|
+
# One launcher check, exactly as the launcher runs it (Windows PowerShell 5.1),
|
|
504
|
+
# bounded; returns its decision record and whether the stub provisioner ran.
|
|
505
|
+
function Invoke-EnsureDetector([string[]]$Arguments, [int]$TimeoutSeconds) {
|
|
506
|
+
Remove-Item -LiteralPath $decisionFile, $setupMarker -Force -ErrorAction SilentlyContinue
|
|
507
|
+
$argumentLine = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', ('"' + $ensure + '"'),
|
|
508
|
+
'-DecisionPath', ('"' + $decisionFile + '"')) + $Arguments
|
|
509
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
510
|
+
$process = Start-Process -FilePath 'powershell.exe' -ArgumentList ($argumentLine -join ' ') -PassThru -WindowStyle Hidden
|
|
511
|
+
if (-not $process.WaitForExit($TimeoutSeconds * 1000)) {
|
|
512
|
+
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
|
|
513
|
+
throw ('the launcher check did not finish in ' + $TimeoutSeconds + ' s')
|
|
514
|
+
}
|
|
515
|
+
$decision = if (Test-Path -LiteralPath $decisionFile) { Get-Content -LiteralPath $decisionFile -Raw | ConvertFrom-Json } else { $null }
|
|
516
|
+
return [pscustomobject]@{ seconds = [math]::Round($watch.Elapsed.TotalSeconds, 1); exit = $process.ExitCode
|
|
517
|
+
decision = $decision; setupRan = (Test-Path -LiteralPath $setupMarker) }
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function Start-SlowHealth([int]$ListenPort, [double]$DelaySeconds, [int]$Status) {
|
|
521
|
+
$server = Start-Process -FilePath $py -ArgumentList @('-I', ('"' + $slowServer + '"'), $ListenPort, $DelaySeconds, $Status) -PassThru -WindowStyle Hidden
|
|
522
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
523
|
+
while (-not @(Get-NetTCPConnection -LocalPort $ListenPort -State Listen -ErrorAction SilentlyContinue).Count) {
|
|
524
|
+
if ($watch.Elapsed.TotalSeconds -gt 20) { throw ('the stand-in /health on ' + $ListenPort + ' did not start') }
|
|
525
|
+
Start-Sleep -Milliseconds 200
|
|
526
|
+
}
|
|
527
|
+
return $server
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function Stop-RealDetector {
|
|
531
|
+
$null = & (Join-Path $deploy 'stop-local-ai.ps1') -Service Detector -ToolPath $detectorExe -Port 9380
|
|
532
|
+
Enable-ScheduledTask -TaskName 'TrillboardsDetector' -TaskPath '\' | Out-Null
|
|
533
|
+
if (Get-ListenerPid) { throw 'the detector still listens after its stop' }
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function Assert-Launcher([string]$Name, $Run, [string]$Decision, [bool]$SetupRan) {
|
|
537
|
+
$got = if ($Run.decision) { [string]$Run.decision.decision } else { '(no decision file)' }
|
|
538
|
+
if ($Run.exit -ne 0) { throw ('(' + $Name + ') the launcher check exited ' + $Run.exit) }
|
|
539
|
+
if ($got -ne $Decision) { throw ('(' + $Name + ') decision ' + $got + ', expected ' + $Decision) }
|
|
540
|
+
if ($Run.setupRan -ne $SetupRan) { throw ('(' + $Name + ') the provisioner ' + $(if ($Run.setupRan) { 'ran' } else { 'did not run' })) }
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
# (d) busy: 503 after 4 s, on a stand-in port (the real detector is not involved).
|
|
544
|
+
$case = [ordered]@{ name = 'busy detector: /health answers 503 after 4 s' }
|
|
545
|
+
$receipt.cases.d = $case
|
|
546
|
+
$pidBefore = Get-ListenerPid
|
|
547
|
+
$slow = Start-SlowHealth 19381 4 503
|
|
548
|
+
try { $run = Invoke-EnsureDetector @('-HealthUrl', 'http://127.0.0.1:19381/health', '-SetupScript', ('"' + $setupStub + '"')) 120 }
|
|
549
|
+
finally { Stop-Process -Id $slow.Id -Force -ErrorAction SilentlyContinue }
|
|
550
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
551
|
+
$case.detectorPidUnchanged = ((Get-ListenerPid) -eq $pidBefore)
|
|
552
|
+
Write-Receipt
|
|
553
|
+
Assert-Launcher 'd' $run 'answered' $false
|
|
554
|
+
if ([int]$run.decision.probes[0].code -ne 503 -or [int]$run.decision.probes[0].ms -lt 3500) { throw '(d) the answer was not the slow 503' }
|
|
555
|
+
if (-not $case.detectorPidUnchanged) { throw '(d) the detector process changed' }
|
|
556
|
+
$case.passed = $true
|
|
557
|
+
|
|
558
|
+
# (i) a listener that never answers: three timeouts, left alone.
|
|
559
|
+
$case = [ordered]@{ name = 'listener that never answers: three 2 s timeouts' }
|
|
560
|
+
$receipt.cases.i = $case
|
|
561
|
+
$slow = Start-SlowHealth 19382 600 200
|
|
562
|
+
try { $run = Invoke-EnsureDetector @('-HealthUrl', 'http://127.0.0.1:19382/health', '-ProbeTimeoutSec', '2', '-SetupScript', ('"' + $setupStub + '"')) 120 }
|
|
563
|
+
finally { Stop-Process -Id $slow.Id -Force -ErrorAction SilentlyContinue }
|
|
564
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
565
|
+
Write-Receipt
|
|
566
|
+
Assert-Launcher 'i' $run 'no_answer_left_alone' $false
|
|
567
|
+
if (@($run.decision.probes | Where-Object { $_.error -eq 'timeout' }).Count -ne 3) { throw '(i) expected three timed-out probes' }
|
|
568
|
+
$case.passed = $true
|
|
569
|
+
|
|
570
|
+
# (h) the provisioner is running: its per-user mutex, held here.
|
|
571
|
+
$case = [ordered]@{ name = 'provisioner running: its mutex held' }
|
|
572
|
+
$receipt.cases.h = $case
|
|
573
|
+
$sid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
|
574
|
+
$setupMutex = New-Object System.Threading.Mutex($false, ('Global\TrillboardsDetectorSetup-' + $sid))
|
|
575
|
+
if (-not $setupMutex.WaitOne(0)) { throw '(h) could not take the provisioner mutex' }
|
|
576
|
+
try { $run = Invoke-EnsureDetector @('-SetupScript', ('"' + $setupStub + '"')) 120 }
|
|
577
|
+
finally { $setupMutex.ReleaseMutex(); $setupMutex.Dispose() }
|
|
578
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
579
|
+
Write-Receipt
|
|
580
|
+
Assert-Launcher 'h' $run 'provisioning_in_progress' $false
|
|
581
|
+
$case.passed = $true
|
|
582
|
+
|
|
583
|
+
# (e) the task registered and enabled, its process stopped: the check starts it.
|
|
584
|
+
$case = [ordered]@{ name = 'task registered, process stopped' }
|
|
585
|
+
$receipt.cases.e = $case
|
|
586
|
+
$pidBefore = Get-ListenerPid
|
|
587
|
+
Stop-RealDetector
|
|
588
|
+
$run = Invoke-EnsureDetector @('-SetupScript', ('"' + $setupStub + '"')) 240
|
|
589
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
590
|
+
$case.pidBefore = $pidBefore; $case.pidAfter = Get-ListenerPid
|
|
591
|
+
Write-Receipt
|
|
592
|
+
Assert-Launcher 'e' $run 'started_task' $false
|
|
593
|
+
if ($null -eq $run.decision.answeredAfterStartMs -or [int]$run.decision.answeredAfterStartMs -gt 60000) { throw '(e) the detector did not answer within 60 s of the task start' }
|
|
594
|
+
if (-not $case.pidAfter -or $case.pidAfter -eq $pidBefore) { throw '(e) no new detector process listens' }
|
|
595
|
+
$null = Wait-HealthCode 200 180
|
|
596
|
+
$case.passed = $true
|
|
597
|
+
|
|
598
|
+
# (f) the task registered but unable to start: re-provisioned after the wait.
|
|
599
|
+
$case = [ordered]@{ name = 'task registered, executable renamed: the start fails' }
|
|
600
|
+
$receipt.cases.f = $case
|
|
601
|
+
Stop-RealDetector
|
|
602
|
+
$parked = $detectorExe + '.parked'
|
|
603
|
+
Move-Item -LiteralPath $detectorExe -Destination $parked -Force
|
|
604
|
+
try { $run = Invoke-EnsureDetector @('-StartWaitSec', '15', '-SetupScript', ('"' + $setupStub + '"')) 240 }
|
|
605
|
+
finally {
|
|
606
|
+
Move-Item -LiteralPath $parked -Destination $detectorExe -Force
|
|
607
|
+
Start-ScheduledTask -TaskName 'TrillboardsDetector' -TaskPath '\'
|
|
608
|
+
}
|
|
609
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
610
|
+
Write-Receipt
|
|
611
|
+
Assert-Launcher 'f' $run 'reprovision_still_refused' $true
|
|
612
|
+
if ([string]$run.decision.setupExit -ne '0') { throw ('(f) the provisioner exit was ' + $run.decision.setupExit) }
|
|
613
|
+
$null = Wait-HealthCode 200 180
|
|
614
|
+
$case.passed = $true
|
|
615
|
+
|
|
616
|
+
# (g) the task unregistered: re-provisioned at once, whatever /health says.
|
|
617
|
+
$case = [ordered]@{ name = 'task unregistered' }
|
|
618
|
+
$receipt.cases.g = $case
|
|
619
|
+
$taskXml = Export-ScheduledTask -TaskName 'TrillboardsDetector' -TaskPath '\'
|
|
620
|
+
Unregister-ScheduledTask -TaskName 'TrillboardsDetector' -TaskPath '\' -Confirm:$false
|
|
621
|
+
try { $run = Invoke-EnsureDetector @('-SetupScript', ('"' + $setupStub + '"')) 120 }
|
|
622
|
+
finally { Register-ScheduledTask -TaskName 'TrillboardsDetector' -TaskPath '\' -Xml $taskXml | Out-Null }
|
|
623
|
+
$case.decision = $run.decision; $case.seconds = $run.seconds; $case.setupRan = $run.setupRan
|
|
624
|
+
Write-Receipt
|
|
625
|
+
Assert-Launcher 'g' $run 'reprovision_task_missing' $true
|
|
626
|
+
$case.passed = $true
|
|
627
|
+
|
|
628
|
+
$receipt.passed = $true
|
|
629
|
+
Write-Receipt
|
|
630
|
+
Write-Host ('PASS: (a) refused with the old detector serving; (b) {0} connection(s) before the cut, 0 after, [{1}] trial {2} s; (c) down {3} ms; (d)-(i) launcher check {4}' -f
|
|
631
|
+
$receipt.cases.b.connectionsBeforeCut, $receipt.cases.b.extras, $receipt.cases.b.trialSeconds, $receipt.cases.c.downMs,
|
|
632
|
+
((@('d', 'e', 'f', 'g', 'h', 'i') | ForEach-Object { $_ + '=' + [string]$receipt.cases[$_].decision.decision }) -join ' '))
|
|
633
|
+
} catch {
|
|
634
|
+
# Keep the first error: a failure to record it must not replace it.
|
|
635
|
+
$proofFailure = $_
|
|
636
|
+
try { $receipt['failure'] = $proofFailure.Exception.Message; Write-Receipt }
|
|
637
|
+
catch { Write-Host "could not record the failure in the receipt: $($_.Exception.Message)" }
|
|
638
|
+
throw $proofFailure
|
|
639
|
+
} finally {
|
|
640
|
+
if ($proxyProcess -and -not $proxyProcess.HasExited) { Stop-Process -Id $proxyProcess.Id -Force -ErrorAction SilentlyContinue }
|
|
641
|
+
if (Test-Path -LiteralPath $setupLog) { Copy-Item -LiteralPath $setupLog -Destination (Join-Path $evidence 'detector-setup.log') -ErrorAction SilentlyContinue }
|
|
642
|
+
$serviceLog = Join-Path $env:LOCALAPPDATA 'Trillboards\logs\detector.service.log'
|
|
643
|
+
if (Test-Path -LiteralPath $serviceLog) { Copy-Item -LiteralPath $serviceLog -Destination (Join-Path $evidence 'detector.service.log') -ErrorAction SilentlyContinue }
|
|
644
|
+
Write-Receipt
|
|
645
|
+
}
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
subject is the production publisher's CN and which only this runner trusts;
|
|
50
50
|
C's cli.js exits 3 whenever it is started to sense. Every .ps1/.vbs/.exe in
|
|
51
51
|
bin\ keeps the release's real signatures. setup-litertlm.ps1 and
|
|
52
|
-
setup-detector.ps1
|
|
52
|
+
setup-detector.ps1 (and the launcher's detector check, ensure-detector.ps1)
|
|
53
|
+
are left out of every tree so the launcher's local-AI
|
|
53
54
|
repair never starts a download on the runner; the model service is a stub
|
|
54
55
|
that lists the pinned Gemma id.
|
|
55
56
|
|
|
@@ -306,7 +307,7 @@ try {
|
|
|
306
307
|
foreach ($rel in @('bin\node.exe', 'bin\apply-update.ps1', 'bin\install-update.ps1', 'lib\edge-sdk\dist\cli.js', 'lib\edge-sdk\package.json')) {
|
|
307
308
|
if (-not (Test-Path -LiteralPath (Join-Path $treeA $rel))) { throw "The release payload is missing $rel" }
|
|
308
309
|
}
|
|
309
|
-
foreach ($rel in @('bin\setup-litertlm.ps1', 'bin\setup-detector.ps1')) { Remove-Item -LiteralPath (Join-Path $treeA $rel) -Force -ErrorAction SilentlyContinue }
|
|
310
|
+
foreach ($rel in @('bin\setup-litertlm.ps1', 'bin\setup-detector.ps1', 'bin\ensure-detector.ps1')) { Remove-Item -LiteralPath (Join-Path $treeA $rel) -Force -ErrorAction SilentlyContinue }
|
|
310
311
|
$versionA = [string](Get-Content -LiteralPath (Join-Path $treeA 'lib\edge-sdk\package.json') -Raw | ConvertFrom-Json).version
|
|
311
312
|
if ($versionA -notmatch '^(\d+)\.(\d+)\.(\d+)$') { throw "Unreadable release version '$versionA'" }
|
|
312
313
|
$versionB = "$($Matches[1]).$($Matches[2]).$([int]$Matches[3] + 1000)"
|