:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add Front message, comment and lookup tables (#108300)
Tom Owersc97a2a92c083
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex bab09c166d8c..41d2c30a2d3e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -3428,24 +3428,24 @@ Note: Frill's llms.txt lists exactly nine reference pages: announcements, announ## Front — gaps-Today (9): `accounts`, `channels`, `contacts`, `conversations`, `events`, `inboxes`, `tags`, `teammates`, `teams`+Today (18): `accounts`, `account_custom_fields`, `channels`, `contacts`, `contact_custom_fields`, `conversations`, `conversation_comments`, `conversation_custom_fields`, `conversation_messages`, `events`, `inboxes`, `inbox_custom_fields`, `link_custom_fields`, `tags`, `teammates`, `teammate_custom_fields`, `teams`, `ticket_statuses`Diffed against: <https://raw.githubusercontent.com/frontapp/front-api-specs/main/core-api/core-api.json>-- [ ] `conversations/{id}/messages` — the email/SMS message bodies themselves; conversations without messages is metadata only (high)-- [ ] `conversations/{id}/comments` — internal team discussion on each conversation, the collaboration signal (high)-- [ ] `company/statuses (ticket statuses)` — lookup that resolves the ticket status ID already carried on synced conversations (high)+- [x] `conversations/{id}/messages` — the email/SMS message bodies themselves; conversations without messages is metadata only (high)+- [x] `conversations/{id}/comments` — internal team discussion on each conversation, the collaboration signal (high)+- [x] `company/statuses (ticket statuses)` — lookup that resolves the ticket status ID already carried on synced conversations (high)- [ ] `conversations/{id}/followers` — membership table linking teammates to the conversations they watch (medium)- [ ] `teammate_groups (+ /teammates, /teams, /inboxes members)` — org structure and membership joins for the teammates and teams already synced (medium)- [ ] `contact_lists (+ contacts in list)` — customer segmentation lists and their membership rows (medium)- [ ] `contact_groups (+ contacts in group)` — the other contact grouping dimension, needed to break conversations down by contact segment (medium)-- [ ] `custom_fields (accounts, contacts, conversations, inboxes, teammates, links)` — lookup describing the custom field definitions whose values ride on synced records (medium)+- [x] `custom_fields (accounts, contacts, conversations, inboxes, teammates, links)` — lookup describing the custom field definitions whose values ride on synced records (medium)- [ ] `links (+ links/{id}/conversations)` — external resource links attached to conversations — the join to CRM/issue trackers (medium)- [ ] `knowledge_bases/{id}/articles (+ categories)` — help center content for deflection and article-coverage analysis (medium)- [ ] `shifts (+ shifts/{id}/teammates)` — coverage schedule and who was on it, to correlate response time with staffing (low)- [ ] `contacts/{id}/notes` — free-text account context recorded against a contact (low)-Note: Diffed against Front's published OpenAPI 3.0 spec (128 GET operations). The top-level objects are all covered, but the sub-resources under /conversations — where the actual content lives — are entirely missing.+Note: Diffed against Front's published OpenAPI 3.0 spec (128 GET operations). The top-level objects are all covered, as are the message and comment sub-resources under /conversations where the actual content lives. The remaining gaps are membership and grouping joins. `GET /custom_fields` is deprecated in favor of `GET /contacts/custom_fields` and is not synced.## Fulcrum — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/front/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/front/canonical_descriptions.pyindex 14a82bfdd944..a7bcc0939493 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/front/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/front/canonical_descriptions.py@@ -128,4 +128,119 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"members": "Teammates that belong to the team.",},},+ "conversation_messages": {+ "description": "A message exchanged in a conversation, such as an inbound email or an outbound SMS.",+ "docs_url": "https://dev.frontapp.com/reference/messages",+ "columns": {+ "id": "Unique identifier for the message.",+ "conversation_id": "Identifier of the conversation the message belongs to.",+ "message_uid": "Secondary unique identifier generated by Front when the message is created.",+ "type": "Type of the message (e.g. email, sms, custom).",+ "is_inbound": "Whether the message was received rather than sent.",+ "draft_mode": "For a draft, whether it is visible to its author only or to the whole team.",+ "error_type": "Type of the error, when a draft failed to send.",+ "version": "Current version of the message in Front.",+ "created_at": "Time at which the message was sent or received, as Unix epoch seconds.",+ "subject": "Subject of the message.",+ "blurb": "Preview of the message body.",+ "author": "Front teammate who sent the message.",+ "recipients": "The message's recipients and their roles (to, cc, bcc).",+ "body": "Body of the message.",+ "text": "Plain text version of the body, for email messages.",+ "attachments": "Files attached to the message.",+ "signature": "Signature attached to the message.",+ "metadata": "Optional metadata about the message.",+ },+ },+ "conversation_comments": {+ "description": "An internal comment posted by a teammate on a conversation, not visible to the customer.",+ "docs_url": "https://dev.frontapp.com/reference/comments",+ "columns": {+ "id": "Unique identifier for the comment.",+ "conversation_id": "Identifier of the conversation the comment was posted on.",+ "author": "Teammate who wrote the comment.",+ "body": "Content of the comment.",+ "posted_at": "Time at which the comment was posted, as Unix epoch seconds.",+ "attachments": "Files attached to the comment.",+ "is_pinned": "Whether the comment is pinned in its conversation.",+ },+ },+ "ticket_statuses": {+ "description": "A ticket status a conversation can be set to, including the company's custom statuses.",+ "docs_url": "https://dev.frontapp.com/reference/statuses",+ "columns": {+ "id": "Unique identifier for the ticket status.",+ "name": "Name of the ticket status. Default statuses match their category name.",+ "category": "Category of the ticket status.",+ "description": "Description of the ticket status.",+ "created_at": "Time at which the ticket status was created, as Unix epoch seconds.",+ "updated_at": "Time at which the ticket status was last updated, as Unix epoch seconds.",+ },+ },+ "account_custom_fields": {+ "description": "Definition of a custom field that can be attached to an account.",+ "docs_url": "https://dev.frontapp.com/reference/list-account-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },+ "contact_custom_fields": {+ "description": "Definition of a custom field that can be attached to a contact.",+ "docs_url": "https://dev.frontapp.com/reference/list-contact-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },+ "conversation_custom_fields": {+ "description": "Definition of a custom field that can be attached to a conversation.",+ "docs_url": "https://dev.frontapp.com/reference/list-conversation-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },+ "inbox_custom_fields": {+ "description": "Definition of a custom field that can be attached to an inbox.",+ "docs_url": "https://dev.frontapp.com/reference/list-inbox-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },+ "link_custom_fields": {+ "description": "Definition of a custom field that can be attached to a link.",+ "docs_url": "https://dev.frontapp.com/reference/list-link-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },+ "teammate_custom_fields": {+ "description": "Definition of a custom field that can be attached to a teammate.",+ "docs_url": "https://dev.frontapp.com/reference/list-teammate-custom-fields",+ "columns": {+ "id": "Unique identifier for the custom field.",+ "name": "Name of the custom field.",+ "description": "Description of the custom field.",+ "type": "Type of the custom field (e.g. string, boolean, number, datetime, enum).",+ "values": "Possible values, for a custom field of type `enum`.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/front/front.py b/products/warehouse_sources/backend/temporal/data_imports/sources/front/front.pyindex 36a8ce96f956..15b32c06c431 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/front/front.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/front/front.py@@ -1,19 +1,27 @@import dataclasses+from collections.abc import AsyncIterable, Callable, Iterablefrom datetime import UTC, date, datetime, timedelta-from typing import Any, Optional+from typing import Any, Optional, castfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,rest_api_resource,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ build_dependent_resource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (JSONResponsePaginator,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (+ ClientConfig,+ Endpoint,+ EndpointResource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe-from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse+from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse, TDataTypefrom products.warehouse_sources.backend.temporal.data_imports.sources.front.settings import (FRONT_ENDPOINTS,FrontEndpointConfig,@@ -25,9 +33,16 @@ FRONT_NEXT_URL_PATH = "_pagination.next"MAX_RETRIES = 6[email protected](frozen=True)class FrontResumeConfig:- next_url: str+ # Top-level endpoints resume from the absolute next-page link Front hands back.+ next_url: Optional[str] = None+ # Fan-out endpoints resume by parent: the child paths already fully synced, the parent in+ # progress, and that parent's paginator state — see+ # `common.rest_source.__init__._make_paginate_dependent_resource`.+ completed: Optional[list[str]] = None+ current: Optional[str] = None+ child_state: Optional[dict[str, Any]] = Nonedef _accept_headers() -> dict[str, str]:@@ -110,6 +125,102 @@ def validate_credentials(api_token: str, path: str, require_scope: bool) -> tuplreturn True, None+def _client_config(api_token: str) -> ClientConfig:+ return {+ "base_url": FRONT_BASE_URL,+ "headers": _accept_headers(),+ "auth": {"type": "bearer", "token": api_token},+ "max_retries": MAX_RETRIES,+ }+++def _endpoint_extra() -> Endpoint:+ # Front pages carry rows under ``_results``; a missing key is a legit empty page+ # (deleted resources can shrink a page), so this is not data_selector_required.+ return {+ "data_selector": "_results",+ "paginator": JSONResponsePaginator(next_url_path=FRONT_NEXT_URL_PATH),+ }+++def _source_response(+ config: FrontEndpointConfig,+ items: Callable[[], Iterable[Any] | AsyncIterable[Any]],+ column_hints: dict[str, TDataType | None] | None = None,+) -> SourceResponse:+ return SourceResponse(+ name=config.name,+ items=items,+ primary_keys=config.primary_keys,+ partition_count=1,+ partition_size=1,+ partition_mode="datetime" if config.partition_key else None,+ partition_format=config.partition_format if config.partition_key else None,+ partition_keys=[config.partition_key] if config.partition_key else None,+ sort_mode=config.sort_mode,+ column_hints=column_hints,+ )+++def _fanout_source(+ config: FrontEndpointConfig,+ api_token: str,+ team_id: int,+ job_id: str,+ resumable_source_manager: ResumableSourceManager[FrontResumeConfig],+) -> SourceResponse:+ assert config.fanout is not None+ parent_config = FRONT_ENDPOINTS[config.fanout.parent_name]+ # Both listings already describe their own query params, so carry those through and let the+ # builder add none of its own.+ fanout = dataclasses.replace(+ config.fanout,+ parent_params=_build_initial_params(parent_config, False, None),+ child_params=_build_initial_params(config, False, None),+ )++ initial_state: Optional[dict[str, Any]] = None+ if resumable_source_manager.can_resume():+ resume = resumable_source_manager.load_state()+ if resume is not None and (resume.completed or resume.current):+ initial_state = {+ "completed": resume.completed or [],+ "current": resume.current,+ "child_state": resume.child_state,+ }++ def save_checkpoint(state: Optional[dict[str, Any]]) -> None:+ if state is not None:+ resumable_source_manager.save_state(+ FrontResumeConfig(+ completed=state.get("completed"),+ current=state.get("current"),+ child_state=state.get("child_state"),+ )+ )++ dependent_resource = cast(+ Iterable[Any],+ build_dependent_resource(+ endpoint_configs=FRONT_ENDPOINTS,+ child_endpoint=config.name,+ fanout=fanout,+ client_config=_client_config(api_token),+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ db_incremental_field_last_value=None,+ parent_endpoint_extra=_endpoint_extra(),+ child_endpoint_extra=_endpoint_extra(),+ page_size_param=None,+ resume_hook=save_checkpoint,+ initial_paginator_state=initial_state,+ ),+ )++ return _source_response(config, lambda: dependent_resource)++def front_source(api_token: str,endpoint: str,@@ -121,34 +232,25 @@ def front_source() -> SourceResponse:config = FRONT_ENDPOINTS[endpoint]+ if config.fanout is not None:+ return _fanout_source(config, api_token, team_id, job_id, resumable_source_manager)+params = _build_initial_params(config, should_use_incremental_field, db_incremental_field_last_value)resource_config: EndpointResource = {"name": endpoint,- "endpoint": {- "path": config.path,- "params": params,- # Front pages carry rows under ``_results``; a missing key is a legit empty page- # (deleted resources can shrink a page), so this is not data_selector_required.- "data_selector": "_results",- "paginator": JSONResponsePaginator(next_url_path=FRONT_NEXT_URL_PATH),- },+ "endpoint": {**_endpoint_extra(), "path": config.path, "params": params},}rest_config: RESTAPIConfig = {- "client": {- "base_url": FRONT_BASE_URL,- "headers": _accept_headers(),- "auth": {"type": "bearer", "token": api_token},- "max_retries": MAX_RETRIES,- },+ "client": _client_config(api_token),"resources": [resource_config],}initial_paginator_state: Optional[dict[str, Any]] = Noneif resumable_source_manager.can_resume():resume = resumable_source_manager.load_state()- if resume is not None:+ if resume is not None and resume.next_url:initial_paginator_state = {"next_url": resume.next_url}def save_checkpoint(state: Optional[dict[str, Any]]) -> None:@@ -166,15 +268,4 @@ def front_source(initial_paginator_state=initial_paginator_state,)- return SourceResponse(- name=endpoint,- items=lambda: resource,- primary_keys=config.primary_keys,- partition_count=1,- partition_size=1,- partition_mode="datetime" if config.partition_key else None,- partition_format=config.partition_format if config.partition_key else None,- partition_keys=[config.partition_key] if config.partition_key else None,- sort_mode="asc",- column_hints=resource.column_hints,- )+ return _source_response(config, lambda: resource, column_hints=resource.column_hints)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/front/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/front/settings.pyindex 0d7ff1aebce8..fa7357fbc4c0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/front/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/front/settings.py@@ -1,11 +1,18 @@from dataclasses import dataclass, fieldfrom typing import Optional-from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import PartitionFormat+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ DependentEndpointConfig,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import PartitionFormat, SortModefrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType+# Page size the fan-out helper reads for an endpoint that declares no ``limit`` of its own.+# Front's documented maximum.+DEFAULT_PAGE_SIZE = 100-@dataclass++@dataclass(frozen=True)class FrontEndpointConfig:name: strpath: str@@ -25,6 +32,30 @@ class FrontEndpointConfig:incremental_query_property: Optional[str] = None# Bound the first incremental sync to the last N days (None = full history).default_lookback_days: Optional[int] = None+ # Order rows actually arrive in, which is not always the order we ask for: some endpoints+ # take no sort param and Front fixes the order itself.+ sort_mode: SortMode = "asc"+ # Set when the endpoint hangs off a parent resource and has to be fanned out from it.+ fanout: Optional[DependentEndpointConfig] = None++ @property+ def page_size(self) -> int:+ return self.limit if self.limit is not None else DEFAULT_PAGE_SIZE++ @property+ def default_incremental_field(self) -> Optional[str]:+ return self.incremental_fields[0]["field"] if self.incremental_fields else None+++# Every sub-resource under /conversations resolves the same way: one request per conversation,+# with the parent's id carried onto each child row.+_CONVERSATION_FANOUT = DependentEndpointConfig(+ parent_name="conversations",+ resolve_param="conversation_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "conversation_id"},+)def _datetime_incremental_field(field_name: str) -> IncrementalField:@@ -91,6 +122,39 @@ FRONT_ENDPOINTS: dict[str, FrontEndpointConfig] = {),# The remaining endpoints take no query params and have no stable creation timestamp in the# response, so they're plain full-refresh listings.+ # Front returns messages newest-first by default; `created_at` is the only sort it accepts,+ # so ask for ascending and page through with the same cursor the top-level endpoints use.+ "conversation_messages": FrontEndpointConfig(+ name="conversation_messages",+ path="/conversations/{conversation_id}/messages",+ partition_key="created_at",+ limit=100,+ sort_by="created_at",+ sort_order="asc",+ fanout=_CONVERSATION_FANOUT,+ ),+ # Comments take no query params at all — no paging, no sorting — and arrive newest-first.+ "conversation_comments": FrontEndpointConfig(+ name="conversation_comments",+ path="/conversations/{conversation_id}/comments",+ partition_key="posted_at",+ sort_mode="desc",+ fanout=_CONVERSATION_FANOUT,+ ),+ # Resolves the ticket status id carried on each synced conversation.+ "ticket_statuses": FrontEndpointConfig(+ name="ticket_statuses", path="/company/statuses", partition_key="created_at"+ ),+ # Custom field definitions are listed per resource type, so each is its own lookup table.+ # `/custom_fields` is deprecated in favor of `/contacts/custom_fields` and is not synced.+ "account_custom_fields": FrontEndpointConfig(name="account_custom_fields", path="/accounts/custom_fields"),+ "contact_custom_fields": FrontEndpointConfig(name="contact_custom_fields", path="/contacts/custom_fields"),+ "conversation_custom_fields": FrontEndpointConfig(+ name="conversation_custom_fields", path="/conversations/custom_fields"+ ),+ "inbox_custom_fields": FrontEndpointConfig(name="inbox_custom_fields", path="/inboxes/custom_fields"),+ "link_custom_fields": FrontEndpointConfig(name="link_custom_fields", path="/links/custom_fields"),+ "teammate_custom_fields": FrontEndpointConfig(name="teammate_custom_fields", path="/teammates/custom_fields"),"teammates": FrontEndpointConfig(name="teammates", path="/teammates"),"inboxes": FrontEndpointConfig(name="inboxes", path="/inboxes"),"channels": FrontEndpointConfig(name="channels", path="/channels"),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/front/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/front/source.pyindex c1cc2549d9cf..8eae960c31e5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/front/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/front/source.py@@ -97,7 +97,11 @@ Grant read scopes for the resources you want to sync (e.g. `shared_resources:reaENDPOINTS,INCREMENTAL_FIELDS,names,- descriptions={"events": "Only syncs the last 365 days on initial sync"},+ descriptions={+ "events": "Only syncs the last 365 days on initial sync",+ "conversation_messages": "Fetched one conversation at a time, so a sync takes longer the more conversations you have",+ "conversation_comments": "Fetched one conversation at a time, so a sync takes longer the more conversations you have",+ },)def validate_credentials(@@ -109,7 +113,13 @@ Grant read scopes for the resources you want to sync (e.g. `shared_resources:reareturn validate_front_credentials(config.api_token, "/teammates", require_scope=False)endpoint_config = FRONT_ENDPOINTS.get(schema_name)- path = endpoint_config.path if endpoint_config else "/teammates"+ if endpoint_config is None:+ path = "/teammates"+ elif endpoint_config.fanout is not None:+ # A fan-out path needs a parent id we don't have here, so probe the parent listing.+ path = FRONT_ENDPOINTS[endpoint_config.fanout.parent_name].path+ else:+ path = endpoint_config.pathreturn validate_front_credentials(config.api_token, path, require_scope=True)def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[FrontResumeConfig]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/front/tests/test_front.py b/products/warehouse_sources/backend/temporal/data_imports/sources/front/tests/test_front.pyindex b567eacb2cce..80a2fbd4d025 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/front/tests/test_front.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/front/tests/test_front.py@@ -239,6 +239,92 @@ class TestPagination:assert snapshots[0]["params"]["limit"] == 15+class TestFanout:+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_messages_fan_out_carries_conversation_id(self, MockSession: mock.MagicMock) -> None:+ session = MockSession.return_value+ snapshots = _wire(+ session,+ [+ # parent: one page of conversations+ _response({"_results": [{"id": "cnv_1"}, {"id": "cnv_2"}], "_pagination": {"next": None}}),+ _response({"_results": [{"id": "msg_1"}], "_pagination": {"next": None}}),+ _response({"_results": [{"id": "msg_2"}], "_pagination": {"next": None}}),+ ],+ )+ manager = _make_manager()++ rows = _rows(+ front_source("tok", "conversation_messages", team_id=1, job_id="j", resumable_source_manager=manager)+ )++ assert [(r["id"], r["conversation_id"]) for r in rows] == [("msg_1", "cnv_1"), ("msg_2", "cnv_2")]+ assert snapshots[1]["url"].endswith("/conversations/cnv_1/messages")+ assert snapshots[2]["url"].endswith("/conversations/cnv_2/messages")+ # The child carries the message listing's own sort params, not the parent's.+ assert snapshots[1]["params"]["sort_by"] == "created_at"+ assert snapshots[0]["params"]["sort_by"] == "date"++ @mock.patch(CLIENT_SESSION_PATCH)+ def test_comments_fan_out_sends_no_query_params(self, MockSession: mock.MagicMock) -> None:+ # /conversations/{id}/comments documents no query params at all, so we must send none.+ session = MockSession.return_value+ snapshots = _wire(+ session,+ [+ _response({"_results": [{"id": "cnv_1"}], "_pagination": {"next": None}}),+ _response({"_results": [{"id": "com_1"}]}),+ ],+ )+ manager = _make_manager()++ rows = _rows(+ front_source("tok", "conversation_comments", team_id=1, job_id="j", resumable_source_manager=manager)+ )++ assert [r["id"] for r in rows] == ["com_1"]+ assert snapshots[1]["params"] == {}+ # A comments response carries no `_pagination` key, which has to end the child walk.+ assert session.send.call_count == 2++ @mock.patch(CLIENT_SESSION_PATCH)+ def test_fan_out_resume_skips_completed_parents(self, MockSession: mock.MagicMock) -> None:+ session = MockSession.return_value+ snapshots = _wire(+ session,+ [+ _response({"_results": [{"id": "cnv_1"}, {"id": "cnv_2"}], "_pagination": {"next": None}}),+ _response({"_results": [{"id": "msg_2"}], "_pagination": {"next": None}}),+ ],+ )+ manager = _make_manager(FrontResumeConfig(completed=["/conversations/cnv_1/messages"]))++ rows = _rows(+ front_source("tok", "conversation_messages", team_id=1, job_id="j", resumable_source_manager=manager)+ )++ assert [r["id"] for r in rows] == ["msg_2"]+ assert [s["url"] for s in snapshots][1:] == ["https://api2.frontapp.com/conversations/cnv_2/messages"]++ @mock.patch(CLIENT_SESSION_PATCH)+ def test_fan_out_checkpoints_each_finished_parent(self, MockSession: mock.MagicMock) -> None:+ session = MockSession.return_value+ _wire(+ session,+ [+ _response({"_results": [{"id": "cnv_1"}], "_pagination": {"next": None}}),+ _response({"_results": [{"id": "msg_1"}], "_pagination": {"next": None}}),+ ],+ )+ manager = _make_manager()++ _rows(front_source("tok", "conversation_messages", team_id=1, job_id="j", resumable_source_manager=manager))++ saved = [call.args[0] for call in manager.save_state.call_args_list]+ assert saved[-1].completed == ["/conversations/cnv_1/messages"]+ assert saved[-1].current is None++class TestFrontSourceResponse:@parameterized.expand([@@ -246,6 +332,10 @@ class TestFrontSourceResponse:("conversations", "created_at", "month", "asc"),("accounts", "created_at", "month", "asc"),("tags", "created_at", "month", "asc"),+ # Fan-out endpoints build their response down a separate branch.+ ("conversation_messages", "created_at", "month", "asc"),+ # Front returns comments newest-first and offers no sort param.+ ("conversation_comments", "posted_at", "month", "desc"),])def test_partitioned_endpoints(@@ -259,7 +349,9 @@ class TestFrontSourceResponse:assert response.partition_format == partition_formatassert response.sort_mode == sort_mode- @parameterized.expand([("contacts",), ("teammates",), ("inboxes",), ("channels",), ("teams",)])+ @parameterized.expand(+ [("contacts",), ("teammates",), ("inboxes",), ("channels",), ("teams",), ("contact_custom_fields",)]+ )def test_non_partitioned_endpoints(self, endpoint: str) -> None:response = front_source("tok", endpoint, team_id=1, job_id="j", resumable_source_manager=_make_manager())assert response.primary_keys == ["id"]