oclaw/tests/test_oclaw_generalist_executor.py
oliver 5d67303d22 修复 Admin Skills 安装区块不显示,并支持卸载 _workspace/public lane。
同时补齐 _workspace/public 目录约定、公共技能免绑定规则,并为 run_command 增加默认禁用开关与回归测试。

Made-with: Cursor
2026-05-01 03:34:32 +08:00

53 lines
2.2 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
from oclaw.runtime.agents.factory import build_gateway_executor
from oclaw.platform.persistence.sqlite_store import SqliteStore
def test_build_gateway_executor_defaults_to_generalist(tmp_path: Path) -> None:
store = SqliteStore(str(tmp_path / "ops.sqlite"))
ex = build_gateway_executor(store, lang="zh")
assert type(ex).__name__ == "Agent"
assert hasattr(ex, "tools")
assert hasattr(ex, "model")
def test_build_gateway_executor_generalist_run_command_is_disabled_by_default(tmp_path: Path) -> None:
os.environ.pop("AIA_ENABLE_RUN_COMMAND", None)
os.environ["AIA_PUBLIC_TOOLS_ALLOW_HIGH"] = "1"
os.environ["OPS_ASSISTANT_DB_PATH"] = str(tmp_path / "ops.sqlite")
try:
store = SqliteStore(str(tmp_path / "ops.sqlite"))
ex = build_gateway_executor(store, lang="zh", specialist="generalist")
run_tool = next((t for t in ex.tools.list() if t.name == "run_command"), None)
assert run_tool is not None
out = run_tool.handler({"command": "echo hi"})
assert isinstance(out, dict)
assert out.get("ok") is False
assert out.get("error") == "disabled"
finally:
os.environ.pop("AIA_PUBLIC_TOOLS_ALLOW_HIGH", None)
os.environ.pop("OPS_ASSISTANT_DB_PATH", None)
def test_build_gateway_executor_generalist_run_command_prefers_db_setting(tmp_path: Path) -> None:
os.environ["AIA_ENABLE_RUN_COMMAND"] = "0"
os.environ["AIA_PUBLIC_TOOLS_ALLOW_HIGH"] = "1"
os.environ["OPS_ASSISTANT_DB_PATH"] = str(tmp_path / "ops.sqlite")
try:
store = SqliteStore(str(tmp_path / "ops.sqlite"))
store.set_setting("AIA_ENABLE_RUN_COMMAND", "1")
ex = build_gateway_executor(store, lang="zh", specialist="generalist")
run_tool = next((t for t in ex.tools.list() if t.name == "run_command"), None)
assert run_tool is not None
out = run_tool.handler({"command": "echo hi"})
assert isinstance(out, dict)
assert out.get("ok") is True
finally:
os.environ.pop("AIA_ENABLE_RUN_COMMAND", None)
os.environ.pop("AIA_PUBLIC_TOOLS_ALLOW_HIGH", None)
os.environ.pop("OPS_ASSISTANT_DB_PATH", None)