File size: 5,619 Bytes
e940395 1464612 e940395 1464612 e940395 1464612 e940395 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # drAIML WebGPU installer (webgpu-enable.ps1) tests, run in Microsoft's PowerShell container:
# docker run --rm -v "$PWD/webgpu/installer:/inst:ro" -v "$PWD/tests:/work-src:ro" mcr.microsoft.com/powershell:latest \
# pwsh -NoProfile -Command 'New-Item -ItemType Directory /work | Out-Null; & /work-src/webgpu_installer.ps1'
# This covers PowerShell 7 (System.Text.Json). The Windows PowerShell 5.1 path (JavaScriptSerializer) needs a real Windows.
$ErrorActionPreference = "Stop"
$S = "/inst/webgpu-enable.ps1"; $fail = 0
function Check($cond, $what) { if ($cond) { Write-Host " ok $what" } else { Write-Host " FAIL $what"; $script:fail++ } }
function Labs($d) { ([System.Text.Json.Nodes.JsonNode]::Parse([IO.File]::ReadAllText("$d/Local State")))["browser"]["enabled_labs_experiments"].ToJsonString() }
function Run([string[]]$a) { $o = & pwsh -NoProfile -File $S @a 2>&1 | Out-String; @{ out = $o; code = $LASTEXITCODE } }
Write-Host "PowerShell $($PSVersionTable.PSVersion)"
Write-Host "1. Chromium profile (-Dir)"
$c = "/work/chrome"; New-Item -ItemType Directory -Force $c | Out-Null
[IO.File]::WriteAllText("$c/Local State", '{"browser":{"enabled_labs_experiments":["smooth-scrolling@2"],"other":true},"x":1,"Case":1,"case":2,"n":12345678901234567890}')
$r = Run @("-Dir", $c, "-DryRun"); Check ($r.out -match "would add enable-unsafe-webgpu") "dry run says what it would add"
Check ((Labs $c) -eq '["smooth-scrolling@2"]') "dry run changed nothing"
$r = Run @("-Dir", $c); Check ($r.code -eq 0 -and $r.out -match "add enable-unsafe-webgpu") "adds the flag"
Check ((Labs $c) -eq '["smooth-scrolling@2","enable-unsafe-webgpu"]') "flag list = existing + enable-unsafe-webgpu"
$r = Run @("-Dir", $c); Check ($r.out -match "unchanged") "second run is unchanged"
Check ((Get-ChildItem "$c/Local State.bak-webgpu-*").Count -ge 1) "backup written"
Check (Test-Path "$c/Local State.webgpu-helper.json") "sidecar written"
$r = Run @("-Dir", $c, "-Blocklist"); Check ((Labs $c) -match "ignore-gpu-blocklist") "-Blocklist adds ignore-gpu-blocklist"
$r = Run @("-Dir", $c, "-Undo"); Check ((Labs $c) -eq '["smooth-scrolling@2"]') "undo removes exactly what was added"
$t = [IO.File]::ReadAllText("$c/Local State")
Check ($t -match '"Case":1' -and $t -match '"case":2') "keys differing only in case survive"
Check ($t -match '"other":true' -and $t -match '"x":1') "other settings survive"
Check ($t -match '12345678901234567890') "large numbers survive"
Check (-not (Test-Path "$c/Local State.webgpu-helper.json")) "sidecar removed on undo"
Write-Host "2. Firefox profile (-Dir)"
$f = "/work/ff"; New-Item -ItemType Directory -Force $f | Out-Null
Set-Content "$f/prefs.js" @('user_pref("other", 1);')
$r = Run @("-Dir", $f); Check ((Get-Content "$f/user.js" -Raw) -match 'user_pref\("dom.webgpu.enabled", true\);') "user.js gets the pref"
$r = Run @("-Dir", $f); Check ($r.out -match "unchanged") "second run is unchanged"
Check ([IO.File]::ReadAllBytes("$f/user.js")[0] -ne 0xEF) "user.js has no BOM"
Add-Content "$f/prefs.js" 'user_pref("dom.webgpu.enabled", true);' # Firefox copies the value on exit
$r = Run @("-Dir", $f, "-Undo")
Check (-not ((Get-Content "$f/user.js" -Raw) -match "webgpu")) "undo clears user.js"
Check (-not ((Get-Content "$f/prefs.js" -Raw) -match "webgpu") -and ((Get-Content "$f/prefs.js" -Raw) -match '"other"')) "undo clears only the pref from prefs.js"
$g = "/work/ff2"; New-Item -ItemType Directory -Force $g | Out-Null
Set-Content "$g/prefs.js" @('user_pref("dom.webgpu.enabled", true);')
$r = Run @("-Dir", $g); $r = Run @("-Dir", $g, "-Undo")
Check ((Get-Content "$g/prefs.js" -Raw) -match "dom.webgpu.enabled") "undo keeps a pref that was the user's own"
Write-Host "3. Default search (Windows-style LOCALAPPDATA / APPDATA)"
$env:LOCALAPPDATA = "/work/L"; $env:APPDATA = "/work/R"
foreach ($d in @("/work/L/Google/Chrome/User Data", "/work/L/BraveSoftware/Brave-Browser/User Data", "/work/R/Opera Software/Opera Stable")) {
New-Item -ItemType Directory -Force $d | Out-Null; [IO.File]::WriteAllText("$d/Local State", '{}') }
New-Item -ItemType Directory -Force "/work/R/Mozilla/Firefox/Profiles/abc.default" | Out-Null; Set-Content "/work/R/Mozilla/Firefox/Profiles/abc.default/prefs.js" ""
$r = Run @("-Firefox"); Write-Host ($r.out.Trim() -replace "(?m)^", " ")
Check ($r.out -match "Done: 4 changed") "finds Chrome, Brave, Opera and the Firefox profile"
Check ((Labs "/work/L/Google/Chrome/User Data") -eq '["enable-unsafe-webgpu"]') "a Local State without a browser key gets one"
$r = Run @("-Undo", "-Firefox"); Check ($r.out -match "Done: 4 changed") "undo across all of them"
Write-Host "4. A locked profile is skipped"
$l = "/work/locked"; New-Item -ItemType Directory -Force $l | Out-Null; [IO.File]::WriteAllText("$l/Local State", '{}')
$fs = [IO.File]::Open("$l/lockfile", 'Create', 'ReadWrite', 'None')
$env:LOCALAPPDATA = "/work/L2"; $env:APPDATA = "/work/R2"; New-Item -ItemType Directory -Force "/work/L2/Google/Chrome" | Out-Null
New-Item -ItemType SymbolicLink -Path "/work/L2/Google/Chrome/User Data" -Target $l | Out-Null
$r = Run @(); Check ($r.code -eq 3 -and $r.out -match "running") "held lockfile → skipped, exit 3"; if ($r.code -ne 3) { Write-Host "code=$($r.code)"; Write-Host $r.out }
$env:APPDATA = "/work/R"; $r = Run @(); Check ($r.code -eq 0 -and $r.out -match "1 running browser\(s\) were skipped") "mixed run names the skipped browser"
$fs.Close()
Check ([IO.File]::ReadAllText("$l/Local State") -eq '{}') "locked profile untouched"
Write-Host ""; if ($fail) { Write-Host "$fail FAILED"; exit 1 } else { Write-Host "all passed" }
|