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

116 lines
3.7 KiB
Python

from __future__ import annotations
import yaml
from langbot_plugin.cli.commands import gencomponent
def _write_plugin_manifest(path):
(path / "manifest.yaml").write_text(
yaml.safe_dump(
{
"apiVersion": "v1",
"kind": "Plugin",
"metadata": {
"author": "tester",
"name": "demo",
"label": {"en_US": "Demo"},
"version": "0.1.0",
},
"spec": {"components": {}},
"execution": {"python": {"path": "main.py", "attr": "Demo"}},
},
sort_keys=False,
),
encoding="utf-8",
)
def test_generate_component_requires_plugin_root(tmp_path, monkeypatch, capsys):
monkeypatch.chdir(tmp_path)
gencomponent.generate_component_process("Command")
assert "!!" in capsys.readouterr().out
def test_generate_component_reports_unknown_component(tmp_path, monkeypatch, capsys):
_write_plugin_manifest(tmp_path)
monkeypatch.chdir(tmp_path)
gencomponent.generate_component_process("Nope")
output = capsys.readouterr().out
assert "!!" in output
assert "Command" in output
def test_generate_command_component_creates_files_and_updates_manifest(
tmp_path, monkeypatch
):
_write_plugin_manifest(tmp_path)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(gencomponent, "cli_print", lambda *args: None)
monkeypatch.setattr(
gencomponent,
"input_form_values",
lambda fields: {
"cmd_name": "hello",
"cmd_description": "Say hello",
},
)
gencomponent.generate_component_process("Command")
assert (tmp_path / "components" / "__init__.py").is_file()
assert (tmp_path / "components" / "commands" / "__init__.py").is_file()
assert (tmp_path / "components" / "commands" / "hello.yaml").is_file()
assert (tmp_path / "components" / "commands" / "hello.py").is_file()
manifest = yaml.safe_load((tmp_path / "manifest.yaml").read_text())
assert manifest["spec"]["components"]["Command"] == {
"fromDirs": [{"path": "components/commands/"}]
}
def test_generate_page_component_skips_python_package_init_files(tmp_path, monkeypatch):
_write_plugin_manifest(tmp_path)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(gencomponent, "cli_print", lambda *args: None)
monkeypatch.setattr(
gencomponent,
"input_form_values",
lambda fields: {"page_name": "settings"},
)
gencomponent.generate_component_process("Page")
assert not (tmp_path / "components" / "__init__.py").exists()
assert not (tmp_path / "components" / "pages" / "__init__.py").exists()
assert (tmp_path / "components" / "pages" / "settings.yaml").is_file()
assert (tmp_path / "components" / "pages" / "settings.html").is_file()
def test_generate_runner_declares_usage_and_builds(tmp_path, monkeypatch):
from langbot_plugin.cli.commands.buildplugin import build_plugin_process
from langbot_plugin.utils.discover.engine import ComponentDiscoveryEngine
_write_plugin_manifest(tmp_path)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(
gencomponent,
"input_form_values",
lambda fields: {
"runner_name": "echo",
"runner_label": "Echo",
"runner_description": "Echo input",
"runner_attr": "EchoRunner",
},
)
gencomponent.generate_component_process("Runner")
component = ComponentDiscoveryEngine().load_component_manifest(
"components/runner/echo.yaml"
)
assert component is not None
assert component.spec["usages"] == ["agent"]
assert build_plugin_process(str(tmp_path / "dist"))