Files
LangBot/sdk/tests/runtime/test_event_loop_monitor.py
0d84c334ba feat(sdk): move the plugin SDK into the monorepo with independent releases (LANG-420) (#2993)
* chore(sdk): import langbot-plugin-sdk v0.7.24 snapshot into sdk/ (LANG-420)

Snapshot of langbot-app/langbot-plugin-sdk at 76443bb8 (tag v0.7.24),
without history. The repository's .github/ workflows are not imported;
they are replaced by sdk-*.yml workflows in the next commit. The root
.gitignore keeps the template .vscode/launch.json.example tracked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(sdk): move the plugin SDK into the monorepo with independent releases (LANG-420)

- CI: sdk-tests.yml / sdk-box-docker.yml run the SDK suite from sdk/ in
  its own environment (Python 3.10-3.12); run-tests.yml gains a
  "Core with in-tree SDK" job that overlays sdk/ on Core's venv.
- Releases: sdk-publish.yml publishes langbot-plugin from sdk/vX.Y.Z tag
  pushes and never creates a GitHub Release. Core release workflows now
  only accept v* tags, and scripts/check_sdk_release_pin.py blocks a Core
  PyPI/Docker release whose langbot-plugin pin differs from the released,
  unchanged sdk/.
- Packaging: Core still installs the PyPI pin. Core wheel/sdist, git
  export, Docker context, release ZIP and fnOS package exclude sdk/.
- Generator/tests: generate_plugin_workspace_api.py writes sdk/ directly;
  the SDK's generator drift tests now run instead of skipping.
- Docs: AGENTS/ARCHITECTURE, sdk/ guides (+ RELEASING.md, SOURCE.json),
  agent skills and lbs probes, public docs (zh/en/ja) and dev-docs
  point at sdk/ instead of the sibling langbot-plugin-sdk checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-11-11 23:12:53 +08:00

79 lines
2.1 KiB
Python

from __future__ import annotations
import asyncio
import time
import pytest
from langbot_plugin.runtime.event_loop_monitor import EventLoopLagMonitor
@pytest.mark.parametrize(
"kwargs",
[
{"sample_interval_seconds": 0},
{"sample_interval_seconds": float("inf")},
{"recent_sample_count": 1},
{"recent_sample_count": 3601},
],
)
def test_event_loop_monitor_rejects_unbounded_configuration(kwargs) -> None:
with pytest.raises(ValueError):
EventLoopLagMonitor(**kwargs)
def test_event_loop_monitor_snapshot_is_bounded_and_reports_p95() -> None:
monitor = EventLoopLagMonitor(recent_sample_count=4)
for lag_seconds in (0.001, 0.002, 0.003, 0.004, 0.100):
monitor._record_lag_seconds(lag_seconds)
snapshot = monitor.snapshot()
assert snapshot == {
"running": False,
"samples_total": 5,
"last_lag_ms": 100,
"recent_p95_lag_ms": 100,
"recent_max_lag_ms": 100,
"max_lag_ms": 100,
}
assert len(monitor._recent_lag_ms) == 4
async def test_event_loop_monitor_start_and_stop_are_idempotent() -> None:
monitor = EventLoopLagMonitor(
sample_interval_seconds=0.001,
recent_sample_count=4,
)
monitor.start()
task = monitor._task
monitor.start()
assert monitor._task is task
for _ in range(20):
if monitor.snapshot()["samples_total"] > 0:
break
await asyncio.sleep(0.005)
assert monitor.snapshot()["samples_total"] > 0
assert monitor.snapshot()["running"] is True
await monitor.stop()
await monitor.stop()
assert monitor.snapshot()["running"] is False
assert task is not None and task.done()
async def test_event_loop_monitor_observes_real_scheduler_stall() -> None:
monitor = EventLoopLagMonitor(
sample_interval_seconds=0.005,
recent_sample_count=8,
)
monitor.start()
try:
await asyncio.sleep(0.01)
time.sleep(0.05)
await asyncio.sleep(0.01)
assert monitor.snapshot()["recent_max_lag_ms"] >= 35
finally:
await monitor.stop()