Skip to content

chore: make source map tests line-number resilient#129

Merged
dustinbyrne merged 1 commit into
mainfrom
chore/ci-source-map-tests
Jun 5, 2026
Merged

chore: make source map tests line-number resilient#129
dustinbyrne merged 1 commit into
mainfrom
chore/ci-source-map-tests

Conversation

@dustinbyrne

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Main CI is failing because SourcesTest hard-coded that defmodule PostHog.ErrorTracking.Sources do appears on line 4 of lib/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.exs
  • mix test
  • mix format --check-formatted
  • mix credo --strict

📝 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 sampo add to generate a changeset file

@dustinbyrne dustinbyrne requested review from a team and rafaeelaudibert as code owners June 5, 2026 16:54
@dustinbyrne dustinbyrne merged commit 27e25f4 into main Jun 5, 2026
27 checks passed
@dustinbyrne dustinbyrne deleted the chore/ci-source-map-tests branch June 5, 2026 16:56
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
Fix 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

Comment on lines +36 to +38
|> Enum.find_value(fn {line, line_number} ->
if line == expected_line, do: line_number
end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

Comment on lines +130 to +132
source_path = "lib/posthog/error_tracking/sources.ex"
source_line = "defmodule PostHog.ErrorTracking.Sources do"
line_number = line_number_for(source_path, source_line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 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!

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-06-05 16:57:17 UTC
Duration: 107281ms

⚠️ Some Tests Failed

42/45 tests passed, 3 failed


Capture Tests

29/29 tests passed

View Details
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

⚠️ 13/16 tests passed, 3 failed

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

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.

2 participants