Skip to content
Open
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
16 changes: 16 additions & 0 deletions tests/test_workmux_add/test_named_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for known agent auto-detection and prompt injection."""

import os
import shlex
from pathlib import Path

Expand All @@ -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."""

Expand All @@ -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 <agent:> placeholder, no global agent
write_workmux_config(
mux_repo_path,
Expand Down Expand Up @@ -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=[
Expand Down