From 792ede0a364bbe607f02aeb8fe38787f84e5e523 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 22 Jul 2026 21:17:43 -0700 Subject: [PATCH] test: pin repo root on PYTHONPATH for subprocess-boundary kanban isolation tests The three subprocess tests spawn 'sys.executable -c' children that import hermes_cli. From a worktree, the child resolved the MAIN checkout's editable install instead of the tree under test, so the new DB/CLI guards appeared missing and the tests failed with rc=0. Route the spawns through a helper that pins the repo root under test on PYTHONPATH. --- tests/tools/test_delegate_kanban_isolation.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/tools/test_delegate_kanban_isolation.py b/tests/tools/test_delegate_kanban_isolation.py index 803ea995eca5..10e72efd3b45 100644 --- a/tests/tools/test_delegate_kanban_isolation.py +++ b/tests/tools/test_delegate_kanban_isolation.py @@ -5,9 +5,25 @@ import json import os import shlex import sys +from pathlib import Path import pytest +# The subprocess-boundary tests below spawn ``sys.executable -c`` with a tmp +# cwd. Without an explicit PYTHONPATH the child resolves ``hermes_cli`` / +# ``agent`` through whatever install is on sys.path (in a worktree that is the +# MAIN checkout's editable install, which may not contain the code under +# test). Pin the repo root so the child always imports the tree being tested. +_REPO_ROOT = Path(__file__).resolve().parents[2] + + +def _python_with_repo_path(code: str) -> str: + """Build a shell command running *code* with the repo under test on PYTHONPATH.""" + return ( + f"PYTHONPATH={shlex.quote(str(_REPO_ROOT))} " + f"{shlex.quote(sys.executable)} -c {shlex.quote(code)}" + ) + def _make_running_kanban_task(monkeypatch, tmp_path): home = tmp_path / ".hermes" @@ -365,7 +381,7 @@ def test_delegate_child_local_execute_cannot_complete_parent_via_kanban_cli( try: with delegated_child_context(): result = env.execute( - f"{shlex.quote(sys.executable)} -c {shlex.quote(code)}", + _python_with_repo_path(code), timeout=15, ) finally: @@ -416,7 +432,7 @@ def test_delegate_child_subprocess_cannot_complete_parent_by_importing_kanban_db try: with delegated_child_context(): result = env.execute( - f"{shlex.quote(sys.executable)} -c {shlex.quote(code)}", + _python_with_repo_path(code), timeout=15, ) finally: @@ -463,7 +479,7 @@ def test_delegate_child_kanban_cli_cannot_delete_parent_board( try: with delegated_child_context(): result = env.execute( - f"{shlex.quote(sys.executable)} -c {shlex.quote(code)}", + _python_with_repo_path(code), timeout=15, ) finally: