161 lines
16 KiB
PowerShell
161 lines
16 KiB
PowerShell
param([Parameter(Mandatory)][string]$ApkPath,[Parameter(Mandatory)][string]$EvidenceDir,[string]$Serial='emulator-5554')
|
|
$ErrorActionPreference='Stop'
|
|
$EvidenceDir=(Resolve-Path -LiteralPath $EvidenceDir).Path
|
|
$sdk=if ($env:ANDROID_SDK_ROOT) { $env:ANDROID_SDK_ROOT } else { Join-Path $env:LOCALAPPDATA 'Android/Sdk' }
|
|
$adb=Join-Path $sdk 'platform-tools/adb.exe'
|
|
$checks=[Collections.Generic.List[object]]::new(); $commands=[Collections.Generic.List[object]]::new(); $recorders=[Collections.Generic.List[object]]::new()
|
|
$package='com.magnetismheroes.game'; $activity="$package/com.unity3d.player.UnityPlayerGameActivity"; $remote="/sdcard/Android/data/$package/files/progress.json"
|
|
$result=[ordered]@{milestone='Composition';sourceCommit=(& git rev-parse HEAD);sourceDirty=[bool](& git status --porcelain);serial=$Serial;apkSha256=(Get-FileHash $ApkPath -Algorithm SHA256).Hash;status='failed';checks=@();commands=@()}
|
|
$result.rendererProjection=@{fieldOfView=62;fixedWorldPivot=@(0,.65,0);rawCamera='Saved Board.camera JSON remains canonical';viewport='Landscape wm size max/min; remaining UI and physical touch helper assume sole 2400x1080 AVD'}
|
|
$networkBefore=$null
|
|
$physicalInput=$false
|
|
function Adb([string[]]$Arguments) {
|
|
$output=& $adb -s $Serial @Arguments 2>&1; $code=$LASTEXITCODE
|
|
$commands.Add(@{command=('adb -s '+$Serial+' '+($Arguments -join ' '));exitCode=$code;output=($output -join "`n")})
|
|
if ($code -ne 0) { throw "ADB exit $code : $($Arguments -join ' ')" }; return ($output -join "`n").Trim()
|
|
}
|
|
function Check([string]$Id,[bool]$Passed,[string]$Actual) {
|
|
$checks.Add(@{id=$Id;passed=$Passed;actual=$Actual}); if (!$Passed) { throw "Composition check failed: $Id ($Actual)" }
|
|
}
|
|
function Step([string]$Name,[string[]]$Arguments=@(),[int]$Delay=500) {
|
|
& (Join-Path $PSScriptRoot 'observe.ps1') -Step $Name -AdbArguments $Arguments -Serial $Serial -EvidenceDir $EvidenceDir -DelayMilliseconds $Delay
|
|
if ($Arguments.Count -gt 1 -and $Arguments[1] -eq 'input') { $script:physicalInput=$false }
|
|
}
|
|
function Save([string]$Name) { Adb @('pull',$remote,(Join-Path $EvidenceDir "$Name.json")) | Out-Null; return Get-Content (Join-Path $EvidenceDir "$Name.json") -Raw | ConvertFrom-Json }
|
|
function Fixture([int]$Stage) {
|
|
Adb @('shell','am','force-stop',$package) | Out-Null
|
|
$fixture=[ordered]@{schemaVersion=1;completedStageIds=@(1..($Stage-1));seenTutorialIds=@();puzzleStates=@();latestFreePlay=$null}
|
|
$path=Join-Path $EvidenceDir "fixture-$Stage.json"; $fixture | ConvertTo-Json -Depth 8 | Set-Content $path -Encoding utf8
|
|
Adb @('shell','mkdir','-p',"/sdcard/Android/data/$package/files") | Out-Null
|
|
Adb @('push',$path,$remote) | Out-Null
|
|
Adb @('shell','rm','-f',($remote+'.bak')) | Out-Null
|
|
Step "stage-$Stage-home" @('shell','am','start','-W','-n',$activity) 6500
|
|
Step "stage-$Stage-selection" @('shell','input','tap','1200','616')
|
|
}
|
|
function Restart([string]$Name) {
|
|
Adb @('shell','input','keyevent','3') | Out-Null; Adb @('shell','am','force-stop',$package) | Out-Null
|
|
Step "$Name-home" @('shell','am','start','-W','-n',$activity) 6500
|
|
}
|
|
function StartAudio([string]$Name,[int]$Seconds) {
|
|
$path=Join-Path $EvidenceDir "$Name.wav"
|
|
$arguments=@('-NoProfile','-File',(Join-Path $PSScriptRoot 'record-audio.ps1'),'-OutputPath',$path,'-Seconds',"$Seconds")
|
|
$process=Start-Process pwsh -ArgumentList ($arguments | ForEach-Object {'"'+$_+'"'}) -WindowStyle Hidden -RedirectStandardOutput (Join-Path $EvidenceDir "$Name.stdout") -RedirectStandardError (Join-Path $EvidenceDir "$Name.stderr") -PassThru
|
|
$recorders.Add(@{name=$Name;process=$process}); Start-Sleep -Seconds 2
|
|
}
|
|
function Touch([int[]]$Contacts) {
|
|
if (!$script:physicalInput) {
|
|
# ADB injects a virtual touchscreen. Finish one harmless physical contact before changing devices.
|
|
& (Join-Path $PSScriptRoot 'send-composition-touch.ps1') -Contacts @(30,400,999,100)
|
|
Start-Sleep -Milliseconds 100
|
|
& (Join-Path $PSScriptRoot 'send-composition-touch.ps1') -Contacts @(30,400,999,0)
|
|
Start-Sleep -Milliseconds 100
|
|
$commands.Add(@{command='EmulatorController.sendTouch physical-device warmup: 30,400,999,100 then 30,400,999,0';exitCode=0})
|
|
$script:physicalInput=$true
|
|
}
|
|
& (Join-Path $PSScriptRoot 'send-composition-touch.ps1') -Contacts $Contacts
|
|
$commands.Add(@{command=('EmulatorController.sendTouch contacts='+($Contacts -join ','));exitCode=0})
|
|
}
|
|
function SameJson($First,$Second) { return ($First | ConvertTo-Json -Depth 12 -Compress) -eq ($Second | ConvertTo-Json -Depth 12 -Compress) }
|
|
function BallPoint($Board,[string]$Id) {
|
|
$ball=@($Board.balls | Where-Object id -eq $Id)[0]; $camera=$Board.camera
|
|
$rotation=[Numerics.Quaternion]::new($camera.rotation.x,$camera.rotation.y,$camera.rotation.z,$camera.rotation.w)
|
|
$origin=[Numerics.Vector3]::new($camera.target.x,($camera.target.y+.65),$camera.target.z)+[Numerics.Vector3]::Transform([Numerics.Vector3]::new(0,0,-$camera.distance),$rotation)
|
|
$local=[Numerics.Vector3]::Transform([Numerics.Vector3]::new($ball.position.x,$ball.position.y,$ball.position.z)-$origin,[Numerics.Quaternion]::Inverse($rotation))
|
|
$size=Adb @('shell','wm','size'); if ($size -notmatch '(\d+)x(\d+)') { throw "Unknown device resolution: $size" }
|
|
$width=[Math]::Max([int]$Matches[1],[int]$Matches[2]); $height=[Math]::Min([int]$Matches[1],[int]$Matches[2])
|
|
$scale=($height/2)/([Math]::Tan(31*[Math]::PI/180)*$local.Z)
|
|
return @([int][Math]::Round(($width/2)+$local.X*$scale),[int][Math]::Round(($height/2)-$local.Y*$scale))
|
|
}
|
|
function TapPoint([string]$Name,$Point) { Step $Name @('shell','input','tap',"$($Point[0])","$($Point[1])") }
|
|
function DragPoint([string]$Name,$Point,[int]$Dx,[int]$Dy=0) { Step $Name @('shell','input','swipe',"$($Point[0])","$($Point[1])","$($Point[0]+$Dx)","$($Point[1]+$Dy)",'650') }
|
|
try {
|
|
Check 'clean-source' (!$result.sourceDirty) $result.sourceCommit
|
|
$build=Get-Content (Join-Path $EvidenceDir 'androidbuild-evidence.json') -Raw | ConvertFrom-Json
|
|
Check 'build-provenance' ($build.status -eq 'passed' -and $build.exitCode -eq 0 -and !$build.sourceDirty -and !$build.sourceDirtyEnd -and $build.sourceCommit -eq $result.sourceCommit -and $build.apkSha256 -eq $result.apkSha256) $result.apkSha256
|
|
Adb @('install','-r',$ApkPath) | Out-Null; Adb @('logcat','-c') | Out-Null
|
|
$networkBefore=@{airplane=(Adb @('shell','settings','get','global','airplane_mode_on'));wifi=(Adb @('shell','settings','get','global','wifi_on'));data=(Adb @('shell','settings','get','global','mobile_data'))}
|
|
$result.networkBefore=$networkBefore
|
|
Adb @('shell','cmd','connectivity','airplane-mode','enable') | Out-Null; Adb @('shell','svc','wifi','disable') | Out-Null; Adb @('shell','svc','data','disable') | Out-Null
|
|
Check 'offline-real-device-network' ((Adb @('shell','settings','get','global','airplane_mode_on')) -eq '1' -and (Adb @('shell','settings','get','global','wifi_on')) -eq '0' -and (Adb @('shell','settings','get','global','mobile_data')) -eq '0' -and (Adb @('shell','dumpsys','connectivity')) -match 'Active default network: none') 'Airplane1 wifi0 data0; no active default network'
|
|
$result.device=@{model=(Adb @('shell','getprop','ro.product.model'));abi=(Adb @('shell','getprop','ro.product.cpu.abilist'));bridge=(Adb @('shell','getprop','ro.dalvik.vm.native.bridge'));api=(Adb @('shell','getprop','ro.build.version.sdk'))}
|
|
Check 'landscape-resolution' ((Adb @('shell','wm','size')) -match '1080x2400') 'Physical resolution1080x2400, landscape2400x1080'
|
|
Adb @('shell','pm','clear',$package) | Out-Null
|
|
Step 'new-save-home' @('shell','am','start','-W','-n',$activity) 6500
|
|
Step 'new-save-selection' @('shell','input','tap','1200','616')
|
|
Step 'new-save-locked-six' @('shell','input','tap','480','560')
|
|
$locked=Save 'new-save-after-locked-six'; Check 'new-save-six-remains-locked' ($locked.puzzleStates.Count -eq 0 -and $locked.completedStageIds.Count -eq 0) 'No puzzle created by tapping locked6'
|
|
Fixture 6; StartAudio 'audio-guide-merge' 10
|
|
Step 'six-initial-face-number' @('shell','input','tap','480','560') 1200
|
|
$sixBefore=Save 'six-before'; Check 'six-real-initial' ((($sixBefore.puzzleStates[0].groups | ForEach-Object {$_.ballIds.Count}) -join ',') -eq '1,1') 'Two initial singleton groups'
|
|
# Hold real Android touch while observing the contact candidate; no runtime control server.
|
|
$left=BallPoint $sixBefore.puzzleStates[0] $sixBefore.puzzleStates[0].balls[0].id
|
|
$right=BallPoint $sixBefore.puzzleStates[0] $sixBefore.puzzleStates[0].balls[1].id
|
|
$destination=@(($right[0]-45),$right[1])
|
|
Touch @($left[0],$left[1],401,100); Start-Sleep -Milliseconds 100; Touch @($destination[0],$destination[1],401,100); Step 'six-contact-candidate'
|
|
$preview=Save 'six-preview'; Check 'six-preview-not-saved' (SameJson $preview $sixBefore) 'Preview JSON equals committed initial JSON'
|
|
Touch @($destination[0],$destination[1],401,0); Step 'six-success-face-number'
|
|
$six=Save 'six-success'; Check 'six-final-two' ($six.completedStageIds -contains 6 -and $six.puzzleStates.Count -eq 0 -and $six.latestFreePlay.groups.Count -eq 1 -and $six.latestFreePlay.groups[0].ballIds.Count -eq 2) 'Completed6; one2 group; no unfinished'
|
|
Check 'six-ids-preserved' ((($six.latestFreePlay.balls.id | Sort-Object) -join ',') -eq (($sixBefore.puzzleStates[0].balls.id | Sort-Object) -join ',')) 'All original IDs preserved'
|
|
Fixture 10; StartAudio 'audio-guide-split' 12
|
|
Step 'ten-initial-face-number' @('shell','input','tap','1920','560') 1000
|
|
$tenInitial=Save 'ten-initial'; $left=BallPoint $tenInitial.puzzleStates[0] $tenInitial.puzzleStates[0].balls[0].id; $right=BallPoint $tenInitial.puzzleStates[0] $tenInitial.puzzleStates[0].balls[1].id
|
|
TapPoint 'ten-choose-friend' $left; Step 'ten-split-mode' @('shell','input','tap','312','832')
|
|
$tenBefore=Save 'ten-before'
|
|
DragPoint 'ten-zero-selection-drag' $left -190
|
|
Check 'ten-zero-unchanged' (SameJson $tenBefore (Save 'ten-zero-after')) 'Zero selection preserves JSON'
|
|
TapPoint 'ten-select-left' $left; TapPoint 'ten-select-right' $right
|
|
DragPoint 'ten-all-selection-drag' $left -190
|
|
Check 'ten-all-unchanged' (SameJson $tenBefore (Save 'ten-all-after')) 'Entire selection preserves JSON'
|
|
TapPoint 'ten-deselect-right' $right; Step 'ten-selected-count-face-number'
|
|
# Android injection preserves the out-of-window endpoint; emulator physical touch clamps its coordinates.
|
|
Step 'ten-outside-cancel' @('shell','input','swipe',"$($left[0])","$($left[1])",'2500',"$($left[1])",'650')
|
|
Check 'ten-outside-cancel-unchanged' (SameJson $tenBefore (Save 'ten-outside-after')) 'Off-board release keeps committed JSON'
|
|
TapPoint 'ten-select-again' $left; Step 'ten-split-again' @('shell','input','tap','312','832'); TapPoint 'ten-selection-again' $left
|
|
Touch @($left[0],$left[1],421,100); Touch @(($left[0]-65),$left[1],421,100); Touch @(($right[0]+75),$right[1],422,100)
|
|
Touch @(($left[0]-65),$left[1],421,0,($right[0]+75),$right[1],422,0); Step 'ten-pinch-switch'
|
|
$pinch=Save 'ten-pinch-after'; Check 'ten-pinch-no-split' ($pinch.puzzleStates[0].groups.Count -eq 1 -and (SameJson $pinch.puzzleStates[0].balls $tenBefore.puzzleStates[0].balls)) 'Pinch aborts split, all ball positions unchanged'
|
|
# Return to unchanged committed camera by restarting from the fresh fixture before the successful split.
|
|
Fixture 10; Step 'ten-success-start' @('shell','input','tap','1920','560'); TapPoint 'ten-success-choose' $left
|
|
Step 'ten-success-split' @('shell','input','tap','312','832'); TapPoint 'ten-success-select' $left
|
|
DragPoint 'ten-success-drag' $left -190
|
|
$ten=Save 'ten-success'; Check 'ten-final-one-one-no-remerge' ($ten.completedStageIds -contains 10 -and $ten.puzzleStates.Count -eq 0 -and $ten.latestFreePlay.groups.Count -eq 2 -and @($ten.latestFreePlay.groups | Where-Object {$_.ballIds.Count -ne 1}).Count -eq 0) 'Completed10; exactly1,1; no auto-remerge'
|
|
Fixture 14; Step 'fourteen-initial' @('shell','input','tap','1200','366'); $initial=Save 'fourteen-initial-board'
|
|
$group=$initial.puzzleStates[0].groups[0]; $left=BallPoint $initial.puzzleStates[0] $group.ballIds[0]; $right=BallPoint $initial.puzzleStates[0] $group.ballIds[2]
|
|
TapPoint 'fourteen-choose-three' $left
|
|
Step 'fourteen-split-mode' @('shell','input','tap','312','832'); TapPoint 'fourteen-select-end-one' $left; TapPoint 'fourteen-select-end-two' $right
|
|
Step 'fourteen-disconnected-selected' @(); DragPoint 'fourteen-disconnected-split' $left -270
|
|
$fourteenBefore=Save 'fourteen-unfinished-before'; $sizes=@($fourteenBefore.puzzleStates[0].groups | ForEach-Object {$_.ballIds.Count} | Sort-Object)
|
|
Check 'fourteen-disconnected-two-results' (($sizes -join ',') -eq '1,1,2') 'Selected disconnected ends form one2 friend; rest one1; original other1'
|
|
Restart 'fourteen-restore'; Step 'fourteen-restore-selection' @('shell','input','tap','1200','616'); Step 'fourteen-restored' @('shell','input','tap','1200','366')
|
|
Check 'fourteen-unfinished-restored' (SameJson $fourteenBefore (Save 'fourteen-unfinished-after')) 'All unfinished JSON including IDs positions groups camera restored'
|
|
$singles=@($fourteenBefore.puzzleStates[0].groups | Where-Object {$_.ballIds.Count -eq 1})
|
|
$left=BallPoint $fourteenBefore.puzzleStates[0] $singles[0].ballIds[0]; $right=BallPoint $fourteenBefore.puzzleStates[0] $singles[1].ballIds[0]
|
|
Step 'fourteen-single-merge' @('shell','input','swipe',"$($left[0])","$($left[1])","$($right[0]-45)","$($right[1])",'650')
|
|
$fourteen=Save 'fourteen-success'; Check 'fourteen-final-two-two' ($fourteen.completedStageIds -contains 14 -and $fourteen.puzzleStates.Count -eq 0 -and $fourteen.latestFreePlay.groups.Count -eq 2 -and @($fourteen.latestFreePlay.groups | Where-Object {$_.ballIds.Count -ne 2}).Count -eq 0) 'Exactly2,2 completes14 after split then merge'
|
|
Restart 'free-restore'; Step 'free-restored' @('shell','input','tap','1200','810')
|
|
Check 'free-json-restored' (SameJson $fourteen (Save 'free-after-restore')) 'Final free board restores all groups IDs positions camera'
|
|
Step 'free-rotate-underneath' @('shell','input','swipe','2100','650','2250','980','700')
|
|
foreach ($recorder in $recorders) {
|
|
if (!$recorder.process.WaitForExit(30000)) { throw 'PCM collection did not finish' }; $recorder.process.Refresh()
|
|
Check "pcm-recorder-$($recorder.name)" ($recorder.process.ExitCode -eq 0) "$($recorder.process.ExitCode)"
|
|
$id=if ($recorder.name -eq 'audio-guide-merge') {'guide_merge'} else {'guide_split'}
|
|
$comparison=Join-Path $EvidenceDir ($recorder.name+'-match.json')
|
|
& pwsh -NoProfile -File (Join-Path $PSScriptRoot 'compare-audio.ps1') -ReferencePath "Assets/MagnetismHeroes/UnityRuntime/Presentation/Audio/Voice/$id.wav" -CapturedPath (Join-Path $EvidenceDir ($recorder.name+'.wav')) -OutputPath $comparison
|
|
$match=Get-Content $comparison -Raw | ConvertFrom-Json; Check "pcm-$id" ($LASTEXITCODE -eq 0 -and $match.passed -and $match.normalizedCorrelation -ge .95) ($match | ConvertTo-Json -Compress)
|
|
}
|
|
Adb @('logcat','-d','-s','Unity','AndroidRuntime') | Set-Content (Join-Path $EvidenceDir 'android-runtime.log') -Encoding utf8
|
|
Check 'no-runtime-fatal' (!(Get-Content (Join-Path $EvidenceDir 'android-runtime.log') -Raw | Select-String 'FATAL EXCEPTION|NullReferenceException|MissingReferenceException|IndexOutOfRangeException')) 'No fatal or missing-reference runtime exception'
|
|
$result.status='passed'
|
|
} catch { $result.error=$_.Exception.Message; Write-Host $result.error -ForegroundColor Red }
|
|
finally {
|
|
if ($networkBefore) {
|
|
Adb @('shell','cmd','connectivity','airplane-mode',$(if ($networkBefore.airplane -eq '1') {'enable'} else {'disable'})) | Out-Null
|
|
Adb @('shell','svc','wifi',$(if ($networkBefore.wifi -eq '1') {'enable'} else {'disable'})) | Out-Null
|
|
Adb @('shell','svc','data',$(if ($networkBefore.data -eq '1') {'enable'} else {'disable'})) | Out-Null
|
|
$result.networkAfter=@{airplane=(Adb @('shell','settings','get','global','airplane_mode_on'));wifi=(Adb @('shell','settings','get','global','wifi_on'));data=(Adb @('shell','settings','get','global','mobile_data'))}
|
|
}
|
|
$result.checks=$checks.ToArray(); $result.commands=$commands.ToArray(); $result.finishedUtc=[DateTime]::UtcNow.ToString('o')
|
|
$result | ConvertTo-Json -Depth 12 | Set-Content (Join-Path $EvidenceDir 'android-composition-evidence.json') -Encoding utf8
|
|
}
|
|
if ($result.status -ne 'passed') { exit 1 }; Write-Host "Composition actual Android checks passed: $($checks.Count). PNG visual review remains explicit."; exit 0
|