This commit is contained in:
@@ -121,12 +121,6 @@ async def test_concurrent_readiness_checks_share_one_probe(tmp_path: Path) -> No
|
||||
PROVIDERS,
|
||||
["/global/health", "/doc"],
|
||||
),
|
||||
(
|
||||
{"healthy": True, "version": "1.18.4"},
|
||||
API_DOCUMENT,
|
||||
{**PROVIDERS, "connected": ["anthropic"]},
|
||||
["/global/health", "/doc", "/provider"],
|
||||
),
|
||||
(
|
||||
{"healthy": True, "version": "1.18.4"},
|
||||
API_DOCUMENT,
|
||||
@@ -349,169 +343,3 @@ async def test_structured_validation_retry_exhaustion_reports_final_error(
|
||||
assert "without repeating repository work" in prompts[1]
|
||||
assert paths[-1] == "/session/ses_existing/abort"
|
||||
await value.close()
|
||||
|
||||
|
||||
async def test_cleanup_failure_does_not_mask_turn_error(tmp_path: Path) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
workspace.mkdir()
|
||||
paths: list[str] = []
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
paths.append(request.url.path)
|
||||
if request.url.path.endswith("/abort"):
|
||||
return httpx.Response(500, text="abort failed")
|
||||
return httpx.Response(200, json={"unexpected": True})
|
||||
|
||||
value = client(tmp_path, handler)
|
||||
with pytest.raises(
|
||||
OpenCodeError,
|
||||
match="OpenCode response did not include assistant metadata",
|
||||
):
|
||||
await value.resume(
|
||||
session_id="ses_existing",
|
||||
workspace=workspace,
|
||||
prompt="continue",
|
||||
model="openai/model",
|
||||
variant=None,
|
||||
schema_name="agent_result.json",
|
||||
result_type=AgentResult,
|
||||
)
|
||||
|
||||
assert paths == [
|
||||
"/session/ses_existing/message",
|
||||
"/session/ses_existing/abort",
|
||||
]
|
||||
await value.close()
|
||||
|
||||
|
||||
async def test_close_aborts_an_active_session(tmp_path: Path) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
workspace.mkdir()
|
||||
message_started = asyncio.Event()
|
||||
release_message = asyncio.Event()
|
||||
paths: list[str] = []
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
paths.append(request.url.path)
|
||||
if request.url.path.endswith("/abort"):
|
||||
assert request.headers["x-opencode-directory"] == str(workspace.resolve())
|
||||
return httpx.Response(200, json=True)
|
||||
message_started.set()
|
||||
await release_message.wait()
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"info": {"structured": {"summary_markdown": "finished", "tests": []}},
|
||||
"parts": [],
|
||||
},
|
||||
)
|
||||
|
||||
value = client(tmp_path, handler)
|
||||
turn = asyncio.create_task(
|
||||
value.resume(
|
||||
session_id="ses_active",
|
||||
workspace=workspace,
|
||||
prompt="continue",
|
||||
model="openai/model",
|
||||
variant=None,
|
||||
schema_name="agent_result.json",
|
||||
result_type=AgentResult,
|
||||
)
|
||||
)
|
||||
await message_started.wait()
|
||||
|
||||
await value.close()
|
||||
release_message.set()
|
||||
result = await turn
|
||||
|
||||
assert result.summary_markdown == "finished"
|
||||
assert paths == ["/session/ses_active/message", "/session/ses_active/abort"]
|
||||
assert value.client.is_closed
|
||||
|
||||
|
||||
async def test_close_continues_after_active_session_abort_failure(tmp_path: Path) -> None:
|
||||
paths: list[str] = []
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
paths.append(request.url.path)
|
||||
if "/failed/" in request.url.path:
|
||||
return httpx.Response(503)
|
||||
return httpx.Response(200, json=True)
|
||||
|
||||
value = client(tmp_path, handler)
|
||||
value._active_sessions.update(
|
||||
{
|
||||
"failed": tmp_path / "first",
|
||||
"succeeds": tmp_path / "second",
|
||||
}
|
||||
)
|
||||
|
||||
await value.close()
|
||||
|
||||
assert paths == ["/session/failed/abort", "/session/succeeds/abort"]
|
||||
assert value.client.is_closed
|
||||
|
||||
|
||||
async def test_aborts_timed_out_session(tmp_path: Path) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
workspace.mkdir()
|
||||
abort_count = 0
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
nonlocal abort_count
|
||||
if request.url.path.endswith("/abort"):
|
||||
abort_count += 1
|
||||
return httpx.Response(200, json=True)
|
||||
raise httpx.ReadTimeout("slow", request=request)
|
||||
|
||||
value = client(tmp_path, handler)
|
||||
with pytest.raises(OpenCodeError, match="exceeded 60 seconds"):
|
||||
await value.resume(
|
||||
session_id="ses_existing",
|
||||
workspace=workspace,
|
||||
prompt="continue",
|
||||
model="openai/model",
|
||||
variant=None,
|
||||
schema_name="agent_result.json",
|
||||
result_type=AgentResult,
|
||||
)
|
||||
|
||||
assert abort_count == 1
|
||||
await value.close()
|
||||
|
||||
|
||||
async def test_aborts_cancelled_session(tmp_path: Path) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
workspace.mkdir()
|
||||
started = asyncio.Event()
|
||||
aborted = False
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
nonlocal aborted
|
||||
if request.url.path.endswith("/abort"):
|
||||
aborted = True
|
||||
return httpx.Response(200, json=True)
|
||||
started.set()
|
||||
await asyncio.Event().wait()
|
||||
raise AssertionError("unreachable")
|
||||
|
||||
value = client(tmp_path, handler)
|
||||
turn = asyncio.create_task(
|
||||
value.resume(
|
||||
session_id="ses_existing",
|
||||
workspace=workspace,
|
||||
prompt="continue",
|
||||
model="openai/model",
|
||||
variant=None,
|
||||
schema_name="agent_result.json",
|
||||
result_type=AgentResult,
|
||||
)
|
||||
)
|
||||
await started.wait()
|
||||
turn.cancel()
|
||||
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await turn
|
||||
|
||||
assert aborted
|
||||
await value.close()
|
||||
|
||||
Reference in New Issue
Block a user