: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(warehouse_sources): support help scout API version v3 (#113226)
Tom Owers0155b1f9399c
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 2bee6ba25c91..3f172d02967d 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -106,6 +106,7 @@ The opposite gap also occurs: a reference rendered from one version-blind OpenAP- A vendor that falls forward on a retired pin — serving the oldest accessible version instead of rejecting the request — has no rejection signature to add. Its sunset still needs the repin migration: the pin silently stops being honored, with no failed sync to surface it.- A version bump can change the auth scheme, not just the wire format. Then the source config needs both credential shapes as optional fields, auth construction dispatches on the resolved version, and `validate_credentials` enforces the pair that version needs — form-level `required` can't express "depends on the pin".- A new version can page a horizon the old one returned whole (a fixed record cap plus `next`/`prev` links). For a snapshot-polling source, keep one request per sync rather than following the links — vendors bill each page — and state the resulting horizon in each table's description, since it can be shorter than the old version's.+- A version that drops the sort parameters the old request path used to order rows by the incremental field (for example a fixed newest-first order) breaks the per-batch watermark checkpoint that `sort_mode="asc"` implies. Report `sort_mode="desc"` for those endpoints under the new pin, so the pipeline persists the watermark only when a sync completes, and stop sending the sort params the new version rejects.- A version that changes the pagination _mechanism_ (e.g. offset→cursor, or one opaque cursor param for another, since a token one generation issued means nothing to the other) also changes the resumable checkpoint's persisted shape. Add a new defaulted field to the resume-config dataclass rather than repurposing the existing one — so state persisted under the old version still decodes — and make the seed and save-checkpoint logic dispatch on the resolved version. Reusing one field across incompatible mechanisms corrupts in-flight resumes of the other version. When a table stays on its old wire under the new pin, key the check on the wire that issued the cursor, not on the pin.- When the vendor renames a collection between versions, keep the schema/table name set identical across versions and put the rename in a per-version path on the endpoint config — otherwise discovery diffs orphan the table on repin.- When the new version has no equivalent for an old endpoint (a dropped collection, not a rename), keep that table only on the versions that serve it and let the table set differ by version — never map it to a guessed path just to keep the sets equal, since docs are the sole source of truth and an unverified path makes a new source surface a table that 404s at sync time.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/helpscout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/helpscout.pyindex 16a349b0aacd..c0574dd3fcb3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/helpscout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/helpscout.py@@ -22,6 +22,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.soufrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.settings import (HELP_SCOUT_API_BASE,+ HELP_SCOUT_API_BASE_V3,+ HELP_SCOUT_API_VERSION_V2,+ HELP_SCOUT_API_VERSION_V3,HELP_SCOUT_ENDPOINTS,HelpScoutEndpointConfig,)@@ -45,9 +48,19 @@ class HelpScoutResumeConfig:fanout_state: Optional[dict[str, Any]] = None-def _client_config(access_token: str) -> ClientConfig:+def _uses_v3_route(config: HelpScoutEndpointConfig, api_version: str) -> bool:+ if api_version not in (HELP_SCOUT_API_VERSION_V2, HELP_SCOUT_API_VERSION_V3):+ raise ValueError(f"Unsupported Help Scout API version: {api_version}")+ return api_version == HELP_SCOUT_API_VERSION_V3 and config.has_v3_route+++def _api_base(config: HelpScoutEndpointConfig, api_version: str) -> str:+ return HELP_SCOUT_API_BASE_V3 if _uses_v3_route(config, api_version) else HELP_SCOUT_API_BASE+++def _client_config(access_token: str, base_url: str) -> ClientConfig:return {- "base_url": HELP_SCOUT_API_BASE,+ "base_url": base_url,"auth": BearerTokenAuth(token=access_token),"paginator": JSONResponsePaginator(next_url_path=_NEXT_URL_PATH),# Pagination follows absolute `_links.next.href` URLs straight out of the response body,@@ -75,10 +88,17 @@ def _format_since(value: Any) -> str:def _list_params(config: HelpScoutEndpointConfig,+ use_v3_route: bool,should_use_incremental_field: bool,incremental_field: Optional[str],db_incremental_field_last_value: Any,) -> dict[str, Any]:+ if use_v3_route:+ # v3 always returns newest-first and rejects `sortField`/`sortOrder` with a 400.+ if should_use_incremental_field and config.updated_since_param and db_incremental_field_last_value is not None:+ return {config.updated_since_param: _format_since(db_incremental_field_last_value)}+ return {}+if not config.supports_sort:return {}@@ -98,6 +118,7 @@ def _list_params(def _top_level_resource(client_config: ClientConfig,config: HelpScoutEndpointConfig,+ use_v3_route: bool,team_id: int,job_id: str,resumable_source_manager: ResumableSourceManager[HelpScoutResumeConfig],@@ -113,7 +134,11 @@ def _top_level_resource("endpoint": {"path": config.path,"params": _list_params(- config, should_use_incremental_field, incremental_field, db_incremental_field_last_value+ config,+ use_v3_route,+ should_use_incremental_field,+ incremental_field,+ db_incremental_field_last_value,),"data_selector": f"_embedded.{config.embedded_key}",},@@ -195,12 +220,14 @@ def helpscout_source(team_id: int,job_id: str,resumable_source_manager: ResumableSourceManager[HelpScoutResumeConfig],+ api_version: str,should_use_incremental_field: bool = False,incremental_field: Optional[str] = None,db_incremental_field_last_value: Optional[Any] = None,) -> SourceResponse:config = HELP_SCOUT_ENDPOINTS[endpoint]- client_config = _client_config(access_token)+ use_v3_route = _uses_v3_route(config, api_version)+ client_config = _client_config(access_token, _api_base(config, api_version))if config.fanout:resource: Resource = _threads_resource(client_config, team_id, job_id, resumable_source_manager)@@ -208,6 +235,7 @@ def helpscout_source(resource = _top_level_resource(client_config,config,+ use_v3_route,team_id,job_id,resumable_source_manager,@@ -225,12 +253,15 @@ def helpscout_source(partition_mode="datetime" if config.partition_key else None,partition_format="week" if config.partition_key else None,partition_keys=[config.partition_key] if config.partition_key else None,- sort_mode="asc",+ # v3 lists come back newest-first by createdAt, not ordered by the modifiedAt watermark,+ # so the pipeline must only persist the watermark once a sync completes.+ sort_mode="desc" if use_v3_route and config.updated_since_param else "asc",)def validate_credentials(access_token: str,+ api_version: str,schema_name: Optional[str] = None,) -> tuple[bool, str | None]:auth = BearerTokenAuth(token=access_token)@@ -253,13 +284,13 @@ def validate_credentials(return False, f"Unknown Help Scout table '{schema_name}'"# threads has no bare list endpoint (it's always scoped to a conversation); probe# conversations instead, since that's the parent it fans out from.- probe_path = HELP_SCOUT_ENDPOINTS["conversations"].path if config.fanout else config.path+ probe_config = HELP_SCOUT_ENDPOINTS["conversations"] if config.fanout else config# capture=False: same free-text-content rationale as `_client_config` above — the probed# endpoint can be `conversations`, whose responses carry customer-authored subjects.ok, status = validate_via_probe(lambda: make_tracked_session(redact_values=(access_token,), capture=False),- f"{HELP_SCOUT_API_BASE}{probe_path}",+ f"{_api_base(probe_config, api_version)}{probe_config.path}",auth=auth,)if ok:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/settings.pyindex 62e541fb17ec..96f3cffcc76d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/settings.py@@ -11,7 +11,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import incremental_fieldfrom products.warehouse_sources.backend.types import IncrementalField+HELP_SCOUT_API_VERSION_V2 = "v2"+HELP_SCOUT_API_VERSION_V3 = "v3"+HELP_SCOUT_API_BASE = "https://api.helpscout.net/v2"+HELP_SCOUT_API_BASE_V3 = "https://api.helpscout.net/v3"@frozen@@ -30,6 +34,9 @@ class HelpScoutEndpointConfig:# Only conversations/customers document a `sortField`/`sortOrder` param; other list# endpoints don't accept one (and reject unknown params on some Help Scout API versions).supports_sort: bool = False+ # Help Scout versions its Mailbox API per endpoint: only these endpoints have a v3 route, so+ # a v3 pin moves them and leaves every other endpoint on its v2 route.+ has_v3_route: bool = False# Structural requirement of `FanoutEndpointLike` (see common/rest_source/fanout.py); unused# here since threads' fan-out passes `page_size_param=None` (Help Scout has no page-size param).page_size: int = 50@@ -45,6 +52,7 @@ HELP_SCOUT_ENDPOINTS: dict[str, HelpScoutEndpointConfig] = {default_incremental_field="modifiedAt",updated_since_param="modifiedSince",supports_sort=True,+ has_v3_route=True,),"customers": HelpScoutEndpointConfig(name="customers",@@ -54,6 +62,7 @@ HELP_SCOUT_ENDPOINTS: dict[str, HelpScoutEndpointConfig] = {default_incremental_field="modifiedAt",updated_since_param="modifiedSince",supports_sort=True,+ has_v3_route=True,),"mailboxes": HelpScoutEndpointConfig(name="mailboxes",@@ -82,6 +91,7 @@ HELP_SCOUT_ENDPOINTS: dict[str, HelpScoutEndpointConfig] = {# Thread ids are unique only within their conversation, so the parent id is part of the# key to keep it unique across the whole table.primary_key=["conversation_id", "id"],+ has_v3_route=True,fanout=DependentEndpointConfig(parent_name="conversations",resolve_param="conversation_id",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/source.pyindex 717a4b0775fd..d2054de0a0da 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/source.py@@ -30,6 +30,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.)from products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.settings import (ENDPOINTS,+ HELP_SCOUT_API_VERSION_V2,+ HELP_SCOUT_API_VERSION_V3,INCREMENTAL_FIELDS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -37,8 +39,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass HelpScoutSource(OAuthMixin, ResumableSource[HelpScoutSourceConfig, HelpScoutResumeConfig]):- supported_versions = ("v2",)- default_version = "v2"+ supported_versions = (HELP_SCOUT_API_VERSION_V2, HELP_SCOUT_API_VERSION_V3)+ default_version = HELP_SCOUT_API_VERSION_V3api_docs_url = "https://developer.helpscout.com/mailbox-api/"lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@@ -127,7 +129,7 @@ class HelpScoutSource(OAuthMixin, ResumableSource[HelpScoutSourceConfig, HelpSco) -> tuple[bool, str | None]:try:access_token = self._get_access_token(config, team_id)- return validate_helpscout_credentials(access_token, schema_name)+ return validate_helpscout_credentials(access_token, self.resolve_api_version(api_version), schema_name)except Exception as e:return False, str(e)@@ -148,6 +150,7 @@ class HelpScoutSource(OAuthMixin, ResumableSource[HelpScoutSourceConfig, HelpScoteam_id=inputs.team_id,job_id=inputs.job_id,resumable_source_manager=resumable_source_manager,+ api_version=self.resolve_api_version(inputs.api_version),should_use_incremental_field=inputs.should_use_incremental_field,incremental_field=inputs.incremental_field,db_incremental_field_last_value=inputs.db_incremental_field_last_valuediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout.pyindex 7d9d9d8a582c..80bd47a4b826 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout.py@@ -9,7 +9,6 @@ from requests import Responsefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import BearerTokenAuthfrom products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.helpscout import (- HELP_SCOUT_API_BASE,HelpScoutResumeConfig,_client_config,helpscout_source,@@ -17,6 +16,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.)from products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.settings import (ENDPOINTS,+ HELP_SCOUT_API_BASE,+ HELP_SCOUT_API_BASE_V3,HELP_SCOUT_ENDPOINTS,)@@ -95,8 +96,16 @@ def _wire(session: mock.MagicMock, responses: list[Response]) -> tuple[list[str]return url_snapshots, param_snapshots-def _source(endpoint: str, manager: mock.MagicMock, **kwargs: Any):- return helpscout_source("token", endpoint, team_id=1, job_id="job-1", resumable_source_manager=manager, **kwargs)+def _source(endpoint: str, manager: mock.MagicMock, api_version: str = "v2", **kwargs: Any):+ return helpscout_source(+ "token",+ endpoint,+ team_id=1,+ job_id="job-1",+ resumable_source_manager=manager,+ api_version=api_version,+ **kwargs,+ )def _rows(source_response: Any) -> list[dict[str, Any]]:@@ -106,21 +115,21 @@ def _rows(source_response: Any) -> list[dict[str, Any]]:class TestAuth:def test_client_config_sends_bearer_token(self) -> None:# The token now comes from the Integration, so the source must not mint its own.- auth = _client_config("token")["auth"]+ auth = _client_config("token", HELP_SCOUT_API_BASE)["auth"]assert isinstance(auth, BearerTokenAuth)assert auth.token == "token"def test_client_config_pins_requests_to_the_api_host(self) -> None:# Pagination follows `_links.next.href` out of the response body, so the client must# refuse off-host URLs and redirects rather than replay the bearer token elsewhere.- config = _client_config("token")+ config = _client_config("token", HELP_SCOUT_API_BASE)assert config["allowed_hosts"] == []assert config["allow_redirects"] is Falsedef test_client_config_excludes_requests_from_sample_capture(self) -> None:# Conversation subjects and thread bodies are free-text, customer-authored support# content, so responses must not land in HTTP sample capture.- assert _client_config("token")["capture"] is False+ assert _client_config("token", HELP_SCOUT_API_BASE)["capture"] is False@mock.patch(CLIENT_SESSION_PATCH)def test_off_host_next_link_is_rejected(self, MockSession) -> None:@@ -137,6 +146,36 @@ class TestAuth:_rows(_source("mailboxes", _manager()))+class TestVersionRouting:+ @pytest.mark.parametrize(+ "api_version,endpoint,base",+ [+ ("v2", "conversations", HELP_SCOUT_API_BASE),+ ("v2", "customers", HELP_SCOUT_API_BASE),+ ("v2", "mailboxes", HELP_SCOUT_API_BASE),+ ("v3", "conversations", HELP_SCOUT_API_BASE_V3),+ ("v3", "customers", HELP_SCOUT_API_BASE_V3),+ # Help Scout has no v3 route for these, so a v3 pin keeps them on v2.+ ("v3", "mailboxes", HELP_SCOUT_API_BASE),+ ("v3", "users", HELP_SCOUT_API_BASE),+ ("v3", "tags", HELP_SCOUT_API_BASE),+ ("v3", "workflows", HELP_SCOUT_API_BASE),+ ],+ )+ def test_request_url_follows_the_pinned_version(self, api_version: str, endpoint: str, base: str) -> None:+ with mock.patch(CLIENT_SESSION_PATCH) as MockSession:+ urls, _params = _wire(+ MockSession.return_value, [_response(HELP_SCOUT_ENDPOINTS[endpoint].embedded_key, [])]+ )+ _rows(_source(endpoint, _manager(), api_version=api_version))++ assert urls[0] == f"{base}/{endpoint}"++ def test_unknown_version_is_rejected(self) -> None:+ with pytest.raises(ValueError, match="Unsupported Help Scout API version"):+ _source("conversations", _manager(), api_version="v9")++class TestTopLevelPagination:@mock.patch(CLIENT_SESSION_PATCH)def test_paginates_via_hal_next_link(self, MockSession) -> None:@@ -266,6 +305,36 @@ class TestIncrementalParams:assert params[0]["modifiedSince"] == "2024-06-01T00:00:00Z"+ @pytest.mark.parametrize("endpoint", ["conversations", "customers"])+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_v3_incremental_sends_only_modified_since(self, MockSession, endpoint) -> None:+ session = MockSession.return_value+ _, params = _wire(session, [_response(endpoint, [])])++ _rows(+ _source(+ endpoint,+ _manager(),+ api_version="v3",+ should_use_incremental_field=True,+ incremental_field="modifiedAt",+ db_incremental_field_last_value="2024-01-01T00:00:00Z",+ )+ )++ assert params[0] == {"modifiedSince": "2024-01-01T00:00:00Z"}++ @pytest.mark.parametrize("endpoint", ["conversations", "customers"])+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_v3_full_refresh_sends_no_sort_params(self, MockSession, endpoint) -> None:+ # v3 rejects sortField/sortOrder with a 400, so the v2 full-refresh sort must not leak in.+ session = MockSession.return_value+ _, params = _wire(session, [_response(endpoint, [])])++ _rows(_source(endpoint, _manager(), api_version="v3"))++ assert params[0] == {}+@pytest.mark.parametrize("endpoint", ["mailboxes", "users", "tags", "workflows"])@mock.patch(CLIENT_SESSION_PATCH)def test_endpoints_without_sort_support_send_no_extra_params(self, MockSession, endpoint) -> None:@@ -316,15 +385,16 @@ class TestThreadsFanout:def _build(self, **kwargs: Any) -> tuple[_FakeResource, list[Any]]:child = _FakeResource("threads")with mock.patch(FANOUT_RESOURCES_PATCH, return_value=[_FakeResource("conversations"), child]) as mocked:- helpscout_source(- "token", "threads", team_id=1, job_id="job-1", resumable_source_manager=_manager(), **kwargs- )+ _source("threads", _manager(), **kwargs)return child, mocked.call_args[0]- def test_parent_and_child_endpoints(self) -> None:- _, args = self._build()+ @pytest.mark.parametrize("api_version,base", [("v2", HELP_SCOUT_API_BASE), ("v3", HELP_SCOUT_API_BASE_V3)])+ def test_parent_and_child_endpoints(self, api_version: str, base: str) -> None:+ _, args = self._build(api_version=api_version)parent, child = args[0]["resources"]+ assert args[0]["client"]["base_url"] == base+assert parent["endpoint"]["path"] == "/conversations"assert child["endpoint"]["path"] == "/conversations/{conversation_id}/threads"assert child["endpoint"]["params"]["conversation_id"] == {@@ -350,7 +420,7 @@ class TestThreadsFanout:child = _FakeResource("threads")with mock.patch(FANOUT_RESOURCES_PATCH, return_value=[_FakeResource("conversations"), child]) as mocked:- helpscout_source("token", "threads", team_id=1, job_id="job-1", resumable_source_manager=manager)+ _source("threads", manager)assert mocked.call_args.kwargs["initial_paginator_state"] == state@@ -359,7 +429,7 @@ class TestThreadsFanout:child = _FakeResource("threads")with mock.patch(FANOUT_RESOURCES_PATCH, return_value=[_FakeResource("conversations"), child]) as mocked:- helpscout_source("token", "threads", team_id=1, job_id="job-1", resumable_source_manager=manager)+ _source("threads", manager)resume_hook = mocked.call_args.kwargs["resume_hook"]resume_hook({"completed": ["/conversations/1/threads"], "current": None, "child_state": None})@@ -369,17 +439,27 @@ class TestThreadsFanout:class TestSourceResponseShape:+ @pytest.mark.parametrize(+ "api_version,desc_endpoints",+ [+ ("v2", {}),+ # v3 lists are newest-first, not ordered by the modifiedAt watermark.+ ("v3", {"conversations": "desc", "customers": "desc"}),+ ],+ )@mock.patch(CLIENT_SESSION_PATCH)- def test_response_metadata_per_top_level_endpoint(self, _MockSession) -> None:+ def test_response_metadata_per_top_level_endpoint(+ self, _MockSession, api_version: str, desc_endpoints: dict[str, str]+ ) -> None:for endpoint in ENDPOINTS:if endpoint == "threads":continueconfig = HELP_SCOUT_ENDPOINTS[endpoint]- response = _source(endpoint, _manager())+ response = _source(endpoint, _manager(), api_version=api_version)assert response.name == endpointassert response.primary_keys == config.primary_key- assert response.sort_mode == "asc"+ assert response.sort_mode == desc_endpoints.get(endpoint, "asc")assert response.partition_mode == "datetime"assert response.partition_keys == ["createdAt"]@@ -397,7 +477,7 @@ class TestValidateCredentials:def test_source_create_probes_users_me(self, helpscout_session) -> None:helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)- ok, error = validate_credentials("token", schema_name=None)+ ok, error = validate_credentials("token", "v2", schema_name=None)assert ok is Trueassert error is None@@ -409,17 +489,17 @@ class TestValidateCredentials:# (e.g. a conversation subject), so neither must land in HTTP sample capture.helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)- validate_credentials("token", schema_name=None)+ validate_credentials("token", "v2", schema_name=None)assert helpscout_session.call_args.kwargs["capture"] is False- validate_credentials("token", schema_name="mailboxes")+ validate_credentials("token", "v2", schema_name="mailboxes")assert helpscout_session.call_args.kwargs["capture"] is False@mock.patch(HELPSCOUT_SESSION_PATCH)def test_revoked_token_fails_at_source_create(self, helpscout_session) -> None:helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=401)- ok, error = validate_credentials("token", schema_name=None)+ ok, error = validate_credentials("token", "v2", schema_name=None)assert ok is Falseassert error is not None@@ -428,7 +508,7 @@ class TestValidateCredentials:def test_schema_probe_success(self, helpscout_session) -> None:helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)- ok, error = validate_credentials("token", schema_name="mailboxes")+ ok, error = validate_credentials("token", "v2", schema_name="mailboxes")assert ok is Trueassert error is None@@ -437,7 +517,7 @@ class TestValidateCredentials:def test_schema_probe_401_reports_auth_error(self, helpscout_session) -> None:helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=401)- ok, error = validate_credentials("token", schema_name="mailboxes")+ ok, error = validate_credentials("token", "v2", schema_name="mailboxes")assert ok is Falseassert error is not None and "authentication failed" in error@@ -446,18 +526,29 @@ class TestValidateCredentials:def test_unknown_schema_fails_without_probing(self, helpscout_session) -> None:helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)- ok, error = validate_credentials("token", schema_name="not_a_table")+ ok, error = validate_credentials("token", "v2", schema_name="not_a_table")assert ok is Falseassert error == "Unknown Help Scout table 'not_a_table'"helpscout_session.return_value.get.assert_not_called()- @mock.patch(HELPSCOUT_SESSION_PATCH)- def test_threads_probe_uses_conversations_endpoint(self, helpscout_session) -> None:- helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)-- ok, _error = validate_credentials("token", schema_name="threads")+ @pytest.mark.parametrize(+ "api_version,schema_name,expected_url",+ [+ ("v2", "threads", f"{HELP_SCOUT_API_BASE}/conversations"),+ ("v3", "threads", f"{HELP_SCOUT_API_BASE_V3}/conversations"),+ ("v3", "customers", f"{HELP_SCOUT_API_BASE_V3}/customers"),+ ("v3", "mailboxes", f"{HELP_SCOUT_API_BASE}/mailboxes"),+ ("v3", None, f"{HELP_SCOUT_API_BASE}/users/me"),+ ],+ )+ def test_probe_url_follows_the_pinned_version(+ self, api_version: str, schema_name: str | None, expected_url: str+ ) -> None:+ with mock.patch(HELPSCOUT_SESSION_PATCH) as helpscout_session:+ helpscout_session.return_value.get.return_value = mock.MagicMock(status_code=200)++ ok, _error = validate_credentials("token", api_version, schema_name=schema_name)assert ok is True- probed_url = helpscout_session.return_value.get.call_args.args[0]- assert probed_url == f"{HELP_SCOUT_API_BASE}/conversations"+ assert helpscout_session.return_value.get.call_args.args[0] == expected_urldiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout_source.pyindex f90d1fc6402f..1d1cbec670c6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/helpscout/tests/test_helpscout_source.py@@ -102,7 +102,7 @@ class TestHelpScoutSource:assert is_valid is Trueassert error_message is Nonemock_get_integration.assert_called_once_with(456, self.team_id)- mock_validate.assert_called_once_with("token", "tags")+ mock_validate.assert_called_once_with("token", "v3", "tags")@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.source.HelpScoutSource.get_oauth_integration"@@ -155,7 +155,10 @@ class TestHelpScoutSource:"products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.source.HelpScoutSource.get_oauth_integration")@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.source.helpscout_source")- def test_source_for_pipeline_plumbs_arguments(self, mock_helpscout_source, mock_get_integration, mock_oauth):+ @pytest.mark.parametrize("pinned_version,expected_version", [("v2", "v2"), ("v3", "v3"), (None, "v3")])+ def test_source_for_pipeline_plumbs_arguments(+ self, mock_helpscout_source, mock_get_integration, mock_oauth, pinned_version, expected_version+ ):mock_get_integration.return_value = mock.MagicMock(access_token="token", kind="helpscout")mock_oauth.return_value.access_token_expired.return_value = Falseinputs = mock.MagicMock()@@ -163,6 +166,7 @@ class TestHelpScoutSource:inputs.should_use_incremental_field = Trueinputs.incremental_field = "modifiedAt"inputs.db_incremental_field_last_value = "2024-01-01T00:00:00Z"+ inputs.api_version = pinned_versionmanager = mock.MagicMock()self.source.source_for_pipeline(self.config, manager, inputs)@@ -175,6 +179,7 @@ class TestHelpScoutSource:assert kwargs["should_use_incremental_field"] is Trueassert kwargs["incremental_field"] == "modifiedAt"assert kwargs["db_incremental_field_last_value"] == "2024-01-01T00:00:00Z"+ assert kwargs["api_version"] == expected_version@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.helpscout.source.OauthIntegration")@mock.patch(@@ -190,6 +195,7 @@ class TestHelpScoutSource:inputs.schema_name = "mailboxes"inputs.should_use_incremental_field = Falseinputs.db_incremental_field_last_value = "should-be-ignored"+ inputs.api_version = "v2"manager = mock.MagicMock()self.source.source_for_pipeline(self.config, manager, inputs)