Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/inner/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
Pytest fixtures shared across ``tests/inner/`` test files.
"""
Expand All @@ -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
Expand All @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions tests/inner/egress/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/inner/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions tests/runner/test_app_sessions_native_terminals_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host>; 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()
Expand Down
8 changes: 8 additions & 0 deletions tests/runtime/test_openai_agents_sdk_spawn_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions tests/runtime/test_provider_spawn_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Loading