Skip to content

: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.

fix(signals): label merge duplicate_of links with a write path (#122851)

Andrew Maguiref9347b92866e
diff --git a/products/signals/backend/enums.py b/products/signals/backend/enums.py
index 19753e2d1689..bb491bd8786d 100644
--- a/products/signals/backend/enums.py
+++ b/products/signals/backend/enums.py
@@ -72,9 +72,11 @@ class SuggestedSourceProduct(LabeledStrEnum):
class ReportLinkWritePath(StrEnum):
# Which surface wrote a `report_link`. `EMIT` writes it with the report, before auto-start reads
# the link gates. `EDIT` writes it on a report that exists, possibly after auto-start ran.
+ # `MERGE` writes the `duplicate_of` link when the merge endpoint folds a report into another.
EMIT = "emit"
EDIT = "edit"
PIPELINE = "pipeline"
+ MERGE = "merge"
class SignalSourceProduct(StrEnum):
diff --git a/products/signals/backend/report_merge.py b/products/signals/backend/report_merge.py
index e42296570f75..a71fdb6c98b2 100644
--- a/products/signals/backend/report_merge.py
+++ b/products/signals/backend/report_merge.py
@@ -34,7 +34,7 @@ from products.signals.backend.artefact_schemas import (
NoteArtefact,
ReportLink,
)
-from products.signals.backend.enums import ReportLinkKind
+from products.signals.backend.enums import ReportLinkKind, ReportLinkWritePath
from products.signals.backend.models import (
SignalReport,
SignalReportArtefact,
@@ -290,6 +290,7 @@ def _merge_source_into(
report_id=str(source.id),
content=ReportLink(kind=ReportLinkKind.DUPLICATE_OF, report_id=str(survivor.id), reason=reason),
attribution=attribution,
+ write_path=ReportLinkWritePath.MERGE,
)
_dismiss_as_merged(source, survivor=survivor, attribution=attribution, reason=reason)
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 0d45f8defb46..9d4b2b532f28 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -52,7 +52,7 @@ from products.signals.backend.artefact_schemas import (
RankingScore,
ReportLink,
)
-from products.signals.backend.enums import ReportLinkKind, ReportPriority
+from products.signals.backend.enums import ReportLinkKind, ReportLinkWritePath, ReportPriority
from products.signals.backend.implementation_pr import (
ImplementationPr,
fetch_implementation_pr_state_for_reports,
@@ -4270,6 +4270,33 @@ class TestSignalReportMergeAPI(APIBaseTest):
team_id=self.team.id, survivor_report_id=str(survivor.id), source_report_ids=[str(source.id)]
)
+ def test_merge_labels_the_duplicate_link_event_with_the_merge_write_path(self):
+ survivor = self._report()
+ source = self._report()
+
+ with (
+ patch("products.signals.backend.tasks.move_merged_report_signals.delay"),
+ patch("products.signals.backend.typed_report_links.capture_report_linked") as capture,
+ ):
+ with self.captureOnCommitCallbacks(execute=True):
+ assert (
+ self.client.post(
+ self._merge_url(str(survivor.id)),
+ data=json.dumps({"source_report_ids": [str(source.id)]}),
+ content_type="application/json",
+ ).status_code
+ == status.HTTP_200_OK
+ )
+
+ capture.assert_called_once()
+ kwargs = capture.call_args.kwargs
+ assert (kwargs["edge"].source_id, kwargs["edge"].kind, kwargs["edge"].target_id) == (
+ str(source.id),
+ ReportLinkKind.DUPLICATE_OF,
+ str(survivor.id),
+ )
+ assert kwargs["write_path"] == ReportLinkWritePath.MERGE
+
class TestAvailableReviewersAPI(APIBaseTest):
"""GET signals/reports/available_reviewers/: returns every eligible org member (no cap), with server-side search."""