mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
feat(marketing): project-branded drafts + project badges on the X/video queues (#570)
Item B+C of the video/X per-project targeting spec, plus the company_goals.company_name field they depend on (migration 075). - CompanyGoalsService.resolve_product_name is the single fallback chain (project name -> charter company_name -> RoboCo); XEngine and VideoEngine both call it and their prompt builders are pure functions taking product_name — release posts/videos stop hardcoding RoboCo. - The X and video queue responses carry project_slug/project_name via one shared unloaded-guard helper (api/schemas/project_fields.py); both panel queues render a shared ProjectBadge so multi-project drafts are tellable apart. - Business -> Goals editor gains the company-name input. - Fixes a pre-existing test-isolation leak: the company-goals routes test commits the charter singleton into the session-scoped test DB and polluted later suites; it now deletes the row on teardown. Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
@@ -3,22 +3,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from unittest.mock import MagicMock
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from fastapi import HTTPException
|
||||
from roboco.api.routes.company_goals import get_company_goals, update_company_goals
|
||||
from roboco.api.schemas.company_goals import CompanyGoalsUpdate
|
||||
from roboco.db.tables import CompanyGoalsTable
|
||||
from roboco.models import AgentRole
|
||||
from roboco.models.permissions import AgentContext
|
||||
from sqlalchemy import delete
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
|
||||
def _agent(role: AgentRole) -> AgentContext:
|
||||
return AgentContext(agent_id=uuid4(), role=role, team=None)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(autouse=True)
|
||||
async def _cleanup_company_goals(db_session: Any) -> AsyncIterator[None]:
|
||||
yield
|
||||
# update_company_goals() calls db.commit() (real behavior — see the route
|
||||
# docstring), so a CEO update here persists past the per-test rollback
|
||||
# into every later test in this session-scoped DB run. Delete the
|
||||
# singleton row so it reads back to empty defaults for whatever runs
|
||||
# next (mirrors the ceo_client teardown in test_release_routes.py).
|
||||
await db_session.execute(delete(CompanyGoalsTable))
|
||||
await db_session.commit()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_returns_charter_to_any_agent(db_session: Any) -> None:
|
||||
resp = await get_company_goals(db_session, _agent(AgentRole.DEVELOPER))
|
||||
@@ -52,6 +70,19 @@ async def test_ceo_can_update_and_persist_brand_voice(db_session: Any) -> None:
|
||||
assert again.brand_voice == "Confident, dry wit."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ceo_can_update_and_persist_company_name(db_session: Any) -> None:
|
||||
ceo = _agent(AgentRole.CEO)
|
||||
resp = await update_company_goals(
|
||||
CompanyGoalsUpdate(company_name="Acme Robotics"), db_session, ceo
|
||||
)
|
||||
assert resp.company_name == "Acme Robotics"
|
||||
# Persisted and readable by a non-CEO agent (round-trips through the
|
||||
# Pydantic response schema, not just the service-layer dict).
|
||||
again = await get_company_goals(db_session, _agent(AgentRole.QA))
|
||||
assert again.company_name == "Acme Robotics"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_non_ceo_cannot_update() -> None:
|
||||
# The CEO check fires before any DB access, so a dummy session suffices.
|
||||
|
||||
@@ -414,6 +414,7 @@ async def test_list_posts_returns_open_draft(
|
||||
db_session: AsyncSession, ceo_client: AsyncClient
|
||||
) -> None:
|
||||
task = await _seed_draft(db_session)
|
||||
project = await db_session.get(ProjectTable, task.project_id)
|
||||
resp = await ceo_client.get("/api/video/posts")
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
body = resp.json()
|
||||
@@ -425,6 +426,9 @@ async def test_list_posts_returns_open_draft(
|
||||
"square": "/render/out/1-square.mp4",
|
||||
"vertical": "/render/out/1-vertical.mp4",
|
||||
}
|
||||
assert project is not None
|
||||
assert body[0]["project_slug"] == project.slug
|
||||
assert body[0]["project_name"] == project.name
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -471,6 +475,7 @@ async def test_pipeline_lists_non_terminal_authoring_task(
|
||||
db_session: AsyncSession, ceo_client: AsyncClient
|
||||
) -> None:
|
||||
task = await _seed_authoring_task(db_session, status=TaskStatus.IN_PROGRESS)
|
||||
project = await db_session.get(ProjectTable, task.project_id)
|
||||
resp = await ceo_client.get("/api/video/pipeline")
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
body = resp.json()
|
||||
@@ -481,6 +486,9 @@ async def test_pipeline_lists_non_terminal_authoring_task(
|
||||
assert row["render_attempts"] == 0
|
||||
assert row["max_attempts"] == markers.MAX_VIDEO_RENDER_ATTEMPTS
|
||||
assert row["render_error"] is None
|
||||
assert project is not None
|
||||
assert row["project_slug"] == project.slug
|
||||
assert row["project_name"] == project.name
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -706,6 +714,7 @@ async def test_history_returns_posted_and_rejected_newest_first(
|
||||
json={"reason": "wrong occasion"},
|
||||
)
|
||||
posted = await _seed_draft(db_session, platforms=["x"])
|
||||
posted_project = await db_session.get(ProjectTable, posted.project_id)
|
||||
creds_svc = get_x_credentials_service(db_session)
|
||||
await creds_svc.set_credentials(
|
||||
api_key="ak", api_secret="as", access_token="at", access_token_secret="ats"
|
||||
@@ -736,6 +745,9 @@ async def test_history_returns_posted_and_rejected_newest_first(
|
||||
posted_row = next(row for row in body if row["task_id"] == str(posted.id))
|
||||
assert posted_row["status"] == "completed"
|
||||
assert posted_row["posted"] == {"x": "xid42"}
|
||||
assert posted_project is not None
|
||||
assert posted_row["project_slug"] == posted_project.slug
|
||||
assert posted_row["project_name"] == posted_project.name
|
||||
rejected_row = next(row for row in body if row["task_id"] == str(rejected.id))
|
||||
assert rejected_row["status"] == "cancelled"
|
||||
assert rejected_row["reject_reason"] == "wrong occasion"
|
||||
|
||||
@@ -132,6 +132,7 @@ async def test_list_posts_returns_open_draft(
|
||||
db_session: AsyncSession, ceo_client: AsyncClient
|
||||
) -> None:
|
||||
task = await _seed_draft(db_session)
|
||||
project = await db_session.get(ProjectTable, task.project_id)
|
||||
resp = await ceo_client.get("/api/x/posts")
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
body = resp.json()
|
||||
@@ -139,6 +140,9 @@ async def test_list_posts_returns_open_draft(
|
||||
assert body[0]["task_id"] == str(task.id)
|
||||
assert body[0]["body"] == "draft body"
|
||||
assert body[0]["release_version"] == "0.17.0"
|
||||
assert project is not None
|
||||
assert body[0]["project_slug"] == project.slug
|
||||
assert body[0]["project_name"] == project.name
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -204,6 +208,7 @@ async def test_history_returns_posted_and_rejected_newest_first(
|
||||
f"/api/x/posts/{rejected.id}/reject", json={"reason": "off-brand tone"}
|
||||
)
|
||||
posted = await _seed_draft(db_session)
|
||||
posted_project = await db_session.get(ProjectTable, posted.project_id)
|
||||
with (
|
||||
patch(
|
||||
"roboco.services.x_post_service.build_x_client",
|
||||
@@ -224,6 +229,9 @@ async def test_history_returns_posted_and_rejected_newest_first(
|
||||
posted_row = next(row for row in body if row["task_id"] == str(posted.id))
|
||||
assert posted_row["status"] == "completed"
|
||||
assert posted_row["tweet_id"] == "42"
|
||||
assert posted_project is not None
|
||||
assert posted_row["project_slug"] == posted_project.slug
|
||||
assert posted_row["project_name"] == posted_project.name
|
||||
rejected_row = next(row for row in body if row["task_id"] == str(rejected.id))
|
||||
assert rejected_row["status"] == "cancelled"
|
||||
assert rejected_row["reject_reason"] == "off-brand tone"
|
||||
|
||||
Reference in New Issue
Block a user