ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s

This commit is contained in:
2026-08-20 13:12:50 +00:00
commit b119135836
10275 changed files with 3284984 additions and 0 deletions
@@ -0,0 +1,32 @@
import asyncio
import pytest
import sys
from pathlib import Path
# Ensure chapter10/parallel-web-research is in sys.path
sys.path.insert(0, str(Path(__file__).parent))
from agents import WorkerAgent
from message_bus import MessageBus, BROADCAST
from sources import Website
@pytest.mark.asyncio
async def test_worker_exits_early_when_terminate_arrives_before_task_assigned():
"""Contract proved: WorkerAgent handles terminate broadcast received before task_assigned without hanging or ignoring the signal.
Bug locked out: infinite loop awaiting task_assigned while ignoring terminate signal."""
bus = MessageBus(verbose=False)
site = Website("s1", "http://site1.edu", "College 1")
w = WorkerAgent("worker-1", site, bus, "target", None)
# Broadcast terminate to bus BEFORE worker-1 gets task_assigned
await bus.send("coordinator", BROADCAST, "terminate", {"reason": "target_found_by_other"})
# w.run() must exit promptly (not hang awaiting task_assigned), set terminate event, and send ACK
await asyncio.wait_for(w.run(), timeout=2.0)
assert w.terminate.is_set()
assert w._termination_reason == "target_found_by_other"
acks = [m for m in bus.history if m.type == "ack" and m.sender_id == "worker-1"]
assert len(acks) == 1
assert acks[0].payload.get("acked") == "terminate"