Skip to content

fix(desktop): 构建与验证拒绝 Rosetta 翻译环境 / reject Rosetta-translated macOS builds - #28

Merged
Qiuner merged 2 commits into
Qiuner:masterfrom
ruijayfeng:fix/macos-reject-rosetta
Sep 22, 2026
Merged

Qiuner merged 2 commits into
Qiuner:masterfrom
ruijayfeng:fix/macos-reject-rosetta

Conversation

@ruijayfeng

Copy link
Copy Markdown
Contributor

Closes #23

实现

  • 架构判定收敛到 apps/desktop/darwin-target.mjs 单一来源:resolveHostDarwinTarget 为输入注入的纯函数(Windows CI 兼容),新增 --print-shell-env CLI 输出 NODE_ARCH / FILE_ARCH
  • build-darwin.mjs:在 requireBuiltArtifacts() 与任何产物落盘前过门禁;翻译环境直接抛错终止。
  • verify-darwin.sh:删除本地 uname -m 判定,eval 同一规则,构建与验证保持一致;门禁失败时给出干净退出信息。
  • 指引信息明确:取消终端「使用 Rosetta 打开」或 arch -arm64 进入原生 shell、确认原生 Node;确需 Intel 包须在真正的 Intel Mac 上构建。不静默更改输出架构。

关键检测依据

hw.optional.arm64(硬件级,Intel 上 unknown oid → 判为原生 x64,不误伤)+ Node 自身 process.arch。不使用逐进程的 proc_translated:实测其读数随 exec 链漂移——Rosetta shell 中启动的原生 arm64 Node 的子 sysctl 会误报 1,导致矛盾判定。

验证(本次实际执行)

  • node --test apps/desktop/darwin-target.test.mjs:11 项通过(含 sysctl 各分支注入、shell env 导出、不支持架构不误伤路径)。
  • Apple Silicon(macOS 26.x,arm64,Node 26.8.1 原生)实机:
    1. 原生终端 → NODE_ARCH=arm64 放行;
    2. arch -x86_64 bash 中的原生 arm64 Node → 放行(其子进程天然原生,构建安全);
    3. 官方 node-v24.10.0-darwin-x64 翻译执行 → 拒绝 exit=1,输出完整切换指引;verify-darwin.sh 在该环境同样干净拒绝。
  • node scripts/check-doc-i18n-sync.mjs --working-treecheck-qcode-namingbash -ngit diff --check 通过。

未覆盖

…builds

macOS 构建与验证在产出任何构建产物前按硬件级 hw.optional.arm64 核对 Node
自身架构,拒绝 Apple Silicon 上的 x86_64 翻译执行并给出切换原生终端与
Node 的指引,不静默更改输出架构。判定规则收敛到 darwin-target.mjs 单一
来源(纯函数注入可测,Windows CI 兼容),verify-darwin.sh 经
--print-shell-env 复用同一规则。不采用逐进程的 proc_translated:其实测
读数随 exec 链漂移,会误判原生 Node。

Apple Silicon 实机覆盖原生放行、官方 darwin-x64 Node 翻译拒绝、Rosetta
shell 内原生 arm64 Node 放行三条路径;Intel 真机与完整重新打包未覆盖。

@Qiuner Qiuner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体方向和实机证据认可,合并前请补一个 fail-closed 小修。

readHardwareArm64() 当前将 sysctl 成功但输出为空字符串与明确输出 0 同等处理为 Intel:

if (output === '0' || output === '') return false

这里与本 PR“检测环境异常时停止构建、不得据此继续”的口径不一致。请仅将明确的 0 视为 Intel;空输出和其他意外值统一抛出检测失败,并补一项空白输出测试。完成后这项即可复核合并。

仅明确的 0 判定为 Intel;空输出与其他意外值统一抛出检测失败,
与 PR 的 fail-closed 口径一致。补充空白输出测试。

Treat empty hw.optional.arm64 output as a detection failure instead of
silently selecting Intel; keep explicit 0 as the only Intel signal.
@ruijayfeng

Copy link
Copy Markdown
Contributor Author

已按评审补上 fail-closed 小修(229f41b):仅明确的 0 判定 Intel;空输出抛"输出为空,无法判定硬件架构"检测失败,与其他意外值同口径。新增空白输出与纯空白输出(' \\n')两项测试,darwin-target.test.mjs 11/11 通过,CI 三项已绿,请复核。

@Qiuner Qiuner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核 229f41b:空与纯空白 sysctl 输出均 fail closed,明确 0 才判定 Intel;新增断言覆盖该分支,三项 CI 通过。批准合并。

@Qiuner
Qiuner merged commit 92d428f into Qiuner:master Sep 22, 2026
3 checks passed
@ruijayfeng
ruijayfeng deleted the fix/macos-reject-rosetta branch September 22, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS]: 构建与验证时明确拒绝 Rosetta 翻译环境

2 participants