Files
roboco/tests/unit/services/test_git_commit_trailer.py
T
Renn F a9fc870415 fix(orchestrator): harden external-PR supersede close-on-land
Scope close_pull_request repo resolution by project_id and thread the
umbrella's project into close-on-land, so a contributor PR is never
resolved (or closed) against a same-numbered PR in another project's
repo. Skip the comment + close PATCH when the PR is already closed, so a
retried sweep never re-posts the 'superseded' comment.

Require a non-cancelled descendant that actually landed a PR before
retiring the contributor PR, so an umbrella force-completed over a
cancelled code subtask leaves the contributor's still-valid PR open.

Run close-on-land from the always-on sweeper rather than the default-off
poll loop, so a supersede that lands after the feature is toggled off is
still reconciled. Serialize concurrent supersede triggers under a lock so
a double-click can't cut two branches / spawn two umbrellas. Anchor the
supersede marker checks to the marker line so appended CEO notes can't be
mistaken for the closed/dedup tokens. Make the fork-head branch cut
idempotent (forced refspec) so a commit-fail retry converges.

Also drop an importlib.reload(roboco.config) in a unit test that rebound
the settings singleton and leaked into the PM decision-window test.
2026-06-16 18:01:40 +02:00

140 lines
4.5 KiB
Python

"""Unit tests: commit-trailer links use ROBOCO_PUBLIC_BASE_URL."""
import pytest
import roboco.config as config_module
from roboco.templates.git.commit import (
CommitContext,
CommitMessageError,
build_commit_message,
)
def _make_ctx() -> CommitContext:
return CommitContext(
task_id="t-1",
root_task_id="r-1",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="feat",
scope=None,
description="add user authentication",
)
def test_build_commit_message_uses_given_api_base() -> None:
"""build_commit_message embeds the api_base it receives."""
ctx = _make_ctx()
out = build_commit_message(ctx, "https://roboco.example.com/api")
assert "https://roboco.example.com/api" in out
assert "127.0.0.1" not in out
def test_build_commit_message_strips_trailing_slash() -> None:
"""Trailing slash on api_base is stripped to avoid double slashes."""
ctx = _make_ctx()
out = build_commit_message(ctx, "https://roboco.example.com/api/")
assert "//tasks/" not in out
assert "https://roboco.example.com/api/tasks/" in out
def test_links_use_public_base_url(monkeypatch: pytest.MonkeyPatch) -> None:
"""settings.public_base_url drives the api_base passed to build_commit_message."""
# Construct a fresh Settings() to read the patched env — do NOT
# importlib.reload(roboco.config), which would rebind the module-level
# ``settings`` singleton to a new object and leak that divergence into any
# other test that captured the original reference via ``from roboco.config
# import settings`` (e.g. the PM decision-window gate).
monkeypatch.setenv("ROBOCO_PUBLIC_BASE_URL", "https://roboco.example.com")
settings = config_module.Settings()
api_base = settings.public_base_url.rstrip("/") + "/api"
ctx = _make_ctx()
out = build_commit_message(ctx, api_base)
assert "https://roboco.example.com" in out
assert "127.0.0.1" not in out
def test_commit_context_invalid_type_raises() -> None:
"""Lines 49-52: invalid commit_type raises CommitMessageError."""
with pytest.raises(CommitMessageError, match="Invalid commit type"):
CommitContext(
task_id="t-1",
root_task_id="r-1",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="garbage",
scope=None,
description="x",
)
def test_commit_context_missing_description_raises() -> None:
"""Line 54: missing description raises."""
with pytest.raises(CommitMessageError, match="description is required"):
CommitContext(
task_id="t-1",
root_task_id="r-1",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="feat",
scope=None,
description="",
)
def test_commit_context_missing_task_id_raises() -> None:
"""Line 56: missing task_id raises."""
with pytest.raises(CommitMessageError, match="Task ID is required"):
CommitContext(
task_id="",
root_task_id="r-1",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="feat",
scope=None,
description="x",
)
def test_commit_context_missing_root_task_id_raises() -> None:
"""Line 58: missing root_task_id raises."""
with pytest.raises(CommitMessageError, match="Root task ID is required"):
CommitContext(
task_id="t-1",
root_task_id="",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="feat",
scope=None,
description="x",
)
def test_commit_context_missing_agent_slug_raises() -> None:
"""Line 60: missing agent_slug raises."""
with pytest.raises(CommitMessageError, match="Agent slug is required"):
CommitContext(
task_id="t-1",
root_task_id="r-1",
agent_slug="",
session_id="s-1",
commit_type="feat",
scope=None,
description="x",
)
def test_build_commit_message_with_body() -> None:
"""Line 85: ctx.body present → body section appended."""
ctx = CommitContext(
task_id="t-1",
root_task_id="r-1",
agent_slug="be-dev-1",
session_id="s-1",
commit_type="feat",
scope="auth",
description="add login",
body="Implements OAuth2 login flow",
)
out = build_commit_message(ctx, "https://example.com/api")
assert "Implements OAuth2 login flow" in out