Skip to content

chore: deduplicate dry4swift findings#618

Merged
marandaneto merged 4 commits into
mainfrom
refactor/dry4swift-poc-dedupe
Jun 5, 2026
Merged

chore: deduplicate dry4swift findings#618
marandaneto merged 4 commits into
mainfrom
refactor/dry4swift-poc-dedupe

Conversation

@marandaneto

@marandaneto marandaneto commented May 27, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

PoC for using dry4swift to identify structural duplicate Swift code and apply low-risk deduplication in the iOS SDK.

This PR intentionally focuses on mechanical/refactor-only changes where shared helpers reduce duplicate implementation patterns without changing public behavior.

Key examples:

  • shared integration install/uninstall state handling
  • shared survey enum string decoding helper
  • shared remote-config cached value/dictionary helpers
  • shared SDK helpers for autocapture/rageclick, feature events, and exception capture
  • shared URLSession request execution and a few small replay/survey UI helpers

The initial dry4swift candidate count was reduced from 203 to 120 after the POC refactors.

💚 How did you test it?

  • make format
  • make test — 559 tests passed
  • Re-ran dry4swift locally to compare duplicate candidate counts

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

@marandaneto

Copy link
Copy Markdown
Member Author

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

posthog-ios Compliance Report

Date: 2026-06-05 07:08:00 UTC
Duration: 194152ms

⚠️ Some Tests Failed

34/45 tests passed, 11 failed


Capture Tests

⚠️ 24/29 tests passed, 5 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 2233ms
Format Validation.Event Has Uuid 2214ms
Format Validation.Event Has Lib Properties 2288ms
Format Validation.Distinct Id Is String 2185ms
Format Validation.Token Is Present 2239ms
Format Validation.Custom Properties Preserved 2252ms
Format Validation.Event Has Timestamp 2227ms
Retry Behavior.Retries On 503 7307ms
Retry Behavior.Does Not Retry On 400 4260ms
Retry Behavior.Does Not Retry On 401 4452ms
Retry Behavior.Respects Retry After Header 7216ms
Retry Behavior.Implements Backoff 17272ms
Retry Behavior.Retries On 500 7290ms
Retry Behavior.Retries On 502 7276ms
Retry Behavior.Retries On 504 7253ms
Retry Behavior.Max Retries Respected 17389ms
Deduplication.Generates Unique Uuids 2394ms
Deduplication.Preserves Uuid On Retry 7299ms
Deduplication.Preserves Uuid And Timestamp On Retry 12195ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7319ms
Deduplication.No Duplicate Events In Batch 2509ms
Deduplication.Different Events Have Different Uuids 2328ms
Compression.Sends Gzip When Enabled 2364ms
Batch Format.Uses Proper Batch Structure 2267ms
Batch Format.Flush With No Events Sends Nothing 2225ms
Batch Format.Multiple Events Batched Together 2539ms
Error Handling.Does Not Retry On 403 4218ms
Error Handling.Does Not Retry On 413 4238ms
Error Handling.Retries On 408 7412ms

Failures

retry_behavior.retries_on_503

Expected at least 3 requests, got 2

retry_behavior.max_retries_respected

Expected 4 requests, got 3

deduplication.preserves_uuid_and_timestamp_on_retry

Expected at least 3 requests, got 2

batch_format.multiple_events_batched_together

Expected 1 requests, got 3

error_handling.does_not_retry_on_413

Expected 1 requests, got 2

Feature_Flags Tests

⚠️ 10/16 tests passed, 6 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 2422ms
Request Payload.Flags Request Uses V2 Query Param 2355ms
Request Payload.Flags Request Hits Flags Path Not Decide 2201ms
Request Payload.Flags Request Omits Authorization Header 2240ms
Request Payload.Token In Flags Body Matches Init 2266ms
Request Payload.Groups Round Trip 2419ms
Request Payload.Groups Default To Empty Object 2233ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 2337ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 2393ms
Request Payload.Disable Geoip Omitted Defaults To False 2325ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 2252ms
Request Lifecycle.No Flags Request On Init Alone 113ms
Request Lifecycle.No Flags Request On Normal Capture 2227ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 4362ms
Request Lifecycle.Mock Response Value Is Returned To Caller 2284ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 4276ms

Failures

request_payload.request_with_person_properties_device_id

Expected distinct_id='test_user_123', got '019E969B-9D95-79BC-BF7A-4CFBB0B2F3E8'

request_payload.groups_default_to_empty_object

Field 'group_properties' not found in /flags request body at path 'group_properties'. Available keys: ['groups', 'timezone', '$device_id', 'api_key', 'person_properties', '$anon_distinct_id', 'distinct_id']

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

Field 'distinct_id' not found in /flags request body at path 'person_properties.distinct_id'. Available keys: ['$os_name', '$os_version', 'email', '$lib_version', '$lib', '$app_namespace', '$device_type']

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['$device_id', '$anon_distinct_id', 'groups', 'timezone', 'api_key', 'distinct_id', 'person_properties']

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['timezone', 'person_properties', '$device_id', 'distinct_id', 'groups', 'api_key', '$anon_distinct_id']

request_payload.flag_keys_to_evaluate_contains_only_requested_key

Field 'flag_keys_to_evaluate' not found in /flags request body at path 'flag_keys_to_evaluate'. Available keys: ['api_key', 'timezone', '$device_id', 'person_properties', 'groups', 'distinct_id', '$anon_distinct_id']

@marandaneto

Copy link
Copy Markdown
Member Author

@ioannisj @turnipdabeets wdyt? this could be in CI as well

@ioannisj

Copy link
Copy Markdown
Contributor

@ioannisj @turnipdabeets wdyt? this could be in CI as well

Had me at installIfNeeded()

@ioannisj

Copy link
Copy Markdown
Contributor

No familiar at all with dry4swift and can't find it online? Is this under github.com/dryproject?

@marandaneto

marandaneto commented May 29, 2026

Copy link
Copy Markdown
Member Author

dry4swift

https://github.com/marandaneto/dry4swift

i have made a similar pr for python PostHog/posthog-python#623

@marandaneto marandaneto changed the title POC: deduplicate dry4swift findings chore: deduplicate dry4swift findings Jun 4, 2026
@marandaneto marandaneto marked this pull request as ready for review June 4, 2026 12:59
@marandaneto marandaneto requested a review from a team as a code owner June 4, 2026 12:59
@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: resolve survey build failures" | Re-trigger Greptile

@turnipdabeets turnipdabeets left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup — this is behavior-preserving as far as I can tell. LGTM!

Comment thread PostHog/ErrorTracking/PostHogExceptionProcessor.swift
@marandaneto marandaneto merged commit 2d0100d into main Jun 5, 2026
36 checks passed
@marandaneto marandaneto deleted the refactor/dry4swift-poc-dedupe branch June 5, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants