import os, sys, subprocess, tempfile sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src")) from pgar.launcher import build_command, remote_shell_line def test_prompt_file_reaches_client_as_one_argument(): """Simulate the remote shell line locally with a fake `claude` that prints its argv, and check the whole prompt arrives as one argument.""" d = tempfile.mkdtemp(); pf = os.path.join(d, "prompt.txt"); open(pf, "w").write("Begin now. The task is in TASK.md; stop when done.\n") fake = os.path.join(d, "claude"); open(fake, "w").write("#!/bin/sh\nfor a in \"$@\"; do printf '%s\\n' \"$a\"; done\n"); os.chmod(fake, 0o755) open(os.path.join(d, ".env"), "w").write("X=1\n") argv = build_command(d, d, pf, os.path.join(d, "sys.md"), "m", "sid", 1.0, 5) line = remote_shell_line(d, argv, env_file=os.path.join(d, ".env")).replace("export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH", f"export PATH={d}:$PATH") out = subprocess.run(["bash", "-c", line], capture_output=True, text=True).stdout.splitlines() i = out.index("-p") + 1 assert out[i].startswith("Begin now. The task is in TASK.md"), out[:6]