|
| 1 | +# Wait out the Ynison go-away ban, then run the cold-start measurement ONCE. |
| 2 | +# |
| 3 | +# Why this exists: every music tool call during a ban renews it for another hour, |
| 4 | +# so the only way to close the music track is to stay completely silent until the |
| 5 | +# deadline and then make exactly one measurement. Doing that by hand means sitting |
| 6 | +# and watching the clock; this script does it unattended. |
| 7 | +# |
| 8 | +# pwsh -File tools\verify-music-after-ban.ps1 [-MarginSec 70] [-SkipKill] |
| 9 | +# |
| 10 | +# Exit codes: 0 = measurement ran, 1 = prerequisite missing (app/serve/deadline). |
| 11 | +param( |
| 12 | + [int]$MarginSec = 70, |
| 13 | + [switch]$SkipKill, |
| 14 | + [string]$Serial = "3B15AX00M9E00000" |
| 15 | +) |
| 16 | + |
| 17 | +$ErrorActionPreference = "Stop" |
| 18 | +$adb = "C:\Users\OLD\AppData\Local\Android\Sdk\platform-tools\adb.exe" |
| 19 | +$pkg = "org.opencode.mobile.debug" |
| 20 | +$goaway = "/storage/emulated/0/Documents/OpencodeTerminal/ynison-goaway.json" |
| 21 | + |
| 22 | +function Adb([string]$cmd) { & $adb -s $Serial shell $cmd 2>&1 } |
| 23 | + |
| 24 | +function Get-BanUntil { |
| 25 | + $raw = (Adb "cat $goaway" | Out-String).Trim() |
| 26 | + if (-not $raw) { return $null } |
| 27 | + try { |
| 28 | + return [DateTimeOffset]::FromUnixTimeMilliseconds([int64](($raw | ConvertFrom-Json).until)).LocalDateTime |
| 29 | + } catch { |
| 30 | + return $null |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +function Wait-Until([datetime]$target) { |
| 35 | + while ($true) { |
| 36 | + $left = ($target - (Get-Date)).TotalSeconds |
| 37 | + if ($left -le 0) { return } |
| 38 | + $chunk = [math]::Min(60, [math]::Ceiling($left)) |
| 39 | + Write-Host ("waiting: {0:n0}s left (chunk {1}s)" -f $left, $chunk) |
| 40 | + Start-Sleep -Seconds $chunk |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +function Ensure-App { |
| 45 | + if ((Adb "pidof $pkg" | Out-String).Trim()) { return } |
| 46 | + Write-Host "app is not running - launching" |
| 47 | + & $adb -s $Serial shell monkey -p $pkg -c android.intent.category.LAUNCHER 1 2>&1 | Out-Null |
| 48 | + Start-Sleep -Seconds 20 |
| 49 | +} |
| 50 | + |
| 51 | +function Ensure-Serve { |
| 52 | + for ($i = 0; $i -lt 12; $i++) { |
| 53 | + if ((Adb "pgrep -f 'serve --port 4096'" | Out-String).Trim()) { return } |
| 54 | + Write-Host "serve is not up yet - waiting 5s" |
| 55 | + Start-Sleep -Seconds 5 |
| 56 | + } |
| 57 | + throw "serve did not start within 60s" |
| 58 | +} |
| 59 | + |
| 60 | +$until = Get-BanUntil |
| 61 | +if ($until) { |
| 62 | + $target = $until.AddSeconds($MarginSec) |
| 63 | + Write-Host ("ban until {0:yyyy-MM-dd HH:mm:ss}, measuring at {1:HH:mm:ss}" -f $until, $target) |
| 64 | + Wait-Until $target |
| 65 | +} else { |
| 66 | + Write-Host "no go-away file on device - measuring now" |
| 67 | +} |
| 68 | + |
| 69 | +Ensure-App |
| 70 | +Ensure-Serve |
| 71 | + |
| 72 | +$log = Join-Path (Get-Location) "measure-music.log" |
| 73 | +$measureArgs = @("-NoProfile", "-File", "tools\measure-cold-start.ps1") |
| 74 | +if ($SkipKill) { $measureArgs += "-SkipKill" } |
| 75 | +& pwsh @measureArgs *> $log |
| 76 | +$code = $LASTEXITCODE |
| 77 | +"EXIT: $code" | Out-File $log -Append |
| 78 | +Write-Host "measurement finished with exit $code, log: $log" |
| 79 | +exit $code |
0 commit comments