Files
LangBot/sdk/tests/cli/test_cli_main.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

165 lines
3.9 KiB
Python

from __future__ import annotations
import sys
import pytest
from langbot_plugin import cli
from langbot_plugin.box import server as box_server
def _run(monkeypatch, argv: list[str]):
monkeypatch.setattr(sys, "argv", ["lbp", *argv])
return cli.main()
def test_help_prints_usage(monkeypatch, capsys):
_run(monkeypatch, ["help"])
assert "LangBot Plugin CLI" in capsys.readouterr().out
def test_ver_prints_version(monkeypatch):
calls: list = []
monkeypatch.setattr(cli, "cli_print", lambda *args: calls.append(args))
_run(monkeypatch, ["ver"])
assert calls and calls[0][0] == "version_info"
def test_no_command_exits(monkeypatch):
monkeypatch.setattr(sys, "argv", ["lbp"])
with pytest.raises(SystemExit):
cli.main()
def test_unknown_command_exits(monkeypatch):
monkeypatch.setattr(cli, "cli_print", lambda *args: None)
with pytest.raises(SystemExit):
_run(monkeypatch, ["does-not-exist"])
def test_login_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli, "login_process", lambda token=None: captured.setdefault("token", token)
)
_run(monkeypatch, ["login", "--token", "abc"])
assert captured["token"] == "abc"
def test_logout_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli, "logout_process", lambda: captured.setdefault("called", True)
)
_run(monkeypatch, ["logout"])
assert captured["called"] is True
def test_init_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli, "init_plugin_process", lambda name: captured.setdefault("name", name)
)
_run(monkeypatch, ["init", "demo"])
assert captured["name"] == "demo"
def test_comp_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli,
"generate_component_process",
lambda kind: captured.setdefault("kind", kind),
)
_run(monkeypatch, ["comp", "tool"])
assert captured["kind"] == "tool"
def test_run_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(cli, "cli_print", lambda *args: None)
monkeypatch.setattr(
cli,
"run_plugin_process",
lambda *args, **kwargs: captured.update(args=args, kwargs=kwargs),
)
_run(monkeypatch, ["run", "--prod", "--plugin-debug-key", "key", "--tag", "demo"])
assert captured["args"][1] is True
assert captured["args"][2] == "key"
assert captured["kwargs"]["tag"] == "demo"
def test_run_dispatches_without_tag(monkeypatch):
captured: dict = {}
monkeypatch.setattr(cli, "cli_print", lambda *args: None)
monkeypatch.setattr(
cli,
"run_plugin_process",
lambda *args, **kwargs: captured.update(args=args, kwargs=kwargs),
)
_run(monkeypatch, ["run"])
assert captured["kwargs"]["tag"] == ""
def test_build_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli,
"build_plugin_process",
lambda output: captured.setdefault("output", output),
)
_run(monkeypatch, ["build", "-o", "outdir"])
assert captured["output"] == "outdir"
def test_publish_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli, "publish_process", lambda: captured.setdefault("called", True)
)
_run(monkeypatch, ["publish"])
assert captured["called"] is True
def test_rt_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
cli.runtime_app, "main", lambda args: captured.setdefault("args", args)
)
_run(monkeypatch, ["rt", "--ws-control-port", "1234"])
assert captured["args"].ws_control_port == 1234
def test_box_dispatches(monkeypatch):
captured: dict = {}
monkeypatch.setattr(
box_server, "main", lambda args: captured.setdefault("args", args)
)
_run(monkeypatch, ["box", "--ws-control-port", "2222"])
assert captured["args"].ws_control_port == 2222