diff --git a/tests/inner/conftest.py b/tests/inner/conftest.py index 5cd8999f36..9ed5694712 100644 --- a/tests/inner/conftest.py +++ b/tests/inner/conftest.py @@ -12,8 +12,11 @@ import logging import os import pathlib +import shutil import sys +import tempfile import time +from collections.abc import Iterator from types import SimpleNamespace import pytest @@ -22,6 +25,24 @@ from tests import _model_pools +@pytest.fixture +def short_tmp_parent() -> Iterator[pathlib.Path]: + """A short-pathed temp dir under ``/tmp`` for Unix-socket-binding tests. + + macOS caps an ``AF_UNIX`` path at ~103 bytes and its ``$TMPDIR`` is already + ~48 bytes, so pytest's ``tmp_path`` (which embeds the test name) overflows + before a socket filename is appended (issue #4279). Tests that bind a real + Unix socket — the private tmux server, the egress proxy — must place it + under a short parent. Production sockets already live under a short + ``$TMPDIR/omnigent-...`` path, so this is a test-path artifact only. + """ + parent = pathlib.Path(tempfile.mkdtemp(prefix="omni-inner-", dir="/tmp")) + try: + yield parent + finally: + shutil.rmtree(parent, ignore_errors=True) + + @pytest.fixture(autouse=True) def _stub_executor_catalog_defaults(monkeypatch: pytest.MonkeyPatch) -> None: """Keep executor unit tests deterministic without catalog network access.""" diff --git a/tests/inner/egress/test_proxy.py b/tests/inner/egress/test_proxy.py index 047977579a..1cf4ec9927 100644 --- a/tests/inner/egress/test_proxy.py +++ b/tests/inner/egress/test_proxy.py @@ -51,13 +51,14 @@ async def test_proxy_start_stop_tcp( @pytest.mark.asyncio -async def test_proxy_start_unix(ca_paths: tuple[Path, Path, Path], tmp_path: Path) -> None: +async def test_proxy_start_unix(ca_paths: tuple[Path, Path, Path], short_tmp_parent: Path) -> None: """Proxy can listen on a Unix socket.""" cert_path, key_path, _ = ca_paths rules = parse_rules(["GET example.com/**"]) proxy = EgressProxy(rules, cert_path, key_path) - sock_path = tmp_path / "test.sock" + # short_tmp_parent (not tmp_path): the AF_UNIX path cap overflows on macOS. + sock_path = short_tmp_parent / "test.sock" await proxy.start_unix(sock_path) # Socket file is created diff --git a/tests/inner/test_terminal.py b/tests/inner/test_terminal.py index 95b6c89551..caea5d5325 100644 --- a/tests/inner/test_terminal.py +++ b/tests/inner/test_terminal.py @@ -368,7 +368,9 @@ async def fake_create_subprocess_exec( @pytest.mark.skipif(shutil.which("tmux") is None, reason="requires a real tmux binary") @pytest.mark.asyncio -async def test_server_survives_inner_process_exit_real_tmux(tmp_path: Path) -> None: +async def test_server_survives_inner_process_exit_real_tmux( + tmp_path: Path, short_tmp_parent: Path +) -> None: """ The private tmux server outlives an inner-process exit (issue #540). @@ -384,7 +386,9 @@ async def test_server_survives_inner_process_exit_real_tmux(tmp_path: Path) -> N instance = TerminalInstance( name="bash", session_key="s1", - socket_path=tmp_path / "tmux.sock", + # short_tmp_parent (not tmp_path): tmux's AF_UNIX socket path overflows + # the macOS 103-byte cap when it embeds pytest's long tmp_path (#4279). + socket_path=short_tmp_parent / "tmux.sock", private_dir=tmp_path, command="sh", args=["-c", "exit 0"], diff --git a/tests/runner/test_app_sessions_native_terminals_runtime.py b/tests/runner/test_app_sessions_native_terminals_runtime.py index 91e310e78e..bd3f7a1311 100644 --- a/tests/runner/test_app_sessions_native_terminals_runtime.py +++ b/tests/runner/test_app_sessions_native_terminals_runtime.py @@ -158,6 +158,11 @@ async def test_create_session_threads_workspace_to_pi_cwd( ) -> None: """Pi pre-spawn receives the session workspace, not the bundle dir.""" monkeypatch.setenv("OMNIGENT_CONFIG_HOME", str(tmp_path / "config-home")) + # Isolate $HOME too: ambient provider detection reads ~/.databrickscfg, + # which on a multi-profile Databricks dev box otherwise 400s the create + # with "match ; use --profile" (issue #4279). + monkeypatch.setenv("HOME", str(tmp_path / "config-home")) + monkeypatch.setenv("USERPROFILE", str(tmp_path / "config-home")) session_id = "18f39ab73f49285e4dab0c80ff7b8455" runner_workspace = tmp_path / "runner-workspace" runner_workspace.mkdir() diff --git a/tests/runtime/test_openai_agents_sdk_spawn_env.py b/tests/runtime/test_openai_agents_sdk_spawn_env.py index 1f01f39003..1b515a1a7b 100644 --- a/tests/runtime/test_openai_agents_sdk_spawn_env.py +++ b/tests/runtime/test_openai_agents_sdk_spawn_env.py @@ -37,11 +37,19 @@ def _isolate_global_config(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> N this file so tests that don't explicitly set up a global config are not affected by the developer's real ``~/.omnigent/config.yaml``. + Also redirect ``$HOME`` (and ``$USERPROFILE`` on Windows) to that temp + dir: ambient provider detection reads ``~/.codex/config.toml`` and + ``~/.databrickscfg``, which live under HOME, not OMNIGENT_CONFIG_HOME. On + a Databricks developer machine those otherwise pin a provider and break + these tests (issue #4279). + Tests that need a specific global config write their own config.yaml into a separate temp dir and set OMNIGENT_CONFIG_HOME themselves — that setenv call wins because monkeypatch applies in call order. """ monkeypatch.setenv("OMNIGENT_CONFIG_HOME", str(tmp_path)) + monkeypatch.setenv("HOME", str(tmp_path)) + monkeypatch.setenv("USERPROFILE", str(tmp_path)) def _make_spec( diff --git a/tests/runtime/test_provider_spawn_env.py b/tests/runtime/test_provider_spawn_env.py index 30ade9eac7..dd20b843af 100644 --- a/tests/runtime/test_provider_spawn_env.py +++ b/tests/runtime/test_provider_spawn_env.py @@ -80,6 +80,25 @@ def _clear_ambient_keys(monkeypatch: pytest.MonkeyPatch) -> None: ) +@pytest.fixture(autouse=True) +def _isolate_ambient_provider_state(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: + """Isolate host state ambient provider detection reads (issue #4279). + + Two ambient sources leak past ``$OMNIGENT_CONFIG_HOME``: + + - ``~/.codex/config.toml`` and ``~/.databrickscfg`` live under ``$HOME`` + (``$USERPROFILE`` on Windows), so redirect it to an empty temp dir. + - On macOS ``_claude_login_detected()`` falls back to ``claude auth status``, + which reads the **Keychain** — no ``$HOME`` override can hide it. A + signed-in Mac would inject a ``subscription`` provider that outranks the + test's own configured entry, so stub it to "not logged in". Tests that + exercise a detected login can still override this in call order. + """ + monkeypatch.setenv("HOME", str(tmp_path)) + monkeypatch.setenv("USERPROFILE", str(tmp_path)) + monkeypatch.setattr("omnigent.onboarding.ambient._claude_login_detected", lambda: False) + + @pytest.fixture def config_home(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path: """