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:
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user