fix: shows live sessions for pty view
This commit is contained in:
@@ -234,6 +234,48 @@ async def test_complete_fresh_session_yields_events(tmp_path: Path) -> None:
|
||||
assert harness.seed_files == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_sessions_visible_during_turn_and_after(tmp_path: Path) -> None:
|
||||
"""A session must appear in ``live_sessions`` *while* its turn runs — so
|
||||
the admin terminal viewer can attach mid-flight, not only once the turn
|
||||
is done — and must stay visible as an idle pooled session afterwards so
|
||||
snapshots / interaction with a quiet terminal keep working.
|
||||
|
||||
Regression guard: the session is popped from the fingerprint pool (or
|
||||
not yet pooled, on a fresh spawn) for the duration of the turn, so
|
||||
without the in-flight ``_active`` registry an active session is
|
||||
invisible to ``live_sessions``.
|
||||
"""
|
||||
scripts_per_session = [
|
||||
[
|
||||
[_user_rec("hi", "S0"), _assistant_rec("hello there", "S0")],
|
||||
],
|
||||
]
|
||||
harness = FakeFactoryHarness(scripts_per_session)
|
||||
backend = ClaudeCodeBackend(
|
||||
BackendOptions(cwd=str(tmp_path)),
|
||||
_session_factory=harness,
|
||||
)
|
||||
|
||||
seen_live_mid = False
|
||||
async for _event in backend.complete([{"role": "user", "content": "hi"}]):
|
||||
live = backend.live_sessions
|
||||
if live:
|
||||
seen_live_mid = True
|
||||
# The only live pty is the one the harness spawned for this turn.
|
||||
assert list(live.values()) == [harness.spawned[0]]
|
||||
|
||||
# The regression we're guarding against: visible *during* the turn.
|
||||
assert seen_live_mid
|
||||
# Still visible once the turn finishes — repooled idle session, so the
|
||||
# viewer can snapshot / interact exactly as before.
|
||||
assert list(backend.live_sessions.values()) == [harness.spawned[0]]
|
||||
|
||||
await backend.aclose()
|
||||
# Teardown clears the pool.
|
||||
assert backend.live_sessions == {}
|
||||
|
||||
|
||||
# --- multi-turn fingerprint reuse ----------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user