Download tests/webgpu_installer.ps1 from PYTHAI/drAIML: direct link, hf CLI and curl.
- Browser
- Download file 5.62 kB
-
https://huggingface.co/spaces/PYTHAI/drAIML/resolve/main/tests/webgpu_installer.ps1
- Command line
-
hf download hf://spaces/PYTHAI/drAIML/tests/webgpu_installer.ps1
-
curl -L -o webgpu_installer.ps1 https://huggingface.co/spaces/PYTHAI/drAIML/resolve/main/tests/webgpu_installer.ps1
5.62 kB
| # 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" } | |