Skip to content

Commit b672f17

Browse files
committed
test(app-server): simplify real binary command stream
1 parent 34f6b6b commit b672f17

1 file changed

Lines changed: 19 additions & 38 deletions

File tree

tests/test_integration_real_binary.py

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import base64
55
import os
6-
import subprocess
76
from pathlib import Path
87

98
import pytest
@@ -13,7 +12,7 @@
1312
from codex.app_server.options import AppServerProcessOptions
1413
from codex.protocol import types as protocol
1514

16-
_COMMAND_UNDER_TEST = "git diff --no-color HEAD~1...HEAD"
15+
_COMMAND_OUTPUT_UNDER_TEST = "codex-python-integration-output"
1716

1817

1918
def _integration_binary_and_env(tmp_path: Path) -> tuple[Path, str, dict[str, str]]:
@@ -55,32 +54,6 @@ def _integration_binary_and_env(tmp_path: Path) -> tuple[Path, str, dict[str, st
5554
return binary, api_key, child_env
5655

5756

58-
def _create_git_repo(path: Path) -> Path:
59-
path.mkdir()
60-
_git(path, "init")
61-
_git(path, "config", "user.email", "codex-python-tests@example.com")
62-
_git(path, "config", "user.name", "Codex Python Tests")
63-
64-
tracked_file = path / "notes.txt"
65-
tracked_file.write_text("one\n", encoding="utf-8")
66-
_git(path, "add", "notes.txt")
67-
_git(path, "commit", "-m", "initial")
68-
69-
tracked_file.write_text("two\nthree\n", encoding="utf-8")
70-
_git(path, "commit", "-am", "second")
71-
return path
72-
73-
74-
def _git(repo: Path, *args: str) -> None:
75-
subprocess.run(
76-
["git", *args],
77-
cwd=repo,
78-
check=True,
79-
capture_output=True,
80-
text=True,
81-
)
82-
83-
8457
def test_run_with_real_codex_binary_and_api_key(tmp_path: Path) -> None:
8558
binary, api_key, child_env = _integration_binary_and_env(tmp_path)
8659

@@ -118,7 +91,6 @@ def test_run_with_real_codex_binary_and_api_key(tmp_path: Path) -> None:
11891

11992
def test_streamed_command_exec_events_with_real_codex_binary(tmp_path: Path) -> None:
12093
binary, _api_key, child_env = _integration_binary_and_env(tmp_path)
121-
repo = _create_git_repo(tmp_path / "repo")
12294

12395
async def scenario() -> None:
12496
client = await AsyncAppServerClient.connect_stdio(
@@ -132,15 +104,16 @@ async def scenario() -> None:
132104
subscription = client.events.subscribe({"command/exec/outputDelta"})
133105
command_task = asyncio.create_task(
134106
client.command.execute(
135-
command=["/bin/sh", "-lc", _COMMAND_UNDER_TEST],
136-
cwd=str(repo),
107+
command=["/bin/sh", "-c", f"printf {_COMMAND_OUTPUT_UNDER_TEST}"],
108+
cwd=str(tmp_path),
137109
process_id=process_id,
138110
stream_stdout_stderr=True,
139111
timeout_ms=5000,
140112
)
141113
)
142114

143115
stdout_chunks: list[str] = []
116+
stderr_chunks: list[str] = []
144117
observed_events: list[str] = []
145118

146119
while True:
@@ -157,20 +130,28 @@ async def scenario() -> None:
157130
continue
158131
if event.params.processId != process_id:
159132
continue
160-
if event.params.stream.root != "stdout":
161-
continue
162-
stdout_chunks.append(base64.b64decode(event.params.deltaBase64).decode())
133+
output_chunk = base64.b64decode(event.params.deltaBase64).decode()
134+
if event.params.stream.root == "stdout":
135+
stdout_chunks.append(output_chunk)
136+
if event.params.stream.root == "stderr":
137+
stderr_chunks.append(output_chunk)
163138

164139
result = await command_task
165140
await subscription.close()
166141
event_summary = "\n".join(observed_events)
167142
streamed_stdout = "".join(stdout_chunks)
168-
assert result.exit_code == 0
143+
streamed_stderr = "".join(stderr_chunks)
144+
failure_context = (
145+
f"result={result!r}\n"
146+
f"streamed_stdout={streamed_stdout!r}\n"
147+
f"streamed_stderr={streamed_stderr!r}\n"
148+
f"{event_summary}"
149+
)
150+
assert result.exit_code == 0, failure_context
169151
assert result.stderr == ""
170152
assert result.stdout == ""
171-
assert "-one" in streamed_stdout, event_summary
172-
assert "+two" in streamed_stdout, event_summary
173-
assert "+three" in streamed_stdout, event_summary
153+
assert streamed_stdout == _COMMAND_OUTPUT_UNDER_TEST, failure_context
154+
assert streamed_stderr == "", failure_context
174155
finally:
175156
await client.close()
176157

0 commit comments

Comments
 (0)