fix(bridge): session_runner 将 stderr 合并到 stdout 流

将子进程 stderr=PIPE 改为 stderr=STDOUT,确保 stderr
输出不会因无人读取而阻塞子进程,同时简化调用方对输出流的处理

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
yl-jiang
2026-04-27 17:02:11 +08:00
parent 0305dfb3ec
commit 593dcbcaeb
2 changed files with 33 additions and 1 deletions
+1 -1
View File
@@ -41,6 +41,6 @@ async def spawn_session(
command,
cwd=resolved_cwd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
)
return SessionHandle(session_id=session_id, process=process, cwd=resolved_cwd)
+32
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
from pathlib import Path
import asyncio
import pytest
@@ -27,3 +28,34 @@ async def test_spawn_session_and_kill(tmp_path: Path):
assert handle.process.returncode is None
await handle.kill()
assert handle.process.returncode is not None
@pytest.mark.asyncio
async def test_spawn_session_merges_stderr_into_stdout(monkeypatch, tmp_path: Path):
seen_kwargs = {}
class FakeProcess:
returncode = 0
def terminate(self):
pass
def kill(self):
pass
async def wait(self):
return 0
async def fake_create_shell_subprocess(*args, **kwargs):
seen_kwargs.update(kwargs)
return FakeProcess()
monkeypatch.setattr(
"openharness.bridge.session_runner.create_shell_subprocess",
fake_create_shell_subprocess,
)
await spawn_session(session_id="s1", command="printf err >&2", cwd=tmp_path)
assert seen_kwargs["stdout"] is asyncio.subprocess.PIPE
assert seen_kwargs["stderr"] is asyncio.subprocess.STDOUT