tests: feed MCP stdio input from a file, not a pipe

A fresh-clone distcheck run failed the dry-run check once with empty stdout:
rc=0, normal startup on stderr, no replies. The same input works everywhere
else, so the variable is the stdin pipe. Write the payload to a temp file and
pass the fd as stdin; the child then cannot miss bytes that were supposedly
written, and a silent exit with rc=0 becomes a real signal instead of a race.
Diagnostics on empty stdout stay in place.

Two local suites green. Version stays 0.26.0.
This commit is contained in:
lotherk committed 2026-11-21 09:05:24 +00:00
1 parent 97c79a7f1f
commit 69f941a816
1 file changed
+20 -2
+20 -2
View File
@@ -46,8 +46,26 @@ def run(msgs, home=None, extra_env=None):
env["APEX_HOME"] = home or ROOT
if extra_env:
env.update(extra_env)
proc = subprocess.run([BIN], input="\n".join(json.dumps(m) for m in msgs) + "\n",
capture_output=True, text=True, env=env, timeout=180)
payload = ("\n".join(json.dumps(m) for m in msgs) + "\n").encode()
# Feed stdin from a file, not a pipe: a pipe write that the child never sees
# would look like a silent exit and has produced a rare empty-output flake.
fd, in_path = tempfile.mkstemp(prefix="apex-stdin-")
try:
off = 0
while off < len(payload):
n = os.write(fd, payload[off:])
if n <= 0:
break
off += n
os.lseek(fd, 0, os.SEEK_SET)
proc = subprocess.run([BIN], stdin=fd, capture_output=True, text=True,
env=env, timeout=180)
finally:
os.close(fd)
try:
os.unlink(in_path)
except OSError:
pass
if not proc.stdout.strip():
sys.stderr.write("run: empty stdout (rc=%r, stderr=%r)\n" %
(proc.returncode, proc.stderr[:400]))