Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

test(e2e): let a harness claim its own runtime root so teardown may stop its detached helpers (#2676)

Call White87f13e3293df
diff --git a/tests/conftest.py b/tests/conftest.py
index de7c41900..fb438eb2a 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -636,11 +636,13 @@ class _ForeignSignalGuard:
The test owns its ``subprocess.Popen`` children and any process it has
signalled as its own; the founder rule keeps an orphan in a spawned child's
- group signalable after reparenting hides it from ancestry. The ``tmp_path``
+ group signalable after reparenting hides it from ancestry. The directory
rule covers a detached grandchild, which keeps nothing else that ties it to
- the test and is what harnesses such as the Model Hub e2e driver clean up by.
- It is the only grant over processes outside the tree, so it names this
- test's directory, never the shared temp root. A pid that names no process
+ the test and is what harnesses such as the Model Hub e2e driver clean up by:
+ a process whose command line names this test's ``tmp_path``, or a fresh
+ directory the test claimed for its own runtime (``claim_test_directory``).
+ It is the only grant over processes outside the tree, so it names the
+ test's own directories, never a shared temp root. A pid that names no process
gets the ESRCH the real call would raise, delivered to nothing, because a
descendant the test collected may exit before it is signalled. Signal 0 is
a liveness probe and passes.
@@ -662,7 +664,7 @@ class _ForeignSignalGuard:
def __init__(self, test_temp: Path) -> None:
self.me = _REAL_OS_GETPID()
# The whole final component: `test_x1` must not claim `test_x10`.
- self.names_test_temp = process_reaper.names_path(test_temp)
+ self.names_own_directory = [process_reaper.names_path(test_temp)]
self.owned: set[int] = set()
# Every pid psutil listed while this test ran: a scan finds real processes by design.
self.listed: set[int] = set()
@@ -695,7 +697,7 @@ class _ForeignSignalGuard:
cmdline = _REAL_PSUTIL_PROCESS(pid).cmdline()
except psutil.Error:
cmdline = []
- if any(self.names_test_temp(part) for part in cmdline):
+ if any(names(part) for names in self.names_own_directory for part in cmdline):
self.owned.add(pid)
return True
return False
@@ -792,6 +794,22 @@ class _ForeignSignalGuard:
_active_signal_guard: _ForeignSignalGuard | None = None
+def claim_test_directory(path: Path) -> None:
+ """Let the running test signal the processes whose command line names ``path``.
+
+ For a harness that roots its runtime in a fresh directory of its own outside
+ ``tmp_path``, such as the Model Hub e2e app under ``/tmp``, whose socket
+ paths would not fit under ``tmp_path``. Claim only a directory this test
+ just created with a unique name, never a shared root. Both spellings are
+ claimed, as written and as resolved: on macOS ``/tmp`` is ``/private/tmp``,
+ and what the app starts names whichever spelling it was handed.
+ """
+
+ if _active_signal_guard is not None:
+ for spelling in dict.fromkeys((os.path.abspath(path), os.path.realpath(path))):
+ _active_signal_guard.names_own_directory.append(process_reaper.names_path(Path(spelling)))
+
+
def _called_from_product(caller) -> bool:
return caller.f_globals.get("__name__", "").partition(".")[0] in _PRODUCT_PACKAGES
diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py
index b560dace8..1fe659f8e 100644
--- a/tests/e2e/conftest.py
+++ b/tests/e2e/conftest.py
@@ -14,7 +14,7 @@ import pytest
import urllib.request
import urllib.error
-from tests.conftest import REAL_USER_HOME
+from tests.conftest import REAL_USER_HOME, claim_test_directory
from tests.e2e.drivers.model_hub_app import ModelHubTestApp
from tests.e2e.drivers.mock_llm_upstream import MockLLMUpstream
@@ -100,9 +100,13 @@ def model_hub_app_factory():
if enabled
else "avibe-model-hub-disabled-e2e-"
)
+ # Under /tmp, not tmp_path: the app's socket paths must fit macOS's
+ # 104-byte limit. Claimed, so the guard lets teardown stop what the
+ # app's detached helpers leave behind.
with tempfile.TemporaryDirectory(
prefix=prefix, dir="/tmp"
) as runtime_root:
+ claim_test_directory(Path(runtime_root))
runtime = ModelHubTestApp(
repo_root,
Path(runtime_root),
diff --git a/tests/test_conftest_signal_guard.py b/tests/test_conftest_signal_guard.py
index 0142dc747..26f29aac3 100644
--- a/tests/test_conftest_signal_guard.py
+++ b/tests/test_conftest_signal_guard.py
@@ -25,7 +25,7 @@ import psutil
import pytest
from core.process_isolation import process_group_exists
-from tests.conftest import _REAL_OS_KILL
+from tests.conftest import _REAL_OS_KILL, claim_test_directory
from tests.fake_pid_helpers import fake_pid
from vibe import runtime
@@ -221,6 +221,24 @@ def test_a_detached_process_naming_this_tests_tmp_path_stays_signalable(stop, tm
_REAL_OS_KILL(detached, signal.SIGKILL)
[email protected]("spelling", ["as-claimed", "resolved"])
+def test_a_detached_process_naming_a_directory_the_test_claimed_stays_signalable(tmp_path_factory, spelling):
+ # A harness root outside tmp_path, such as the Model Hub e2e app's under /tmp,
+ # which macOS resolves to /private/tmp: the app's helpers may name either spelling.
+ real = tmp_path_factory.mktemp("harness-root")
+ claimed = tmp_path_factory.mktemp("links") / "root"
+ claimed.symlink_to(real, target_is_directory=True)
+ claim_test_directory(claimed)
+ named = claimed if spelling == "as-claimed" else real
+ _, detached = _spawn_detached(sleeper_session=True, sleeper=[*_SLEEP, str(named / "runtime" / "ui.log")])
+ try:
+ os.killpg(detached, signal.SIGTERM)
+ assert _wait_until_gone(detached)
+ finally:
+ with suppress(ProcessLookupError):
+ _REAL_OS_KILL(detached, signal.SIGKILL)
+
+
@pytest.mark.parametrize(
"named",
[