diff --git a/CHANGELOG.md b/CHANGELOG.md index 503181a..c52c4c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Add `extra-install-packages` input to install additional apt packages required by custom dangerfiles - Custom dangerfiles receive full Danger API access (`fail`, `warn`, `message`, `markdown`, `danger`) - Enables repositories to extend Danger checks without overwriting shared workflow comments +- Sentry-CLI integration test action - Add `InvokeSentryResult::Events()` method to extract events from envelopes ([#137](https://github.com/getsentry/github-workflows/pull/137)) ## 3.1.0 diff --git a/sentry-cli/integration-test/action.psm1 b/sentry-cli/integration-test/action.psm1 index 73b2fbf..f385a93 100644 --- a/sentry-cli/integration-test/action.psm1 +++ b/sentry-cli/integration-test/action.psm1 @@ -39,6 +39,32 @@ class InvokeSentryResult return $envelopes } + # Events are extracted from envelopes, each event body as single item. + # Note: Unlike Envelopes(), this method discards potential duplicates based on event_id. + [string[]]Events() + { + $ids = @() + $events = @() + foreach ($envelope in $this.Envelopes()) + { + $lines = @($envelope -split "\\n") + $header = $lines[0].Trim() | ConvertFrom-Json + $eventId = $header | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue + if ($eventId -and $ids -notcontains $eventId) + { + $body = $lines | Select-Object -Skip 1 | Where-Object { + ($_ | ConvertFrom-Json | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue) -eq $eventId + } | Select-Object -First 1 + if ($body) + { + $ids += $eventId + $events += $body + } + } + } + return $events + } + [bool]HasErrors() { return $this.ServerStdErr.Length -gt 0 diff --git a/sentry-cli/integration-test/tests/action.Tests.ps1 b/sentry-cli/integration-test/tests/action.Tests.ps1 index 0c674bf..2bab19a 100644 --- a/sentry-cli/integration-test/tests/action.Tests.ps1 +++ b/sentry-cli/integration-test/tests/action.Tests.ps1 @@ -97,4 +97,30 @@ helloworld $result.Envelopes().Length | Should -Be 1 $result.Envelopes()[0].Length | Should -Be 357 } + + It "discards duplicate events" { + $result = Invoke-SentryServer { + param([string]$url) + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:52:42.924Z"} +{"type":"session","length":42} +{"sid":"66356dadc138458a8d5cd9e258065175"} +'@ + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"} +{"type":"event","length":47,"content_type":"application/json"} +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"} +'@ + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:41.505Z"} +{"type":"event","length":47,"content_type":"application/json"} +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"} +'@ + } + + Should -ActualValue $result.HasErrors() -BeFalse + $result.Envelopes().Length | Should -Be 3 + $result.Events().Length | Should -Be 1 + $result.Events()[0].Length | Should -Be 47 + } }