Skip to content

E2E core code types and helper functions - #3903

Open
joe-ayoub-segment wants to merge 4 commits into
mainfrom
e2e-type-helpers
Open

E2E core code types and helper functions#3903
joe-ayoub-segment wants to merge 4 commits into
mainfrom
e2e-type-helpers

Conversation

@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

This PR adds a set of shared TypeScript types and event-construction helpers to packages/core that support the end-to-end (E2E) test framework for Action Destinations. These primitives let destination authors write E2E fixtures — real HTTP calls against a running serve server - with strong typing and consistent event payloads.

  • Note: The E2E test runner that consumes these types currently lives in a temporary repo (joe-ayoub-segment/action-destinations-e2e) until it's polished and
  • merged into action-destinations. This PR lands the shared type/helper surface in core first so the runner and destinations can import a single canonical source.

What's included

packages/core/src/e2e-types.ts — Type definitions for the E2E framework:

  • Fixtures - E2EFixture union covering single, batch, and batchWithMultistatus execution modes, each with description, subscribe (FQL), mapping, expect, optional features (feature flags), retries, and verboseFailureHint.
  • Expectations - E2ESuccessExpectation, E2EFailureExpectation, and E2EErrorExpectation to assert on 2xx responses, non-2xx responses, or pre-request action errors (e.g. PayloadValidationError), with bodyContains / jsonContains partial matching.
  • Dynamic value markers — $now, $guid, $guid:, and $externalAudienceId, resolved by the runner at execution time.
  • Audience event option/shape types — for Engage (track + identify), Journeys V1, Journeys V2, and RETL audience events, typed on a generic ComputationKey.
  • Config types — E2EDestinationConfig, E2EAudienceDestinationConfig, E2EAudienceConfig, teardown contexts, and E2ESettingsSecretValue ($env indirection for
    secrets).
  • HTTP status unions — E2EHttpSuccessCode / E2EHttpFailureCode.

packages/core/src/e2e-helpers.ts — Event builders:

  • createE2EEvent — a plain Segment Connections event (track/page/screen/identify/group, etc.).
  • createE2EEngageAudienceEvent — Engage audience track or identify events, with add/remove membership.
  • createE2EJourneysV1AudienceEvent — Journeys V1 Audience Entered track events (entry-only, no membership boolean).
  • createE2EJourneysV2AudienceEvent — Journeys V2 journey_step track events carrying journey_context / journey_metadata and an add/remove membership boolean.
  • createE2ERetlAudienceEvent — Reverse ETL audience events using new / updated / deleted event names.

packages/core/src/index.ts — Re-exports the helpers and types from the package root.

Impact

  • Additive only — no existing exports or behavior change.
  • Types/helpers are self-contained (no new runtime dependencies); no destinations import them yet.

Testing

  • yarn core build / yarn typecheck pass.
  • No other testing needed.

Security Review

Please ensure sensitive data is properly protected in your integration.

  • Reviewed all field definitions for sensitive data (API keys, tokens, passwords, client secrets) and confirmed they use type: 'password'

New Destination Checklist

  • Extracted all action API versions to verioning-info.ts file. example

Copilot AI review requested due to automatic review settings July 24, 2026 07:56
@joe-ayoub-segment
joe-ayoub-segment requested a review from a team as a code owner July 24, 2026 07:56
@joe-ayoub-segment joe-ayoub-segment self-assigned this Jul 24, 2026

Copilot AI 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.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds shared E2E TypeScript primitives to packages/core so destination authors and an external E2E runner can construct strongly-typed events and fixtures with consistent payloads.

Changes:

  • Added e2e-types.ts defining fixture/expectation/config and audience event types for the E2E framework
  • Added e2e-helpers.ts with event-construction helpers for standard events and multiple audience systems (Engage/Journeys/RETL)
  • Re-exported the new helpers/types from the core package root

Reviewed changes

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

File Description
packages/core/src/index.ts Re-exports the new E2E helper functions and types from the package entrypoint
packages/core/src/e2e-types.ts Introduces E2E fixture/expectation/config types and typed audience-event shapes
packages/core/src/e2e-helpers.ts Adds helper functions to build typed Segment events and audience events for E2E fixtures

Comment thread packages/core/src/e2e-helpers.ts
Comment thread packages/core/src/e2e-types.ts
Comment thread packages/core/src/e2e-types.ts
Copilot AI review requested due to automatic review settings July 24, 2026 08:12

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread packages/core/src/e2e-helpers.ts
Comment thread packages/core/src/e2e-types.ts
Comment thread packages/core/src/e2e-helpers.ts Outdated
Comment thread packages/core/src/e2e-types.ts Outdated
Comment thread packages/core/src/e2e-helpers.ts Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 10:57

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread packages/core/src/e2e-helpers.ts
Comment thread packages/core/src/e2e-helpers.ts
Comment thread packages/core/src/e2e-types.ts
Comment thread packages/core/src/e2e-types.ts
Copilot AI review requested due to automatic review settings July 24, 2026 14:34

Copilot AI 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.

Pull request overview

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

Comment on lines +31 to +56
export function createE2EEvent(type: SegmentEvent['type'], name?: string, overrides?: E2EEventOverrides): SegmentEvent {
if (type === 'track') {
return {
type,
event: name,
messageId: '$guid',
timestamp: '$now',
...overrides
}
}

if (type === 'page' || type === 'screen') {
return {
type,
name,
messageId: '$guid',
timestamp: '$now',
...overrides
}
}

if (name) {
throw new Error(
`createE2EEvent: "name" is not supported for "${type}" events. Only track, page, and screen accept a name.`
)
}
Comment on lines +9 to +27
export interface E2ESuccessExpectation {
status: 'success'
httpStatus?: E2EHttpSuccessCode
bodyContains?: string
/** Partial deep match against the JSON response body. Arrays must match length and each item is partial-matched. */
jsonContains?: unknown
}

/**
* The HTTP request was sent and the destination API returned a non-2xx response.
* Use this to verify that the destination rejects specific inputs (e.g., bad auth, invalid payload).
*/
export interface E2EFailureExpectation {
status: 'failure'
httpStatus: E2EHttpFailureCode
bodyContains?: string
/** Partial deep match against the JSON response body. Arrays must match length and each item is partial-matched. */
jsonContains?: unknown
}
Comment on lines +148 to +168
const event = {
messageId: '$guid',
timestamp: '$now',
...(userId && { userId }),
...(anonymousId && { anonymousId }),
type: 'track',
event: 'Audience Entered',
properties: {
...enrichedTraits
},
context: {
personas: {
computation_class: 'journey_step',
computation_key: computationKey,
computation_id: computationId,
...(externalAudienceId && { external_audience_id: externalAudienceId })
},
...(audienceFields && { audienceFields }),
...(email && { traits: { email } })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants