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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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