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:
Renzo F
2026-07-18 19:11:03 +02:00
committed by GitHub
co-authored by Renn F
parent 388bab2488
commit 7e01c0cecf
30 changed files with 750 additions and 40 deletions
@@ -0,0 +1,93 @@
"""``roboco/api/routes/video.py`` response-builder wiring for project_slug/
project_name. The sa_inspect(task).unloaded guard branches themselves are
covered once on the shared helper in tests/unit/api/schemas/test_project_fields.py
— this only asserts the three builders actually populate the response from it
(loaded case; a real ORM task always resolves the "loaded" branch since
``project`` is lazy="joined")."""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import MagicMock, patch
from roboco.api.routes.video import (
_to_history_response,
_to_pipeline_item,
_to_response,
)
def _stub_task(*, with_project: bool = False) -> Any:
"""A TaskTable stand-in matching the three response builders' reads."""
return SimpleNamespace(
id="task-1",
source="video_post",
title="Video post: release 1.0.0",
status="pending",
pr_number=None,
orchestration_markers=None,
project=(
SimpleNamespace(slug="acme-robotics", name="Acme Robotics")
if with_project
else None
),
updated_at=None,
created_at="2026-07-18T00:00:00+00:00",
)
def _loaded_inspector() -> MagicMock:
inspector = MagicMock()
inspector.unloaded = set()
return inspector
def test_to_response_includes_project_fields_when_loaded() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_response(_stub_task(with_project=True))
assert resp.project_slug == "acme-robotics"
assert resp.project_name == "Acme Robotics"
def test_to_pipeline_item_includes_project_fields_when_loaded() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_pipeline_item(_stub_task(with_project=True))
assert resp.project_slug == "acme-robotics"
assert resp.project_name == "Acme Robotics"
def test_to_pipeline_item_omits_project_fields_when_project_unset() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_pipeline_item(_stub_task(with_project=False))
assert resp.project_slug is None
assert resp.project_name is None
def test_to_history_response_includes_project_fields_when_loaded() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_history_response(_stub_task(with_project=True))
assert resp.project_slug == "acme-robotics"
assert resp.project_name == "Acme Robotics"
def test_to_history_response_omits_project_fields_when_project_unset() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_history_response(_stub_task(with_project=False))
assert resp.project_slug is None
assert resp.project_name is None
@@ -0,0 +1,79 @@
"""``roboco/api/routes/x.py`` response-builder wiring for project_slug/
project_name. The sa_inspect(task).unloaded guard branches themselves are
covered once on the shared helper in tests/unit/api/schemas/test_project_fields.py
— this only asserts _to_response/_to_history_response actually populate
the response from it (loaded case; a real ORM task always resolves the
"loaded" branch since ``project`` is lazy="joined")."""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import MagicMock, patch
from roboco.api.routes.x import _to_history_response, _to_response
def _stub_task(*, with_project: bool = False) -> Any:
"""A TaskTable stand-in matching _to_response/_to_history_response's reads."""
return SimpleNamespace(
id="task-1",
source="x_post",
title="X post: release v1.0.0",
status="pending",
description="",
orchestration_markers=None,
project=(
SimpleNamespace(slug="acme-robotics", name="Acme Robotics")
if with_project
else None
),
updated_at=None,
created_at="2026-07-18T00:00:00+00:00",
)
def _loaded_inspector() -> MagicMock:
inspector = MagicMock()
inspector.unloaded = set()
return inspector
def test_to_response_includes_project_fields_when_loaded() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_response(_stub_task(with_project=True))
assert resp.project_slug == "acme-robotics"
assert resp.project_name == "Acme Robotics"
def test_to_response_omits_project_fields_when_project_unset() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_response(_stub_task(with_project=False))
assert resp.project_slug is None
assert resp.project_name is None
def test_to_history_response_includes_project_fields_when_loaded() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_history_response(_stub_task(with_project=True))
assert resp.project_slug == "acme-robotics"
assert resp.project_name == "Acme Robotics"
def test_to_history_response_omits_project_fields_when_project_unset() -> None:
with patch(
"roboco.api.schemas.project_fields.sa_inspect",
return_value=_loaded_inspector(),
):
resp = _to_history_response(_stub_task(with_project=False))
assert resp.project_slug is None
assert resp.project_name is None
@@ -0,0 +1,52 @@
"""``task_project_fields`` — the shared (project_slug, project_name)
response-builder helper the X and video routes' five builders all call.
Mirrors tests/unit/api/test_schemas_tasks.py's task_to_response project_slug
coverage for the same sa_inspect(task).unloaded guard convention."""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import MagicMock, patch
from roboco.api.schemas.project_fields import task_project_fields
def _stub_task(*, with_project: bool = False) -> Any:
return SimpleNamespace(
project=(
SimpleNamespace(slug="acme-robotics", name="Acme Robotics")
if with_project
else None
),
)
def test_omits_fields_when_project_unloaded() -> None:
stub = _stub_task(with_project=False)
fake_inspector = MagicMock()
fake_inspector.unloaded = {"project"}
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == (None, None)
def test_omits_fields_when_project_id_unset() -> None:
stub = _stub_task(with_project=False)
fake_inspector = MagicMock()
fake_inspector.unloaded = set() # loaded, but task.project is None
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == (None, None)
def test_returns_slug_and_name_when_loaded() -> None:
stub = _stub_task(with_project=True)
fake_inspector = MagicMock()
fake_inspector.unloaded = set()
with patch(
"roboco.api.schemas.project_fields.sa_inspect", return_value=fake_inspector
):
assert task_project_fields(stub) == ("acme-robotics", "Acme Robotics")
@@ -2,6 +2,7 @@
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from uuid import uuid4
@@ -29,6 +30,7 @@ async def test_get_returns_empty_defaults_when_unset(db_session: Any) -> None:
assert goals["constraints"] == []
assert goals["operating_policy"] == {}
assert goals["brand_voice"] == ""
assert goals["company_name"] == ""
@pytest.mark.asyncio
@@ -89,3 +91,70 @@ async def test_brand_voice_untouched_by_partial_upsert(db_session: Any) -> None:
goals = await svc.get()
assert goals["brand_voice"] == "Speak as 'we'."
assert goals["north_star"] == "Ship a delightful product"
@pytest.mark.asyncio
async def test_company_name_roundtrips(db_session: Any) -> None:
svc = get_company_goals_service(db_session)
await svc.upsert({"company_name": "Acme Robotics"})
goals = await svc.get()
assert goals["company_name"] == "Acme Robotics"
@pytest.mark.asyncio
async def test_company_name_untouched_by_partial_upsert(db_session: Any) -> None:
svc = get_company_goals_service(db_session)
await svc.upsert({"company_name": "Acme Robotics"})
# Mirrors brand_voice's partial-update contract.
await svc.upsert({"north_star": "Ship a delightful product"})
goals = await svc.get()
assert goals["company_name"] == "Acme Robotics"
assert goals["north_star"] == "Ship a delightful product"
# --------------------------------------------------------------------------- #
# resolve_product_name — the shared fallback chain XEngine and VideoEngine
# both brand their drafting prompts with (project name -> company_name ->
# "RoboCo"). A SimpleNamespace stands in for a ProjectTable: the method only
# reads ``.name``, so a full project/agent seed adds nothing here.
# --------------------------------------------------------------------------- #
def _project_stub(name: str) -> Any:
"""A ProjectTable stand-in for resolve_product_name, which only reads
``.name`` — returning ``Any`` (not the SimpleNamespace type) so it type-
checks against the real ``ProjectTable | None`` parameter with no cast."""
return SimpleNamespace(name=name)
@pytest.mark.asyncio
async def test_resolve_product_name_uses_project_name(db_session: Any) -> None:
svc = get_company_goals_service(db_session)
name = await svc.resolve_product_name(_project_stub("Acme Robotics"))
assert name == "Acme Robotics"
@pytest.mark.asyncio
async def test_resolve_product_name_falls_back_to_company_name(db_session: Any) -> None:
svc = get_company_goals_service(db_session)
await svc.upsert({"company_name": "Acme Robotics"})
name = await svc.resolve_product_name(None)
assert name == "Acme Robotics"
@pytest.mark.asyncio
async def test_resolve_product_name_ignores_a_project_with_no_name(
db_session: Any,
) -> None:
svc = get_company_goals_service(db_session)
await svc.upsert({"company_name": "Acme Robotics"})
name = await svc.resolve_product_name(_project_stub(""))
assert name == "Acme Robotics"
@pytest.mark.asyncio
async def test_resolve_product_name_defaults_to_roboco(db_session: Any) -> None:
svc = get_company_goals_service(db_session)
await svc.upsert({"company_name": ""})
name = await svc.resolve_product_name(None)
assert name == "RoboCo"
+43
View File
@@ -675,6 +675,49 @@ async def test_draft_release_video_brief_contains_brand_voice_when_set(
assert "Dry wit, never an exclamation point." in draft["brief"]
# --------------------------------------------------------------------------- #
# Product-name resolution (release-video prompts brand off the target
# project, not a hardcoded "RoboCo" literal). The fallback-chain unit
# coverage (project name -> company_name -> "RoboCo") lives on the shared
# helper, CompanyGoalsService.resolve_product_name, in
# test_company_goals_service.py — this only asserts the end-to-end wiring
# through draft_release_video.
# --------------------------------------------------------------------------- #
@pytest.mark.asyncio
async def test_draft_release_video_uses_project_name_when_set(
db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
await _seed(db_session)
_enable(monkeypatch, video_on_release=True)
acme = ProjectTable(
name="Acme Robotics",
slug="acme-robotics",
git_url="https://github.com/x/acme.git",
default_branch="master",
protected_branches=["master"],
assigned_cell=Team.BACKEND,
created_by=SYSTEM_UUID,
is_active=True,
video_engine_enabled=True,
)
db_session.add(acme)
await db_session.flush()
_mock_local_model(monkeypatch, None) # force the deterministic fallback template
engine = video_engine_module.VideoEngine(db_session)
task = await engine.draft_release_video(
version="1.0.0", changelog=_CHANGELOG, project_id=cast("UUID", acme.id)
)
assert task is not None
draft = markers.get_video_draft(task)
assert draft is not None
assert "Acme Robotics" in draft["script"]
assert "RoboCo" not in draft["script"]
assert "Acme Robotics" in draft["brief"]
assert "RoboCo" not in draft["brief"]
# --------------------------------------------------------------------------- #
# brief enrichment shared by every occasion — brand voice + motion pointer
# (spec Task 2: "Feed the video brief")
+53 -4
View File
@@ -1334,8 +1334,8 @@ async def test_voice_guide_falls_back_when_brand_voice_unset(
) -> None:
await get_company_goals_service(db_session).upsert({"brand_voice": ""})
engine = x_engine_module.XEngine(db_session, client=_FakeClient())
voice = await engine._voice_guide()
assert voice == x_engine_module._HOM_VOICE
voice = await engine._voice_guide("RoboCo")
assert voice == x_engine_module._hom_voice("RoboCo")
@pytest.mark.asyncio
@@ -1346,6 +1346,55 @@ async def test_voice_guide_appends_brand_voice_when_set(
{"brand_voice": "Dry wit, never an exclamation point."}
)
engine = x_engine_module.XEngine(db_session, client=_FakeClient())
voice = await engine._voice_guide()
assert x_engine_module._HOM_VOICE in voice
voice = await engine._voice_guide("RoboCo")
assert x_engine_module._hom_voice("RoboCo") in voice
assert "Dry wit, never an exclamation point." in voice
@pytest.mark.asyncio
async def test_voice_guide_uses_the_given_product_name(
db_session: AsyncSession,
) -> None:
engine = x_engine_module.XEngine(db_session, client=_FakeClient())
voice = await engine._voice_guide("Acme Robotics")
assert "Acme Robotics" in voice
assert "RoboCo" not in voice
# --------------------------------------------------------------------------- #
# Product-name resolution (release-post prompts brand off the target project,
# not a hardcoded "RoboCo" literal). The fallback-chain unit coverage
# (project name -> company_name -> "RoboCo") lives on the shared helper,
# CompanyGoalsService.resolve_product_name, in test_company_goals_service.py —
# this only asserts the end-to-end wiring through draft_release_post.
# --------------------------------------------------------------------------- #
@pytest.mark.asyncio
async def test_draft_release_post_uses_project_name_when_set(
db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch
) -> None:
await _seed(db_session)
_enable(monkeypatch)
acme = ProjectTable(
name="Acme Robotics",
slug="acme-robotics",
git_url="https://github.com/x/acme.git",
default_branch="master",
protected_branches=["master"],
assigned_cell=Team.BACKEND,
created_by=SYSTEM_UUID,
is_active=True,
)
db_session.add(acme)
await db_session.flush()
_mock_local_model(monkeypatch, None) # force the deterministic fallback template
engine = x_engine_module.XEngine(db_session, client=_FakeClient())
task = await engine.draft_release_post(
version=_VERSION, highlights=["feat: x"], project_id=cast("UUID", acme.id)
)
assert task is not None
body = markers.get_x_draft_body(task)
assert body is not None
assert "Acme Robotics" in body
assert "RoboCo" not in body