Skip to content

The agent that grows with you

test(install-e2e): capture PM desktop launches on macOS through the isolated launcher

ethernet48c78669b147
diff --git a/tests/install/macos-desktop-e2e.sh b/tests/install/macos-desktop-e2e.sh
index 4a096a05b17..41d3a6bdbb9 100755
--- a/tests/install/macos-desktop-e2e.sh
+++ b/tests/install/macos-desktop-e2e.sh
@@ -362,10 +362,17 @@ PYEOF
hermes="$(source_hermes "$INSTALL_DIR")" || fail "no installed desktop command"
local spec="$WORK_ROOT/launch-spec.json"
local rc=0
- (cd "$INSTALL_DIR" && \
- PYTHONPATH="$ASSETS/launch-capture${PYTHONPATH:+:$PYTHONPATH}" \
- HERMES_E2E_CAPTURE_LAUNCH="$spec" \
- source_build_env "$hermes" desktop < /dev/null 2>&1 | ts_prefix > "$LOG_DIR/desktop-launch-capture.log") || rc=$?
+ if [ "$hermes" = "$INSTALL_DIR/.hermes/bin/hermes" ]; then
+ # PM launchers use -I, which ignores PYTHONPATH/sitecustomize. Inject
+ # the capture hook into the installed launcher's isolated command.
+ (cd "$INSTALL_DIR" && source_build_env python3 -I "$ASSETS/launch-capture/pm-launch.py" \
+ "$hermes" "$spec" < /dev/null 2>&1 | ts_prefix > "$LOG_DIR/desktop-launch-capture.log") || rc=$?
+ else
+ (cd "$INSTALL_DIR" && \
+ PYTHONPATH="$ASSETS/launch-capture${PYTHONPATH:+:$PYTHONPATH}" \
+ HERMES_E2E_CAPTURE_LAUNCH="$spec" \
+ source_build_env "$hermes" desktop < /dev/null 2>&1 | ts_prefix > "$LOG_DIR/desktop-launch-capture.log") || rc=$?
+ fi
log_group "hermes desktop (launch capture) transcript" "$LOG_DIR/desktop-launch-capture.log"
[ "$rc" -eq 0 ] || fail "hermes desktop exited $rc during launch capture"
[ -f "$spec.captured" ] || fail "hermes desktop exited 0 but no launch was captured"
diff --git a/tests/scripts/install/test_pm_desktop_launch_capture.py b/tests/scripts/install/test_pm_desktop_launch_capture.py
index 514ae37d3aa..2b6376a3e2b 100644
--- a/tests/scripts/install/test_pm_desktop_launch_capture.py
+++ b/tests/scripts/install/test_pm_desktop_launch_capture.py
@@ -11,7 +11,12 @@ import pytest
@pytest.mark.platforms("posix")
-def test_isolated_pm_launch_captures_only_final_electron_spawn(tmp_path):
[email protected]("packaged", [False, True])
+def test_isolated_pm_launch_captures_only_final_electron_spawn(tmp_path, packaged):
+ launch_argv = (
+ [str(tmp_path / "apps/desktop/release/mac-arm64/Hermes.app/Contents/MacOS/Hermes")]
+ if packaged else ["npm", "exec", "--", "electron", "."]
+ )
root = Path(__file__).resolve().parents[3]
helper = root / "tests/install/e2e-assets/launch-capture/pm-launch.py"
launcher = tmp_path / "hermes"
@@ -22,7 +27,7 @@ def test_isolated_pm_launch_captures_only_final_electron_spawn(tmp_path):
"assert os.environ.get('PYTHONPATH') is None\n"
"assert sys.argv[1:] == ['desktop']\n"
"subprocess.run(['npm', 'run', 'build'], check=True)\n"
- "subprocess.run(['npm', 'exec', '--', 'electron', '.'], "
+ f"subprocess.run({launch_argv!r}, "
"cwd=os.getcwd(), env={**os.environ, 'PRODUCT_SENTINEL': 'present'}, check=True)\n",
encoding="utf-8",
)
@@ -60,9 +65,10 @@ def test_isolated_pm_launch_captures_only_final_electron_spawn(tmp_path):
assert result.returncode == 0, result.stderr
assert (tmp_path / "build-ran").is_file()
assert not (tmp_path / "ambient-hook-ran").exists()
- assert spec.with_name(spec.name + ".captured").read_text() == "source"
+ shape = "packaged" if packaged else "source"
+ assert spec.with_name(spec.name + ".captured").read_text() == shape
captured = json.loads(spec.read_text())
- assert captured["argv"] == ["npm", "exec", "--", "electron", "."]
+ assert captured["argv"] == launch_argv
+ assert captured["matchedShape"] == shape
assert captured["cwd"] == str(tmp_path)
assert captured["env"]["PRODUCT_SENTINEL"] == "present"
- assert captured["matchedShape"] == "source"