Files
LangBot/sdk/tests/runtime/plugin/test_container.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

125 lines
3.8 KiB
Python

from __future__ import annotations
from langbot_plugin.api.definition.components.base import NoneComponent
from langbot_plugin.api.definition.components.manifest import ComponentManifest
from langbot_plugin.api.definition.plugin import NonePlugin
from langbot_plugin.runtime.plugin.container import (
ComponentContainer,
PluginContainer,
RuntimeContainerStatus,
)
def _manifest(kind: str = "Plugin", name: str = "demo") -> ComponentManifest:
return ComponentManifest(
owner="tester",
manifest={
"apiVersion": "v1",
"kind": kind,
"metadata": {
"name": name,
"label": {"en_US": name.title()},
"author": "tester",
"version": "1.0.0",
},
"spec": {"components": {}},
},
rel_path="manifest.yaml",
)
def test_component_container_dump_excludes_runtime_instance():
container = ComponentContainer(
manifest=_manifest(kind="Tool", name="weather"),
component_instance=NoneComponent(),
component_config={"enabled": True},
)
dumped = container.model_dump()
assert dumped["component_instance"] is None
assert dumped["component_config"] == {"enabled": True}
assert dumped["manifest"]["manifest"]["kind"] == "Tool"
def test_component_container_roundtrip_uses_none_component_placeholder():
original = ComponentContainer(
manifest=_manifest(kind="Command", name="hello"),
component_instance=NoneComponent(),
component_config={"prefix": "/"},
)
restored = ComponentContainer.from_dict(original.model_dump())
assert isinstance(restored.component_instance, NoneComponent)
assert restored.component_config == {"prefix": "/"}
assert restored.manifest.kind == "Command"
def test_plugin_container_dump_excludes_plugin_instance_and_serializes_status():
component = ComponentContainer(
manifest=_manifest(kind="Tool", name="weather"),
component_instance=NoneComponent(),
component_config={},
)
container = PluginContainer(
debug=True,
install_source="local",
install_info={"path": "."},
manifest=_manifest(),
plugin_instance=NonePlugin(),
enabled=True,
priority=10,
plugin_config={"token": "x"},
status=RuntimeContainerStatus.INITIALIZED,
components=[component],
)
dumped = container.model_dump()
assert dumped["plugin_instance"] is None
assert dumped["status"] == "initialized"
assert dumped["components"][0]["component_instance"] is None
def test_plugin_container_roundtrip_uses_none_plugin_placeholder():
container = PluginContainer(
debug=False,
install_source="marketplace",
install_info={"id": "tester/demo"},
manifest=_manifest(),
plugin_instance=NonePlugin(),
enabled=False,
priority=0,
plugin_config={},
status=RuntimeContainerStatus.MOUNTED,
components=[],
)
restored = PluginContainer.from_dict(container.model_dump())
assert isinstance(restored.plugin_instance, NonePlugin)
assert restored.status is RuntimeContainerStatus.MOUNTED
assert restored.enabled is False
assert restored.components == []
def test_plugin_container_roundtrip_should_preserve_install_metadata():
container = PluginContainer(
debug=False,
install_source="marketplace",
install_info={"id": "tester/demo"},
manifest=_manifest(),
plugin_instance=NonePlugin(),
enabled=True,
priority=0,
plugin_config={},
status=RuntimeContainerStatus.MOUNTED,
components=[],
)
restored = PluginContainer.from_dict(container.model_dump())
assert restored.install_source == "marketplace"
assert restored.install_info == {"id": "tester/demo"}