mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* feat(release): add release-manager feature flag (default off) * feat(release): change classification + semver-bump derivation * feat(release): readiness audit (changelog/version-ref/docs/migration/gate) * feat(release): release-manager engine proposes a gated release * feat(release): fail-closed release executor (bump, gate, publish) * feat(release): CEO approve/reject release-proposal surface * docs(release): document the gated release manager * feat(memory): add org-memory feature flags (default off) * feat(memory): add playbooks table + status enum + migration * feat(memory): playbook service with auditor curation transitions * feat(memory): playbooks RAG index plugin * feat(memory): index a playbook into RAG on approval * feat(memory): distill a high-signal lesson at task completion * feat(memory): keep private journal reflections out of the shared RAG corpus * feat(memory): draft_playbook verb + auditor curation verbs * fix(ci): resolve mypy tests/ errors blocking the gate (UUID casts, annotations) * feat(memory): auto-inject similar lessons/playbooks into the briefing * feat(memory): auditor playbook review queue (api + panel) * docs(memory): document the org-memory loop + playbook verbs * fix(provisioning): idempotent pitch provisioning (reuse product/project by slug on re-approval) * fix(memory): add chunks_playbooks to the chunk schema + isolate release route tests - Migration 030's CHUNK_TABLES was missing chunks_playbooks, breaking the IndexType<->migration parity guard once the PLAYBOOKS index landed. The upgrade is ALTER ... IF EXISTS so adding it is safe on any DB shape. - The release-route fixture's approve/reject paths call db.commit() (real behavior), so a held proposal outlived the per-test rollback and leaked into engine tests that read the global list_open_release_proposals(). Tear down source=release_manager rows after each test. - Make the gather_snapshot real-repo smoke version-agnostic (semver match) so it stops pinning the literal repo version. * chore(release): 0.13.0 * ++ --------- Co-authored-by: Renn F <rennf93@users.noreply.github.com>
113 lines
3.9 KiB
Python
113 lines
3.9 KiB
Python
"""Playbook curation routes — Auditor/CEO list + approve/reject; others 403."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from http import HTTPStatus
|
|
from typing import TYPE_CHECKING
|
|
from uuid import UUID, uuid4
|
|
|
|
import pytest
|
|
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.playbooks import router as playbooks_router
|
|
from roboco.models import AgentRole
|
|
from roboco.models.permissions import AgentContext
|
|
from roboco.models.playbook import PlaybookCreate
|
|
from roboco.services.playbook import PlaybookService
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import AsyncIterator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
def _build_app(db_session: AsyncSession, role: AgentRole, agent_id: UUID) -> FastAPI:
|
|
app = FastAPI()
|
|
app.include_router(playbooks_router, prefix="/api/playbooks")
|
|
|
|
async def _override_db() -> AsyncIterator[AsyncSession]:
|
|
yield db_session
|
|
|
|
async def _override_agent() -> AgentContext:
|
|
return AgentContext(agent_id=agent_id, role=role, team=None)
|
|
|
|
app.dependency_overrides[get_db] = _override_db
|
|
app.dependency_overrides[get_agent_context] = _override_agent
|
|
return app
|
|
|
|
|
|
async def _seed_draft(db_session: AsyncSession, title: str = "Retry flaky pg") -> UUID:
|
|
pb = await PlaybookService(db_session).draft(
|
|
PlaybookCreate(
|
|
title=title,
|
|
problem="connection resets intermittently",
|
|
procedure="1. retry with backoff",
|
|
tags=["backend"],
|
|
),
|
|
created_by=uuid4(),
|
|
)
|
|
return pb.id
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def auditor_client(db_session: AsyncSession) -> AsyncIterator[AsyncClient]:
|
|
app = _build_app(db_session, AgentRole.AUDITOR, uuid4())
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_drafts_as_auditor(
|
|
db_session: AsyncSession, auditor_client: AsyncClient
|
|
) -> None:
|
|
await _seed_draft(db_session, title="Draft to list")
|
|
resp = await auditor_client.get("/api/playbooks", params={"status": "draft"})
|
|
assert resp.status_code == HTTPStatus.OK
|
|
titles = [p["title"] for p in resp.json()]
|
|
assert "Draft to list" in titles
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_approve_as_auditor_flips_to_approved(
|
|
db_session: AsyncSession, auditor_client: AsyncClient
|
|
) -> None:
|
|
pid = await _seed_draft(db_session, title="Approve me")
|
|
resp = await auditor_client.post(f"/api/playbooks/{pid}/approve")
|
|
assert resp.status_code == HTTPStatus.OK
|
|
assert resp.json()["status"] == "approved"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_reject_as_auditor_archives(
|
|
db_session: AsyncSession, auditor_client: AsyncClient
|
|
) -> None:
|
|
pid = await _seed_draft(db_session, title="Reject me")
|
|
resp = await auditor_client.post(
|
|
f"/api/playbooks/{pid}/reject", json={"reason": "duplicate of an existing one"}
|
|
)
|
|
assert resp.status_code == HTTPStatus.OK
|
|
assert resp.json()["status"] == "archived"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_approve_missing_is_404(auditor_client: AsyncClient) -> None:
|
|
resp = await auditor_client.post(f"/api/playbooks/{uuid4()}/approve")
|
|
assert resp.status_code == HTTPStatus.NOT_FOUND
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_non_curator_is_forbidden(db_session: AsyncSession) -> None:
|
|
pid = await _seed_draft(db_session, title="Guarded")
|
|
app = _build_app(db_session, AgentRole.DEVELOPER, uuid4())
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
get_resp = await client.get("/api/playbooks")
|
|
approve_resp = await client.post(f"/api/playbooks/{pid}/approve")
|
|
assert get_resp.status_code == HTTPStatus.FORBIDDEN
|
|
assert approve_resp.status_code == HTTPStatus.FORBIDDEN
|
|
app.dependency_overrides.clear()
|