: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): add CQC inspection-area tables (#101623)
Tom Owers68ff9e387e32
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex ba8b30b6df65..2dde03949bd8 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -369,7 +369,6 @@1 products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule_crm.py1 products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/care_quality_commission.py-1 products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/cast_ai.py1 products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/census/census.pydiff --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 c1073f90cc6e..1f02c025282b 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@@ -1283,14 +1283,14 @@ Note: The `kases` table PostHog already exposes is the legacy alias for Projects## CareQualityCommission — gaps-Today (2): `locations`, `providers`+Today (5): `inspection_areas`, `location_inspection_areas`, `locations`, `provider_inspection_areas`, `providers`Diffed against: <https://raw.githubusercontent.com/microsoft/PowerPlatformConnectors/dev/independent-publisher-connectors/Care%20Quaility%20Comission%20For%20England/CQC-Connector.swagger.json>-- [ ] `/public/v1/inspection-areas` — the global taxonomy of CQC inspection areas - the lookup table that names every inspection-area code appearing on providers and locations (high)-- [ ] `/public/v1/locations/{location_id}/inspection-areas` — per-location inspected areas and their ratings, the actual regulatory outcome data users come for (high)-- [ ] `/public/v1/providers/{provider_id}/inspection-areas` — provider-level inspected areas and ratings, the same at the parent org level (high)-- [ ] `/public/v1/locations/{location_id}/provider-inspection-areas` — provider-level areas scoped to a location, needed to join site ratings to org ratings (medium)+- [x] `/public/v1/inspection-areas` — the global taxonomy of CQC inspection areas - the lookup table that names every inspection-area code appearing on providers and locations (high); landed as `inspection_areas`, one unpaginated request+- [x] `/public/v1/locations/{location_id}/inspection-areas` — per-location inspected areas and their ratings, the actual regulatory outcome data users come for (high); landed as `location_inspection_areas`, fanning out over `/locations`+- [x] `/public/v1/providers/{provider_id}/inspection-areas` — provider-level inspected areas and ratings, the same at the parent org level (high); landed as `provider_inspection_areas`, fanning out over `/providers`+- [ ] `/public/v1/locations/{location_id}/provider-inspection-areas` — provider-level areas scoped to a location, needed to join site ratings to org ratings (medium); not a route on the live v1 API — it 404s at the gateway for every location id and with or without a partner code, while every sibling route (including `/locations/{id}/inspection-areas` with the same bogus id) 403s for a missing subscription key. A stale operation in the connector swagger; `provider_inspection_areas` joined on `locations.providerId` covers the same question- [ ] `/public/v1/changes/{organisation_type}` — the delta feed of providers/locations changed in a time window - enables cheap incremental sync and change-over-time analysis (medium)Note: CQC publishes no reachable OpenAPI of its own (api.cqc.org.uk/public/v1/swagger.json and api.service.cqc.org.uk equivalents both 404; the api-portal developer portal is JS-rendered and subscription-key gated). Verified instead against the Microsoft Power Platform independent-publisher connector swagger, which targets host api.cqc.org.uk basePath /public/v1 and enumerates 12 operations; cross-checked against the CQC connector summary page on Microsoft Learn. /reports/{id} endpoints return PDF or report text rather than tabular rows, so they were excluded.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/canonical_descriptions.pyindex dba317b4d219..700abc5cde91 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/canonical_descriptions.py@@ -79,4 +79,48 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"relationships": "Relationships between this location and others (e.g. predecessor/successor).",},},+ "inspection_areas": {+ "description": "The global CQC taxonomy of inspection areas — the lookup table naming every inspection-area code that appears on providers and locations, with whether the area is still used for new inspections. One row per inspection area.",+ "docs_url": "https://api-portal.service.cqc.org.uk",+ "columns": {+ "inspectionAreaId": "Unique CQC identifier for the inspection area.",+ "inspectionAreaName": "Name of the inspection area (e.g. Acute Services, Residential Social Care).",+ "inspectionAreaType": "Classification of the inspection area within the CQC framework.",+ "status": "Whether the area is current or has been superseded for new inspections.",+ "endDate": "Date the inspection area stopped being used for new inspections, if applicable.",+ "supersededBy": "Identifiers of the inspection areas that replaced this one.",+ "inspectionCategories": "Inspection categories that sit under this inspection area.",+ "orgInspectionAreaRetirementDate": "Date from which the area is retired at organisation level.",+ },+ },+ "provider_inspection_areas": {+ "description": "Inspection areas that have been inspected at provider level, one row per provider and inspection area. Globally retired areas are excluded, but an area that is superseded globally stays here — along with its ratings — until the provider is re-inspected under the superseding area.",+ "docs_url": "https://api-portal.service.cqc.org.uk",+ "columns": {+ "providerId": "CQC identifier of the provider this inspection area was inspected at.",+ "inspectionAreaId": "Unique CQC identifier for the inspection area.",+ "inspectionAreaName": "Name of the inspection area (e.g. Acute Services, Residential Social Care).",+ "inspectionAreaType": "Classification of the inspection area within the CQC framework.",+ "status": "Whether the area is current or has been superseded for new inspections.",+ "endDate": "Date the inspection area stopped being used for new inspections, if applicable.",+ "supersededBy": "Identifiers of the inspection areas that replaced this one.",+ "inspectionCategories": "Inspection categories that sit under this inspection area.",+ "orgInspectionAreaRetirementDate": "Date the area was retired for this provider.",+ },+ },+ "location_inspection_areas": {+ "description": "Inspection areas that have been inspected at a location, one row per location and inspection area. Globally retired areas are excluded, but an area that is superseded globally stays here — along with its ratings — until the location is re-inspected under the superseding area.",+ "docs_url": "https://api-portal.service.cqc.org.uk",+ "columns": {+ "locationId": "CQC identifier of the location this inspection area was inspected at.",+ "inspectionAreaId": "Unique CQC identifier for the inspection area.",+ "inspectionAreaName": "Name of the inspection area (e.g. Acute Services, Residential Social Care).",+ "inspectionAreaType": "Classification of the inspection area within the CQC framework.",+ "status": "Whether the area is current or has been superseded for new inspections.",+ "endDate": "Date the inspection area stopped being used for new inspections, if applicable.",+ "supersededBy": "Identifiers of the inspection areas that replaced this one.",+ "inspectionCategories": "Inspection categories that sit under this inspection area.",+ "orgInspectionAreaRetirementDate": "Date the area was retired for this location.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/care_quality_commission.py b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/care_quality_commission.pyindex f808be8a9b2f..894ef0c2f026 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/care_quality_commission.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/care_quality_commission.py@@ -7,6 +7,13 @@ registration dates, organisation/service types, regulated activities, specialismratings — only comes from the per-id detail endpoints (`/providers/{id}`, `/locations/{id}`). Soeach stream pages the list and fans out one detail call per id.+Inspection areas come in three streams. `/inspection-areas` is the global taxonomy: one unpaginated+body holding every area code CQC inspects against. `/providers/{id}/inspection-areas` and+`/locations/{id}/inspection-areas` give the areas actually inspected at one organisation, along with+the ratings for them, so both fan out over their parent list the same way the detail streams do.+CQC publishes no schema for the per-organisation variants, so they are parsed like the taxonomy+endpoint they mirror — rows nested under `inspectionAreas`.+Authentication is a single subscription/primary key (obtained from the CQC developer portal atapi-portal.service.cqc.org.uk) sent as the `Ocp-Apim-Subscription-Key` header. A `partnerCode`query param is recommended on every request — clients sending it get the 2000 req/min tier; without@@ -16,7 +23,7 @@ Incremental sync: the API only surfaces change detection via `/changes/provider``/changes/location` (which return changed ids for a `startTimestamp`/`endTimestamp` window). Thosewould require fanning out to detail per changed id, but — critically — the detail records carry nostable "last modified" timestamp we can anchor the pipeline's incremental watermark to. Without a-row-level cursor field the watermark can't advance correctly, so both streams ship full-refresh+row-level cursor field the watermark can't advance correctly, so every stream ships full-refreshonly. Full refresh is resumable at list-page granularity so a long fan-out survives heartbeattimeouts."""@@ -108,7 +115,40 @@ def validate_credentials(api_key: str, partner_code: str | None) -> bool:return False-def _iter_detail_rows(+def _rows_for_item(+ session: requests.Session,+ config: CQCEndpointConfig,+ item: dict,+ headers: dict[str, str],+ partner_code: str | None,+ logger: FilteringBoundLogger,+) -> Iterator[dict]:+ if config.detail_path is None or config.id_field is None:+ yield item+ return++ # Direct access: a list record missing its id field is an API contract violation worth+ # surfacing as a KeyError rather than silently skipping the row.+ record_id = item[config.id_field]++ detail = _fetch(+ session,+ _build_url(config.detail_path.format(id=record_id), {"partnerCode": partner_code}),+ headers,+ logger,+ )++ if config.detail_data_key is None:+ yield detail+ return++ for row in detail.get(config.detail_data_key) or []:+ # Stamp the parent id: the same inspectionAreaId recurs across organisations, so it only+ # identifies a row together with the organisation it was inspected at.+ yield {**row, config.id_field: record_id}+++def _iter_endpoint_rows(session: requests.Session,config: CQCEndpointConfig,headers: dict[str, str],@@ -120,12 +160,13 @@ def _iter_detail_rows() -> Iterator[Any]:page = start_pagewhile True:- list_data = _fetch(- session,- _build_url(config.list_path, {"page": page, "perPage": LIST_PAGE_SIZE, "partnerCode": partner_code}),- headers,- logger,- )+ params: dict[str, Any] = {}+ if config.paginated:+ params["page"] = page+ params["perPage"] = LIST_PAGE_SIZE+ params["partnerCode"] = partner_code++ list_data = _fetch(session, _build_url(config.list_path, params), headers, logger)items = list_data.get(config.list_data_key, [])if not items:@@ -138,25 +179,16 @@ def _iter_detail_rows(total_pages = math.inffor item in items:- # Direct access: a list record missing its id field is an API contract violation worth- # surfacing as a KeyError rather than silently skipping the row.- record_id = item[config.id_field]-- detail = _fetch(- session,- _build_url(config.detail_path.format(id=record_id), {"partnerCode": partner_code}),- headers,- logger,- )- batcher.batch(detail)-- if batcher.should_yield():- yield batcher.get_table()- # Save AFTER yielding so a crash re-fetches the current page rather than skipping- # rows; merge dedupes the re-pulled records on the primary key.- resumable_source_manager.save_state(CQCResumeConfig(page=page))-- if page >= total_pages:+ for row in _rows_for_item(session, config, item, headers, partner_code, logger):+ batcher.batch(row)++ if batcher.should_yield():+ yield batcher.get_table()+ # Save AFTER yielding so a crash re-fetches the current page rather than+ # skipping rows; merge dedupes the re-pulled records on the primary key.+ resumable_source_manager.save_state(CQCResumeConfig(page=page))++ if not config.paginated or page >= total_pages:breakpage += 1@@ -185,7 +217,7 @@ def get_rows(if resume is not None:logger.debug(f"CQC: resuming {endpoint} from page {start_page}")- yield from _iter_detail_rows(+ yield from _iter_endpoint_rows(session, config, headers, partner_code, logger, batcher, resumable_source_manager, start_page)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/settings.pyindex 141bc51b29c4..a298d0ef4f8c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/settings.py@@ -1,23 +1,32 @@-from dataclasses import dataclass, field+from dataclasses import fieldfrom typing import Optional+from posthog.dataclasses import frozen+from products.warehouse_sources.backend.types import IncrementalField-@dataclass+@frozenclass CQCEndpointConfig:name: str- # List endpoint returning summary records + pagination metadata (e.g. "/providers").+ # List endpoint returning the rows, or the summary records to fan out from (e.g. "/providers").list_path: str# Key under which the list endpoint nests its records (e.g. "providers").list_data_key: str- # Per-record id field on the summary record (e.g. "providerId").- id_field: str- # Detail endpoint template fetched per id for the full record (e.g. "/providers/{id}").- detail_path: str# Required, no default: each endpoint has its own key (providerId vs locationId), so a generic# default would silently mis-key any future endpoint that forgot to set it.primary_keys: list[str]+ # Per-record id field on the summary record (e.g. "providerId"). Set together with+ # `detail_path`; both stay None when the list records are already the full rows.+ id_field: Optional[str] = None+ # Detail endpoint template fetched per id (e.g. "/providers/{id}").+ detail_path: Optional[str] = None+ # Key under which the detail endpoint nests a list of rows. None means the detail body is+ # itself a single row.+ detail_data_key: Optional[str] = None+ # Whether the list endpoint takes page/perPage. The inspection-area taxonomy returns the whole+ # table in one body and ignores paging, so asking for page 2 would re-serve page 1 forever.+ paginated: bool = True# Stable date field used for datetime partitioning. `registrationDate` is the date the# provider/location first registered with CQC — it never changes once set, unlike rating# or inspection dates which move on every re-inspection.@@ -31,23 +40,59 @@ CQC_ENDPOINTS: dict[str, CQCEndpointConfig] = {name="providers",list_path="/providers",list_data_key="providers",+ primary_keys=["providerId"],id_field="providerId",detail_path="/providers/{id}",- primary_keys=["providerId"],),"locations": CQCEndpointConfig(name="locations",list_path="/locations",list_data_key="locations",+ primary_keys=["locationId"],id_field="locationId",detail_path="/locations/{id}",- primary_keys=["locationId"],+ ),+ "inspection_areas": CQCEndpointConfig(+ name="inspection_areas",+ list_path="/inspection-areas",+ list_data_key="inspectionAreas",+ primary_keys=["inspectionAreaId"],+ paginated=False,+ # Taxonomy rows carry no creation date — `endDate` and `orgInspectionAreaRetirementDate`+ # both move when CQC retires an area.+ partition_key=None,+ ),+ "provider_inspection_areas": CQCEndpointConfig(+ name="provider_inspection_areas",+ list_path="/providers",+ list_data_key="providers",+ primary_keys=["providerId", "inspectionAreaId"],+ id_field="providerId",+ detail_path="/providers/{id}/inspection-areas",+ detail_data_key="inspectionAreas",+ partition_key=None,+ # One request per registered provider, on top of whatever the `providers` stream already+ # costs, so let the user opt in rather than doubling every new connection's first sync.+ should_sync_default=False,+ ),+ "location_inspection_areas": CQCEndpointConfig(+ name="location_inspection_areas",+ list_path="/locations",+ list_data_key="locations",+ primary_keys=["locationId", "inspectionAreaId"],+ id_field="locationId",+ detail_path="/locations/{id}/inspection-areas",+ detail_data_key="inspectionAreas",+ partition_key=None,+ # CQC registers far more locations than providers, so this fan-out is the most expensive+ # stream of the set — off by default.+ should_sync_default=False,),}ENDPOINTS = tuple(CQC_ENDPOINTS.keys())-# Both endpoints ship full-refresh only. The CQC API exposes change detection solely through the+# Every endpoint ships full-refresh only. The CQC API exposes change detection solely through the# dedicated /changes/provider and /changes/location endpoints, which return changed ids for a# timestamp window — but the per-record detail returned by /providers/{id} and /locations/{id}# carries no stable "last modified" column to anchor the pipeline's incremental watermark to, so adiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission.py b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission.pyindex ee51c0c505f9..ddc93df7cd32 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission.py@@ -227,6 +227,67 @@ class TestGetRowsFanOut:assert rows == [{"providerId": "1-A"}]+class TestGetRowsInspectionAreas:+ def test_unpaginated_endpoint_fetches_a_single_page(self, monkeypatch: Any) -> None:+ # The taxonomy endpoint ignores page/perPage and re-serves the whole table, so a request+ # for page 2 would duplicate every row forever. Only page 1 is registered here, so a+ # second fetch fails the test.+ pages = {+ f"{CQC_BASE_URL}/inspection-areas?partnerCode=PC": {+ "inspectionAreas": [{"inspectionAreaId": "IA-1"}, {"inspectionAreaId": "IA-2"}],+ },+ }+ rows = _collect(_FakeResumableManager(), monkeypatch, pages, endpoint="inspection_areas")+ assert rows == [{"inspectionAreaId": "IA-1"}, {"inspectionAreaId": "IA-2"}]++ @pytest.mark.parametrize(+ "endpoint,collection,id_field,org_id",+ [+ ("provider_inspection_areas", "providers", "providerId", "1-P"),+ ("location_inspection_areas", "locations", "locationId", "1-L"),+ ],+ )+ def test_nested_rows_carry_the_parent_id(+ self, monkeypatch: Any, endpoint: str, collection: str, id_field: str, org_id: str+ ) -> None:+ pages = {+ f"{CQC_BASE_URL}/{collection}?page=1&perPage=500&partnerCode=PC": {+ collection: [{id_field: org_id}],+ "totalPages": 1,+ },+ f"{CQC_BASE_URL}/{collection}/{org_id}/inspection-areas?partnerCode=PC": {+ "inspectionAreas": [+ {"inspectionAreaId": "IA-1", "status": "Active"},+ {"inspectionAreaId": "IA-2", "status": "Superseded"},+ ]+ },+ }+ rows = _collect(_FakeResumableManager(), monkeypatch, pages, endpoint=endpoint)+ # The same inspectionAreaId recurs across organisations, so the parent id has to land on+ # the row for the composite primary key to identify it.+ assert rows == [+ {id_field: org_id, "inspectionAreaId": "IA-1", "status": "Active"},+ {id_field: org_id, "inspectionAreaId": "IA-2", "status": "Superseded"},+ ]++ def test_organisation_without_inspection_areas_is_skipped(self, monkeypatch: Any) -> None:+ # Most organisations have no inspected areas, so an empty or absent list is routine — it+ # must not stop the sweep over the remaining organisations.+ pages = {+ f"{CQC_BASE_URL}/providers?page=1&perPage=500&partnerCode=PC": {+ "providers": [{"providerId": "1-A"}, {"providerId": "1-B"}, {"providerId": "1-C"}],+ "totalPages": 1,+ },+ f"{CQC_BASE_URL}/providers/1-A/inspection-areas?partnerCode=PC": {"inspectionAreas": []},+ f"{CQC_BASE_URL}/providers/1-B/inspection-areas?partnerCode=PC": {},+ f"{CQC_BASE_URL}/providers/1-C/inspection-areas?partnerCode=PC": {+ "inspectionAreas": [{"inspectionAreaId": "IA-1"}]+ },+ }+ rows = _collect(_FakeResumableManager(), monkeypatch, pages, endpoint="provider_inspection_areas")+ assert rows == [{"providerId": "1-C", "inspectionAreaId": "IA-1"}]++class TestSourceResponse:@parameterized.expand([("providers", ["providerId"]), ("locations", ["locationId"])])def test_response_shape(self, endpoint: str, expected_keys: list[str]) -> None:@@ -243,6 +304,27 @@ class TestSourceResponse:assert response.partition_mode == "datetime"assert response.partition_keys == [CQC_ENDPOINTS[endpoint].partition_key]+ @parameterized.expand(+ [+ ("inspection_areas", ["inspectionAreaId"]),+ ("provider_inspection_areas", ["providerId", "inspectionAreaId"]),+ ("location_inspection_areas", ["locationId", "inspectionAreaId"]),+ ]+ )+ def test_inspection_area_responses_are_unpartitioned(self, endpoint: str, expected_keys: list[str]) -> None:+ response = care_quality_commission_source(+ api_key="key",+ partner_code="PC",+ endpoint=endpoint,+ logger=MagicMock(),+ resumable_source_manager=MagicMock(),+ )+ assert response.primary_keys == expected_keys+ # Inspection-area rows carry no stable creation date, so there is nothing safe to+ # partition on — `endDate` and the retirement dates both move when CQC retires an area.+ assert response.partition_mode is None+ assert response.partition_keys is None+class TestValidateCredentials:@parameterized.expand([("ok", 200, True), ("unauthorized", 401, False), ("forbidden", 403, False)])diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission_source.pyindex 4da4b4a9e3f3..6d50325f966e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/care_quality_commission/tests/test_care_quality_commission_source.py@@ -40,15 +40,39 @@ class TestSourceConfig:class TestGetSchemas:- def test_returns_both_streams_as_full_refresh(self) -> None:+ def test_returns_every_stream_as_full_refresh(self) -> None:schemas = {s.name: s for s in CareQualityCommissionSource().get_schemas(MagicMock(), team_id=1)}- assert set(schemas) == {"providers", "locations"}+ assert set(schemas) == {+ "providers",+ "locations",+ "inspection_areas",+ "provider_inspection_areas",+ "location_inspection_areas",+ }for schema in schemas.values():assert schema.supports_incremental is Falseassert schema.supports_append is Falseassert schema.incremental_fields == []- @parameterized.expand([("providers", ["providerId"]), ("locations", ["locationId"])])+ def test_per_organisation_fan_outs_are_not_selected_by_default(self) -> None:+ # The per-organisation inspection-area streams cost one request per registered+ # organisation, so they must not be pre-ticked in the wizard.+ schemas = CareQualityCommissionSource().get_schemas(MagicMock(), team_id=1)+ assert {s.name for s in schemas if s.should_sync_default} == {+ "providers",+ "locations",+ "inspection_areas",+ }++ @parameterized.expand(+ [+ ("providers", ["providerId"]),+ ("locations", ["locationId"]),+ ("inspection_areas", ["inspectionAreaId"]),+ ("provider_inspection_areas", ["providerId", "inspectionAreaId"]),+ ("location_inspection_areas", ["locationId", "inspectionAreaId"]),+ ]+ )def test_primary_keys(self, endpoint: str, expected_keys: list[str]) -> None:schemas = {s.name: s for s in CareQualityCommissionSource().get_schemas(MagicMock(), team_id=1)}assert schemas[endpoint].detected_primary_keys == expected_keys@@ -65,10 +89,20 @@ class TestDocumentedTables:def test_documented_tables_carry_descriptions_and_keys(self) -> None:tables = {t["name"]: t for t in CareQualityCommissionSource().get_documented_tables()}- assert set(tables) == {"providers", "locations"}+ assert set(tables) == {+ "providers",+ "locations",+ "inspection_areas",+ "provider_inspection_areas",+ "location_inspection_areas",+ }assert tables["providers"]["primary_keys"] == ["providerId"]assert tables["providers"]["sync_methods"] == ["Full refresh"]- assert tables["providers"]["description"]+ assert tables["location_inspection_areas"]["primary_keys"] == ["locationId", "inspectionAreaId"]+ # Curated descriptions are keyed by schema name — a mismatch silently empties the+ # published table catalog.+ for table in tables.values():+ assert table["description"]class TestValidateCredentials: