Files
paseo/packages/desktop/src/system/arm64-translation.test.ts
T
Mohamed BoudraandGitHub 6a61066e2c fix(desktop): warn about Rosetta installs on Apple Silicon (#621)
* fix(desktop): warn about Rosetta installs on Apple Silicon

* docs: note workspace build sync before type fixes
2026-04-30 13:13:30 +08:00

60 lines
1.6 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { detectRunningUnderARM64Translation } from "./arm64-translation";
describe("detectRunningUnderARM64Translation", () => {
it("returns false outside macOS without probing sysctl", () => {
const execFileSyncImpl = vi.fn();
expect(
detectRunningUnderARM64Translation({
platform: "linux",
electronReportedTranslation: true,
execFileSyncImpl,
}),
).toBe(false);
expect(execFileSyncImpl).not.toHaveBeenCalled();
});
it("trusts Electron when it reports ARM64 translation", () => {
const execFileSyncImpl = vi.fn();
expect(
detectRunningUnderARM64Translation({
platform: "darwin",
electronReportedTranslation: true,
execFileSyncImpl,
}),
).toBe(true);
expect(execFileSyncImpl).not.toHaveBeenCalled();
});
it("falls back to sysctl when Electron does not report translation", () => {
const execFileSyncImpl = vi.fn(() => "1\n");
expect(
detectRunningUnderARM64Translation({
platform: "darwin",
electronReportedTranslation: false,
execFileSyncImpl,
}),
).toBe(true);
expect(execFileSyncImpl).toHaveBeenCalledWith("sysctl", ["-in", "sysctl.proc_translated"], {
encoding: "utf-8",
timeout: 1000,
});
});
it("treats missing sysctl support as not translated", () => {
const execFileSyncImpl = vi.fn(() => {
throw new Error("unknown oid");
});
expect(
detectRunningUnderARM64Translation({
platform: "darwin",
execFileSyncImpl,
}),
).toBe(false);
});
});