Skip to content

The agent that grows with you

test(desktop): pin the Electron temp-root invariant without mocking launch options

teknium1455ecbdc39ec
diff --git a/tests/hermes_cli/test_desktop_socket_tmpdir.py b/tests/hermes_cli/test_desktop_socket_tmpdir.py
index 30a1511b484..272abe7423a 100644
--- a/tests/hermes_cli/test_desktop_socket_tmpdir.py
+++ b/tests/hermes_cli/test_desktop_socket_tmpdir.py
@@ -1,56 +1,41 @@
-"""The Electron child needs a socket-safe temp root, not a long CLI scratch path."""
+"""The Electron child needs a socket-safe temp root, not a long CLI scratch path (#124688)."""
import argparse
-import os
import socket
import tempfile
from pathlib import Path
-from unittest.mock import patch
import pytest
from hermes_cli import main_desktop
-def _launch(tmp_path):
- with patch.object(main_desktop, "_desktop_launch_options", return_value=([], "auto", "basic", "auto")):
- return main_desktop._desktop_launch_env(argparse.Namespace(cwd=str(tmp_path)))
+def _launch_env(tmp_path) -> dict:
+ env, _flags = main_desktop._desktop_launch_env(argparse.Namespace(cwd=str(tmp_path)))
+ return env
@pytest.mark.platforms("linux")
-def test_long_scratch_root_can_host_electron_singleton_socket(monkeypatch, tmp_path):
+def test_long_scratch_tmpdir_still_hosts_electrons_singleton_socket(monkeypatch, tmp_path):
scratch = tmp_path / ("long-home-" * 8) / "cache" / "scratch"
scratch.mkdir(parents=True)
- for key in ("TMPDIR", "TMP", "TEMP"):
+ for key in ("TMPDIR", "TMP", "TEMP", "HERMES_SCRATCH_DIR"):
monkeypatch.setenv(key, str(scratch))
- monkeypatch.setenv("HERMES_SCRATCH_DIR", str(scratch))
monkeypatch.setattr(tempfile, "tempdir", None)
- env, _ = _launch(tmp_path)
+ env = _launch_env(tmp_path)
+ # Chromium's ProcessSingleton binds $TMPDIR/scoped_dirXXXXXX/SingletonSocket.
with tempfile.TemporaryDirectory(prefix="scoped_dir", dir=env["TMPDIR"]) as directory:
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as server:
server.bind(str(Path(directory) / "SingletonSocket"))
- assert os.environ["TMPDIR"] == str(scratch)
- assert env["TMP"] == env["TEMP"] == str(scratch)
- assert env["HERMES_SCRATCH_DIR"] == str(scratch)
@pytest.mark.platforms("linux")
-def test_short_caller_selected_temp_root_is_preserved(monkeypatch, tmp_path):
- # Use the existing short-root resolver so this fixture also works under deep CI homes.
+def test_short_caller_tmpdir_is_passed_through(monkeypatch, tmp_path):
from hermes_constants import socket_safe_tmpdir
with tempfile.TemporaryDirectory(prefix="dt-", dir=socket_safe_tmpdir()) as directory:
monkeypatch.setenv("TMPDIR", directory)
monkeypatch.setattr(tempfile, "tempdir", None)
- env, _ = _launch(tmp_path)
- assert env["TMPDIR"] == directory
-
-
-def test_windows_temp_environment_is_not_retargeted(monkeypatch, tmp_path):
- for key in ("TMPDIR", "TMP", "TEMP"):
- monkeypatch.setenv(key, str(tmp_path))
- env, _ = _launch(tmp_path)
- assert all(env[key] == str(tmp_path) for key in ("TMPDIR", "TMP", "TEMP"))
+ assert _launch_env(tmp_path)["TMPDIR"] == directory