mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
Harden the architectural-conventions standard so it works out-of-the-box on any project and resolves for projects that predate it, and make RoboCo pass its own gate. General defaults (apply to every project, not just one with a tuned file): - The auto-scan excludes test and documentation trees (tests/, docs/) — those legitimately define fixtures and aren't enforced code. - Helper placement seeds at warn, not block: `helper` matches any top-level function, too blunt a signal to hard-block a route file's small private glue. Misplaced model/route/component stay block; the body-level thin_routes check remains the real fat-handler guard. - thin_routes no longer counts transaction-lifecycle calls (commit/flush/ refresh) as data access — an explicit `db.commit()` after delegating to a service is a valid pattern. - no_lint_suppressions exempts a small allowlist of structurally-unavoidable framework codes (ruff TC001-TC003, pydantic prop-decorator); bare or other suppressions still flag. - CLAUDE.md rule-lifting skips bare common-word tokens that would match everywhere (e.g. "commit"), keeping only specific identifiers. - The ambient prompt block lists only constrained modules and truncates at a line boundary with a "+N more" pointer instead of cutting mid-line. Backfill: the standard previously read the committed file + repo scan from project.workspace_path, a field only a manual API call set — so an older project (or one whose workspace was cleared) showed an empty "missing" map no matter what was pushed. The service now ensures a dedicated, default-branch read clone on demand (WorkspaceService.ensure_read_clone) and resolves from it, persisting the resolved path + real HEAD. The panel tab, the spawn-time ambient block, and the per-task constraints all resolve the committed standard with no manual setup. Adopt in-repo: relocate the inline request/response models from the system and *_live route modules into roboco/api/schemas/ so the codebase passes its own placement gate, and ship a canonical .roboco/conventions.yml. no_models_in_routes and modular_cohesion are now clean and enforced at block. Docs updated across the user guide, the agent-facing RAG standard, the developer and pr_reviewer role prompts, CLAUDE.md, and the changelog. New unit tests cover the scan exclusions, helper-warn, the suppression allowlist, the commit exemption, and the resolve/backfill path; the conventions + project integration suites pass against Postgres.
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
"""roboco.api.routes.secretary_live — live-bridge endpoints (mocked deps)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from http import HTTPStatus
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
from roboco.api.routes import secretary_live as sl
|
|
from roboco.api.schemas.secretary_live import (
|
|
AgentEvent,
|
|
LiveMessageRequest,
|
|
StartSecretaryRequest,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_start_spawns_session(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
orch = MagicMock()
|
|
orch.start_secretary_session = AsyncMock()
|
|
monkeypatch.setattr(sl, "get_orchestrator", lambda: orch)
|
|
resp = await sl.start_live(StartSecretaryRequest(initial_message="hi"))
|
|
assert resp.session_id
|
|
orch.start_secretary_session.assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_messages_delivers(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
reg = MagicMock()
|
|
reg.deliver = AsyncMock(return_value=True)
|
|
monkeypatch.setattr(sl, "get_live_registry", lambda: reg)
|
|
out = await sl.send_message("sid", LiveMessageRequest(text="hi"))
|
|
assert out == {"delivered": True}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_messages_404_when_not_live(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
reg = MagicMock()
|
|
reg.deliver = AsyncMock(return_value=False)
|
|
monkeypatch.setattr(sl, "get_live_registry", lambda: reg)
|
|
with pytest.raises(HTTPException) as exc:
|
|
await sl.send_message("sid", LiveMessageRequest(text="hi"))
|
|
assert exc.value.status_code == HTTPStatus.NOT_FOUND
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_stop_reaps(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
orch = MagicMock()
|
|
orch.reap_secretary_session = AsyncMock()
|
|
monkeypatch.setattr(sl, "get_orchestrator", lambda: orch)
|
|
out = await sl.stop_live("sid")
|
|
assert out == {"stopped": True}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_relay_event_pushes(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
reg = MagicMock()
|
|
reg.push = MagicMock(return_value=True)
|
|
monkeypatch.setattr(sl, "get_live_registry", lambda: reg)
|
|
out = await sl.relay_event("sid", AgentEvent(kind="text", text="hello"))
|
|
assert out == {"pushed": True}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_status(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
reg = MagicMock()
|
|
reg.is_alive = MagicMock(return_value=True)
|
|
monkeypatch.setattr(sl, "get_live_registry", lambda: reg)
|
|
out = await sl.session_status("sid")
|
|
assert out == {"alive": True}
|