EV_John_Liu on X: "能不能出个windows on arm的版本啊…看到magpie是转译的".
magpie ships magpie-windows-arm64.exe and magpie-cli-windows-arm64.exe,
and the site's Windows button offers it on Arm, but an x64 install on an
Arm64 computer fetched the x64 build on every update and stayed emulated.
update's arch() swapped only an Intel Mac under Rosetta.
- internal/winarm: Emulated() asks IsWow64Process2 (x/sys/windows) once;
an amd64 build whose nativeMachine is IMAGE_FILE_MACHINE_ARM64 runs
emulated. A failed call (no IsWow64Process2 before Windows 10 1709)
means not emulated. false off Windows.
- update: arch() gives arm64 for windows/amd64 when emulated, so
BinaryAsset picks magpie-windows-arm64.exe (GUI) and
magpie-cli-windows-arm64.exe (CLI). The swap is the x64 one: canStart
starts the downloaded exe (it runs natively there), the running exe is
moved aside, the arm64 one renamed in under the same name, and
magpie.com is rewritten from the new app's own launcher.
- pii (sibling found on the way): pf-serve has no windows-arm64 build.
After the switch an arm64 magpie looked for a windows-arm64 pf-serve,
found none, and left Privacy Filter / AstrLink Guard "not downloaded"
while on. target() now maps windows-arm64 to the x64 pf-serve Windows 11
runs emulated; candidates() runs it on the CPU (the x64
pf-serve-vulkan has no x64 Vulkan driver there), then pf-serve-base
for an emulation without AVX2. The guard's status says emulated
(Status.Emulated), and its row reads "On, slowly under x64 emulation:
the next update installs magpie for Arm" in all five languages, like
the Rosetta line. app.js's and the core's script budgets grow by its
66 bytes.
- gui feedback: the diagnostics block's Arch line says
"amd64 (emulated on arm64)" / "amd64 (under Rosetta on arm64)".
Checked, not changed:
- site/public/index.html: the Windows main button already turns to
/download/windows-arm64 when userAgentData's architecture is "arm".
Run in Playwright Chromium and WebKit with a Windows Edge UA and
injected userAgentData: arm -> windows-arm64; x86 and no
userAgentData -> windows-amd64.
- telemetry (stats "arch") sends the build's GOARCH; left so, since what
is sent and the privacy text stay as they are. After the update it is
arm64 by itself.
- rtk: an arm64 magpie no longer upgrades a standalone x64 rtk.exe
(rtkArch == "amd64" only), filed as #6896.
- claudecode (win32-arm64) and Bun (windows-aarch64) downloads already
have arm64 builds.
Run (worktree at origin/main 17da22414):
- mote: go test -count=1 ./internal/winarm ./internal/update
./internal/pii ok; ./internal/gui -run Feedback ok.
- mote: go vet ./... ok; GOOS=linux go vet -tags nogui ./... ok;
GOOS=windows go vet ./... ok; GOOS=windows GOARCH=arm64 go vet of
winarm, update, pii, gui ok; darwin, windows and linux builds ok;
gofmt -l clean.
- mote: node --test privacy-model.test.cjs (Chromium and WebKit, five
languages, two widths) ok; i18n-keys' "a plugin's words are its own"
is red at this base on claude_image_budget_test.go's ", with an
image", already #6877.
- xiaomi-gpu (x64 Windows 11, real IsWow64Process2 saying not
emulated): win-run go test ./internal/winarm, ./internal/update -run
'WindowsOnArm|Rosetta|Asset|InstallBinary', ./internal/pii -run
'ArmWindows|GuardNow|Base', ./internal/gui -run Feedback ok.
- magpie-desktop (WSL2): winarm, update, pii ok; gui -tags nogui -run
Feedback ok.
- mote: go test -count=1 -tags nogui -timeout 45m ./... : every
package ok but internal/gui's TestCoreScriptBudget (app.js 66 bytes
over: the new pmSub line). The budgets are raised by those 66 with
why (pmSub draws every Privacy row, no lazy page to move it to);
internal/gui then ok in full.
- mote: gui-de, gui-ja, gui-zh-tw, i18n-en-no-cjk and the three other
privacy-*.test.cjs, in Chromium and WebKit: 28 of 28 each. Not the
whole GUI suite: the change is one string in one row, no API,
selector, CSS or layout.
Broken by hand (each red, then restored):
- arch() without the windows clause: TestWindowsOnArmUpdatesToArm64
(BinaryAsset magpie-windows-amd64.exe) and
TestWindowsOnArmInstallsArm64Exe (magpie.exe still "2.0 for x64").
- pii target() without the mapping: TestArmWindowsRunsX64Serve
(target windows-arm64, Supported false); candidates() without the
Arm branch: its subtests start pf-serve-vulkan.
- Status without Emulated: TestGuardNowSaysEmulated.
- archNote without the emulated case: TestFeedbackArchSaysTranslated.
- app.js without the emulated line: privacy-model's "AstrLink Guard
says what runs it" red in every language.
Not tried: real Windows on ARM (no such machine); detection is injected
in the tests, and the real call was only seen saying "not emulated" on
x64 Windows.
199 lines
6.3 KiB
Go
199 lines
6.3 KiB
Go
package pii
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// noFullX86 holds fullX86 at have for the test.
|
|
func noFullX86(t *testing.T, have bool) {
|
|
was := fullX86
|
|
fullX86 = func() bool { return have }
|
|
t.Cleanup(func() { fullX86 = was })
|
|
}
|
|
|
|
// withBase puts the stand-in as pf-serve-base too.
|
|
func withBase(t *testing.T) {
|
|
t.Helper()
|
|
b, err := os.ReadFile(exe("pf-serve"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(exe("pf-serve-base"), b, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// A CPU without AVX2, FMA or BMI2 ended pf-serve with SIGILL on the GPU
|
|
// and on the CPU (echo_yip on X): pf-serve-base runs there, on the CPU
|
|
// alone, since pf-serve-vulkan is built like pf-serve.
|
|
func TestBaseWhereTheCPULacksAVX2(t *testing.T) {
|
|
log := fakeInstall(t, "ok", true)
|
|
withBase(t)
|
|
noFullX86(t, false)
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve-base CPU"}) {
|
|
t.Fatalf("starts = %q", starts)
|
|
}
|
|
}
|
|
|
|
// A CPU with all of them never runs pf-serve-base; and a pf-serve from
|
|
// before pf-serve-base was built is run as it was.
|
|
func TestBaseOnlyWhereNeeded(t *testing.T) {
|
|
t.Run("full CPU", func(t *testing.T) {
|
|
log := fakeInstall(t, "novulkan", true)
|
|
withBase(t)
|
|
noFullX86(t, true)
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve-vulkan MTL0", "start pf-serve CPU"}) {
|
|
t.Fatalf("starts = %q", starts)
|
|
}
|
|
})
|
|
t.Run("no base on disk", func(t *testing.T) {
|
|
log := fakeInstall(t, "novulkan", true)
|
|
noFullX86(t, false)
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve-vulkan MTL0", "start pf-serve CPU"}) {
|
|
t.Fatalf("starts = %q", starts)
|
|
}
|
|
})
|
|
}
|
|
|
|
// rosettaInstall is an Intel magpie's pf-serve of serveTag (pf-v9), as
|
|
// fetched before magpie knew it ran under Rosetta, and from then on under
|
|
// Rosetta, Apple silicon's served at want's paths.
|
|
func rosettaInstall(t *testing.T, want map[string][]byte) string {
|
|
t.Helper()
|
|
wasArch, wasTr := osArch, translated
|
|
wasTag, wasOld, wasBase, wasServe := serveTag, oldTags, serveBase, serveSHA
|
|
t.Cleanup(func() {
|
|
upgrades.Wait()
|
|
osArch, translated = wasArch, wasTr
|
|
serveTag, oldTags, serveBase, serveSHA = wasTag, wasOld, wasBase, wasServe
|
|
})
|
|
osArch, translated = "darwin-amd64", func() bool { return false }
|
|
serveTag, oldTags = "pf-v9", nil
|
|
log := fakeInstall(t, "ok", false)
|
|
translated = func() bool { return true }
|
|
if target() != "darwin-arm64" {
|
|
t.Fatalf("target = %s under Rosetta", target())
|
|
}
|
|
s := httptest.NewServer(&files{m: want})
|
|
t.Cleanup(s.Close)
|
|
zipSum := sum([]byte("nothing"))
|
|
if z, ok := want["/rel/pf-v9/pf-serve-darwin-arm64.zip"]; ok {
|
|
zipSum = sum(z)
|
|
}
|
|
serveBase, serveSHA = s.URL+"/rel/", map[string]string{"darwin-arm64": zipSum, "darwin-amd64": "x"}
|
|
return log
|
|
}
|
|
|
|
// Under Rosetta, Apple silicon's pf-serve is fetched before the first
|
|
// start, run, and the Intel one deleted.
|
|
func TestRosettaRunsAppleSiliconsServe(t *testing.T) {
|
|
self, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(self)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var zb bytes.Buffer
|
|
zw := zip.NewWriter(&zb)
|
|
w, _ := zw.Create(filepath.Base(exeIn("", "pf-serve")))
|
|
w.Write(b)
|
|
zw.Close()
|
|
log := rosettaInstall(t, map[string][]byte{"/rel/pf-v9/pf-serve-darwin-arm64.zip": zb.Bytes()})
|
|
intel := filepath.Join(dir(), "pf-v9-darwin-amd64")
|
|
if !Installed() {
|
|
t.Fatal("the Intel pf-serve wasn't taken for installed")
|
|
}
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := fakeLines(t, log, "path "); !reflect.DeepEqual(got, []string{"path pf-v9-darwin-arm64"}) {
|
|
t.Fatalf("started from %q", got)
|
|
}
|
|
upgrades.Wait()
|
|
if _, err := os.Stat(intel); !os.IsNotExist(err) {
|
|
t.Fatalf("the Intel pf-serve was left: %v", err)
|
|
}
|
|
}
|
|
|
|
// One that can't be fetched leaves the Intel one to run.
|
|
func TestRosettaKeepsIntelsWhereNoneIsFetched(t *testing.T) {
|
|
log := rosettaInstall(t, map[string][]byte{})
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
upgrades.Wait()
|
|
if got := fakeLines(t, log, "path "); !reflect.DeepEqual(got, []string{"path pf-v9-darwin-amd64"}) {
|
|
t.Fatalf("started from %q", got)
|
|
}
|
|
if _, err := os.Stat(exeIn(filepath.Join(dir(), "pf-v9-darwin-amd64"), "pf-serve")); err != nil {
|
|
t.Fatalf("the Intel pf-serve was deleted: %v", err)
|
|
}
|
|
}
|
|
|
|
// onArm runs the test as a magpie for windows-arm64: built for it, or the
|
|
// x64 one updated to it on Windows on Arm (update's arch).
|
|
func onArm(t *testing.T) {
|
|
t.Helper()
|
|
was := osArch
|
|
t.Cleanup(func() { osArch = was })
|
|
osArch = "windows-arm64"
|
|
}
|
|
|
|
// pf-serve has no arm64 build: Windows on Arm runs the x64 one, emulated,
|
|
// as it ran the x64 magpie that updated to arm64 there. Before, an arm64
|
|
// magpie had no Privacy Filter, and the x64 one's update left the model
|
|
// on in the settings and "not downloaded".
|
|
func TestArmWindowsRunsX64Serve(t *testing.T) {
|
|
onArm(t)
|
|
if target() != "windows-amd64" || !Supported() {
|
|
t.Fatalf("target = %s, Supported = %v on windows-arm64", target(), Supported())
|
|
}
|
|
if !strings.HasSuffix(serveDir(), "-windows-amd64") {
|
|
t.Fatalf("serveDir = %s, not the x64 pf-serve's", serveDir())
|
|
}
|
|
// on the CPU: the x64 pf-serve-vulkan has no x64 Vulkan driver there
|
|
t.Run("on the CPU", func(t *testing.T) {
|
|
log := fakeInstall(t, "ok", true)
|
|
noFullX86(t, true)
|
|
if !Installed() {
|
|
t.Fatal("the x64 pf-serve on disk isn't installed")
|
|
}
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve CPU"}) {
|
|
t.Fatalf("starts = %q", starts)
|
|
}
|
|
})
|
|
// an emulation without AVX2 ends pf-serve at once: pf-serve-base then
|
|
t.Run("no AVX2", func(t *testing.T) {
|
|
log := fakeInstall(t, "noavx2", true)
|
|
withBase(t)
|
|
noFullX86(t, true)
|
|
if _, err := Find([]string{"hi Alice"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve CPU", "start pf-serve-base CPU"}) {
|
|
t.Fatalf("starts = %q", starts)
|
|
}
|
|
})
|
|
}
|