desktopArchitectureGuard.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. detectArchitectureMismatch,
  4. formatArchitectureMismatchDialogText,
  5. resolveArchitectureDownloadUrl,
  6. } from "../src/main/desktopArchitectureGuard.js";
  7. describe("detectArchitectureMismatch", () => {
  8. it("Apple 芯片上运行 x64 包(Rosetta 转译)应判定为不匹配", () => {
  9. expect(
  10. detectArchitectureMismatch({
  11. platform: "darwin",
  12. binaryArch: "x64",
  13. runningUnderARM64Translation: true,
  14. }),
  15. ).toEqual({ binaryArch: "x64", nativeArch: "arm64" });
  16. });
  17. it("Windows on ARM 上转译运行也应判定为不匹配", () => {
  18. expect(
  19. detectArchitectureMismatch({
  20. platform: "win32",
  21. binaryArch: "x64",
  22. runningUnderARM64Translation: true,
  23. }),
  24. ).toEqual({ binaryArch: "x64", nativeArch: "arm64" });
  25. });
  26. it("原生运行(未转译)应返回 null", () => {
  27. expect(
  28. detectArchitectureMismatch({
  29. platform: "darwin",
  30. binaryArch: "arm64",
  31. runningUnderARM64Translation: false,
  32. }),
  33. ).toBeNull();
  34. });
  35. it("非 macOS/Windows 平台即使报告转译也不误报", () => {
  36. expect(
  37. detectArchitectureMismatch({
  38. platform: "linux",
  39. binaryArch: "x64",
  40. runningUnderARM64Translation: true,
  41. }),
  42. ).toBeNull();
  43. });
  44. });
  45. describe("resolveArchitectureDownloadUrl", () => {
  46. it("按语言分流到官网下载页", () => {
  47. expect(resolveArchitectureDownloadUrl("zh-CN")).toBe("https://zcode.z.ai/cn");
  48. expect(resolveArchitectureDownloadUrl("en-US")).toBe("https://zcode.z.ai/en");
  49. });
  50. });
  51. describe("formatArchitectureMismatchDialogText", () => {
  52. const mismatch = { binaryArch: "x64", nativeArch: "arm64" } as const;
  53. it("中文文案包含运行架构与推荐架构", () => {
  54. const text = formatArchitectureMismatchDialogText(mismatch, "zh-CN");
  55. expect(text.title).toBe("架构不匹配");
  56. expect(text.detail).toContain("x64");
  57. expect(text.detail).toContain("arm64");
  58. expect(text.downloadButton).toBe("前往下载");
  59. });
  60. it("英文文案包含运行架构与推荐架构", () => {
  61. const text = formatArchitectureMismatchDialogText(mismatch, "en-US");
  62. expect(text.title).toBe("Architecture Mismatch");
  63. expect(text.detail).toContain("x64");
  64. expect(text.detail).toContain("arm64");
  65. expect(text.downloadButton).toBe("Download");
  66. });
  67. });