test: replace false-green checks with behavioral coverage (#6282)
* test: replace false-green checks with behavioral coverage * test: complete behavior-focused audit coverage
This commit is contained in:
1 parent
c7ab7aa6da
commit
74942bd190
91 files changed
+1891
-1391
No files matched your search
@@ -64,8 +64,8 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
release = threading.Event()
|
||||
captured = []
|
||||
finalized = []
|
||||
ticks = []
|
||||
ticking = True
|
||||
heartbeat_requested = asyncio.Event()
|
||||
heartbeat_progress = asyncio.Event()
|
||||
|
||||
class Lifecycle(AgentHook):
|
||||
async def on_finally(self, context):
|
||||
@@ -77,15 +77,16 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
context.messages[0]["content"] = "hook-only"
|
||||
|
||||
async def heartbeat():
|
||||
while ticking:
|
||||
ticks.append(runtime_loop.time())
|
||||
await asyncio.sleep(0.01)
|
||||
while True:
|
||||
await heartbeat_requested.wait()
|
||||
heartbeat_requested.clear()
|
||||
heartbeat_progress.set()
|
||||
|
||||
def blocked(operation, *args, **kwargs):
|
||||
captured.append((current_request_context(), current_workspace_scope(), threading.get_ident()))
|
||||
runtime_loop.call_soon_threadsafe(entered.set)
|
||||
try:
|
||||
assert release.wait(5), "test did not release prompt preparation"
|
||||
assert release.wait(10), "test did not release prompt preparation"
|
||||
return operation(*args, **kwargs)
|
||||
finally:
|
||||
runtime_loop.call_soon_threadsafe(finished.set)
|
||||
@@ -127,11 +128,11 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
tasks = [task, pulse]
|
||||
try:
|
||||
await asyncio.wait_for(entered.wait(), timeout=5)
|
||||
before = len(ticks)
|
||||
status = await asyncio.wait_for(loop.process_direct("/status", session_key="cli:status"), 0.5)
|
||||
status = await asyncio.wait_for(loop.process_direct("/status", session_key="cli:status"), 5)
|
||||
assert status is not None and "test-model" in status.content
|
||||
await asyncio.sleep(0.04)
|
||||
assert len(ticks) >= before + 2
|
||||
heartbeat_requested.set()
|
||||
await asyncio.wait_for(heartbeat_progress.wait(), 5)
|
||||
assert not release.is_set()
|
||||
assert not finished.is_set()
|
||||
assert captured[0][2] != threading.get_ident()
|
||||
if phase != "history":
|
||||
@@ -145,7 +146,7 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
if cancel:
|
||||
task.cancel()
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await asyncio.wait_for(task, 0.5)
|
||||
await asyncio.wait_for(task, 5)
|
||||
assert not finished.is_set()
|
||||
if phase != "history":
|
||||
assert len(finalized) == 1
|
||||
@@ -155,15 +156,32 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
assert final_loop is runtime_loop
|
||||
if phase != "prompt":
|
||||
assert snapshot
|
||||
# A new session queues behind the physical worker, even after its caller exits.
|
||||
# Observe the new session entering the real semaphore, not a settling delay.
|
||||
slots = loop.runner.context_governor._preparation_slots
|
||||
acquire_slot = slots.acquire
|
||||
queued = asyncio.Event()
|
||||
acquired = asyncio.Event()
|
||||
|
||||
async def acquire():
|
||||
# History preparation queues before RequestContext is bound.
|
||||
is_waiting = asyncio.current_task() is waiting
|
||||
if is_waiting:
|
||||
queued.set()
|
||||
result = await acquire_slot()
|
||||
if is_waiting:
|
||||
acquired.set()
|
||||
return result
|
||||
|
||||
monkeypatch.setattr(slots, "acquire", acquire)
|
||||
waiting = asyncio.create_task(loop.process_direct("Queued", session_key="cli:waiting"))
|
||||
tasks.append(waiting)
|
||||
await asyncio.sleep(0.04)
|
||||
await asyncio.wait_for(queued.wait(), 5)
|
||||
assert not acquired.is_set()
|
||||
assert len(provider.requests) == expected_requests
|
||||
assert not waiting.done()
|
||||
waiting.cancel()
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await asyncio.wait_for(waiting, 0.5)
|
||||
await asyncio.wait_for(waiting, 5)
|
||||
elif phase == "history":
|
||||
# The live nested payload may change after capture; the worker owns its copy.
|
||||
live.messages[0]["content"][0]["text"] = "Changed after capture"
|
||||
@@ -184,7 +202,6 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
||||
assert current_request_context() is None
|
||||
assert current_workspace_scope() is None
|
||||
finally:
|
||||
ticking = False
|
||||
release.set()
|
||||
for pending in tasks:
|
||||
if not pending.done():
|
||||
|
||||
Reference in new issue
Block a user