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

120 lines
3.9 KiB
Python

from __future__ import annotations
import ntpath
import subprocess
import yaml
from langbot_plugin.cli.commands import initplugin
def test_get_lbp_path_uses_platform_specific_script_location(monkeypatch):
monkeypatch.setattr(initplugin.sys, "executable", "/opt/python/bin/python")
monkeypatch.setattr(initplugin.platform, "system", lambda: "Linux")
assert initplugin.get_lbp_path() == "/opt/python/bin/lbp"
monkeypatch.setattr(initplugin.sys, "executable", r"C:\Python\python.exe")
monkeypatch.setattr(initplugin.platform, "system", lambda: "Windows")
assert initplugin.get_lbp_path() == ntpath.join(r"C:\Python", "Scripts", "lbp.exe")
monkeypatch.setattr(
initplugin.sys,
"executable",
r"C:\workspace\.venv\Scripts\python.exe",
)
assert initplugin.get_lbp_path() == ntpath.join(
r"C:\workspace\.venv\Scripts", "lbp.exe"
)
def test_is_git_available_returns_false_when_git_missing(monkeypatch):
def raise_missing(*args, **kwargs):
raise FileNotFoundError
monkeypatch.setattr(initplugin.subprocess, "run", raise_missing)
assert initplugin.is_git_available() is False
def test_init_git_repo_invokes_git_init(monkeypatch):
calls = []
prints = []
monkeypatch.setattr(
initplugin.subprocess,
"run",
lambda cmd, **kwargs: calls.append((cmd, kwargs)),
)
monkeypatch.setattr(initplugin, "cli_print", lambda *args: prints.append(args))
initplugin.init_git_repo("plugin")
assert calls[0][0] == ["git", "init"]
assert calls[0][1]["cwd"] == "plugin"
assert prints == [("git_repo_initialized", "plugin")]
def test_init_git_repo_reports_git_warning(monkeypatch):
error = subprocess.CalledProcessError(1, ["git"], stderr=b"boom")
prints = []
monkeypatch.setattr(
initplugin.subprocess,
"run",
lambda *args, **kwargs: (_ for _ in ()).throw(error),
)
monkeypatch.setattr(initplugin, "cli_print", lambda *args: prints.append(args))
initplugin.init_git_repo("plugin")
assert prints == [("git_init_warning", b"boom")]
def test_init_plugin_process_generates_plugin_scaffold(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(
initplugin,
"input_form_values",
lambda fields: {
"plugin_author": "tester",
"plugin_description": "Demo plugin",
},
)
monkeypatch.setattr(initplugin, "is_git_available", lambda: False)
monkeypatch.setattr(initplugin, "cli_print", lambda *args: None)
monkeypatch.setattr(initplugin, "get_lbp_path", lambda: "/usr/bin/lbp")
initplugin.init_plugin_process("demo-plugin")
plugin_dir = tmp_path / "demo-plugin"
assert (plugin_dir / "manifest.yaml").is_file()
assert (plugin_dir / "main.py").is_file()
assert (plugin_dir / "assets" / "icon.svg").is_file()
assert (plugin_dir / ".vscode" / "launch.json").is_file()
assert (plugin_dir / "readme" / "README_zh_Hans.md").is_file()
assert (plugin_dir / ".github" / "workflows" / "release.yml").is_file()
manifest = yaml.safe_load((plugin_dir / "manifest.yaml").read_text())
assert manifest["metadata"]["author"] == "tester"
assert manifest["metadata"]["name"] == "demo-plugin"
assert manifest["execution"]["python"]["attr"] == "demoplugin"
def test_init_plugin_process_rejects_invalid_name(tmp_path, monkeypatch, capsys):
monkeypatch.chdir(tmp_path)
initplugin.init_plugin_process("bad name")
assert "!!" in capsys.readouterr().out
assert not (tmp_path / "bad name").exists()
def test_init_plugin_process_rejects_non_empty_existing_directory(
tmp_path, monkeypatch, capsys
):
plugin_dir = tmp_path / "demo"
plugin_dir.mkdir()
(plugin_dir / "main.py").write_text("existing", encoding="utf-8")
monkeypatch.chdir(tmp_path)
initplugin.init_plugin_process("demo")
assert "!!" in capsys.readouterr().out