refactor: streamline agent lifecycle management with new DB service helpers
This commit is contained in:
@@ -30,24 +30,23 @@ def test_api_does_not_import_openclaw_gateway_client_directly() -> None:
|
||||
|
||||
|
||||
def test_api_uses_safe_gateway_dispatch_helper() -> None:
|
||||
"""API modules should use `send_gateway_agent_message_safe`, not direct send."""
|
||||
"""API modules should not call low-level gateway RPC helpers directly."""
|
||||
repo_root = Path(__file__).resolve().parents[2]
|
||||
api_root = repo_root / "backend" / "app" / "api"
|
||||
direct_send_pattern = re.compile(r"\bsend_gateway_agent_message\b")
|
||||
|
||||
forbidden = {"ensure_session", "send_message", "openclaw_call"}
|
||||
violations: list[str] = []
|
||||
for path in api_root.rglob("*.py"):
|
||||
rel = path.relative_to(repo_root)
|
||||
for lineno, raw_line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
|
||||
line = raw_line.strip()
|
||||
if not direct_send_pattern.search(line):
|
||||
if not line.startswith("from app.services.openclaw.gateway_rpc import "):
|
||||
continue
|
||||
if "send_gateway_agent_message_safe" in line:
|
||||
continue
|
||||
violations.append(f"{rel}:{lineno}")
|
||||
if any(re.search(rf"\\b{name}\\b", line) for name in forbidden):
|
||||
violations.append(f"{rel}:{lineno}")
|
||||
|
||||
assert not violations, (
|
||||
"Use `send_gateway_agent_message_safe` from `app.services.openclaw.shared` "
|
||||
"for API-level gateway notification dispatch. "
|
||||
"Use OpenClaw service modules (for example `app.services.openclaw.gateway_dispatch`) "
|
||||
"instead of calling low-level gateway RPC helpers from `app.api`."
|
||||
f"Violations: {', '.join(violations)}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user