Files
roboco/tests/integration/test_project_conventions_routes.py
T
16789c1ca7 Feature/architectural conventions standard (#243)
* feat(conventions): standard schema models + effective-map merge

* feat(conventions): tree-sitter Python classifier + placement checks

* feat(conventions): TS classifier, hygiene/custom checks, runner + CLI

* feat(conventions): ROBOCO_CONVENTIONS_ENABLED flag + cache table + migration

* feat(conventions): repo auto-scan + scaffold draft renderer

* feat(conventions): ConventionsService (cache/baseline/ambient/scaffold/restore)

* feat(conventions): auto-scaffold on project registration (flag-gated)

* feat(conventions): TaskDescription.constraints + auto-baseline attach

* feat(conventions): ambient architecture-map injection at spawn

* test(conventions): subprocess CLI smoke for the agent-image entrypoint

* feat(conventions): block i_am_done on block-level convention violations

* feat(conventions): block pr_pass on unresolved convention violations

* feat(conventions): surface convention findings into QA evidence

* docs(prompts): convention awareness for PO/Intake/Dev/QA/PR-reviewer

* feat(conventions): panel Conventions tab + flag toggle + parity

* test(conventions): end-to-end block, fix, and waiver through the gate

* refactor(conventions): extract pr_pass guards to keep pr_gate under the gate

* style(conventions): format the baseline-constraints attach in task.create

* test(conventions): type-annotate test helpers for the full mypy gate

* build(conventions): ignore types-PyYAML in deptry (mypy-only type stub)

* docs(conventions): document the standard in CLAUDE.md + PM prompt awareness

* fix(conventions): baseline constraints are non-suppressible (dedup-append)

* feat(conventions): scaffold on first workspace clone (threaded workspace)

* feat(conventions): multi-project ambient map for PO/Intake (per-product)

* feat(conventions): persist findings + violations-feed route (migration 044)

* feat(conventions): panel violations feed in the Conventions tab

* test(conventions): intake-spawn mock accepts the ambient layer kwarg

* fix(docker): ollama-init best-effort pull, gate startup on cached models present

A degraded/slow ollama registry made the model manifest re-check fail under
set -e, so ollama-init exited 1 and blocked the orchestrator's
service_completed_successfully gate — taking the whole stack down even though
both models were already cached. Pulls are now best-effort; success is gated on
the models being present, so a flaky registry can't down a cached deployment.

* refactor(content): drop dead TaskDescription.with_baseline_constraints

The structured baseline-merge helper had zero production callers. Project-task baseline constraints are attached by the wired string backstop (TaskService._attach_baseline_constraints), and a real task is free-form prose that cannot form a valid TaskDescription (requires a non-trivial objective + non-empty the_work), so the helper was unreachable from any live path — a leftover from the structured-merge -> string-append design pivot. Removing it leaves a single enforcement path. The constraints field itself stays: it is a member of the well-formed-spec schema (Objective / What This Builds / The Work / Notes / Constraints / Acceptance Criteria), rendered by render_markdown and unit-tested.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-06-22 12:37:46 +02:00

121 lines
3.9 KiB
Python

"""Conventions API routes: GET map+health, PUT commit-back, POST restore."""
from __future__ import annotations
from http import HTTPStatus
from typing import TYPE_CHECKING, cast
from uuid import UUID, uuid4
import pytest_asyncio
from fastapi import FastAPI
from httpx import ASGITransport, AsyncClient
from roboco.api.deps import get_agent_context, get_db
from roboco.api.routes.project import router as project_router
from roboco.db.tables import AgentTable
from roboco.models import AgentRole, AgentStatus
from roboco.models.permissions import AgentContext
if TYPE_CHECKING:
from collections.abc import AsyncIterator
from sqlalchemy.ext.asyncio import AsyncSession
_HDR = {"X-Agent-ID": str(uuid4()), "X-Agent-Role": "main_pm"}
@pytest_asyncio.fixture
async def client(db_session: AsyncSession) -> AsyncIterator[AsyncClient]:
agent = AgentTable(
id=uuid4(),
name="MainPM",
slug=f"main-pm-{uuid4().hex[:8]}",
role=AgentRole.MAIN_PM,
team=None,
status=AgentStatus.ACTIVE,
model_config={},
system_prompt="pm",
capabilities=[],
permissions={},
metrics={},
)
db_session.add(agent)
await db_session.flush()
app = FastAPI()
app.include_router(project_router, prefix="/api/projects")
async def _override_db() -> AsyncIterator[AsyncSession]:
yield db_session
async def _override_agent() -> AgentContext:
return AgentContext(
agent_id=cast("UUID", agent.id), role=AgentRole.MAIN_PM, team=None
)
app.dependency_overrides[get_db] = _override_db
app.dependency_overrides[get_agent_context] = _override_agent
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c
app.dependency_overrides.clear()
async def _make_project(client: AsyncClient) -> str:
resp = await client.post(
"/api/projects",
headers=_HDR,
json={
"name": f"Project {uuid4().hex[:6]}",
"slug": f"proj-{uuid4().hex[:6]}",
"git_url": "https://github.com/example/foo.git",
"default_branch": "master",
"assigned_cell": "backend",
},
)
assert resp.status_code == HTTPStatus.CREATED
return str(resp.json()["id"])
async def test_get_conventions_returns_map_and_health(client: AsyncClient) -> None:
project_id = await _make_project(client)
resp = await client.get(f"/api/projects/{project_id}/conventions", headers=_HDR)
assert resp.status_code == HTTPStatus.OK
body = resp.json()
assert body["standard"]["rules"]["no_models_in_routers"]["level"] == "block"
assert body["health"]["status"] in {"missing", "unknown", "ok", "degraded"}
async def test_put_conventions_commits_back(client: AsyncClient) -> None:
project_id = await _make_project(client)
resp = await client.put(
f"/api/projects/{project_id}/conventions",
headers=_HDR,
json={
"version": 1,
"languages": ["python"],
"modules": [
{"path": "app/models", "purpose": "models", "forbidden": ["route"]}
],
"rules": {"no_inline_comments": {"level": "warn"}},
"custom": [],
"waivers": [],
},
)
assert resp.status_code == HTTPStatus.OK
# No workspace on the test project → PR not opened, but the call succeeds.
assert resp.json()["created"] is False
async def test_restore_conventions(client: AsyncClient) -> None:
project_id = await _make_project(client)
resp = await client.post(
f"/api/projects/{project_id}/conventions/restore", headers=_HDR
)
assert resp.status_code == HTTPStatus.OK
assert "branch" in resp.json()
async def test_get_conventions_unknown_project_404(client: AsyncClient) -> None:
resp = await client.get(f"/api/projects/{uuid4()}/conventions", headers=_HDR)
assert resp.status_code == HTTPStatus.NOT_FOUND