test(ci): remove Docker output and stdin timing races

This commit is contained in:
Xubin Ren committed 2026-11-06 09:01:58 +08:00
1 parent 112ea9d174
commit 475b045b6f
3 files changed
+53 -24

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ echo "=== Validating output ==="
PASS=true PASS=true
check() { check() {
if echo "$STATUS_OUTPUT" | grep -q "$1"; then if [[ "$STATUS_OUTPUT" == *"$1"* ]]; then
echo " PASS: found '$1'" echo " PASS: found '$1'"
else else
echo " FAIL: missing '$1'" echo " FAIL: missing '$1'"
+23 -3
View File
@@ -15,6 +15,10 @@ pytestmark = pytest.mark.skipif(
reason="the Docker smoke script runs under Unix Bash", reason="the Docker smoke script runs under Unix Bash",
) )
SCRIPT = Path(__file__).with_name("test_docker.sh") SCRIPT = Path(__file__).with_name("test_docker.sh")
STATUS_OUTPUT = (
"nanobot Status\nConfig: configured\nWorkspace: ready\nModel: test\n"
"OpenRouter API: unset\nAnthropic API: unset\nOpenAI API: unset"
)
@pytest.fixture @pytest.fixture
@@ -30,14 +34,13 @@ def docker_boundary(tmp_path):
"stage = args[0]\n" "stage = args[0]\n"
"if stage == 'run': stage = args[-1]\n" "if stage == 'run': stage = args[-1]\n"
"if stage == 'status':\n" "if stage == 'status':\n"
" print('nanobot Status\\nConfig: configured\\nWorkspace: ready\\nModel: test\\n'\n" " print(os.environ['DOCKER_STATUS_OUTPUT'])\n"
" 'OpenRouter API: unset\\nAnthropic API: unset\\nOpenAI API: unset')\n"
"if stage == os.environ.get('DOCKER_FAIL_STAGE'): sys.exit(23)\n", "if stage == os.environ.get('DOCKER_FAIL_STAGE'): sys.exit(23)\n",
encoding="utf-8", encoding="utf-8",
) )
executable.chmod(0o755) executable.chmod(0o755)
def run(name, *, fail_stage=""): def run(name, *, fail_stage="", status_output=STATUS_OUTPUT):
log = tmp_path / f"{name}.jsonl" log = tmp_path / f"{name}.jsonl"
result = subprocess.run( result = subprocess.run(
["bash", str(SCRIPT)], ["bash", str(SCRIPT)],
@@ -46,6 +49,7 @@ def docker_boundary(tmp_path):
"PATH": f"{executable.parent}{os.pathsep}{os.environ.get('PATH', '')}", "PATH": f"{executable.parent}{os.pathsep}{os.environ.get('PATH', '')}",
"DOCKER_CALLS": str(log), "DOCKER_CALLS": str(log),
"DOCKER_FAIL_STAGE": fail_stage, "DOCKER_FAIL_STAGE": fail_stage,
"DOCKER_STATUS_OUTPUT": status_output,
}, },
capture_output=True, capture_output=True,
text=True, text=True,
@@ -94,3 +98,19 @@ def test_concurrent_smoke_runs_use_distinct_resources_and_cleanup(docker_boundar
assert "All checks passed" in result.stdout assert "All checks passed" in result.stdout
resources.append(_assert_owned_cleanup(calls)) resources.append(_assert_owned_cleanup(calls))
assert resources[0].isdisjoint(resources[1]) assert resources[0].isdisjoint(resources[1])
def test_smoke_accepts_markers_before_large_diagnostic_output(docker_boundary):
# Status captures stderr too. Early grep exit must not turn valid output into SIGPIPE failure.
result, calls = docker_boundary("large", status_output=STATUS_OUTPUT + "\ndiagnostic" * 8192)
assert result.returncode == 0, result.stdout[-2000:] + result.stderr
assert "All checks passed" in result.stdout
_assert_owned_cleanup(calls)
def test_smoke_rejects_successful_status_with_missing_marker(docker_boundary):
result, calls = docker_boundary("missing", status_output=STATUS_OUTPUT.replace("Model:", ""))
assert result.returncode == 1, result.stdout + result.stderr
assert "FAIL: missing 'Model:'" in result.stdout
assert "All checks passed" not in result.stdout
_assert_owned_cleanup(calls)
+29 -20
View File
@@ -445,7 +445,7 @@ def test_exec_rejects_unsupported_shell(tmp_path):
def test_exec_can_continue_with_stdin(tmp_path): def test_exec_can_continue_with_stdin(tmp_path):
async def run() -> tuple[str, str, str]: async def run() -> tuple[str, str, str]:
manager = ExecSessionManager() manager = ExecSessionManager()
exec_tool = ExecTool(working_dir=str(tmp_path), timeout=5, session_manager=manager) exec_tool = ExecTool(working_dir=str(tmp_path), timeout=30, session_manager=manager)
stdin_tool = ExecSessionTool(manager=manager) stdin_tool = ExecSessionTool(manager=manager)
command = _python_command( command = _python_command(
"import sys; print('ready', flush=True); " "import sys; print('ready', flush=True); "
@@ -453,16 +453,18 @@ def test_exec_can_continue_with_stdin(tmp_path):
) )
try: try:
initial = await exec_tool.execute(command=command, yield_time_ms=500) initial = await exec_tool.execute(command=command, yield_time_ms=0)
sid = _session_id(initial) sid = _session_id(initial)
result = await stdin_tool.execute(session_id=sid, input="ping\n", timeout_ms=1000) if "ready" not in initial:
observed, final = await _poll_if_running(result, stdin_tool) initial += await stdin_tool.execute(session_id=sid, wait_for="ready", timeout_ms=10000)
assert "ready" in initial, initial
result = await stdin_tool.execute(session_id=sid, input="ping\n", timeout_ms=0)
observed, final = await _poll_if_running(result, stdin_tool, timeout_ms=10000)
return initial, observed, final return initial, observed, final
finally: finally:
await manager.close_all() await manager.close_all()
initial, result, final = asyncio.run(run()) initial, result, final = asyncio.run(run())
assert "ready" in initial + result
assert "Process running" in initial assert "Process running" in initial
assert "Elapsed:" in initial assert "Elapsed:" in initial
assert "got:ping" in result assert "got:ping" in result
@@ -471,30 +473,37 @@ def test_exec_can_continue_with_stdin(tmp_path):
def test_exec_session_can_close_stdin(tmp_path): def test_exec_session_can_close_stdin(tmp_path):
async def run() -> tuple[str, str]: async def run() -> tuple[str, str, str]:
manager = ExecSessionManager() manager = ExecSessionManager()
exec_tool = ExecTool(working_dir=str(tmp_path), timeout=5, session_manager=manager) exec_tool = ExecTool(working_dir=str(tmp_path), timeout=30, session_manager=manager)
stdin_tool = ExecSessionTool(manager=manager) stdin_tool = ExecSessionTool(manager=manager)
command = _python_command( command = _python_command(
"import sys; print('ready', flush=True); " "import sys; print('ready', flush=True); "
"data=sys.stdin.read(); print('got:' + data, flush=True)" "data=sys.stdin.read(); print('got:' + data, flush=True)"
) )
initial = await exec_tool.execute(command=command, yield_time_ms=1500) try:
sid = _session_id(initial) initial = await exec_tool.execute(command=command, yield_time_ms=0)
result = await stdin_tool.execute( sid = _session_id(initial)
session_id=sid, if "ready" not in initial:
input="payload", initial += await stdin_tool.execute(session_id=sid, wait_for="ready", timeout_ms=10000)
close_stdin=True, assert "ready" in initial, initial
timeout_ms=1500, # Check the acknowledgement separately from the child's EOF-driven exit.
) result = await stdin_tool.execute(
return initial, result session_id=sid,
input="payload",
close_stdin=True,
timeout_ms=0,
)
observed, final = await _poll_if_running(result, stdin_tool, timeout_ms=10000)
return result, observed, final
finally:
await manager.close_all()
initial, result = asyncio.run(run()) result, observed, final = asyncio.run(run())
assert "ready" in initial + result
assert "got:payload" in result
assert "Stdin closed." in result assert "Stdin closed." in result
assert "Exit code: 0" in result assert "got:payload" in observed
assert "Exit code: 0" in final
def test_exec_session_can_terminate_session(tmp_path): def test_exec_session_can_terminate_session(tmp_path):