diff --git a/tests/test_workmux_add/test_named_agents.py b/tests/test_workmux_add/test_named_agents.py index 64009535..fdf0d9f5 100644 --- a/tests/test_workmux_add/test_named_agents.py +++ b/tests/test_workmux_add/test_named_agents.py @@ -1,5 +1,6 @@ """Tests for known agent auto-detection and prompt injection.""" +import os import shlex from pathlib import Path @@ -13,6 +14,15 @@ from .conftest import add_branch_and_get_worktree +def _write_rc_with_fake_path(env: MuxEnvironment, bin_dir: Path) -> None: + """Write a shell RC file that prepends the fake agent bin dir to PATH.""" + shell = os.environ.get("SHELL", "/bin/zsh") + rc_filename = ".zshrc" if "zsh" in shell else ".bashrc" + rc_path = env.home_path / rc_filename + rc_path.parent.mkdir(parents=True, exist_ok=True) + rc_path.write_text(f'export PATH="{bin_dir}:$PATH"\n') + + class TestKnownAgentAutoDetection: """Tests that literal known agent commands auto-detect for prompt injection.""" @@ -37,6 +47,9 @@ def test_literal_known_agent_gets_prompt_injection( """, ) + # Write RC file so new panes find the fake agent on PATH + _write_rc_with_fake_path(env, fake_agent_installer.bin_dir) + # Use literal "claude" in panes -- no placeholder, no global agent write_workmux_config( mux_repo_path, @@ -96,6 +109,9 @@ def test_two_known_agents_each_get_prompt( """, ) + # Write RC file so new panes find the fake agents on PATH + _write_rc_with_fake_path(env, fake_agent_installer.bin_dir) + write_workmux_config( mux_repo_path, panes=[