@trillboards/edge-sdk 0.2.188 → 0.2.190
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/windows/apply-update.ps1 +100 -1
- package/deploy/windows/ci/test-field-self-update.ps1 +371 -0
- package/deploy/windows/ci/test-update-job-boundary.ps1 +207 -0
- package/dist/AudienceAnalyzeClient.d.ts +4 -0
- package/dist/AudienceAnalyzeClient.d.ts.map +1 -1
- package/dist/AudienceAnalyzeClient.js.map +1 -1
- package/dist/CloudSensingManager.d.ts +22 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +31 -0
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/DurableVlmCandidateSpool.d.ts +12 -0
- package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
- package/dist/DurableVlmCandidateSpool.js +63 -7
- package/dist/DurableVlmCandidateSpool.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/LiteRtVlmProvider.d.ts +13 -0
- package/dist/LiteRtVlmProvider.d.ts.map +1 -1
- package/dist/LiteRtVlmProvider.js +26 -1
- package/dist/LiteRtVlmProvider.js.map +1 -1
- package/dist/VlmCandidateBuffer.d.ts +10 -0
- package/dist/VlmCandidateBuffer.d.ts.map +1 -1
- package/dist/VlmCandidateBuffer.js.map +1 -1
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +4 -2
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/connectorUpdateApply.d.ts +37 -10
- package/dist/connectorUpdateApply.d.ts.map +1 -1
- package/dist/connectorUpdateApply.js +63 -17
- package/dist/connectorUpdateApply.js.map +1 -1
- package/dist/continuousReview.d.ts +22 -0
- package/dist/continuousReview.d.ts.map +1 -1
- package/dist/continuousReview.js +26 -1
- package/dist/continuousReview.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +10 -2
- package/dist/localSensing.js.map +1 -1
- package/package.json +3 -3
- package/retained/ArchiveLifecycle.cjs +9 -2
- package/retained/RetainedCaptureClient.cjs +140 -13
- package/retained/__tests__/realtime-schedule.test.cjs +337 -0
- package/retained/__tests__/runtime.test.cjs +8 -2
- package/retained/manager.cjs +8 -0
- package/retained/website-api-capability.cjs +7 -1
|
@@ -113,8 +113,15 @@ param(
|
|
|
113
113
|
[string]$ExpectedSigner = 'Aethercorp Inc',
|
|
114
114
|
# Escape hatch for the CI control that must FAIL: with this set, a degraded
|
|
115
115
|
# task shape is measured and reported but not repaired. Never set in the field.
|
|
116
|
-
[switch]$SkipTaskShapeRestore
|
|
116
|
+
[switch]$SkipTaskShapeRestore,
|
|
117
|
+
# Start this same phase again OUTSIDE the caller's job object and return the
|
|
118
|
+
# new process id. The connector always asks for it - see Invoke-Detached.
|
|
119
|
+
[switch]$Detach,
|
|
120
|
+
# The connector process handing over the machine. -Commit lets it finish its
|
|
121
|
+
# own shutdown (bounded) before the swap stops whatever is left.
|
|
122
|
+
[int]$ConnectorPid = 0
|
|
117
123
|
)
|
|
124
|
+
$ScriptParameters = $PSBoundParameters
|
|
118
125
|
|
|
119
126
|
$ErrorActionPreference = 'Stop'
|
|
120
127
|
# Invoke-WebRequest renders a progress bar per chunk in Windows PowerShell 5.1,
|
|
@@ -133,6 +140,81 @@ $AttemptedAt = (Get-Date).ToUniversalTime().ToString('o')
|
|
|
133
140
|
|
|
134
141
|
function Log([string]$Message) { Write-Host "[apply-update] $Message" }
|
|
135
142
|
|
|
143
|
+
<#
|
|
144
|
+
The applier's own record, beside outcome.json. Its output used to go to a
|
|
145
|
+
stdio the connector ignores, so a transaction that died left no trace at all.
|
|
146
|
+
#>
|
|
147
|
+
function Start-ApplierLog {
|
|
148
|
+
try {
|
|
149
|
+
New-Item -ItemType Directory -Force -Path $UpdateDir | Out-Null
|
|
150
|
+
$logPath = Join-Path $UpdateDir 'apply-update.log'
|
|
151
|
+
if ((Test-Path -LiteralPath $logPath) -and (Get-Item -LiteralPath $logPath).Length -gt 1MB) {
|
|
152
|
+
Move-Item -LiteralPath $logPath -Destination "$logPath.1" -Force
|
|
153
|
+
}
|
|
154
|
+
Start-Transcript -LiteralPath $logPath -Append | Out-Null
|
|
155
|
+
Log ("applier pid {0} as {1}; profile {2}" -f $PID, [Environment]::UserName, $env:USERPROFILE)
|
|
156
|
+
} catch { }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
<#
|
|
160
|
+
-Detach: run this same phase OUTSIDE the caller's job object.
|
|
161
|
+
|
|
162
|
+
The connector is a Task Scheduler instance, and Task Scheduler holds every
|
|
163
|
+
process of that instance in one job object - an applier the connector starts
|
|
164
|
+
included, because Node's `detached` (libuv) never asks for
|
|
165
|
+
CREATE_BREAKAWAY_FROM_JOB. The swap ends that instance (stop-existing.ps1
|
|
166
|
+
calls Stop-ScheduledTask), and ending it terminates the whole job, so an
|
|
167
|
+
applier started directly by the connector is killed inside its own
|
|
168
|
+
transaction: no swap, no outcome.json, nothing reported.
|
|
169
|
+
|
|
170
|
+
A process created through WMI's Win32_Process.Create is not a member of the
|
|
171
|
+
caller's job, so it outlives the task it is replacing. It does not inherit the
|
|
172
|
+
caller's environment, and the scripts below resolve per-user paths through
|
|
173
|
+
$env:USERPROFILE / APPDATA, so the caller's block travels with it.
|
|
174
|
+
#>
|
|
175
|
+
function Quote-Argument([string]$Value) {
|
|
176
|
+
if ($Value.Length -gt 0 -and $Value -notmatch '[\s"]') { return $Value }
|
|
177
|
+
$out = '"'
|
|
178
|
+
$slashes = 0
|
|
179
|
+
foreach ($ch in $Value.ToCharArray()) {
|
|
180
|
+
if ($ch -eq [char]'\') { $slashes++; continue }
|
|
181
|
+
if ($ch -eq [char]'"') { $out += ('\' * ($slashes * 2 + 1)) + '"'; $slashes = 0; continue }
|
|
182
|
+
$out += ('\' * $slashes) + $ch
|
|
183
|
+
$slashes = 0
|
|
184
|
+
}
|
|
185
|
+
return $out + ('\' * ($slashes * 2)) + '"'
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function Invoke-Detached {
|
|
189
|
+
$parts = @((Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'),
|
|
190
|
+
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', $PSCommandPath)
|
|
191
|
+
foreach ($entry in $script:ScriptParameters.GetEnumerator()) {
|
|
192
|
+
if ($entry.Key -eq 'Detach') { continue }
|
|
193
|
+
if ($entry.Value -is [System.Management.Automation.SwitchParameter]) {
|
|
194
|
+
if ($entry.Value.IsPresent) { $parts += ('-' + $entry.Key) }
|
|
195
|
+
} else {
|
|
196
|
+
$parts += ('-' + $entry.Key)
|
|
197
|
+
$parts += [string]$entry.Value
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
$commandLine = ($parts | ForEach-Object { Quote-Argument ([string]$_) }) -join ' '
|
|
201
|
+
$environment = [string[]]@(Get-ChildItem env: | ForEach-Object { $_.Name + '=' + $_.Value })
|
|
202
|
+
try {
|
|
203
|
+
$startupClass = Get-CimClass -ClassName Win32_ProcessStartup
|
|
204
|
+
$startup = New-CimInstance -CimClass $startupClass -ClientOnly -Property @{ EnvironmentVariables = $environment; ShowWindow = [uint16]0 }
|
|
205
|
+
$created = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
|
|
206
|
+
CommandLine = $commandLine; CurrentDirectory = $InstallDir; ProcessStartupInformation = $startup }
|
|
207
|
+
} catch {
|
|
208
|
+
Write-Output ('detach-failed=' + $_.Exception.Message)
|
|
209
|
+
exit 4
|
|
210
|
+
}
|
|
211
|
+
if ($created.ReturnValue -ne 0) {
|
|
212
|
+
Write-Output ('detach-failed=Win32_Process.Create returned ' + $created.ReturnValue)
|
|
213
|
+
exit 4
|
|
214
|
+
}
|
|
215
|
+
Write-Output ('detached-pid=' + $created.ProcessId)
|
|
216
|
+
}
|
|
217
|
+
|
|
136
218
|
<#
|
|
137
219
|
Write the terminal state, atomically, then leave. The connector reads this on
|
|
138
220
|
its next start; a torn file would be read as a malformed outcome and dropped,
|
|
@@ -491,6 +573,21 @@ function Invoke-Commit {
|
|
|
491
573
|
# task on every one of its exit paths.
|
|
492
574
|
Disable-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue | Out-Null
|
|
493
575
|
|
|
576
|
+
# Let the connector finish the shutdown it began when it handed over, so the
|
|
577
|
+
# swap stops a process that has already flushed its state rather than one
|
|
578
|
+
# mid-flush. Bounded: whatever is still running after this is stopped anyway.
|
|
579
|
+
if ($ConnectorPid -gt 0) {
|
|
580
|
+
$deadline = [DateTime]::UtcNow.AddSeconds(90)
|
|
581
|
+
while ([DateTime]::UtcNow -lt $deadline -and (Get-Process -Id $ConnectorPid -ErrorAction SilentlyContinue)) {
|
|
582
|
+
Start-Sleep -Milliseconds 500
|
|
583
|
+
}
|
|
584
|
+
if (Get-Process -Id $ConnectorPid -ErrorAction SilentlyContinue) {
|
|
585
|
+
Log "connector $ConnectorPid is still running after 90 s - the swap stops it"
|
|
586
|
+
} else {
|
|
587
|
+
Log "connector $ConnectorPid has exited"
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
494
591
|
$installUpdate = Join-Path $PayloadDir 'bin\install-update.ps1'
|
|
495
592
|
try {
|
|
496
593
|
# install-update.ps1 owns the whole swap transaction, including disabling the
|
|
@@ -535,6 +632,8 @@ function Invoke-Commit {
|
|
|
535
632
|
|
|
536
633
|
# ---------------------------------------------------------------------------
|
|
537
634
|
if ($Stage -and $Commit) { Fail 'rejected' 'pass exactly one of -Stage or -Commit' }
|
|
635
|
+
if ($Detach) { Invoke-Detached; exit 0 }
|
|
636
|
+
Start-ApplierLog
|
|
538
637
|
if ($Stage) { Invoke-Stage; exit 0 }
|
|
539
638
|
if ($Commit) { Invoke-Commit; exit 0 }
|
|
540
639
|
Fail 'rejected' 'pass -Stage or -Commit'
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
<#
|
|
2
|
+
test-field-self-update.ps1 - does a connector that is ALREADY IN THE FIELD
|
|
3
|
+
update itself?
|
|
4
|
+
|
|
5
|
+
Installs a published connector from its immutable address, gives it a real
|
|
6
|
+
RTSP camera and a stub API, starts it under its own scheduled task exactly as
|
|
7
|
+
pairing does, and then waits for it to take the live root release with no
|
|
8
|
+
help. PASS only when the installed tree, the task and the connector's own
|
|
9
|
+
status report all name the root version.
|
|
10
|
+
|
|
11
|
+
-InstallerUrl auto (the default) picks the newest published build that
|
|
12
|
+
carries the job-safe updater (>= $JobSafeUpdaterSince) and is older than the
|
|
13
|
+
root. Builds before it start their applier inside the task the swap stops, so
|
|
14
|
+
they cannot pass this test; pass one explicitly to watch that happen.
|
|
15
|
+
|
|
16
|
+
Why this exists. The release gate proves apply-update.ps1 in isolation
|
|
17
|
+
(verify-update-applier.ps1, arms A-K), but no CI step had ever let an
|
|
18
|
+
installed connector drive its own update: the update service deciding to
|
|
19
|
+
stage, the applier running as the connector's child under Task Scheduler,
|
|
20
|
+
the safe point, the exit, the swap and the relaunch. Every Windows and macOS
|
|
21
|
+
connector reporting on 2026-11-03 was behind with no recorded attempt.
|
|
22
|
+
|
|
23
|
+
Execute only on a fresh GitHub-hosted Windows runner. Do not run on a
|
|
24
|
+
customer PC.
|
|
25
|
+
#>
|
|
26
|
+
[CmdletBinding()]
|
|
27
|
+
param(
|
|
28
|
+
[string]$InstallerUrl = 'auto',
|
|
29
|
+
[Parameter(Mandatory = $true)][string]$PersonFrame,
|
|
30
|
+
[ValidateRange(5, 240)][int]$UpdateDeadlineMinutes = 75
|
|
31
|
+
)
|
|
32
|
+
$ErrorActionPreference = 'Stop'
|
|
33
|
+
Set-StrictMode -Version Latest
|
|
34
|
+
if ($env:GITHUB_ACTIONS -ne 'true' -or $env:RUNNER_OS -ne 'Windows' -or
|
|
35
|
+
$env:RUNNER_ENVIRONMENT -ne 'github-hosted' -or $PSVersionTable.PSVersion.Major -lt 7) {
|
|
36
|
+
throw 'Field self-update qualification requires a fresh GitHub-hosted Windows runner and PowerShell 7'
|
|
37
|
+
}
|
|
38
|
+
if (-not (Test-Path -LiteralPath $PersonFrame -PathType Leaf)) { throw 'Missing committed person-image fixture' }
|
|
39
|
+
# The first release whose applier leaves the connector task before the swap
|
|
40
|
+
# stops it (apply-update.ps1 -Detach).
|
|
41
|
+
$JobSafeUpdaterSince = [version]'0.2.190'
|
|
42
|
+
|
|
43
|
+
$installDir = Join-Path $env:LOCALAPPDATA 'Trillboards\edge'
|
|
44
|
+
if (Test-Path -LiteralPath $installDir) { throw 'The CI profile already holds a connector install' }
|
|
45
|
+
foreach ($name in @('TrillboardsEdge', 'TrillboardsLiteRtLm', 'TrillboardsDetector')) {
|
|
46
|
+
if (Get-ScheduledTask -TaskName $name -TaskPath '\' -ErrorAction SilentlyContinue) { throw ('Scheduled task already present: ' + $name) }
|
|
47
|
+
}
|
|
48
|
+
$root = [IO.Path]::GetFullPath((Join-Path $env:RUNNER_TEMP ('tb-field-update-' + [Guid]::NewGuid().ToString('N'))))
|
|
49
|
+
New-Item -ItemType Directory -Path $root | Out-Null
|
|
50
|
+
$timeline = Join-Path $root 'timeline.log'
|
|
51
|
+
$receipt = [ordered]@{ atUtc = [DateTimeOffset]::UtcNow.ToString('o'); installerUrl = $InstallerUrl; fromVersion = $null;
|
|
52
|
+
githubRunId = $env:GITHUB_RUN_ID; passed = $false; phase = 'start' }
|
|
53
|
+
|
|
54
|
+
function Note([string]$Message) {
|
|
55
|
+
$line = [DateTimeOffset]::UtcNow.ToString('HH:mm:ss') + ' ' + $Message
|
|
56
|
+
Write-Host $line
|
|
57
|
+
Add-Content -LiteralPath $timeline -Value $line -Encoding utf8
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Children run with the native PS5.1 module path, like Explorer would start
|
|
61
|
+
# them; PowerShell 7's PSModulePath breaks the shipped 5.1 scripts.
|
|
62
|
+
function Invoke-Owned {
|
|
63
|
+
param([string]$File, [string]$RawArguments, [string]$LogName, [int]$TimeoutSeconds)
|
|
64
|
+
$start = [Diagnostics.ProcessStartInfo]::new($File)
|
|
65
|
+
$start.UseShellExecute = $false; $start.CreateNoWindow = $true
|
|
66
|
+
$start.RedirectStandardOutput = $true; $start.RedirectStandardError = $true
|
|
67
|
+
$null = $start.Environment.Remove('PSModulePath')
|
|
68
|
+
$start.Arguments = $RawArguments
|
|
69
|
+
$process = [Diagnostics.Process]::new(); $process.StartInfo = $start
|
|
70
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
71
|
+
try {
|
|
72
|
+
if (-not $process.Start()) { throw ('Could not start ' + $LogName) }
|
|
73
|
+
$stdout = $process.StandardOutput.ReadToEndAsync(); $stderr = $process.StandardError.ReadToEndAsync()
|
|
74
|
+
while (-not $process.WaitForExit(20000)) {
|
|
75
|
+
if ($watch.Elapsed.TotalSeconds -ge $TimeoutSeconds) { $process.Kill($true); throw ('Deadline exceeded: ' + $LogName) }
|
|
76
|
+
}
|
|
77
|
+
$output = $stdout.GetAwaiter().GetResult() + "`n" + $stderr.GetAwaiter().GetResult()
|
|
78
|
+
[IO.File]::WriteAllText((Join-Path $root $LogName), $output, [Text.UTF8Encoding]::new($false))
|
|
79
|
+
if ($process.ExitCode -ne 0) { throw ($LogName + ' failed with exit ' + $process.ExitCode) }
|
|
80
|
+
return $output
|
|
81
|
+
} finally { $process.Dispose() }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Add-Type -TypeDefinition @'
|
|
85
|
+
using System; using System.Runtime.InteropServices;
|
|
86
|
+
public static class TbJobProbe {
|
|
87
|
+
[DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr OpenProcess(uint access, bool inherit, int pid);
|
|
88
|
+
[DllImport("kernel32.dll", SetLastError = true)] static extern bool IsProcessInJob(IntPtr process, IntPtr job, out bool result);
|
|
89
|
+
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr handle);
|
|
90
|
+
public static string InJob(int pid) {
|
|
91
|
+
IntPtr h = OpenProcess(0x1000, false, pid);
|
|
92
|
+
if (h == IntPtr.Zero) return "unknown";
|
|
93
|
+
try { bool r; return IsProcessInJob(h, IntPtr.Zero, out r) ? (r ? "yes" : "no") : "unknown"; }
|
|
94
|
+
finally { CloseHandle(h); }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
'@
|
|
98
|
+
|
|
99
|
+
function Get-InstalledVersion {
|
|
100
|
+
$pkg = Join-Path $installDir 'lib\edge-sdk\package.json'
|
|
101
|
+
if (-not (Test-Path -LiteralPath $pkg)) { return $null }
|
|
102
|
+
try { return [string](Get-Content -LiteralPath $pkg -Raw | ConvertFrom-Json).version } catch { return $null }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function Get-UpdateProcesses {
|
|
106
|
+
@(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
|
|
107
|
+
$c = [string]$_.CommandLine
|
|
108
|
+
$c -match 'apply-update\.ps1|install-update\.ps1|stop-existing\.ps1|run-connector\.ps1|trillboards-edge-task\.vbs|trillboards-edge\.cmd|edge-sdk\\dist\\cli\.js'
|
|
109
|
+
} | ForEach-Object {
|
|
110
|
+
$c = [string]$_.CommandLine
|
|
111
|
+
$what = if ($c -match 'apply-update\.ps1') { 'apply-update' + $(if ($c -match '-Detach') { ':detach' } elseif ($c -match '-Commit') { ':commit' } elseif ($c -match '-Stage') { ':stage' } else { '' }) }
|
|
112
|
+
elseif ($c -match 'install-update\.ps1') { 'install-update' } elseif ($c -match 'stop-existing\.ps1') { 'stop-existing' }
|
|
113
|
+
elseif ($c -match 'run-connector\.ps1') { 'supervisor' } elseif ($c -match 'trillboards-edge-task\.vbs') { 'task-host' }
|
|
114
|
+
elseif ($_.Name -ieq 'cmd.exe') { 'launcher' } else { 'connector' }
|
|
115
|
+
[pscustomobject]@{ What = $what; Pid = [int]$_.ProcessId; Parent = [int]$_.ParentProcessId; InJob = [TbJobProbe]::InJob([int]$_.ProcessId) }
|
|
116
|
+
} | Sort-Object What, Pid)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
$owned = New-Object System.Collections.Generic.List[System.Diagnostics.Process]
|
|
120
|
+
try {
|
|
121
|
+
# The Task Scheduler record is the only witness of an instance ending or being
|
|
122
|
+
# stopped while the applier runs. It is off by default on Windows.
|
|
123
|
+
& wevtutil.exe sl Microsoft-Windows-TaskScheduler/Operational /e:true | Out-Null
|
|
124
|
+
|
|
125
|
+
$receipt.phase = 'root-manifest'
|
|
126
|
+
$rootManifest = Invoke-RestMethod -Uri 'https://screen.trillboards.com/connector/trillboards-connector-windows.version.json' -Headers @{ 'Cache-Control' = 'no-cache' } -TimeoutSec 30
|
|
127
|
+
$targetVersion = [string]$rootManifest.connectorVersion
|
|
128
|
+
$receipt.targetVersion = $targetVersion
|
|
129
|
+
if ($InstallerUrl -eq 'auto') {
|
|
130
|
+
$published = @($rootManifest)
|
|
131
|
+
if ($rootManifest.PSObject.Properties.Name -contains 'releaseHistory') { $published += @($rootManifest.releaseHistory) }
|
|
132
|
+
$pick = @($published | Where-Object { [version]$_.connectorVersion -ge $JobSafeUpdaterSince -and [version]$_.connectorVersion -lt [version]$targetVersion } |
|
|
133
|
+
Sort-Object { [version]$_.connectorVersion } -Descending) | Select-Object -First 1
|
|
134
|
+
if (-not $pick) {
|
|
135
|
+
Note ('SKIP: no published build with the job-safe updater (>= ' + $JobSafeUpdaterSince + ') is older than the root ' + $targetVersion + ' yet')
|
|
136
|
+
$receipt.phase = 'skipped'; $receipt.passed = $true
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
$InstallerUrl = 'https://screen.trillboards.com/connector/releases/windows/' + $pick.connectorVersion + '/' + $pick.gitSha + '/' + $pick.sha256 + '/SenseAnythingConnector.exe'
|
|
140
|
+
$receipt.installerUrl = $InstallerUrl
|
|
141
|
+
}
|
|
142
|
+
$m = [regex]::Match($InstallerUrl, '^https://screen\.trillboards\.com/connector/releases/windows/(0\.2\.[0-9]+)/([0-9a-f]{40})/([0-9a-f]{64})/SenseAnythingConnector\.exe$')
|
|
143
|
+
if (-not $m.Success) { throw 'InstallerUrl must be auto or an immutable published Windows installer address' }
|
|
144
|
+
$fromVersion = $m.Groups[1].Value
|
|
145
|
+
$fromSha256 = $m.Groups[3].Value
|
|
146
|
+
$receipt.fromVersion = $fromVersion
|
|
147
|
+
if ([version]$targetVersion -le [version]$fromVersion) { throw ('The live root ' + $targetVersion + ' is not newer than ' + $fromVersion + '; nothing to update to') }
|
|
148
|
+
Note ('field build ' + $fromVersion + ' must update itself to the live root ' + $targetVersion)
|
|
149
|
+
|
|
150
|
+
$receipt.phase = 'download'
|
|
151
|
+
$outer = Join-Path $root 'SenseAnythingConnector.exe'
|
|
152
|
+
Invoke-WebRequest -Uri $InstallerUrl -OutFile $outer -TimeoutSec 1500
|
|
153
|
+
if ((Get-FileHash -LiteralPath $outer -Algorithm SHA256).Hash -ine $fromSha256) { throw 'Installer hash differs from its immutable address' }
|
|
154
|
+
$signature = Get-AuthenticodeSignature -LiteralPath $outer
|
|
155
|
+
if ($signature.Status -ne 'Valid' -or $signature.SignerCertificate.Subject -notmatch '(?:^|,\s*)CN=Aethercorp Inc(?:,|$)') { throw 'Installer lacks the Aethercorp signature' }
|
|
156
|
+
|
|
157
|
+
$receipt.phase = 'install'
|
|
158
|
+
$payload = Join-Path $root 'customer-payload'
|
|
159
|
+
$sevenZip = (Get-Command 7z.exe -ErrorAction Stop).Source
|
|
160
|
+
$null = Invoke-Owned -File $sevenZip -RawArguments ('x "' + $outer + '" -o"' + $payload + '" -y') -LogName 'extract.log' -TimeoutSeconds 300
|
|
161
|
+
Remove-Item -LiteralPath $outer -Force
|
|
162
|
+
$inner = Join-Path $payload 'TrillboardsEdgeSetup-core.exe'
|
|
163
|
+
$model = Join-Path $payload 'gemma-4-E2B-it.litertlm'
|
|
164
|
+
foreach ($p in @($inner, $model)) { if (-not (Test-Path -LiteralPath $p -PathType Leaf)) { throw ('Customer package is missing ' + (Split-Path $p -Leaf)) } }
|
|
165
|
+
# The default per-user location, as on a store PC.
|
|
166
|
+
$null = Invoke-Owned -File $inner -RawArguments ('/S /MODEL_SOURCE="' + $model + '"') -LogName 'install.log' -TimeoutSeconds 1500
|
|
167
|
+
$installed = Get-InstalledVersion
|
|
168
|
+
$receipt.installedVersion = $installed
|
|
169
|
+
$receipt.applierBesideRuntime = Test-Path -LiteralPath (Join-Path $installDir 'bin\apply-update.ps1')
|
|
170
|
+
Note ('installed ' + $installed + ' at ' + $installDir + '; bin\apply-update.ps1 present=' + $receipt.applierBesideRuntime)
|
|
171
|
+
if ($installed -ne $fromVersion) { throw ('Installed version ' + $installed + ' differs from ' + $fromVersion) }
|
|
172
|
+
$preexisting = Get-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction SilentlyContinue
|
|
173
|
+
if ($preexisting) {
|
|
174
|
+
Note 'the installer registered TrillboardsEdge before pairing; stopping it to write the paired config'
|
|
175
|
+
Stop-ScheduledTask -TaskName 'TrillboardsEdge' -ErrorAction SilentlyContinue
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
$receipt.phase = 'camera'
|
|
179
|
+
$ffmpeg = Join-Path $installDir 'bin\ffmpeg.exe'
|
|
180
|
+
if (-not (Test-Path -LiteralPath $ffmpeg -PathType Leaf)) { throw 'The installed connector carries no bin\ffmpeg.exe' }
|
|
181
|
+
$rig = Join-Path $root 'rig'
|
|
182
|
+
New-Item -ItemType Directory -Path $rig | Out-Null
|
|
183
|
+
# Official MediaMTX v1.21.2 checksum, the same pin as test-recorder-family.ps1.
|
|
184
|
+
$archive = Join-Path $rig 'mediamtx.zip'
|
|
185
|
+
Invoke-WebRequest -Uri 'https://github.com/bluenviron/mediamtx/releases/download/v1.21.2/mediamtx_v1.21.2_windows_amd64.zip' -OutFile $archive -UseBasicParsing
|
|
186
|
+
if ((Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant() -ne 'a84224f5a490855684e62ba6fb71e80ea2a5e16aed61883bb58380290e93e467') { throw 'MediaMTX checksum mismatch' }
|
|
187
|
+
Expand-Archive -LiteralPath $archive -DestinationPath $rig
|
|
188
|
+
$rtspPort = 8554; $apiPort = 9997; $stubPort = 47391
|
|
189
|
+
@"
|
|
190
|
+
logLevel: warn
|
|
191
|
+
rtspAddress: 127.0.0.1:$rtspPort
|
|
192
|
+
rtspTransports: [tcp]
|
|
193
|
+
rtmp: no
|
|
194
|
+
hls: no
|
|
195
|
+
webrtc: no
|
|
196
|
+
srt: no
|
|
197
|
+
metrics: no
|
|
198
|
+
pprof: no
|
|
199
|
+
playback: no
|
|
200
|
+
api: yes
|
|
201
|
+
apiAddress: 127.0.0.1:$apiPort
|
|
202
|
+
authInternalUsers:
|
|
203
|
+
- user: any
|
|
204
|
+
pass: ""
|
|
205
|
+
ips: [127.0.0.1]
|
|
206
|
+
permissions:
|
|
207
|
+
- action: publish
|
|
208
|
+
- action: read
|
|
209
|
+
- action: api
|
|
210
|
+
paths:
|
|
211
|
+
cam:
|
|
212
|
+
"@ | Set-Content -LiteralPath (Join-Path $rig 'mediamtx.yml') -Encoding utf8
|
|
213
|
+
$owned.Add((Start-Process -FilePath (Join-Path $rig 'mediamtx.exe') -ArgumentList ('"' + (Join-Path $rig 'mediamtx.yml') + '"') -WorkingDirectory $rig -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'mediamtx.log') -RedirectStandardError (Join-Path $root 'mediamtx.err.log')))
|
|
214
|
+
Start-Sleep -Seconds 2
|
|
215
|
+
# The camera is a still scene, so the connector has no motion to review and
|
|
216
|
+
# reaches its safe point the way a quiet store does after hours.
|
|
217
|
+
$frame = Join-Path $rig 'scene.jpg'
|
|
218
|
+
Copy-Item -LiteralPath $PersonFrame -Destination $frame
|
|
219
|
+
$publishArgs = '-hide_banner -loglevel error -re -loop 1 -framerate 4 -i "' + $frame + '" -an -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -r 4 -g 8 -threads 1 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:' + $rtspPort + '/cam'
|
|
220
|
+
# A COPY of the shipped ffmpeg: stop-existing.ps1 stops every process whose
|
|
221
|
+
# image lives under the install root, and the camera must outlive the swap.
|
|
222
|
+
$cameraFfmpeg = Join-Path $rig 'camera-ffmpeg.exe'
|
|
223
|
+
Copy-Item -LiteralPath $ffmpeg -Destination $cameraFfmpeg
|
|
224
|
+
$owned.Add((Start-Process -FilePath $cameraFfmpeg -ArgumentList $publishArgs -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'camera.log') -RedirectStandardError (Join-Path $root 'camera.err.log')))
|
|
225
|
+
$deadline = [DateTime]::UtcNow.AddSeconds(30)
|
|
226
|
+
do {
|
|
227
|
+
Start-Sleep -Seconds 1
|
|
228
|
+
$ready = $false
|
|
229
|
+
try { $ready = @((Invoke-RestMethod -Uri ('http://127.0.0.1:' + $apiPort + '/v3/paths/list') -TimeoutSec 3).items | Where-Object { $_.name -eq 'cam' -and $_.ready }).Count -eq 1 } catch { }
|
|
230
|
+
} while (-not $ready -and [DateTime]::UtcNow -lt $deadline)
|
|
231
|
+
if (-not $ready) { throw 'The RTSP camera never became readable' }
|
|
232
|
+
Note ('camera live at rtsp://127.0.0.1:' + $rtspPort + '/cam')
|
|
233
|
+
|
|
234
|
+
$receipt.phase = 'api-stub'
|
|
235
|
+
$stubLog = Join-Path $root 'stub-requests.jsonl'
|
|
236
|
+
$stubScript = Join-Path $rig 'stub-api.mjs'
|
|
237
|
+
@'
|
|
238
|
+
import http from 'node:http';
|
|
239
|
+
import fs from 'node:fs';
|
|
240
|
+
const [port, log] = process.argv.slice(2);
|
|
241
|
+
http.createServer((req, res) => {
|
|
242
|
+
const chunks = [];
|
|
243
|
+
req.on('data', (c) => chunks.push(c));
|
|
244
|
+
req.on('end', () => {
|
|
245
|
+
const body = Buffer.concat(chunks).toString('utf8').slice(0, 16384);
|
|
246
|
+
fs.appendFileSync(log, JSON.stringify({ at: new Date().toISOString(), method: req.method, url: req.url, body }) + '\n');
|
|
247
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
248
|
+
res.end('{"success":true,"data":{}}');
|
|
249
|
+
});
|
|
250
|
+
}).listen(Number(port), '127.0.0.1');
|
|
251
|
+
'@ | Set-Content -LiteralPath $stubScript -Encoding utf8
|
|
252
|
+
# The runner's own Node, never the install's bin\node.exe: the swap stops
|
|
253
|
+
# every process whose image lives under the install root.
|
|
254
|
+
$systemNode = (Get-Command node.exe -ErrorAction Stop).Source
|
|
255
|
+
$owned.Add((Start-Process -FilePath $systemNode -ArgumentList @($stubScript, $stubPort, $stubLog) -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'stub.log') -RedirectStandardError (Join-Path $root 'stub.err.log')))
|
|
256
|
+
Start-Sleep -Seconds 2
|
|
257
|
+
|
|
258
|
+
$receipt.phase = 'pair'
|
|
259
|
+
$tokens = 1..2 | ForEach-Object { -join ((1..32) | ForEach-Object { '{0:x2}' -f (Get-Random -Maximum 256) }) }
|
|
260
|
+
$config = [ordered]@{
|
|
261
|
+
apiBaseUrl = ('http://127.0.0.1:' + $stubPort)
|
|
262
|
+
deviceToken = $tokens[0]
|
|
263
|
+
cameras = @([ordered]@{ deviceToken = $tokens[1]; screenId = 'tb-e2e-field-update'; rtspUrl = ('rtsp://127.0.0.1:' + $rtspPort + '/cam'); sourceType = 'direct_url'; transport = 'tcp' })
|
|
264
|
+
# The plain local-sense pipeline. The retained website pipeline opens only
|
|
265
|
+
# after the paired API's capability and profile handshakes, which a stub
|
|
266
|
+
# cannot answer; the update loop starts before either pipeline and does not
|
|
267
|
+
# depend on which one senses.
|
|
268
|
+
cloudSensing = [ordered]@{ candidateBuffer = [ordered]@{ continuousReview = [ordered]@{ enabled = $false } } }
|
|
269
|
+
}
|
|
270
|
+
$config | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $installDir 'trillboards.config.json') -Encoding utf8
|
|
271
|
+
$powershell = Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
272
|
+
$null = Invoke-Owned -File $powershell -RawArguments ('-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "' + (Join-Path $installDir 'bin\register-task.ps1') + '" -InstallDir "' + $installDir + '" -Mode auto-sense') -LogName 'register-task.log' -TimeoutSeconds 300
|
|
273
|
+
$task = Get-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop
|
|
274
|
+
Export-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' | Set-Content -LiteralPath (Join-Path $root 'task-before.xml') -Encoding utf8
|
|
275
|
+
$receipt.taskLogonType = [string]$task.Principal.LogonType
|
|
276
|
+
$receipt.taskRunLevel = [string]$task.Principal.RunLevel
|
|
277
|
+
if ($task.State -ne 'Running') { Enable-ScheduledTask -TaskName 'TrillboardsEdge' | Out-Null; Start-ScheduledTask -TaskName 'TrillboardsEdge' }
|
|
278
|
+
Note ('TrillboardsEdge registered (' + $receipt.taskLogonType + ', ' + $receipt.taskRunLevel + ') and started')
|
|
279
|
+
|
|
280
|
+
$receipt.phase = 'self-update'
|
|
281
|
+
$connectorLog = Join-Path $installDir 'logs\connector.log'
|
|
282
|
+
# Lines written before pairing (the installer's own start) are not this run.
|
|
283
|
+
$seenLines = if (Test-Path -LiteralPath $connectorLog) { @(Get-Content -LiteralPath $connectorLog).Count } else { 0 }
|
|
284
|
+
$lastProcs = ''; $lastTask = ''; $lastFiles = ''; $lastReport = ''
|
|
285
|
+
$reportedTarget = $false; $passed = $false; $fatalStarts = 0
|
|
286
|
+
$watch = [Diagnostics.Stopwatch]::StartNew()
|
|
287
|
+
while ($watch.Elapsed.TotalMinutes -lt $UpdateDeadlineMinutes) {
|
|
288
|
+
Start-Sleep -Seconds 4
|
|
289
|
+
if (Test-Path -LiteralPath $connectorLog) {
|
|
290
|
+
$lines = @(Get-Content -LiteralPath $connectorLog -ErrorAction SilentlyContinue)
|
|
291
|
+
if ($lines.Count -lt $seenLines) { $seenLines = 0 }
|
|
292
|
+
for ($i = $seenLines; $i -lt $lines.Count; $i++) {
|
|
293
|
+
if ($lines[$i] -match '\[update\]|\[apply-update\]|\[install-update\]|exiting|uncaught|fatal') { Note ('log: ' + $lines[$i].Substring(0, [Math]::Min(300, $lines[$i].Length))) }
|
|
294
|
+
if ($lines[$i] -match '^Fatal error') { $fatalStarts++ }
|
|
295
|
+
}
|
|
296
|
+
$seenLines = $lines.Count
|
|
297
|
+
}
|
|
298
|
+
$procs = (Get-UpdateProcesses | ForEach-Object { $_.What + '#' + $_.Pid + '<' + $_.Parent + ' job=' + $_.InJob }) -join ', '
|
|
299
|
+
if ($procs -ne $lastProcs) { Note ('processes: ' + $(if ($procs) { $procs } else { '(none)' })); $lastProcs = $procs }
|
|
300
|
+
$t = Get-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction SilentlyContinue
|
|
301
|
+
$taskLine = 'ABSENT'
|
|
302
|
+
if ($t) {
|
|
303
|
+
$taskLine = 'state=' + $t.State + ' enabled=' + $t.Settings.Enabled
|
|
304
|
+
try {
|
|
305
|
+
$ti = Get-ScheduledTaskInfo -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction Stop
|
|
306
|
+
$taskLine += ' lastResult=0x' + ('{0:x}' -f [int64]$ti.LastTaskResult) + ' lastRun=' + ([datetime]$ti.LastRunTime).ToUniversalTime().ToString('HH:mm:ss')
|
|
307
|
+
} catch { $taskLine += ' info=unreadable' }
|
|
308
|
+
}
|
|
309
|
+
if ($taskLine -ne $lastTask) { Note ('task: ' + $taskLine); $lastTask = $taskLine }
|
|
310
|
+
$updateDir = Join-Path $installDir '.auto-update'
|
|
311
|
+
$files = if (Test-Path -LiteralPath $updateDir) { (Get-ChildItem -LiteralPath $updateDir -Force | ForEach-Object { $_.Name }) -join ',' } else { '' }
|
|
312
|
+
if ($files -ne $lastFiles) {
|
|
313
|
+
Note ('.auto-update: ' + $(if ($files) { $files } else { '(absent or empty)' }))
|
|
314
|
+
foreach ($f in @('staged.json', 'outcome.json')) {
|
|
315
|
+
$p = Join-Path $updateDir $f
|
|
316
|
+
if (Test-Path -LiteralPath $p) { Note (' ' + $f + ': ' + (Get-Content -LiteralPath $p -Raw).Trim()) }
|
|
317
|
+
}
|
|
318
|
+
$lastFiles = $files
|
|
319
|
+
}
|
|
320
|
+
if (Test-Path -LiteralPath $stubLog) {
|
|
321
|
+
$reports = @(Get-Content -LiteralPath $stubLog -ErrorAction SilentlyContinue | ForEach-Object { try { $_ | ConvertFrom-Json } catch { } } |
|
|
322
|
+
Where-Object { $_.url -like '*connector-status*' -and $_.body })
|
|
323
|
+
if ($reports.Count -gt 0) {
|
|
324
|
+
$last = $reports[-1].body | ConvertFrom-Json
|
|
325
|
+
$outcome = if ($last.PSObject.Properties.Name -contains 'updateOutcome' -and $last.updateOutcome) { ($last.updateOutcome | ConvertTo-Json -Compress) } else { 'null' }
|
|
326
|
+
$available = if ($last.PSObject.Properties.Name -contains 'availableVersion') { [string]$last.availableVersion } else { '(omitted)' }
|
|
327
|
+
$reportLine = 'version=' + $last.connectorVersion + ' available=' + $available + ' outcome=' + $outcome
|
|
328
|
+
if ($reportLine -ne $lastReport) { Note ('status report #' + $reports.Count + ': ' + $reportLine); $lastReport = $reportLine }
|
|
329
|
+
if ([string]$last.connectorVersion -eq $targetVersion) { $reportedTarget = $true }
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
$installedNow = Get-InstalledVersion
|
|
333
|
+
if ($installedNow -eq $targetVersion -and $reportedTarget -and $t -and $t.Settings.Enabled) {
|
|
334
|
+
$passed = $true
|
|
335
|
+
break
|
|
336
|
+
}
|
|
337
|
+
# A connector that cannot start is a broken rig, not an update result.
|
|
338
|
+
if ($fatalStarts -ge 3 -and $installedNow -eq $fromVersion) { throw 'The paired test connector exits at startup (see log: lines); the rig cannot exercise an update' }
|
|
339
|
+
}
|
|
340
|
+
$receipt.finalInstalledVersion = Get-InstalledVersion
|
|
341
|
+
$receipt.reportedTargetVersion = $reportedTarget
|
|
342
|
+
$receipt.updateMinutes = [Math]::Round($watch.Elapsed.TotalMinutes, 1)
|
|
343
|
+
if (-not $passed) { throw ('The field build did not update itself to ' + $targetVersion + ' within ' + $UpdateDeadlineMinutes + ' minutes (installed now: ' + $receipt.finalInstalledVersion + ')') }
|
|
344
|
+
Note ('PASS: ' + $fromVersion + ' updated itself to ' + $targetVersion + ' in ' + $receipt.updateMinutes + ' min')
|
|
345
|
+
$receipt.phase = 'complete'; $receipt.passed = $true
|
|
346
|
+
} catch {
|
|
347
|
+
$receipt.failure = $_.Exception.Message
|
|
348
|
+
Note ('FAIL in phase ' + $receipt.phase + ': ' + $_.Exception.Message)
|
|
349
|
+
throw
|
|
350
|
+
} finally {
|
|
351
|
+
try {
|
|
352
|
+
$evidence = Join-Path $root 'evidence'
|
|
353
|
+
New-Item -ItemType Directory -Force -Path $evidence | Out-Null
|
|
354
|
+
foreach ($dir in @((Join-Path $installDir 'logs'), (Join-Path $env:LOCALAPPDATA 'Trillboards\logs'))) {
|
|
355
|
+
if (Test-Path -LiteralPath $dir) { Copy-Item -LiteralPath $dir -Destination (Join-Path $evidence ((Split-Path (Split-Path $dir -Parent) -Leaf) + '-logs')) -Recurse -Force }
|
|
356
|
+
}
|
|
357
|
+
$updateDir = Join-Path $installDir '.auto-update'
|
|
358
|
+
if (Test-Path -LiteralPath $updateDir) {
|
|
359
|
+
Get-ChildItem -LiteralPath $updateDir -File -Force | Where-Object { $_.Length -lt 1MB } | Copy-Item -Destination $evidence -Force
|
|
360
|
+
}
|
|
361
|
+
& wevtutil.exe qe Microsoft-Windows-TaskScheduler/Operational /f:text /rd:true /c:600 | Set-Content -LiteralPath (Join-Path $evidence 'task-scheduler-events.txt') -Encoding utf8
|
|
362
|
+
if (Get-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' -ErrorAction SilentlyContinue) {
|
|
363
|
+
Export-ScheduledTask -TaskName 'TrillboardsEdge' -TaskPath '\' | Set-Content -LiteralPath (Join-Path $evidence 'task-after.xml') -Encoding utf8
|
|
364
|
+
}
|
|
365
|
+
} catch { Write-Warning ('Some evidence could not be collected: ' + $_.Exception.Message) }
|
|
366
|
+
foreach ($p in $owned) { try { if (-not $p.HasExited) { $p.Kill($true) } } catch { } }
|
|
367
|
+
$receipt.completedAtUtc = [DateTimeOffset]::UtcNow.ToString('o')
|
|
368
|
+
$receipt | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $root 'receipt.json')
|
|
369
|
+
if ($env:GITHUB_OUTPUT) { ('artifact_path=' + $root) | Out-File -LiteralPath $env:GITHUB_OUTPUT -Append -Encoding utf8 }
|
|
370
|
+
$receipt | ConvertTo-Json -Depth 6
|
|
371
|
+
}
|