Name the Abri trigger builder for its None-or-message contract 🟪

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-07 13:02:25 +00:00
parent c016c8b754
commit d9b441962f
4 changed files with 18 additions and 16 deletions

View file

@ -18,7 +18,7 @@ from etl.hubspot.project_data import ProjectData
from etl.hubspot.utils import parse_hs_date
def build_abri_trigger_message(
def abri_trigger_message_for_scrape(
hubspot_deal_id: str,
new_deal: Dict[str, str],
new_project: Optional[ProjectData],

View file

@ -6,7 +6,7 @@ from backend.app.config import get_settings
from etl.hubspot.hubspotClient import HubspotClient
from etl.hubspot.hubspotDataTodB import CompanyData, HubspotDataToDb
from etl.hubspot.project_data import ProjectData
from etl.hubspot.abri_flow_triggers import build_abri_trigger_message
from etl.hubspot.abri_flow_triggers import abri_trigger_message_for_scrape
from etl.hubspot.hubspot_deal_differ import HubspotDealDiffer
from etl.hubspot.hubspot_trigger_orchestrator_trigger_request import (
HubspotTriggerOrchestratorTriggerRequest,
@ -128,14 +128,16 @@ def handler(body: dict[str, Any], context: Any) -> None:
sqs_client, hubspot_deal, listing, hubspot_deal_id
)
abri_message = build_abri_trigger_message(
# None means no Abri flow fired this scrape; a dict is the message
# naming the flows that did.
abri_message = abri_trigger_message_for_scrape(
hubspot_deal_id=hubspot_deal_id,
new_deal=hubspot_deal,
new_project=project,
new_listing=listing,
old_deal=db_deal,
)
if abri_message:
if abri_message is not None:
logger.info(
f"Triggering Abri flows {abri_message['flows']} for HubSpot "
f"deal ID {hubspot_deal_id}"

View file

@ -3,7 +3,7 @@ from typing import Any, Dict
import uuid
from backend.app.db.models.hubspot_deal_data import HubspotDealData
from etl.hubspot.abri_flow_triggers import build_abri_trigger_message
from etl.hubspot.abri_flow_triggers import abri_trigger_message_for_scrape
BASE_TIME = datetime(2025, 12, 1, 12, 0, 0)
@ -50,7 +50,7 @@ def test_a_first_confirmed_survey_date_builds_a_log_job_message() -> None:
)
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -80,7 +80,7 @@ def test_a_changed_confirmed_survey_date_builds_an_amend_job_message() -> None:
)
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -102,7 +102,7 @@ def test_a_first_expected_commencement_date_builds_a_tenant_sync_message() -> No
new_deal = make_new_deal(expected_commencement_date="2026-07-01")
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -135,7 +135,7 @@ def test_several_flows_firing_in_one_scrape_share_one_message() -> None:
)
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -159,7 +159,7 @@ def test_no_message_when_no_abri_trigger_fires() -> None:
new_deal = make_new_deal(outcome="left voicemail")
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -179,7 +179,7 @@ def test_no_message_for_a_non_abri_deal() -> None:
)
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -200,7 +200,7 @@ def test_abandonment_alone_stays_unwired_and_builds_no_message() -> None:
new_deal = make_new_deal(number_of_attempts="3", outcome="no answer")
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,
@ -226,7 +226,7 @@ def test_a_missing_listing_still_builds_the_message_without_a_place_ref() -> Non
new_deal = make_new_deal(confirmed_survey_date="2026-06-24")
# Act
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=new_deal,
new_project=None,

View file

@ -7,7 +7,7 @@ canned LogJob success carrying a fake job_no. Concretely, the script
1. fetches the deal, listing and project from the real HubSpot portal
(exactly what the scraper lambda sees),
2. reads the deal's row from the real (dev) deal database,
3. runs the real differ predicates via build_abri_trigger_message,
3. runs the real differ predicates via abri_trigger_message_for_scrape,
4. validates the real message contract (AbriTriggerRequest),
5. runs the real dispatch through the real AbriOrchestrator, so the fake
job_no is written to the deal's client_booking_reference property in
@ -129,7 +129,7 @@ def main() -> None:
from applications.abri.abri_trigger_request import AbriTriggerRequest
from applications.abri.dispatch import dispatch_abri_flows
from backend.app.db.models.hubspot_deal_data import HubspotDealData
from etl.hubspot.abri_flow_triggers import build_abri_trigger_message
from etl.hubspot.abri_flow_triggers import abri_trigger_message_for_scrape
from etl.hubspot.hubspotClient import HubspotClient
from infrastructure.abri.abri_client import AbriClient
from infrastructure.abri.config import AbriConfig
@ -196,7 +196,7 @@ def main() -> None:
f"job_no={deal_row.client_booking_reference}"
)
message = build_abri_trigger_message(
message = abri_trigger_message_for_scrape(
hubspot_deal_id=DEAL_ID,
new_deal=hubspot_deal,
new_project=project,