fix(desktop): resolve login-shell PATH at Electron startup - #1316
Conversation
|
Got some review comments, feel free to push back or resolve the convesation! None of the P2 P3s are blocking and it's just discussion. The P1 is a safety blocker we need to address. |
9b0c070 to
e122cc0
Compare
Spawn the user's login shell at Electron startup to recover a full PATH for apps launched from Finder/Dock/Spotlight (port of VS Code's shellEnv.ts). Review (apache#1316) feedback folded in: - short-circuit resolveShellEnv when launched from a terminal (TERM/COLORTERM) - drop the dead xonsh capture branch (intentionally unsupported) - shell-escape process.execPath per quoting context (POSIX/pwsh/nu) - strip XDG_RUNTIME_DIR from the resolved env (microsoft/vscode#22593) - preserve the Electron trio + MAKA_* via a prefix rule; drop MAKA_RESOLVING_ENVIRONMENT - export mergeEnv/buildCaptureCommand/buildMarkerRegex + add unit tests - E2E fixtures set MAKA_SKIP_SHELL_ENV=1 so the probe never taints the sanitized env (P1) Rebased onto main (incorporates apache#1314 visual-smoke -> e2e-fixture rename).
|
Thanks @Astro-Han — all seven comments are addressed in e122cc0. P1 (blocker) — E2E env taint. P2 — terminal short-circuit. #3 — dead xonsh branch. Removed. Its #4 — shell-escape #5 — #6 — prefix-rule preservation + dead marker. Replaced the hand-maintained Re: the rebase — you were right, the branch was stale. It's now rebased onto current #7 — test gap. Exported Verified: |
…nsole PR apache#1316's test job failed the workspace console.* audit: shell-env.ts adds three startup diagnostics (capture-failure warn, shell-stderr debug, PATH-entry-count log). Add the file to the ALLOW map — it matches the sibling main-process diagnostic modules (config-file-watcher, daily-review, app-lifecycle) and leaks no secrets (only PATH count, shell name, error class).
|
I took another pass over There is still one production-path issue. The E2E skip does not cover this. It prevents the probe from running in E2E, while the leak happens during a normal Finder or Dock launch. I would clean up the captured environment before returning it: const PROBE_ENV_KEYS = [
'ELECTRON_RUN_AS_NODE',
'ELECTRON_NO_ATTACH_CONSOLE',
] as const;
export function sanitizeCapturedEnv(
captured: Record<string, string>,
original: NodeJS.ProcessEnv,
): Record<string, string> {
const resolved = { ...captured };
for (const key of PROBE_ENV_KEYS) {
const value = original[key];
if (value === undefined) {
delete resolved[key];
} else {
resolved[key] = value;
}
}
delete resolved.XDG_RUNTIME_DIR;
return resolved;
}Then snapshot the original environment before adding the probe flags: const originalEnv = { ...process.env };
const env = {
...originalEnv,
ELECTRON_RUN_AS_NODE: '1',
ELECTRON_NO_ATTACH_CONSOLE: '1',
};
// After parsing the shell output:
resolve(sanitizeCapturedEnv(parsed, originalEnv));Please add the two cases that match the real probe result: remove an injected value when the original value was absent, and restore the exact value when it was already present. Once cleanup happens here, the Electron-specific preservation in One separate cleanup remains: the After these two fixes, I do not see anything else blocking this PR. |
Spawn the user's login shell at Electron startup to recover a full PATH for apps launched from Finder/Dock/Spotlight (port of VS Code's shellEnv.ts). Review (apache#1316) feedback folded in: - short-circuit resolveShellEnv when launched from a terminal (TERM/COLORTERM) - drop the dead xonsh capture branch (intentionally unsupported) - shell-escape process.execPath per quoting context (POSIX/pwsh/nu) - strip XDG_RUNTIME_DIR from the resolved env (microsoft/vscode#22593) - preserve the Electron trio + MAKA_* via a prefix rule; drop MAKA_RESOLVING_ENVIRONMENT - export mergeEnv/buildCaptureCommand/buildMarkerRegex + add unit tests - E2E fixtures set MAKA_SKIP_SHELL_ENV=1 so the probe never taints the sanitized env (P1) Rebased onto main (incorporates apache#1314 visual-smoke -> e2e-fixture rename).
…nsole PR apache#1316's test job failed the workspace console.* audit: shell-env.ts adds three startup diagnostics (capture-failure warn, shell-stderr debug, PATH-entry-count log). Add the file to the ALLOW map — it matches the sibling main-process diagnostic modules (config-file-watcher, daily-review, app-lifecycle) and leaks no secrets (only PATH count, shell name, error class).
3f29071 to
2b5ddb0
Compare
Summary
PATHbefore desktop stores, tools, and child processes are created, so Finder/Dock/Spotlight launches can find Homebrew, user-local, and version-manager binaries.PATH; shell startup files cannot inject Maka, Electron, renderer, or other application-control variables into the running main process.MAKA_SKIP_SHELL_ENV.Verification
npm run build:testnpm run typechecknpm run lintnpm run format:checknpm --workspace @maka/desktop test— 2863 passednode --test apps/desktop/dist/main/__tests__/shell-env.test.js— 18 passed; repeated runs passedReview focus
The boundary is intentionally PATH-only. The issue is missing CLI lookup paths in GUI launches; importing the full login environment would mix shell-owned data with application control state and require an open-ended denylist.