From 0ff0d8bd546c49d9a8f5d7ac6fd63a572a36944a Mon Sep 17 00:00:00 2001 From: ayoubdiourin7 Date: Tue, 24 Nov 2026 18:36:05 +0100 Subject: [PATCH 1/2] Record the GitHub account and source on runs started by PR mentions --- services/hackbot-api/app/routers/webhooks.py | 8 +++++- .../hackbot-api/tests/test_github_webhook.py | 27 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/services/hackbot-api/app/routers/webhooks.py b/services/hackbot-api/app/routers/webhooks.py index 7cac52818fd..d896c3e1688 100644 --- a/services/hackbot-api/app/routers/webhooks.py +++ b/services/hackbot-api/app/routers/webhooks.py @@ -13,7 +13,7 @@ Response, status, ) -from hackbot_client import HackbotClient +from hackbot_client import HackbotClient, Identity from phabricator_client import PhabricatorClient from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler from sqlalchemy.ext.asyncio import AsyncSession @@ -354,6 +354,12 @@ async def _trigger_github_mention( "comment": mention.comment, }, dedupe_key=mention.dedupe_key, + source="github", + identity=Identity( + identity_provider="github", + user_id=str(mention.sender["id"]), + username=mention.sender["login"], + ), ) if not run.is_new: log.info( diff --git a/services/hackbot-api/tests/test_github_webhook.py b/services/hackbot-api/tests/test_github_webhook.py index 7a42f1d6e5a..f4fcd66dea4 100644 --- a/services/hackbot-api/tests/test_github_webhook.py +++ b/services/hackbot-api/tests/test_github_webhook.py @@ -31,7 +31,7 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from fastapi.testclient import TestClient -from hackbot_client import RunStatus, TriggeredRun +from hackbot_client import Identity, RunStatus, TriggeredRun from pydantic import ValidationError SECRET = "test-github-webhook-secret" @@ -165,7 +165,7 @@ def _base(action: str, sender: dict | None = None) -> dict: "full_name": "mozilla/gecko-dev", "owner": {"login": "mozilla"}, }, - "sender": sender or {"login": "dev", "type": "User"}, + "sender": sender or {"id": 42, "login": "dev", "type": "User"}, } @@ -224,7 +224,7 @@ def test_detect_issue_comment_on_pr(): owner="mozilla", repo="gecko-dev", pr_number=7, - sender={"login": "dev", "type": "User"}, + sender={"id": 42, "login": "dev", "type": "User"}, comment=( ' \n' " @hackbot fix\n" @@ -399,10 +399,14 @@ class _FakeHackbotClient: def __init__(self): self.calls = [] self.dedupe_keys = [] + self.identities = [] self.delay = 0.0 - async def trigger_run(self, agent_name, inputs, *, dedupe_key=None): + async def trigger_run( + self, agent_name, inputs, *, dedupe_key=None, source=None, identity=None + ): self.calls.append((agent_name, inputs)) + self.identities.append((source, identity)) is_new = dedupe_key is None or dedupe_key not in self.dedupe_keys self.dedupe_keys.append(dedupe_key) # After recording: like the real API, the run exists even if the caller @@ -562,7 +566,12 @@ def test_route_ignores_unauthorized_sender(client, api, authorizer, head_lookups resp = _post(client, "issue_comment", _issue_comment()) assert resp.json() == {"status": "ignored", "reason": "unauthorized user"} assert authorizer.checked == [ - (INSTALLATION_ID, "mozilla", "gecko-dev", {"login": "dev", "type": "User"}) + ( + INSTALLATION_ID, + "mozilla", + "gecko-dev", + {"id": 42, "login": "dev", "type": "User"}, + ) ] # Unauthorized senders cost no further GitHub calls. assert head_lookups == [] @@ -635,6 +644,12 @@ def test_route_triggers_run_for_conversation_comment( ) ] assert api.dedupe_keys == ["github-issue-comment:1001"] + assert api.identities == [ + ( + "github", + Identity(identity_provider="github", user_id="42", username="dev"), + ) + ] @pytest.mark.parametrize( @@ -744,7 +759,7 @@ def test_route_surfaces_trigger_failure(client): # A failure before the run exists spends no key, so a manual redelivery from # the App's settings is processed rather than deduped away. class _FailingClient: - async def trigger_run(self, agent_name, inputs, *, dedupe_key=None): + async def trigger_run(self, agent_name, inputs, **kwargs): raise RuntimeError("api down") app.dependency_overrides[get_hackbot_client] = lambda: _FailingClient() From a3d32803c3edd148e0bc805c8427435235862b20 Mon Sep 17 00:00:00 2001 From: ayoubdiourin7 Date: Thu, 26 Nov 2026 07:02:08 +0100 Subject: [PATCH 2/2] Use the source and identity provider enums for GitHub mentions --- services/hackbot-api/app/routers/webhooks.py | 6 +++--- services/hackbot-api/tests/test_github_webhook.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/hackbot-api/app/routers/webhooks.py b/services/hackbot-api/app/routers/webhooks.py index d896c3e1688..e118ee51a37 100644 --- a/services/hackbot-api/app/routers/webhooks.py +++ b/services/hackbot-api/app/routers/webhooks.py @@ -13,7 +13,7 @@ Response, status, ) -from hackbot_client import HackbotClient, Identity +from hackbot_client import HackbotClient, Identity, IdentityProvider, Source from phabricator_client import PhabricatorClient from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler from sqlalchemy.ext.asyncio import AsyncSession @@ -354,9 +354,9 @@ async def _trigger_github_mention( "comment": mention.comment, }, dedupe_key=mention.dedupe_key, - source="github", + source=Source.github, identity=Identity( - identity_provider="github", + identity_provider=IdentityProvider.github, user_id=str(mention.sender["id"]), username=mention.sender["login"], ), diff --git a/services/hackbot-api/tests/test_github_webhook.py b/services/hackbot-api/tests/test_github_webhook.py index f4fcd66dea4..145444b179b 100644 --- a/services/hackbot-api/tests/test_github_webhook.py +++ b/services/hackbot-api/tests/test_github_webhook.py @@ -31,7 +31,13 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from fastapi.testclient import TestClient -from hackbot_client import Identity, RunStatus, TriggeredRun +from hackbot_client import ( + Identity, + IdentityProvider, + RunStatus, + Source, + TriggeredRun, +) from pydantic import ValidationError SECRET = "test-github-webhook-secret" @@ -646,8 +652,10 @@ def test_route_triggers_run_for_conversation_comment( assert api.dedupe_keys == ["github-issue-comment:1001"] assert api.identities == [ ( - "github", - Identity(identity_provider="github", user_id="42", username="dev"), + Source.github, + Identity( + identity_provider=IdentityProvider.github, user_id="42", username="dev" + ), ) ]