Files
LangBot/sdk/tests/runtime/io/test_stdio_encoding.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

67 lines
2.1 KiB
Python

import asyncio
import json
import os
import subprocess
import sys
import pytest
from langbot_plugin.runtime.io.connections.stdio import StdioConnection
from langbot_plugin.runtime.plugin.worker_launcher import (
PluginWorkerLauncher,
PluginWorkerProcessController,
)
@pytest.mark.parametrize(
"noise", ["发起者ID".encode("gbk"), b"{broken}", b"ordinary log", b"[]"]
)
@pytest.mark.parametrize("chunked", [False, True])
async def test_stdio_discards_noise_and_keeps_next_message(noise, chunked, caplog):
reader = asyncio.StreamReader()
message = '{"code": 0}'
if chunked:
reader.feed_data(
json.dumps({"type": "chunk_start", "total_size": len(message)}).encode()
+ b"\n"
)
reader.feed_data(noise + b"\n")
if chunked:
reader.feed_data(
json.dumps({"type": "chunk_data", "offset": 0, "data": message}).encode()
+ b"\n"
)
reader.feed_data(b'{"type": "chunk_end"}\n')
else:
reader.feed_data(message.encode() + b"\n")
reader.feed_eof()
assert await StdioConnection(reader, None).receive() == message
assert "Skipping" in caplog.text
def test_windows_worker_environment_prints_unicode(monkeypatch):
monkeypatch.setenv("PYTHONUTF8", "0")
monkeypatch.setenv("PYTHONIOENCODING", "gbk")
env = PluginWorkerLauncher(platform="win32")._windows_worker_environment()
result = subprocess.run(
[sys.executable, "-c", "print('\\u2717 \\U0001f60e \\u4e2d\\u6587')"],
env=env,
capture_output=True,
timeout=15,
)
assert result.returncode == 0, result.stderr
assert result.stdout.decode("utf-8").strip() == "✗ 😎 中文"
async def test_websocket_worker_stdout_uses_stderr(capfd, tmp_path):
controller = PluginWorkerProcessController(
command=sys.executable,
args=["-c", "print('worker diagnostic')"],
env=os.environ.copy(),
working_dir=str(tmp_path),
)
await controller.run(None)
out, err = capfd.readouterr()
assert out == ""
assert "worker diagnostic" in err