A1: macOS readiness: setup guide, cargo xtask mac-report, unix/macOS fixes

- docs/macos.md: step-by-step setup for a fresh Apple Silicon Mac (Xcode
  CLT, Homebrew, git, PHP, Composer, Node 22, pnpm, rustup, clone from
  Forgejo), the machine report, Gatekeeper notes, macOS differences and
  what Windows cannot check.
- cargo xtask mac-report: versions, the gate steps, the bundled-UI desktop
  build and a self-check over the control channel (project, file,
  Phpactor, hover, git.status, terminal, screenshot, quit); every step
  times out and runs in a lutra_proc group; one report.md to send back.
- Fixes: macOS native menu (system menus only; Cmd+W stays buffer.close,
  Cmd+Q runs app.quit), xcap screenshot region in points on macOS
  (Retina), login shell (-l, /bin/zsh fallback) and LANG for the
  terminal on macOS, PHP lookup in Homebrew/MacPorts dirs for Finder
  starts, case-insensitive LSP path mapping on macOS, rendezvous file
  mode re-set to 0600, CLI-started desktop in its own process group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:47:45 +01:00
parent da58c83158
commit 1bf69ded55
18 changed files with 1795 additions and 36 deletions

View file

@ -160,6 +160,22 @@ fn pty_size(cols: u16, rows: u16) -> Result<PtySize, TerminalError> {
})
}
/// Whether the shell needs `LANG=en_US.UTF-8`: on macOS only, when neither
/// Lutra's environment nor `extra` sets `LANG`, `LC_ALL` or `LC_CTYPE`.
/// An app started from the Finder or Dock gets no locale, and without one
/// zsh and most tools treat non-ASCII text (umlauts in file names and
/// output) as unknown bytes; Terminal.app sets `LANG` the same way.
fn needs_utf8_locale(extra: &[(OsString, OsString)]) -> bool {
const LOCALE_VARS: [&str; 3] = ["LANG", "LC_ALL", "LC_CTYPE"];
cfg!(target_os = "macos")
&& LOCALE_VARS
.iter()
.all(|name| std::env::var_os(name).is_none_or(|v| v.is_empty()))
&& !extra
.iter()
.any(|(key, _)| LOCALE_VARS.iter().any(|name| key == name))
}
/// A spawn error from any displayable cause.
fn spawn_error(e: impl std::fmt::Display) -> TerminalError {
TerminalError::Spawn(e.to_string())
@ -188,6 +204,9 @@ impl Session {
cmd.env("TERM", "xterm-256color");
cmd.env("COLORTERM", "truecolor");
cmd.env("TERM_PROGRAM", "Lutra");
if needs_utf8_locale(&options.env) {
cmd.env("LANG", "en_US.UTF-8");
}
for (key, value) in &options.env {
cmd.env(key, value);
}

View file

@ -27,7 +27,13 @@ impl Shell {
/// - **Windows:** `pwsh.exe` (PowerShell 7) from `PATH`, else
/// `powershell.exe` (Windows PowerShell), else `%COMSPEC%`, else
/// `cmd.exe`. PowerShell starts with `-NoLogo`.
/// - **Unix:** `$SHELL`, else `/bin/sh`.
/// - **macOS:** `$SHELL`, else `/bin/zsh` (the default login shell since
/// macOS 10.15), else `/bin/sh`, started as a login shell (`-l`) the way
/// Terminal.app does. A login shell reads `~/.zprofile`, where Homebrew
/// puts `/opt/homebrew/bin` on the `PATH`; without it, PHP and Composer
/// from Homebrew are missing in a Lutra started from the Finder or Dock,
/// which inherits only the system `PATH`.
/// - **Other Unix:** `$SHELL`, else `/bin/sh`.
pub fn default_shell() -> Shell {
if cfg!(windows) {
for name in ["pwsh.exe", "powershell.exe"] {
@ -46,6 +52,15 @@ pub fn default_shell() -> Shell {
let shell = std::env::var_os("SHELL")
.filter(|s| !s.is_empty())
.map(PathBuf::from);
if cfg!(target_os = "macos") {
let program = shell
.or_else(|| Some(PathBuf::from("/bin/zsh")).filter(|p| p.is_file()))
.unwrap_or_else(|| PathBuf::from("/bin/sh"));
return Shell {
program,
args: vec![OsString::from("-l")],
};
}
Shell::new(shell.unwrap_or_else(|| PathBuf::from("/bin/sh")))
}
@ -101,6 +116,12 @@ mod tests {
assert!(found, "{shell:?}");
}
#[cfg(target_os = "macos")]
#[test]
fn macos_starts_a_login_shell() {
assert_eq!(default_shell().args, vec![OsString::from("-l")]);
}
#[test]
fn finds_programs_in_path() {
let name = if cfg!(windows) { "cmd" } else { "sh" };