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

61 lines
2.3 KiB
Python

import pytest
from langbot_plugin.entities.io.context import PluginWorkerPolicy
from langbot_plugin.runtime.plugin.worker_launcher import PluginWorkerLauncher
from tests.runtime.plugin.test_worker_launcher import _launch_spec, _policy
def split_policy():
data = _policy().model_dump()
data.update(
dedicated={"max_cpus": 0.5, "max_memory_mb": 256},
shared={"max_cpus": 1.0, "max_memory_mb": 512},
)
return PluginWorkerPolicy.model_validate(data)
def test_cloud_worker_modes_get_distinct_hard_limits(tmp_path):
launcher = PluginWorkerLauncher(
nsjail_path="/usr/bin/nsjail", cgroup_v2_available=True, platform="linux"
)
launcher.configure(split_policy(), "shared")
spec = _launch_spec(tmp_path)
for args, cpu, memory in [
(launcher.build_nsjail_args(spec), "500", 256),
(launcher.build_shared_pool_nsjail_args(spec), "1000", 512),
]:
assert args[args.index("--cgroup_cpu_ms_per_sec") + 1] == cpu
assert args[args.index("--cgroup_mem_max") + 1] == str(memory * 1024 * 1024)
assert args[args.index("--cgroup_pids_max") + 1] == "73"
def test_oss_policy_resolution_ignores_cloud_overrides():
policy = split_policy()
for mode in ("dedicated", "shared-runtime-v1"):
resolved = policy.for_execution_mode(mode, "oss_dev")
assert resolved.max_cpus == 1.5
assert resolved.max_memory_mb == 384
assert policy.effective_worker_capacity == _policy().effective_worker_capacity
@pytest.mark.parametrize("value", [0, -1, True, "1", float("inf"), float("nan")])
def test_mode_cpu_overrides_are_strict(value):
data = _policy().model_dump()
data["shared"] = {"max_cpus": value}
with pytest.raises(ValueError):
PluginWorkerPolicy.model_validate(data)
def test_legacy_cloud_policy_is_unchanged(tmp_path):
launcher = PluginWorkerLauncher(
nsjail_path="/usr/bin/nsjail", cgroup_v2_available=True, platform="linux"
)
launcher.configure(_policy(), "shared")
spec = _launch_spec(tmp_path)
for args in (
launcher.build_nsjail_args(spec),
launcher.build_shared_pool_nsjail_args(spec),
):
assert args[args.index("--cgroup_cpu_ms_per_sec") + 1] == "1500"
assert args[args.index("--cgroup_mem_max") + 1] == str(384 * 1024 * 1024)