mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
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>
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
"""``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
|