Skip to content

Conversation

rowanseymour
Copy link
Member

No description provided.

@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 16:57
@rowanseymour rowanseymour changed the title Better event testing Better testing of event persistence Aug 27, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves event testing by enhancing how persisted events are tracked and validated in test cases. The changes migrate from simple event count assertions to detailed per-contact event sequence validation, providing better test coverage and more granular event tracking.

Key changes:

  • Added GetHistoryEvents utility function to extract events by contact from DynamoDB test history
  • Changed test event assertions from aggregate counts to per-contact event sequences
  • Migrated test functions from handlers package to handlers_test package

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

File Description
testsuite/utils.go Added GetHistoryEvents function to scan DynamoDB test history and return events by contact UUID
core/runner/handlers/base_test.go Changed package to handlers_test, updated PersistedEvents type, replaced event counting logic with utility function call
core/runner/handlers/*.go Updated all test files to use new per-contact event tracking format and local test functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

func GetHistoryEvents(t *testing.T, rt *runtime.Runtime) map[flows.ContactUUID][]string {
rt.Writers.History.Flush()

evtTypes := make(map[flows.ContactUUID][]string, 4)
Copy link
Preview

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The hardcoded capacity of 4 appears to be a magic number. Consider using a constant or calculating the capacity based on expected data size, or simply omit the capacity parameter.

Suggested change
evtTypes := make(map[flows.ContactUUID][]string, 4)
evtTypes := make(map[flows.ContactUUID][]string)

Copilot uses AI. Check for mistakes.

Comment on lines +115 to +117
evtTypes := make(map[flows.ContactUUID][]string, 4)
for _, item := range dyntest.ScanAll[models.DynamoItem](t, rt.Dynamo, "TestHistory") {
contactUUID := flows.ContactUUID(item.PK[4:])
Copy link
Preview

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The hardcoded slice index 4 is a magic number that assumes a specific prefix format. Consider defining a constant for the prefix length or adding validation to ensure the PK has the expected format.

Suggested change
evtTypes := make(map[flows.ContactUUID][]string, 4)
for _, item := range dyntest.ScanAll[models.DynamoItem](t, rt.Dynamo, "TestHistory") {
contactUUID := flows.ContactUUID(item.PK[4:])
const historyPKPrefix = "hist"
const historyPKPrefixLen = len(historyPKPrefix)
evtTypes := make(map[flows.ContactUUID][]string, 4)
for _, item := range dyntest.ScanAll[models.DynamoItem](t, rt.Dynamo, "TestHistory") {
require.GreaterOrEqual(t, len(item.PK), historyPKPrefixLen, "item.PK too short: %q", item.PK)
require.Equal(t, historyPKPrefix, item.PK[:historyPKPrefixLen], "item.PK does not start with expected prefix: %q", item.PK)
contactUUID := flows.ContactUUID(item.PK[historyPKPrefixLen:])

Copilot uses AI. Check for mistakes.

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.96%. Comparing base (5937047) to head (a36eeee).

Files with missing lines Patch % Lines
testsuite/utils.go 0.00% 14 Missing ⚠️
testsuite/web.go 0.00% 7 Missing ⚠️
testsuite/runtime.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #765      +/-   ##
==========================================
- Coverage   51.03%   50.96%   -0.08%     
==========================================
  Files         250      250              
  Lines       15112    15133      +21     
==========================================
  Hits         7713     7713              
- Misses       6591     6612      +21     
  Partials      808      808              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rowanseymour rowanseymour merged commit 4f864e0 into main Aug 27, 2025
4 of 5 checks passed
@rowanseymour rowanseymour deleted the better_event_testing branch August 27, 2025 19:51
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants