mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-11-22 13:37:32 +08:00
* 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>
117 lines
3.4 KiB
Python
117 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
from langbot_plugin.runtime.plugin.logbuffer import MAX_LOG_LINE_BYTES, PluginLogBuffer
|
|
|
|
|
|
def test_parses_standard_log_line_level():
|
|
buf = PluginLogBuffer()
|
|
buf.add_line("[06-13 10:30:00.123] main.py (45) - [INFO] : hello world")
|
|
logs = buf.get_logs()
|
|
assert len(logs) == 1
|
|
assert logs[0]["level"] == "INFO"
|
|
assert logs[0]["text"].endswith("hello world")
|
|
|
|
|
|
def test_continuation_line_inherits_level():
|
|
buf = PluginLogBuffer()
|
|
buf.add_line("[06-13 10:30:00.123] main.py (45) - [ERROR] : boom")
|
|
buf.add_line("Traceback (most recent call last):")
|
|
buf.add_line(' File "x.py", line 1, in <module>')
|
|
logs = buf.get_logs()
|
|
assert len(logs) == 3
|
|
assert all(e["level"] == "ERROR" for e in logs)
|
|
|
|
|
|
def test_level_filter():
|
|
buf = PluginLogBuffer()
|
|
buf.add_line("[06-13 10:30:00.1] a.py (1) - [INFO] : i")
|
|
buf.add_line("[06-13 10:30:00.2] a.py (2) - [WARNING] : w")
|
|
buf.add_line("[06-13 10:30:00.3] a.py (3) - [ERROR] : e")
|
|
warn_and_up = buf.get_logs(level="WARNING")
|
|
assert [e["level"] for e in warn_and_up] == ["WARNING", "ERROR"]
|
|
|
|
|
|
def test_ring_buffer_cap():
|
|
buf = PluginLogBuffer(max_lines=5)
|
|
for i in range(20):
|
|
buf.add_line(f"[06-13 10:30:00.1] a.py (1) - [INFO] : line {i}")
|
|
logs = buf.get_logs(limit=100)
|
|
assert len(logs) == 5
|
|
assert logs[-1]["text"].endswith("line 19")
|
|
|
|
|
|
def test_limit():
|
|
buf = PluginLogBuffer()
|
|
for i in range(50):
|
|
buf.add_line(f"[06-13 10:30:00.1] a.py (1) - [INFO] : line {i}")
|
|
logs = buf.get_logs(limit=10)
|
|
assert len(logs) == 10
|
|
assert logs[-1]["text"].endswith("line 49")
|
|
|
|
|
|
def test_empty_lines_skipped():
|
|
buf = PluginLogBuffer()
|
|
buf.add_line("")
|
|
buf.add_line(" \n")
|
|
assert buf.get_logs() == []
|
|
|
|
|
|
def test_add_entry_appends_synthetic_log():
|
|
buf = PluginLogBuffer()
|
|
buf.add_entry("ERROR", "deferred response failed")
|
|
|
|
logs = buf.get_logs()
|
|
|
|
assert logs == [
|
|
{
|
|
"ts": logs[0]["ts"],
|
|
"level": "ERROR",
|
|
"text": "deferred response failed",
|
|
}
|
|
]
|
|
|
|
|
|
def test_has_active_reader_reports_reader_state():
|
|
async def run():
|
|
reader = asyncio.StreamReader()
|
|
buf = PluginLogBuffer()
|
|
buf.start_reader(reader)
|
|
assert buf.has_active_reader is True
|
|
reader.feed_eof()
|
|
await asyncio.sleep(0)
|
|
return buf.has_active_reader
|
|
|
|
assert asyncio.run(run()) is False
|
|
|
|
|
|
def test_attach_stream_reads_to_eof():
|
|
async def run():
|
|
reader = asyncio.StreamReader()
|
|
reader.feed_data(b"[06-13 10:30:00.1] a.py (1) - [INFO] : streamed\n")
|
|
reader.feed_eof()
|
|
buf = PluginLogBuffer()
|
|
await buf.attach_stream(reader)
|
|
return buf.get_logs()
|
|
|
|
logs = asyncio.run(run())
|
|
assert len(logs) == 1
|
|
assert logs[0]["text"].endswith("streamed")
|
|
|
|
|
|
def test_attach_stream_drains_and_clips_line_without_newline():
|
|
async def run():
|
|
reader = asyncio.StreamReader(limit=1024)
|
|
reader.feed_data(b"x" * (MAX_LOG_LINE_BYTES * 3))
|
|
reader.feed_eof()
|
|
buf = PluginLogBuffer()
|
|
await buf.attach_stream(reader)
|
|
return buf.get_logs()
|
|
|
|
logs = asyncio.run(run())
|
|
assert len(logs) == 1
|
|
assert logs[0]["text"].startswith("x" * 100)
|
|
assert f"clipped at {MAX_LOG_LINE_BYTES} bytes" in logs[0]["text"]
|
|
assert len(logs[0]["text"]) < MAX_LOG_LINE_BYTES + 100
|