: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(growth): record icp fit evaluation provenance (#92710)
Matt Brooker78812aae0dd7
diff --git a/products/growth/backend/enrichment/context.py b/products/growth/backend/enrichment/context.pyindex 8b06d3bc2149..4249979e15f5 100644--- a/products/growth/backend/enrichment/context.py+++ b/products/growth/backend/enrichment/context.py@@ -4,12 +4,29 @@ from enum import StrEnumfrom posthog.dataclasses import frozen+# These strings are stored on OrganizationEnrichment.data and captured on events, so a rename+# changes an output contract, not just this module.+FIT_EVALUATION_KIND_INITIAL = "initial"+FIT_EVALUATION_KIND_RECHECK = "recheck"+FIT_EVALUATION_KIND_BACKFILL = "backfill"+FIT_EVALUATION_KIND_SWEEP = "sweep"+class EnrichmentPhase(StrEnum):AT_SIGNUP = "at_signup"RECHECK = "recheck"SWEEP = "sweep"+ @property+ def fit_evaluation_kind(self) -> str:+ match self:+ case EnrichmentPhase.AT_SIGNUP:+ return FIT_EVALUATION_KIND_INITIAL+ case EnrichmentPhase.RECHECK:+ return FIT_EVALUATION_KIND_RECHECK+ case EnrichmentPhase.SWEEP:+ return FIT_EVALUATION_KIND_SWEEP+@frozenclass EnrichmentContext:diff --git a/products/growth/backend/enrichment/core.py b/products/growth/backend/enrichment/core.pyindex b301848263cd..d65ec58347e1 100644--- a/products/growth/backend/enrichment/core.py+++ b/products/growth/backend/enrichment/core.py@@ -10,6 +10,7 @@ score (fit_score.py) on its own `icp_fit_*` keys. The clay path retires once itsconsumers migrate to the fit keys."""+import datetime as dtimport dataclassesfrom typing import Any, Optional@@ -54,13 +55,15 @@ class EnrichmentOutcome:matched/upgraded reporting reads. fit is the ICP fit evaluation, present whenever fitscoring ran (its status distinguishes scored/insufficient_data/not_found/disqualified);None only when it degraded (no active curated-lists row, or an unexpected error).- enrichment_status is the polled status of the org's previously archived tracking URN- (recheck only; always None on a first attempt), so callers can report it without a- second read of the archive.+ fit_evaluated_at is the timestamp the record stores for that evaluation, so an event+ can carry the same value the record does. enrichment_status is the polled status of+ the org's previously archived tracking URN (recheck only; always None on a first+ attempt), so callers can report it without a second read of the archive."""provider_fields: Optional[EnrichmentFields] = Nonefit: Optional[IcpFitResult] = None+ fit_evaluated_at: Optional[dt.datetime] = Noneenrichment_status: Optional[str] = None@@ -357,6 +360,7 @@ async def enrich_organization(fit, fit_mirror_distinct_id = await sync_to_async(_score_fit)(ctx, bridge_inputs=bridge_inputs, raw_payload=lookup.raw_payload)+ fit_evaluated_at = dt.datetime.now(dt.UTC) if fit is not None else Noneif fields is None and fit is None:return EnrichmentOutcome(provider_fields=None, fit=None, enrichment_status=enrichment_status)@@ -368,6 +372,10 @@ async def enrich_organization(icp_score=icp_score,mirror_distinct_id=mirror_distinct_id,fit=fit,+ fit_evaluation_kind=ctx.phase.fit_evaluation_kind,+ fit_evaluated_at=fit_evaluated_at,fit_mirror_distinct_id=fit_mirror_distinct_id,)- return EnrichmentOutcome(provider_fields=lookup.fields, fit=fit, enrichment_status=enrichment_status)+ return EnrichmentOutcome(+ provider_fields=lookup.fields, fit=fit, fit_evaluated_at=fit_evaluated_at, enrichment_status=enrichment_status+ )diff --git a/products/growth/backend/enrichment/writer.py b/products/growth/backend/enrichment/writer.pyindex 21840a65afa7..17af15ec4d59 100644--- a/products/growth/backend/enrichment/writer.py+++ b/products/growth/backend/enrichment/writer.py@@ -13,6 +13,7 @@ threshold-tuned consumers migrate) and the ICP fit score on its own `icp_fit_*`The two never share a key, so neither can misattribute the other's values."""+import datetime as dtfrom collections.abc import Callablefrom typing import Any, Optional, Union@@ -88,15 +89,23 @@ def write_harmonic_enrichment_status(return previous_status-def _fit_record_writes(fit: IcpFitResult) -> tuple[dict[str, Any], list[str]]:+def _fit_record_writes(+ fit: IcpFitResult, *, evaluation_kind: str, evaluated_at: dt.datetime+) -> tuple[dict[str, Any], list[str]]:"""The Postgres (data) writes and key removals for one fit evaluation.Removals are derived from the keys this evaluation actually produced, so a scored orgthat is later disqualified loses its stale components and flags, and a score-lessevaluation (insufficient_data / not_found) strips every numeric key — the status is- the result.+ the result. icp_fit_evaluated_at/icp_fit_evaluation_kind sit outside _FIT_NUMERIC_KEYS+ so a score-less evaluation still records when and how it ran."""- values: dict[str, Any] = {"icp_fit_status": fit.status, "icp_fit_version": fit.version}+ values: dict[str, Any] = {+ "icp_fit_status": fit.status,+ "icp_fit_version": fit.version,+ "icp_fit_evaluated_at": evaluated_at.isoformat(),+ "icp_fit_evaluation_kind": evaluation_kind,+ }if fit.lists_version:values["icp_fit_lists_version"] = fit.lists_version@@ -148,6 +157,8 @@ def write_organization_enrichment(icp_score: Optional[int] = None,mirror_distinct_id: Optional[str] = None,fit: Optional[IcpFitResult] = None,+ fit_evaluation_kind: Optional[str] = None,+ fit_evaluated_at: Optional[dt.datetime] = None,fit_mirror_distinct_id: Optional[str] = None,) -> None:"""Persist enrichment to Postgres and project it onto the organization group.@@ -172,6 +183,12 @@ def write_organization_enrichment(field backfill, a fit-only write (fields=None) is the score backfill and themiss-path status stamp.+ `fit_evaluation_kind` (initial | recheck | backfill | sweep) is required whenever+ `fit` is given. It and `fit_evaluated_at` (defaulting to now) land on every evaluation,+ including score-less ones, because the sweep overwrites scores in place and the record+ must say which run wrote the current value. Both ride the Postgres record only, not the+ group projection or the person mirror.+No-op when there are no set fields and no scores, so a Harmonic miss with fit scoringdegraded leaves the stores untouched."""@@ -181,7 +198,11 @@ def write_organization_enrichment(if icp_score is not None:values = {**values, "icp_score": icp_score, "icp_score_version": SCORE_VERSION}if fit is not None:- fit_values, remove = _fit_record_writes(fit)+ if fit_evaluation_kind is None:+ raise ValueError("fit_evaluation_kind is required when fit is provided")+ fit_values, remove = _fit_record_writes(+ fit, evaluation_kind=fit_evaluation_kind, evaluated_at=fit_evaluated_at or dt.datetime.now(dt.UTC)+ )values = {**values, **fit_values}if not values:diff --git a/products/growth/backend/management/commands/backfill_icp_fit_scores.py b/products/growth/backend/management/commands/backfill_icp_fit_scores.pyindex 8524a77791a7..82fb472bd081 100644--- a/products/growth/backend/management/commands/backfill_icp_fit_scores.py+++ b/products/growth/backend/management/commands/backfill_icp_fit_scores.py@@ -42,6 +42,7 @@ from products.growth.backend.enrichment import (icp_lists as icp_lists_module,)from products.growth.backend.enrichment.bridge import read_organization_bridge_inputs+from products.growth.backend.enrichment.context import FIT_EVALUATION_KIND_BACKFILLfrom products.growth.backend.enrichment.core import latest_matched_payloadfrom products.growth.backend.enrichment.fit_score import IcpFitResult, score_companyfrom products.growth.backend.enrichment.harmonic_adapter import normalize_graphql_company@@ -240,7 +241,11 @@ class Command(BaseCommand):return "written"write_organization_enrichment(- organization_id=str(fetch.organization_id), fields=None, pha_client=pha_client, fit=result+ organization_id=str(fetch.organization_id),+ fields=None,+ pha_client=pha_client,+ fit=result,+ fit_evaluation_kind=FIT_EVALUATION_KIND_BACKFILL,)self.stdout.write(f"wrote {fetch.organization_id}: {result.status} score={result.score}")if delay:diff --git a/products/growth/backend/temporal/signup_enrichment/reenrichment.py b/products/growth/backend/temporal/signup_enrichment/reenrichment.pyindex eac007330b11..8ef5c32c6690 100644--- a/products/growth/backend/temporal/signup_enrichment/reenrichment.py+++ b/products/growth/backend/temporal/signup_enrichment/reenrichment.py@@ -274,6 +274,8 @@ async def reenrich_organization_activity(inputs: ReenrichOrgInputs) -> dict[str,"organization_id": inputs.organization_id,"matched": matched,"icp_fit_status": status,+ "icp_fit_evaluated_at": outcome.fit_evaluated_at and outcome.fit_evaluated_at.isoformat(),+ "icp_fit_evaluation_kind": ctx.phase.fit_evaluation_kind if outcome.fit else None,"harmonic_enrichment_status": outcome.enrichment_status,**observed,},diff --git a/products/growth/backend/temporal/signup_enrichment/tests/test_reenrichment.py b/products/growth/backend/temporal/signup_enrichment/tests/test_reenrichment.pyindex 2a8c579789d0..1723ddf875f2 100644--- a/products/growth/backend/temporal/signup_enrichment/tests/test_reenrichment.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_reenrichment.py@@ -27,6 +27,7 @@ from products.growth.backend.temporal.signup_enrichment.reenrichment import ()_MODULE = "products.growth.backend.temporal.signup_enrichment.reenrichment"+_EVALUATED_AT = dt.datetime(2026, 9, 14, 12, 0, tzinfo=dt.UTC)def _now() -> dt.datetime:@@ -218,6 +219,7 @@ class TestReenrichOrganizationActivity(BaseTest):outcome = EnrichmentOutcome(provider_fields=EnrichmentFields(company_type="STARTUP"),fit=IcpFitResult(status="scored", score=48),+ fit_evaluated_at=_EVALUATED_AT,enrichment_status="NOT_FOUND",)result, pha_client, enrich = self._run(outcome)@@ -236,6 +238,8 @@ class TestReenrichOrganizationActivity(BaseTest):assert event.kwargs["event"] == "icp_reenrichment_completed"assert event.kwargs["properties"]["icp_fit_status"] == "scored"assert event.kwargs["properties"]["matched"] is True+ assert event.kwargs["properties"]["icp_fit_evaluation_kind"] == "sweep"+ assert event.kwargs["properties"]["icp_fit_evaluated_at"] == _EVALUATED_AT.isoformat()assert event.kwargs["properties"]["harmonic_enrichment_status"] == "NOT_FOUND"pha_client.shutdown.assert_called_once()@@ -252,6 +256,16 @@ class TestReenrichOrganizationActivity(BaseTest):}assert pha_client.capture.call_args.kwargs["properties"]["icp_fit_status"] == "not_found"+ def test_a_degraded_fit_evaluation_leaves_the_event_provenance_empty(self):+ outcome = EnrichmentOutcome(provider_fields=EnrichmentFields(company_type="STARTUP"), fit=None)++ _, pha_client, _ = self._run(outcome)++ properties = pha_client.capture.call_args.kwargs["properties"]+ assert properties["icp_fit_status"] is None+ assert properties["icp_fit_evaluated_at"] is None+ assert properties["icp_fit_evaluation_kind"] is None+def test_event_carries_previous_status_attempt_number_and_profile_age(self):OrganizationEnrichment.objects.create(organization=self.organization,diff --git a/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.py b/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.pyindex f8858a9c95e0..9a3d9750abbc 100644--- a/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.py@@ -1,4 +1,5 @@import uuid+import datetime as dtimport pytestfrom unittest.mock import AsyncMock, MagicMock, patch@@ -20,6 +21,7 @@ pytestmark = pytest.mark.asyncio_MODULE = "products.growth.backend.temporal.signup_enrichment.workflow"_INPUTS = SignupEnrichmentInputs(organization_id="org-1", distinct_id="d1", domain="stripe.com")_TASK_QUEUE = "signup-enrichment-test-queue"+_EVALUATED_AT = dt.datetime(2026, 9, 14, 12, 0, tzinfo=dt.UTC)def _events(pha_client: MagicMock, name: str) -> list:@@ -58,7 +60,10 @@ async def test_miss_then_recheck_upgrades_without_a_second_completed_event():fields = EnrichmentFields(company_type="STARTUP", headcount=130, industry="Fintech")miss = EnrichmentOutcome(provider_fields=None, fit=IcpFitResult(status="not_found"))match = EnrichmentOutcome(- provider_fields=fields, fit=IcpFitResult(status="scored", score=61), enrichment_status="COMPLETE"+ provider_fields=fields,+ fit=IcpFitResult(status="scored", score=61),+ fit_evaluated_at=_EVALUATED_AT,+ enrichment_status="COMPLETE",)result, pha_client, enrich, snapshot = await _run([miss, match])@@ -77,6 +82,8 @@ async def test_miss_then_recheck_upgrades_without_a_second_completed_event():"fields_filled": 3,"organization_id": "org-1","icp_fit_status": "scored",+ "icp_fit_evaluated_at": _EVALUATED_AT.isoformat(),+ "icp_fit_evaluation_kind": "recheck","harmonic_enrichment_status": "COMPLETE",}# The launch signal fires exactly once — on the first attempt, unchanged.diff --git a/products/growth/backend/temporal/signup_enrichment/workflow.py b/products/growth/backend/temporal/signup_enrichment/workflow.pyindex 8b022b58c871..2d5471cdcb62 100644--- a/products/growth/backend/temporal/signup_enrichment/workflow.py+++ b/products/growth/backend/temporal/signup_enrichment/workflow.py@@ -159,6 +159,8 @@ async def enrich_signup_organization_activity("fields_filled": len(filled),"organization_id": inputs.organization_id,"icp_fit_status": fit.status if fit else None,+ "icp_fit_evaluated_at": outcome.fit_evaluated_at and outcome.fit_evaluated_at.isoformat(),+ "icp_fit_evaluation_kind": ctx.phase.fit_evaluation_kind if fit else None,"harmonic_enrichment_status": outcome.enrichment_status,},groups={"organization": inputs.organization_id},diff --git a/products/growth/backend/tests/test_backfill_icp_fit_scores.py b/products/growth/backend/tests/test_backfill_icp_fit_scores.pyindex d765b67c8626..2147b8e24e19 100644--- a/products/growth/backend/tests/test_backfill_icp_fit_scores.py+++ b/products/growth/backend/tests/test_backfill_icp_fit_scores.py@@ -106,3 +106,17 @@ class TestBackfillIcpFitScores(BaseTest):record.refresh_from_db()assert record.data == {"signup_role": "engineering"}pha_client.group_identify.assert_not_called()++ def test_writes_the_backfill_evaluation_kind(self):+ record = self._record({})++ with (+ patch(f"{_GATES_MODULE}.get_instance_region", return_value="US"),+ patch(f"{_COMMAND_MODULE}.get_regional_ph_client", return_value=MagicMock()),+ patch(f"{_COMMAND_MODULE}.read_organization_bridge_inputs", return_value=OrganizationBridgeInputs()),+ ):+ call_command("backfill_icp_fit_scores", "--delay=0")++ record.refresh_from_db()+ assert record.data["icp_fit_evaluation_kind"] == "backfill"+ assert record.data["icp_fit_evaluated_at"]diff --git a/products/growth/backend/tests/test_enrichment_core.py b/products/growth/backend/tests/test_enrichment_core.pyindex 2e96f4574825..e2663bb01d39 100644--- a/products/growth/backend/tests/test_enrichment_core.py+++ b/products/growth/backend/tests/test_enrichment_core.py@@ -111,6 +111,7 @@ class TestEnrichmentCore(BaseTest):geoip_country_code=None,domain="stripe.com",provider=None,+ phase=None,):person_patch_kwargs = {"side_effect": person} if isinstance(person, Exception) else {"return_value": person}bridge_error = None@@ -131,7 +132,7 @@ class TestEnrichmentCore(BaseTest):ctx = EnrichmentContext(organization_id=str(self.organization.id),domain=domain,- phase=EnrichmentPhase.RECHECK if is_recheck else EnrichmentPhase.AT_SIGNUP,+ phase=phase or (EnrichmentPhase.RECHECK if is_recheck else EnrichmentPhase.AT_SIGNUP),distinct_id=distinct_id,role_at_organization=role_at_organization,geoip_country_code=geoip_country_code,@@ -518,12 +519,30 @@ class TestEnrichmentCore(BaseTest):assert outcome.provider_fields is Nonerecord = OrganizationEnrichment.objects.get(organization=self.organization)- assert record.data == {+ assert record.data["icp_fit_evaluation_kind"] == "initial"+ assert outcome.fit_evaluated_at is not None+ assert record.data["icp_fit_evaluated_at"] == outcome.fit_evaluated_at.isoformat()+ data = {k: v for k, v in record.data.items() if not k.startswith("icp_fit_eval")}+ assert data == {"icp_fit_status": "not_found","icp_fit_version": "v0.6","icp_fit_lists_version": "test-lists-1",}+ @parameterized.expand(+ [+ ("at_signup", EnrichmentPhase.AT_SIGNUP, "initial"),+ ("recheck", EnrichmentPhase.RECHECK, "recheck"),+ ("sweep", EnrichmentPhase.SWEEP, "sweep"),+ ]+ )+ def test_fit_evaluation_kind_derives_from_the_phase(self, _name, phase, expected_kind):+ fields = EnrichmentFields(company_type="STARTUP", headcount=12)+ self._enrich(ProviderLookup(fields=fields, raw_payload=_company()), phase=phase, domain="acme.ai")++ record = OrganizationEnrichment.objects.get(organization=self.organization)+ assert record.data["icp_fit_evaluation_kind"] == expected_kind+def test_no_active_lists_degrades_to_clay_and_fields_only(self):IcpScoringConfig.objects.update(is_active=False)clear_lists_cache()diff --git a/products/growth/backend/tests/test_enrichment_core_phases.py b/products/growth/backend/tests/test_enrichment_core_phases.pyindex 70ff34d498fc..f92c633f2823 100644--- a/products/growth/backend/tests/test_enrichment_core_phases.py+++ b/products/growth/backend/tests/test_enrichment_core_phases.py@@ -108,6 +108,11 @@ class TestEnrichmentCorePhases(BaseTest):):return async_to_sync(enrich_organization)(ctx, provider=provider, pha_client=pha_client)+ def _record_data_without_evaluated_at(self):+ data = dict(OrganizationEnrichment.objects.get(organization=self.organization).data)+ self.assertTrue(data.pop("icp_fit_evaluated_at"))+ return data+def _rows(self):return list(OrganizationEnrichmentFetch.objects.filter(organization=self.organization)@@ -141,9 +146,8 @@ class TestEnrichmentCorePhases(BaseTest):person=None,)- record = OrganizationEnrichment.objects.get(organization=self.organization)self.assertEqual(- record.data,+ self._record_data_without_evaluated_at(),{"company_type": "STARTUP","headcount": 12,@@ -155,6 +159,7 @@ class TestEnrichmentCorePhases(BaseTest):"icp_fit_status": "scored","icp_fit_version": "v0.6","icp_fit_lists_version": "test-lists-1",+ "icp_fit_evaluation_kind": "initial","icp_fit_score": 100,"icp_fit_components": {"traction": 35,@@ -251,9 +256,8 @@ class TestEnrichmentCorePhases(BaseTest):person=person,)- record = OrganizationEnrichment.objects.get(organization=self.organization)self.assertEqual(- record.data,+ self._record_data_without_evaluated_at(),{"work_email": True,"signup_role": "engineering",@@ -267,6 +271,7 @@ class TestEnrichmentCorePhases(BaseTest):"icp_fit_status": "scored","icp_fit_version": "v0.6","icp_fit_lists_version": "test-lists-1",+ "icp_fit_evaluation_kind": "recheck","icp_fit_score": 100,"icp_fit_components": {"traction": 35,@@ -355,9 +360,8 @@ class TestEnrichmentCorePhases(BaseTest):person=None,)- record = OrganizationEnrichment.objects.get(organization=self.organization)self.assertEqual(- record.data,+ self._record_data_without_evaluated_at(),{"work_email": True,"country": "DE",@@ -368,6 +372,7 @@ class TestEnrichmentCorePhases(BaseTest):"icp_fit_status": "scored","icp_fit_version": "v0.6","icp_fit_lists_version": "test-lists-1",+ "icp_fit_evaluation_kind": "recheck","icp_fit_score": 100,"icp_fit_components": {"traction": 35,diff --git a/products/growth/backend/tests/test_enrichment_writer.py b/products/growth/backend/tests/test_enrichment_writer.pyindex 3b2b6c9c2040..42cf7e65f1f4 100644--- a/products/growth/backend/tests/test_enrichment_writer.py+++ b/products/growth/backend/tests/test_enrichment_writer.py@@ -1,6 +1,17 @@+import datetime as dt++import time_machinefrom posthog.test.base import BaseTestfrom unittest.mock import MagicMock+from parameterized import parameterized++from products.growth.backend.enrichment.context import (+ FIT_EVALUATION_KIND_BACKFILL,+ FIT_EVALUATION_KIND_INITIAL,+ FIT_EVALUATION_KIND_RECHECK,+ FIT_EVALUATION_KIND_SWEEP,+)from products.growth.backend.enrichment.fields import EnrichmentFieldsfrom products.growth.backend.enrichment.fit_score import IcpFitResultfrom products.growth.backend.enrichment.writer import (@@ -96,6 +107,8 @@ class TestEnrichmentWriter(BaseTest):pha_client=pha_client,icp_score=9,fit=_fit(),+ fit_evaluation_kind=FIT_EVALUATION_KIND_INITIAL,+ fit_evaluated_at=dt.datetime(2026, 9, 14, 12, 0, tzinfo=dt.UTC),)record = OrganizationEnrichment.objects.get(organization=self.organization)@@ -105,6 +118,8 @@ class TestEnrichmentWriter(BaseTest):assert record.data["icp_fit_version"] == "v0.6"assert record.data["icp_fit_status"] == "scored"assert record.data["icp_fit_lists_version"] == "lists-1"+ assert record.data["icp_fit_evaluation_kind"] == "initial"+ assert record.data["icp_fit_evaluated_at"] == "2026-09-14T12:00:00+00:00"assert record.data["icp_fit_components"]["capital"] == 30assert record.data["icp_fit_flags"] == {"quality_investor": True,@@ -118,6 +133,8 @@ class TestEnrichmentWriter(BaseTest):assert properties["icp_fit_score"] == 72assert properties["icp_fit_version"] == "v0.6"assert properties["icp_fit_status"] == "scored"+ assert "icp_fit_evaluated_at" not in properties+ assert "icp_fit_evaluation_kind" not in propertiesdef test_fit_flags_record_wizard_evidence_and_ai_pilled_source(self):pha_client = MagicMock()@@ -126,6 +143,7 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=_fit(wizard_ai_sdk=True, ai_pilled_source="both"),+ fit_evaluation_kind=FIT_EVALUATION_KIND_INITIAL,)record = OrganizationEnrichment.objects.get(organization=self.organization)@@ -143,6 +161,7 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=_fit(score=41),+ fit_evaluation_kind=FIT_EVALUATION_KIND_BACKFILL,)record = OrganizationEnrichment.objects.get(organization=self.organization)@@ -164,12 +183,14 @@ class TestEnrichmentWriter(BaseTest):},)pha_client = MagicMock()- write_organization_enrichment(- organization_id=str(self.organization.id),- fields=None,- pha_client=pha_client,- fit=IcpFitResult(status="insufficient_data", lists_version="lists-1"),- )+ with time_machine.travel("2026-09-01T12:00:00Z", tick=False):+ write_organization_enrichment(+ organization_id=str(self.organization.id),+ fields=None,+ pha_client=pha_client,+ fit=IcpFitResult(status="insufficient_data", lists_version="lists-1"),+ fit_evaluation_kind=FIT_EVALUATION_KIND_SWEEP,+ )record = OrganizationEnrichment.objects.get(organization=self.organization)assert record.data == {@@ -178,6 +199,8 @@ class TestEnrichmentWriter(BaseTest):"icp_fit_status": "insufficient_data","icp_fit_version": "v0.6","icp_fit_lists_version": "lists-1",+ "icp_fit_evaluated_at": "2026-09-01T12:00:00+00:00",+ "icp_fit_evaluation_kind": "sweep",}# Group properties cannot be deleted, so only the status key is projected: pairing# the fresh version with the group's stale numeric score would misattribute it.@@ -187,7 +210,11 @@ class TestEnrichmentWriter(BaseTest):def test_disqualification_after_a_scored_pass_strips_the_stale_components_and_flags(self):pha_client = MagicMock()write_organization_enrichment(- organization_id=str(self.organization.id), fields=None, pha_client=pha_client, fit=_fit(score=62)+ organization_id=str(self.organization.id),+ fields=None,+ pha_client=pha_client,+ fit=_fit(score=62),+ fit_evaluation_kind=FIT_EVALUATION_KIND_INITIAL,)record = OrganizationEnrichment.objects.get(organization=self.organization)assert record.data["icp_fit_components"]["capital"] == 30@@ -198,6 +225,7 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=IcpFitResult(status="disqualified", score=0, dq_reason="role=student"),+ fit_evaluation_kind=FIT_EVALUATION_KIND_RECHECK,)record.refresh_from_db()assert record.data["icp_fit_score"] == 0@@ -212,9 +240,14 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=IcpFitResult(status="disqualified", score=0, dq_reason="company_type=SCHOOL"),+ fit_evaluation_kind=FIT_EVALUATION_KIND_INITIAL,)write_organization_enrichment(- organization_id=str(self.organization.id), fields=None, pha_client=pha_client, fit=_fit()+ organization_id=str(self.organization.id),+ fields=None,+ pha_client=pha_client,+ fit=_fit(),+ fit_evaluation_kind=FIT_EVALUATION_KIND_RECHECK,)record = OrganizationEnrichment.objects.get(organization=self.organization)@@ -228,6 +261,7 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=_fit(score=55),+ fit_evaluation_kind=FIT_EVALUATION_KIND_INITIAL,fit_mirror_distinct_id="signer",)pha_client.set.assert_called_once_with(@@ -241,10 +275,39 @@ class TestEnrichmentWriter(BaseTest):fields=None,pha_client=pha_client,fit=IcpFitResult(status="insufficient_data"),+ fit_evaluation_kind=FIT_EVALUATION_KIND_RECHECK,fit_mirror_distinct_id="signer",)pha_client.set.assert_called_once_with(distinct_id="signer", properties={"icp_fit_status": "insufficient_data"})+ @parameterized.expand(+ [+ (FIT_EVALUATION_KIND_INITIAL, "initial"),+ (FIT_EVALUATION_KIND_RECHECK, "recheck"),+ (FIT_EVALUATION_KIND_BACKFILL, "backfill"),+ (FIT_EVALUATION_KIND_SWEEP, "sweep"),+ ]+ )+ def test_fit_evaluation_kind_is_recorded_verbatim(self, kind, stored):+ write_organization_enrichment(+ organization_id=str(self.organization.id),+ fields=None,+ pha_client=MagicMock(),+ fit=_fit(),+ fit_evaluation_kind=kind,+ )+ record = OrganizationEnrichment.objects.get(organization=self.organization)+ assert record.data["icp_fit_evaluation_kind"] == stored++ def test_fit_without_evaluation_kind_raises(self):+ with self.assertRaises(ValueError):+ write_organization_enrichment(+ organization_id=str(self.organization.id),+ fields=None,+ pha_client=MagicMock(),+ fit=_fit(),+ )+def test_record_signup_work_email_merges_without_clobbering_provider_data(self):record_signup_work_email(organization_id=str(self.organization.id), work_email=False)assert OrganizationEnrichment.objects.get(organization=self.organization).data == {"work_email": False}