Files
roboco/tests/unit/services/test_multi_ci_telemetry.py
T
5612375cba Feat/v0.13.0 (#270)
* feat(release): add release-manager feature flag (default off)

* feat(release): change classification + semver-bump derivation

* feat(release): readiness audit (changelog/version-ref/docs/migration/gate)

* feat(release): release-manager engine proposes a gated release

* feat(release): fail-closed release executor (bump, gate, publish)

* feat(release): CEO approve/reject release-proposal surface

* docs(release): document the gated release manager

* feat(memory): add org-memory feature flags (default off)

* feat(memory): add playbooks table + status enum + migration

* feat(memory): playbook service with auditor curation transitions

* feat(memory): playbooks RAG index plugin

* feat(memory): index a playbook into RAG on approval

* feat(memory): distill a high-signal lesson at task completion

* feat(memory): keep private journal reflections out of the shared RAG corpus

* feat(memory): draft_playbook verb + auditor curation verbs

* fix(ci): resolve mypy tests/ errors blocking the gate (UUID casts, annotations)

* feat(memory): auto-inject similar lessons/playbooks into the briefing

* feat(memory): auditor playbook review queue (api + panel)

* docs(memory): document the org-memory loop + playbook verbs

* fix(provisioning): idempotent pitch provisioning (reuse product/project by slug on re-approval)

* fix(memory): add chunks_playbooks to the chunk schema + isolate release route tests

- Migration 030's CHUNK_TABLES was missing chunks_playbooks, breaking the
  IndexType<->migration parity guard once the PLAYBOOKS index landed. The
  upgrade is ALTER ... IF EXISTS so adding it is safe on any DB shape.
- The release-route fixture's approve/reject paths call db.commit() (real
  behavior), so a held proposal outlived the per-test rollback and leaked
  into engine tests that read the global list_open_release_proposals().
  Tear down source=release_manager rows after each test.
- Make the gather_snapshot real-repo smoke version-agnostic (semver match)
  so it stops pinning the literal repo version.

* chore(release): 0.13.0

* ++

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-06-26 01:43:08 +02:00

90 lines
3.3 KiB
Python

"""MultiProjectCITelemetrySource fans out the hardened per-project CI lookup.
One red project yields a breaching sample; a green one a non-breaching sample; a
None signal or a per-project error yields NO sample (unknown, never "green") and
never aborts the sweep. Each project's ci_watch_workflow (or the configured
default) is passed through to the reused lookup.
"""
from __future__ import annotations
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from roboco.config import settings
from roboco.services.telemetry.source import MultiProjectCITelemetrySource
def _project(slug: str, workflow: str | None = None) -> MagicMock:
return MagicMock(slug=slug, ci_watch_workflow=workflow)
def _ci(conclusion: str) -> dict[str, Any]:
return {
"conclusion": conclusion,
"branch": "master",
"run_url": f"https://github.com/x/{conclusion}/actions/runs/1",
"completed_at": "2026-06-25T00:00:00Z",
"run_name": "CI",
}
@pytest.mark.asyncio
async def test_fanout_red_green_and_none() -> None:
projects: list[object] = [_project("red"), _project("green"), _project("nosig")]
async def conclusion(slug: str, **_kwargs: Any) -> Any:
return {"red": _ci("failure"), "green": _ci("success"), "nosig": None}[slug]
git = MagicMock()
git.get_latest_ci_conclusion = AsyncMock(side_effect=conclusion)
with patch("roboco.services.telemetry.source.GitService", return_value=git):
samples = await MultiProjectCITelemetrySource(MagicMock()).fetch(projects)
by_repo = {s.repo_hint: s for s in samples}
assert by_repo["red"].is_breach is True
assert by_repo["green"].is_breach is False
assert "nosig" not in by_repo # None signal → no sample (unknown, not green)
@pytest.mark.asyncio
async def test_per_project_error_isolated() -> None:
projects: list[object] = [_project("boom"), _project("ok")]
async def conclusion(slug: str, **_kwargs: Any) -> Any:
if slug == "boom":
raise RuntimeError("github down")
return _ci("failure")
git = MagicMock()
git.get_latest_ci_conclusion = AsyncMock(side_effect=conclusion)
with patch("roboco.services.telemetry.source.GitService", return_value=git):
samples = await MultiProjectCITelemetrySource(MagicMock()).fetch(projects)
by_repo = {s.repo_hint: s for s in samples}
assert "boom" not in by_repo # error → no sample, never aborts the sweep
assert by_repo["ok"].is_breach is True # others still returned
@pytest.mark.asyncio
async def test_per_project_workflow_passthrough(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(settings, "ci_watch_default_workflow", "ci.yml")
projects: list[object] = [
_project("custom", workflow="release.yml"),
_project("default"),
]
git = MagicMock()
git.get_latest_ci_conclusion = AsyncMock(return_value=_ci("success"))
with patch("roboco.services.telemetry.source.GitService", return_value=git):
await MultiProjectCITelemetrySource(MagicMock()).fetch(projects)
workflows = {
c.args[0]: c.kwargs["workflow"]
for c in git.get_latest_ci_conclusion.await_args_list
}
assert workflows["custom"] == "release.yml"
assert workflows["default"] == "ci.yml"