chore: make source map tests line-number resilient#129
Conversation
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
test/posthog/error_tracking/sources_test.exs:36-38
**Silent `nil` on missing line**
`Enum.find_value` returns `nil` when no line matches. If the target line is ever absent (e.g. the module declaration changes), `line_number` is `nil`, `result[nil]` evaluates to `nil`, and the assertion failure reads `assert nil == "defmodule …"` — which looks like the source map is wrong rather than the helper failing to locate the anchor line. A guard like `assert is_integer(line_number), "line not found in #{path}"` immediately after calling `line_number_for` would surface the real problem clearly.
### Issue 2 of 2
test/posthog/error_tracking/sources_test.exs:130-132
**Repeated constants across test cases**
`source_path` and `source_line` carry the same literal values here (lines 130-131) and again in the `load_files` test (lines 175-176). Extracting them to module attributes (`@source_path` / `@source_line`) or a shared `setup` block would satisfy the OnceAndOnlyOnce principle and make future renaming a one-line change.
Reviews (1): Last reviewed commit: "chore: make source map tests line-number..." | Re-trigger Greptile |
| |> Enum.find_value(fn {line, line_number} -> | ||
| if line == expected_line, do: line_number | ||
| end) |
There was a problem hiding this comment.
Enum.find_value returns nil when no line matches. If the target line is ever absent (e.g. the module declaration changes), line_number is nil, result[nil] evaluates to nil, and the assertion failure reads assert nil == "defmodule …" — which looks like the source map is wrong rather than the helper failing to locate the anchor line. A guard like assert is_integer(line_number), "line not found in #{path}" immediately after calling line_number_for would surface the real problem clearly.
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/posthog/error_tracking/sources_test.exs
Line: 36-38
Comment:
**Silent `nil` on missing line**
`Enum.find_value` returns `nil` when no line matches. If the target line is ever absent (e.g. the module declaration changes), `line_number` is `nil`, `result[nil]` evaluates to `nil`, and the assertion failure reads `assert nil == "defmodule …"` — which looks like the source map is wrong rather than the helper failing to locate the anchor line. A guard like `assert is_integer(line_number), "line not found in #{path}"` immediately after calling `line_number_for` would surface the real problem clearly.
How can I resolve this? If you propose a fix, please make it concise.| source_path = "lib/posthog/error_tracking/sources.ex" | ||
| source_line = "defmodule PostHog.ErrorTracking.Sources do" | ||
| line_number = line_number_for(source_path, source_line) |
There was a problem hiding this comment.
Repeated constants across test cases
source_path and source_line carry the same literal values here (lines 130-131) and again in the load_files test (lines 175-176). Extracting them to module attributes (@source_path / @source_line) or a shared setup block would satisfy the OnceAndOnlyOnce principle and make future renaming a one-line change.
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/posthog/error_tracking/sources_test.exs
Line: 130-132
Comment:
**Repeated constants across test cases**
`source_path` and `source_line` carry the same literal values here (lines 130-131) and again in the `load_files` test (lines 175-176). Extracting them to module attributes (`@source_path` / `@source_line`) or a shared `setup` block would satisfy the OnceAndOnlyOnce principle and make future renaming a one-line change.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
posthog-elixir Compliance ReportDate: 2026-06-05 16:57:17 UTC
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 608ms |
| Format Validation.Event Has Uuid | ✅ | 608ms |
| Format Validation.Event Has Lib Properties | ✅ | 606ms |
| Format Validation.Distinct Id Is String | ✅ | 609ms |
| Format Validation.Token Is Present | ✅ | 608ms |
| Format Validation.Custom Properties Preserved | ✅ | 609ms |
| Format Validation.Event Has Timestamp | ✅ | 608ms |
| Retry Behavior.Retries On 503 | ✅ | 5615ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 2610ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2611ms |
| Retry Behavior.Respects Retry After Header | ✅ | 5614ms |
| Retry Behavior.Implements Backoff | ✅ | 15624ms |
| Retry Behavior.Retries On 500 | ✅ | 5615ms |
| Retry Behavior.Retries On 502 | ✅ | 5615ms |
| Retry Behavior.Retries On 504 | ✅ | 5615ms |
| Retry Behavior.Max Retries Respected | ✅ | 15625ms |
| Deduplication.Generates Unique Uuids | ✅ | 622ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5615ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10619ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 5616ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 613ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 612ms |
| Compression.Sends Gzip When Enabled | ✅ | 609ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 608ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 606ms |
| Batch Format.Multiple Events Batched Together | ✅ | 612ms |
| Error Handling.Does Not Retry On 403 | ✅ | 2612ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2611ms |
| Error Handling.Retries On 408 | ✅ | 5614ms |
Feature_Flags Tests
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 7ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 6ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 5ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 5ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 6ms |
| Request Payload.Groups Round Trip | ✅ | 5ms |
| Request Payload.Groups Default To Empty Object | ✅ | 5ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ✅ | 6ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 5ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 5ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 6ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 3ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 607ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 10ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 6ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 609ms |
Failures
request_payload.disable_geoip_omitted_defaults_to_false
Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['groups', 'api_key', 'distinct_id', 'flag_keys_to_evaluate', 'group_properties', 'person_properties']
request_lifecycle.mock_response_value_is_returned_to_caller
Last action result missing field 'value'. Keys: ['error', 'success']
side_effect_events.get_feature_flag_captures_feature_flag_called_event
Expected 1 events with name '$feature_flag_called', got 0
💡 Motivation and Context
Main CI is failing because
SourcesTesthard-coded thatdefmodule PostHog.ErrorTracking.Sources doappears on line 4 oflib/posthog/error_tracking/sources.ex. The recent license attribution header moved that line down, so the tests failed even though source map line mapping still works correctly.This updates the tests to derive the expected line number from the fixture file content instead of relying on a brittle hard-coded line number.
💚 How did you test it?
mix test test/posthog/error_tracking/sources_test.exsmix testmix format --check-formattedmix credo --strict📝 Checklist
If releasing new changes
sampo addto generate a changeset file