11from __future__ import annotations
22
33import os
4+ import secrets
45import subprocess
56from pathlib import Path
67
910from codex import Codex , CodexOptions , ThreadStartOptions , TurnOptions
1011from codex .protocol import types as protocol
1112
12- _COMMAND_OUTPUT_UNDER_TEST = "codex-python-command-stream"
13-
1413
1514def _integration_binary_and_env (tmp_path : Path ) -> tuple [Path , str , dict [str , str ]]:
1615 if os .environ .get ("CODEX_INTEGRATION_TEST" ) != "1" :
@@ -112,6 +111,8 @@ def test_run_with_real_codex_binary_and_api_key(tmp_path: Path) -> None:
112111def test_streamed_command_events_with_real_codex_binary (tmp_path : Path ) -> None :
113112 binary , api_key , child_env = _integration_binary_and_env (tmp_path )
114113 repo = _create_git_repo (tmp_path / "repo" )
114+ command_output = f"codex-python-command-stream-{ secrets .token_hex (8 )} "
115+ (repo / ".secret-token" ).write_text (f"{ command_output } \n " , encoding = "utf-8" )
115116
116117 with Codex (
117118 CodexOptions (
@@ -133,8 +134,8 @@ def test_streamed_command_events_with_real_codex_binary(tmp_path: Path) -> None:
133134 )
134135 )
135136 stream = thread .run (
136- "Run a shell command exactly once to print "
137- f" { _COMMAND_OUTPUT_UNDER_TEST !r } . After the command completes, reply OK ." ,
137+ "Read the file .secret-token using exactly one shell command, then reply with only "
138+ "the file contents. Do not add punctuation, explanations, or extra text ." ,
138139 TurnOptions (effort = protocol .ReasoningEffort ("low" )),
139140 )
140141 events = list (stream )
@@ -152,6 +153,7 @@ def test_streamed_command_events_with_real_codex_binary(tmp_path: Path) -> None:
152153 and isinstance (event .params .item .root , protocol .CommandExecutionThreadItem )
153154 ]
154155 command_event_context = (
156+ f"expected_output={ command_output !r} \n "
155157 f"started_commands={ [item .command for item in command_started_items ]!r} \n "
156158 f"completed_commands={ [(item .command , item .exitCode , item .aggregatedOutput ) for item in command_completed_items ]!r} \n "
157159 f"final_text={ stream .final_text !r} "
@@ -163,9 +165,9 @@ def test_streamed_command_events_with_real_codex_binary(tmp_path: Path) -> None:
163165 assert any (
164166 item .exitCode == 0
165167 and item .aggregatedOutput is not None
166- and _COMMAND_OUTPUT_UNDER_TEST in item .aggregatedOutput
168+ and item .aggregatedOutput . strip () == command_output
167169 for item in command_completed_items
168170 ), command_event_context
169171 assert stream .final_turn is not None
170172 assert stream .final_turn .status .root == "completed"
171- assert stream .final_text .strip () == "OK"
173+ assert stream .final_text .strip () == command_output , command_event_context
0 commit comments