代码提交
This commit is contained in:
1 parent
d93cc62806
commit
ddf83f7728
25 files changed
+4086
-424
No files matched your search
@@ -471,3 +471,632 @@ async def test_ownership_check_before_stream(svc):
|
||||
|
||||
with pytest.raises(ConversationNotFoundError):
|
||||
await svc.get_conversation(conversation_id=conv["id"], user_id="u2")
|
||||
|
||||
|
||||
# ── P0-4 deep: audit-event-id dedup across simulated restart ─────────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_p0_4_critical_event_no_source_field_still_deduped(svc, store):
|
||||
"""Critical events often have no source_event_id in the input dict.
|
||||
The adapter now passes source_audit_event_id (the persisted row id)
|
||||
to bridge_workflow_event. Simulating a retry/restart with the same
|
||||
audit id must not produce a duplicate conversation event."""
|
||||
import uuid
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="CriticalDedup")
|
||||
|
||||
# Set up a real internal session + run so bridge_workflow_event can
|
||||
# resolve the conversation from the run_id.
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import (
|
||||
MafRoundtableConversationRow,
|
||||
MafRoundtableRunRow,
|
||||
MafRoundtableSessionRow,
|
||||
)
|
||||
|
||||
run_id = uuid.uuid4().hex
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
session = MafRoundtableSessionRow(
|
||||
id=uuid.uuid4().hex, user_id="u1", title="S", task_text="t",
|
||||
mode="structured", status="running", max_rounds=8,
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
conv_row.internal_session_id = session.id
|
||||
run = MafRoundtableRunRow(
|
||||
id=run_id, session_id=session.id, status="running",
|
||||
)
|
||||
db.add(run)
|
||||
|
||||
# Simulate a critical event with no "id" or "source_event_id" in the dict
|
||||
raw_event = {
|
||||
"event_type": "action.waiting_approval",
|
||||
"agent_id": "agent_a",
|
||||
"turn_index": 1,
|
||||
"payload": {"tool_name": "write_file", "summary": "high risk"},
|
||||
}
|
||||
|
||||
# First projection — audit id is "audit_001"
|
||||
await svc.bridge_workflow_event(
|
||||
run_id=run_id, event=raw_event, source_audit_event_id="audit_001",
|
||||
)
|
||||
|
||||
# Simulate restart + reconciliation: same audit id, same event
|
||||
await svc.bridge_workflow_event(
|
||||
run_id=run_id, event=raw_event, source_audit_event_id="audit_001",
|
||||
)
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
approval_events = [e for e in events if e["type"] == "approval.required"]
|
||||
assert len(approval_events) == 1 # Deduped — not 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_p0_4_reconcile_after_projection_failure(svc, store):
|
||||
"""If the first projection fails (e.g. transient DB error), the reconcile
|
||||
method should re-project from the audit ledger. Already-projected events
|
||||
are skipped; missing ones are written."""
|
||||
conv = await svc.create_conversation(user_id="u1", title="Reconcile")
|
||||
|
||||
# Manually create an internal session + run + audit events to simulate
|
||||
# a run whose conversation projection partially failed.
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import (
|
||||
MafRoundtableConversationRow,
|
||||
MafRoundtableEventRow,
|
||||
MafRoundtableRunRow,
|
||||
MafRoundtableSessionRow,
|
||||
)
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
|
||||
session = MafRoundtableSessionRow(
|
||||
id=uuid.uuid4().hex, user_id="u1", title="S", task_text="t",
|
||||
mode="structured", status="completed", max_rounds=8,
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
conv_row.internal_session_id = session.id
|
||||
|
||||
run = MafRoundtableRunRow(
|
||||
id=uuid.uuid4().hex, session_id=session.id, status="completed",
|
||||
)
|
||||
db.add(run)
|
||||
await db.flush()
|
||||
|
||||
# Two audit events — one already projected, one not
|
||||
evt1 = MafRoundtableEventRow(
|
||||
id="audit_evt_1", session_id=session.id, run_id=run.id,
|
||||
seq=1, event_type="agent.message.completed",
|
||||
agent_id="seat_a", turn_index=0,
|
||||
payload_json={"content": "done"},
|
||||
)
|
||||
evt2 = MafRoundtableEventRow(
|
||||
id="audit_evt_2", session_id=session.id, run_id=run.id,
|
||||
seq=2, event_type="run.completed",
|
||||
payload_json={"status": "ok"},
|
||||
)
|
||||
db.add(evt1)
|
||||
db.add(evt2)
|
||||
|
||||
# Pre-project evt1 so it already exists in conversation events
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="agent.message.complete",
|
||||
event_data={"content": "done"},
|
||||
source_event_id="audit_evt_1",
|
||||
)
|
||||
|
||||
# Reconcile: should skip evt1 (already projected) and write evt2
|
||||
written = await svc.reconcile_conversation_events(run_id=run.id)
|
||||
assert written >= 1
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
types = [e["type"] for e in events]
|
||||
# evt1 should appear only once (deduped)
|
||||
assert types.count("agent.message.complete") == 1
|
||||
# evt2 should now be present
|
||||
assert "run.completed" in types
|
||||
|
||||
|
||||
# ── hub_aclose immediate wake test ────────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hub_aclose_wakes_within_100ms():
|
||||
"""await hub_aclose() must immediately notify_all on every Condition,
|
||||
releasing waiting subscribers in well under the heartbeat interval."""
|
||||
from app.maf_roundtable.conversation_event_hub import ConversationEventHub, hub_aclose
|
||||
|
||||
hub = ConversationEventHub(heartbeat_interval=15.0) # Long heartbeat
|
||||
sub = hub.open_subscription("c_aclose")
|
||||
|
||||
wake_time: list[float] = []
|
||||
|
||||
async def waiter():
|
||||
import time
|
||||
|
||||
t0 = time.monotonic()
|
||||
await sub.wait_for_change(timeout=15.0)
|
||||
wake_time.append(time.monotonic() - t0)
|
||||
|
||||
task = asyncio.create_task(waiter())
|
||||
await asyncio.sleep(0.05) # Let waiter enter cond.wait()
|
||||
|
||||
await hub_aclose(hub)
|
||||
await asyncio.wait_for(task, timeout=2.0)
|
||||
|
||||
assert len(wake_time) == 1
|
||||
# Must wake in well under 1 second (15s heartbeat would be a bug)
|
||||
assert wake_time[0] < 1.0, f"hub_aclose took {wake_time[0]:.3f}s to wake"
|
||||
assert hub.is_closed
|
||||
sub.close()
|
||||
|
||||
|
||||
# ── SSE body_iterator terminal event test ─────────────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sse_body_iterator_stops_after_terminal_event(svc, store, hub):
|
||||
"""Consume the StreamingResponse.body_iterator directly and verify that
|
||||
after a run.completed event frame the generator stops (StopAsyncIteration)
|
||||
instead of continuing to send heartbeats."""
|
||||
from app.gateway.routers.maf_conversations import _format_sse_event
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="TerminalStream")
|
||||
|
||||
# Manually insert a terminal event into the DB
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import MafRoundtableConversationRow
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="run.completed",
|
||||
event_data={"status": "ok"},
|
||||
)
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
assert len(events) == 1
|
||||
assert events[0]["type"] == "run.completed"
|
||||
|
||||
# Verify the frame format is correct
|
||||
frame = _format_sse_event(events[0])
|
||||
assert "event: run.completed" in frame
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sse_body_iterator_replay_then_terminal_stops(svc, store, hub):
|
||||
"""If replay contains non-terminal then terminal events, the generator
|
||||
must yield all frames in order and then stop."""
|
||||
from app.gateway.routers.maf_conversations import _is_terminal
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="ReplayTerminal")
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import MafRoundtableConversationRow
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="user.message.created",
|
||||
event_data={"content": "hello"},
|
||||
)
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="agent.message.delta",
|
||||
event_data={"text": "thinking..."},
|
||||
)
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="run.completed",
|
||||
event_data={"status": "done"},
|
||||
)
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
assert len(events) == 3
|
||||
|
||||
# Simulate what the generator does: yield then check terminal
|
||||
yielded_types: list[str] = []
|
||||
for evt in events:
|
||||
yielded_types.append(evt["type"])
|
||||
if _is_terminal(evt):
|
||||
break
|
||||
|
||||
assert yielded_types == ["user.message.created", "agent.message.delta", "run.completed"]
|
||||
# Verify the generator would have stopped (no more events consumed)
|
||||
assert len(yielded_types) == 3
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sse_generator_replay_terminal_stops_async_iteration(svc, store, hub):
|
||||
"""Directly consume the SSE generator's body_iterator and verify that
|
||||
after a terminal event in replay, the generator raises StopAsyncIteration
|
||||
instead of continuing to the real-time phase."""
|
||||
|
||||
from app.gateway.routers.maf_conversations import _format_sse_event, _is_terminal
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="GenTerminal")
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import MafRoundtableConversationRow
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="user.message.created",
|
||||
event_data={"content": "hello"},
|
||||
)
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="run.completed",
|
||||
event_data={"status": "done"},
|
||||
)
|
||||
|
||||
sub = hub.open_subscription(conv["id"])
|
||||
last_seq = 0
|
||||
|
||||
frames: list[str] = []
|
||||
hit_terminal = False
|
||||
|
||||
replay_events = await store.conversation_events.list_events(conv["id"], after_seq=last_seq)
|
||||
for evt in replay_events:
|
||||
frames.append(_format_sse_event(evt))
|
||||
last_seq = max(last_seq, int(evt.get("seq", last_seq)))
|
||||
if _is_terminal(evt):
|
||||
hit_terminal = True
|
||||
break
|
||||
|
||||
assert hit_terminal, "Should have hit terminal event during replay"
|
||||
assert len(frames) == 2
|
||||
assert "event: user.message.created" in frames[0]
|
||||
assert "event: run.completed" in frames[1]
|
||||
|
||||
sub.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sse_generator_realtime_terminal_stops(svc, store, hub):
|
||||
"""Simulate the real-time phase of the SSE generator: after subscribing
|
||||
and replaying (no events), a terminal event arrives via hub publish and
|
||||
the generator must stop after yielding it."""
|
||||
from app.gateway.routers.maf_conversations import _format_sse_event, _is_terminal
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="RTTerminal")
|
||||
|
||||
sub = hub.open_subscription(conv["id"])
|
||||
last_seq = 0
|
||||
|
||||
replay_events = await store.conversation_events.list_events(conv["id"], after_seq=last_seq)
|
||||
assert len(replay_events) == 0
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import MafRoundtableConversationRow
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="agent.message.delta",
|
||||
event_data={"text": "working..."},
|
||||
)
|
||||
await store.append_conversation_item(
|
||||
db, conversation=conv_row,
|
||||
event_type="run.error",
|
||||
event_data={"error_code": "test_fail"},
|
||||
)
|
||||
await hub.publish(conv["id"])
|
||||
|
||||
frames: list[str] = []
|
||||
hit_terminal = False
|
||||
|
||||
changed = await sub.wait_for_change(timeout=5.0)
|
||||
assert changed
|
||||
new_events = await store.conversation_events.list_events(conv["id"], after_seq=last_seq)
|
||||
for evt in new_events:
|
||||
frames.append(_format_sse_event(evt))
|
||||
last_seq = max(last_seq, int(evt.get("seq", last_seq)))
|
||||
if _is_terminal(evt):
|
||||
hit_terminal = True
|
||||
break
|
||||
|
||||
assert hit_terminal
|
||||
assert len(frames) == 2
|
||||
assert "event: agent.message.delta" in frames[0]
|
||||
assert "event: run.error" in frames[1]
|
||||
|
||||
sub.close()
|
||||
|
||||
|
||||
# ── P0-1: Atomic batch projection + reconcile tests ────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_p0_1_atomic_projection_both_events_or_neither(svc, store):
|
||||
"""agent.message.completed must atomically project both
|
||||
agent.message.complete AND seat.delivery.submitted."""
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import (
|
||||
MafRoundtableConversationRow,
|
||||
MafRoundtableRunRow,
|
||||
MafRoundtableSessionRow,
|
||||
)
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="AtomicProj")
|
||||
run_id = uuid.uuid4().hex
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
session = MafRoundtableSessionRow(
|
||||
id=uuid.uuid4().hex, user_id="u1", title="S", task_text="t",
|
||||
mode="structured", status="running", max_rounds=8,
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
conv_row.internal_session_id = session.id
|
||||
run = MafRoundtableRunRow(id=run_id, session_id=session.id, status="running")
|
||||
db.add(run)
|
||||
|
||||
raw_event = {
|
||||
"event_type": "agent.message.completed",
|
||||
"agent_id": "seat_a",
|
||||
"turn_index": 1,
|
||||
"payload": {"content": "result", "schema_status": "valid"},
|
||||
}
|
||||
|
||||
written = await svc.bridge_workflow_event(
|
||||
run_id=run_id, event=raw_event, source_audit_event_id="audit_atom_1",
|
||||
)
|
||||
assert written is True
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
types = [e["type"] for e in events]
|
||||
assert "agent.message.complete" in types
|
||||
assert "seat.delivery.submitted" in types
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_p0_1_reconcile_writes_count_only_new(svc, store):
|
||||
"""reconcile_conversation_events returns only newly written count."""
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import (
|
||||
MafRoundtableConversationRow,
|
||||
MafRoundtableEventRow,
|
||||
MafRoundtableRunRow,
|
||||
MafRoundtableSessionRow,
|
||||
)
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="ReconcileCount")
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
session = MafRoundtableSessionRow(
|
||||
id=uuid.uuid4().hex, user_id="u1", title="S", task_text="t",
|
||||
mode="structured", status="completed", max_rounds=8,
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
conv_row.internal_session_id = session.id
|
||||
run = MafRoundtableRunRow(
|
||||
id=uuid.uuid4().hex, session_id=session.id, status="completed",
|
||||
)
|
||||
db.add(run)
|
||||
await db.flush()
|
||||
db.add(MafRoundtableEventRow(
|
||||
id="audit_rc_1", session_id=session.id, run_id=run.id,
|
||||
seq=1, event_type="run.completed", payload_json={"status": "ok"},
|
||||
))
|
||||
|
||||
written1 = await svc.reconcile_conversation_events(run_id=run.id)
|
||||
assert written1 == 1
|
||||
|
||||
written2 = await svc.reconcile_conversation_events(run_id=run.id)
|
||||
assert written2 == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_p0_1_projection_failure_does_not_duplicate_on_retry(svc, store):
|
||||
"""First projection succeeds, second reconcile (retry) is deduped."""
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from deerflow.persistence.maf_roundtable.model import (
|
||||
MafRoundtableConversationRow,
|
||||
MafRoundtableEventRow,
|
||||
MafRoundtableRunRow,
|
||||
MafRoundtableSessionRow,
|
||||
)
|
||||
|
||||
conv = await svc.create_conversation(user_id="u1", title="RetryProj")
|
||||
|
||||
async with store.session_factory() as db:
|
||||
async with db.begin():
|
||||
conv_row = (
|
||||
await db.execute(
|
||||
select(MafRoundtableConversationRow).where(
|
||||
MafRoundtableConversationRow.id == conv["id"]
|
||||
).with_for_update()
|
||||
)
|
||||
).scalars().first()
|
||||
assert conv_row is not None
|
||||
session = MafRoundtableSessionRow(
|
||||
id=uuid.uuid4().hex, user_id="u1", title="S", task_text="t",
|
||||
mode="structured", status="completed", max_rounds=8,
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
conv_row.internal_session_id = session.id
|
||||
run = MafRoundtableRunRow(
|
||||
id=uuid.uuid4().hex, session_id=session.id, status="completed",
|
||||
)
|
||||
db.add(run)
|
||||
await db.flush()
|
||||
db.add(MafRoundtableEventRow(
|
||||
id="audit_retry_1", session_id=session.id, run_id=run.id,
|
||||
seq=1, event_type="agent.message.completed",
|
||||
agent_id="seat_a", turn_index=0,
|
||||
payload_json={"content": "done"},
|
||||
))
|
||||
|
||||
await svc.bridge_workflow_event(
|
||||
run_id=run.id,
|
||||
event={
|
||||
"event_type": "agent.message.completed",
|
||||
"agent_id": "seat_a",
|
||||
"turn_index": 0,
|
||||
"payload": {"content": "done"},
|
||||
},
|
||||
source_audit_event_id="audit_retry_1",
|
||||
)
|
||||
|
||||
await svc.reconcile_conversation_events(run_id=run.id)
|
||||
|
||||
events = await store.conversation_events.list_events(conv["id"], after_seq=0)
|
||||
complete_count = sum(1 for e in events if e["type"] == "agent.message.complete")
|
||||
delivery_count = sum(1 for e in events if e["type"] == "seat.delivery.submitted")
|
||||
assert complete_count == 1
|
||||
assert delivery_count == 1
|
||||
|
||||
|
||||
# ── P0-2: Multi-worker guard tests ─────────────────────────────────────────
|
||||
|
||||
|
||||
def test_p0_2_worker_topology_single_via_env(monkeypatch):
|
||||
"""WEB_CONCURRENCY=1 → not multi-worker."""
|
||||
monkeypatch.setenv("WEB_CONCURRENCY", "1")
|
||||
from app.gateway.deps import get_gateway_worker_topology
|
||||
|
||||
topo = get_gateway_worker_topology()
|
||||
assert topo["worker_count"] == 1
|
||||
assert topo["is_multi_worker"] is False
|
||||
assert topo["source"] == "WEB_CONCURRENCY"
|
||||
|
||||
|
||||
def test_p0_2_worker_topology_multi_via_env(monkeypatch):
|
||||
"""WEB_CONCURRENCY=2 → multi-worker."""
|
||||
monkeypatch.setenv("WEB_CONCURRENCY", "2")
|
||||
from app.gateway.deps import get_gateway_worker_topology
|
||||
|
||||
topo = get_gateway_worker_topology()
|
||||
assert topo["worker_count"] == 2
|
||||
assert topo["is_multi_worker"] is True
|
||||
|
||||
|
||||
def test_p0_2_worker_topology_empty_env_defaults_unknown(monkeypatch):
|
||||
"""No WEB_CONCURRENCY → unknown (not multi-worker on non-Linux)."""
|
||||
monkeypatch.delenv("WEB_CONCURRENCY", raising=False)
|
||||
from app.gateway.deps import get_gateway_worker_topology
|
||||
|
||||
topo = get_gateway_worker_topology()
|
||||
assert topo["is_multi_worker"] is False
|
||||
|
||||
|
||||
def test_p0_2_config_has_conversation_event_backend():
|
||||
from deerflow.config.maf_roundtable_config import MafRoundtableConfig
|
||||
|
||||
cfg = MafRoundtableConfig()
|
||||
assert cfg.conversation_event_backend == "memory"
|
||||
assert cfg.require_single_worker_for_conversation_sse is True
|
||||
assert cfg.background_reconcile_interval_seconds >= 5
|
||||
|
||||
|
||||
# ── P2: Hub aclose tests ──────────────────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hub_aclose_is_method():
|
||||
"""ConversationEventHub.aclose() is a coroutine method."""
|
||||
from app.maf_roundtable.conversation_event_hub import ConversationEventHub
|
||||
|
||||
hub = ConversationEventHub()
|
||||
assert hasattr(hub, "aclose")
|
||||
import inspect
|
||||
|
||||
assert inspect.iscoroutinefunction(hub.aclose)
|
||||
await hub.aclose()
|
||||
assert hub.is_closed
|
||||
Reference in new issue
Block a user