Skip to content

Prevent overlapping referral program editions#1986

Open
Goader wants to merge 3 commits intomainfrom
task/prevent-edition-overlap
Open

Prevent overlapping referral program editions#1986
Goader wants to merge 3 commits intomainfrom
task/prevent-edition-overlap

Conversation

@Goader
Copy link
Copy Markdown
Member

@Goader Goader commented Apr 23, 2026

Prevent overlapping referral program editions

closes: #1959

Summary

  • Added base referral program edition config type to be a common root between config and summary types
  • Added verification for the overlap

Why


Testing

  • Automatic CI and manual validation
  • Added new tests for the added functionality

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@Goader Goader self-assigned this Apr 23, 2026
Copilot AI review requested due to automatic review settings April 23, 2026 00:57
@Goader Goader requested a review from a team as a code owner April 23, 2026 00:57
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: 4244d61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@namehash/ens-referrals Major
ensapi Major
ensindexer Major
ensadmin Major
ensrainbow Major
fallback-ensapi Major
enssdk Major
enscli Major
enskit Major
ensskills Major
@ensnode/datasources Major
@ensnode/ensrainbow-sdk Major
@ensnode/ensdb-sdk Major
@ensnode/ensnode-react Major
@ensnode/ensnode-sdk Major
@ensnode/integration-test-env Major
@ensnode/ponder-sdk Major
@ensnode/ponder-subgraph Major
@ensnode/shared-configs Major
@docs/ensnode Major
@docs/ensrainbow Major
@namehash/namehash-ui Major
@ensnode/enskit-react-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ensnode.io Ready Ready Preview, Comment Apr 23, 2026 0:36am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Apr 23, 2026 0:36am
ensrainbow.io Skipped Skipped Apr 23, 2026 0:36am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5b680dd8-c2ab-49e6-89e8-c02fbce36ac9

📥 Commits

Reviewing files that changed from the base of the PR and between 44b4385 and 4244d61.

📒 Files selected for processing (12)
  • .changeset/bright-rivers-flow.md
  • .changeset/quiet-mirrors-shine.md
  • .changeset/shiny-tigers-wander.md
  • apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts
  • docs/ensnode.io/ensapi-openapi.json
  • packages/ens-referrals/src/api/zod-schemas.test.ts
  • packages/ens-referrals/src/api/zod-schemas.ts
  • packages/ens-referrals/src/award-models/shared/api/zod-schemas.ts
  • packages/ens-referrals/src/award-models/shared/edition-summary.ts
  • packages/ens-referrals/src/edition.test.ts
  • packages/ens-referrals/src/edition.ts
  • packages/ens-referrals/src/internal.ts

📝 Walkthrough

Walkthrough

Implements validation to prevent overlapping referral program editions for the same subregistryId by extracting shared edition-config fields into a base type, introducing overlap-detection functions, and enforcing non-overlap invariants during config parsing. Also exposes per-award-model Zod schemas via the internal entrypoint.

Changes

Cohort / File(s) Summary
Changesets
.changeset/bright-rivers-flow.md, .changeset/quiet-mirrors-shine.md, .changeset/shiny-tigers-wander.md
Three changesets documenting minor release notes: shared base edition config type, per-award-model Zod schema exposure, and non-overlapping editions constraint.
Type Refactoring
packages/ens-referrals/src/edition.ts, packages/ens-referrals/src/award-models/shared/edition-summary.ts
Extract BaseReferralProgramEditionConfig as shared parent type; introduce findOverlappingEditionPair and validateNonOverlappingEditionTimes functions to detect and reject overlapping time ranges per subregistryId; update ReferralProgramEditionConfig to extend base and call validation in buildReferralProgramEditionConfigSet.
Zod Schema Builders
packages/ens-referrals/src/award-models/shared/api/zod-schemas.ts
Add new exported schema builders: makeReferralProgramEditionSlugSchema and makeBaseReferralProgramEditionConfigSchema; refactor makeBaseReferralProgramEditionSummarySchema to build from the new base config schema.
API Validation
packages/ens-referrals/src/api/zod-schemas.ts
Replace local schema definitions with shared imports; add overlap invariant enforcement to makeReferralProgramEditionConfigSetArraySchema and makeReferralProgramEditionSummariesDataSchema using findOverlappingEditionPair and custom Zod issues.
Overlap Tests
packages/ens-referrals/src/edition.test.ts
New test file covering edge cases: disjoint windows, interior overlaps, boundary-touch overlap, subregistry differentiation, and error messages for findOverlappingEditionPair, validateNonOverlappingEditionTimes, and buildReferralProgramEditionConfigSet.
Schema Validation Tests
packages/ens-referrals/src/api/zod-schemas.test.ts
Extend test suite with edition-summary and config-set overlap validation; adjust fixture timing constants to remain disjoint; add tests for rejecting interior and boundary overlaps and accepting overlaps across different subregistryId values.
Exports & Metadata
packages/ens-referrals/src/internal.ts, docs/ensnode.io/ensapi-openapi.json
Export per-award-model Zod schemas (pie-split, rev-share-cap, shared) via internal entrypoint; bump OpenAPI version to 1.10.1.
Test Update
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts
Refactor edition-leaderboard mocking to construct per-edition ReferrerLeaderboard objects with distinct rules from corresponding edition config instead of sharing a single emptyReferralLeaderboard.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Suggested labels

ensanalytics

Poem

🐰 Editions no longer dance in time's overlapping waltz,
Each subregistry ID claims its own slot with care,
No two shall blur their boundaries, no inclusive faults,
Validation hops in quick to keep the timeline fair!
Share the config base, export schemas with pride—
Constraints and clarity walk side by side. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Prevent overlapping referral program editions' is clear, specific, and directly describes the main change in the changeset.
Description check ✅ Passed The PR description follows the template structure with Summary, Why, Testing, and Pre-Review Checklist sections completed. All required information is present.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #1959: introduces BaseReferralProgramEditionConfig as shared parent type, adds findOverlappingEditionPair and validateNonOverlappingEditionTimes functions, enforces non-overlapping editions per subregistryId with inclusive time ranges, and includes comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are scoped to the overlap prevention feature: type refactoring, validation logic, test coverage, schema updates, and documentation. The OpenAPI version bump is a standard practice for releases and is in-scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/prevent-edition-overlap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 23, 2026

Greptile Summary

This PR prevents overlapping referral program editions by introducing BaseReferralProgramEditionConfig as a shared type root and an O(n log n) findOverlappingEditionPair algorithm (sort by startTime, adjacent-pair scan per subregistryId). The overlap check is wired into both the runtime builder (buildReferralProgramEditionConfigSet) and the Zod validation layer (makeReferralProgramEditionConfigSetArraySchema, makeReferralProgramEditionSummariesDataSchema). Test coverage for boundary conditions (abutting ranges, cross-subregistry exemptions, unrecognized models) is thorough.

Confidence Score: 5/5

Safe to merge — the core algorithm is correct, inclusive-bound semantics are consistent throughout, and address normalization via the existing Zod pipeline prevents key collisions in practice.

All remaining findings are P2 style suggestions. The algorithm correctness is sound (sort + adjacent-pair scan is provably sufficient for detecting any overlap), inclusive-bound handling is consistent, and the test suite covers disjoint, interior-overlapping, abutting, cross-subregistry, and mixed-model cases.

No files require special attention; the one P2 note on address casing in edition.ts is a defensive hardening suggestion only.

Important Files Changed

Filename Overview
packages/ens-referrals/src/edition.ts Introduces BaseReferralProgramEditionConfig, findOverlappingEditionPair (O(n log n), correct inclusive-bound handling), validateNonOverlappingEditionTimes, and wires the check into buildReferralProgramEditionConfigSet. Algorithm is sound.
packages/ens-referrals/src/api/zod-schemas.ts Adds overlap superRefine to both makeReferralProgramEditionConfigSetArraySchema and makeReferralProgramEditionSummariesDataSchema; removes duplicate local helpers now moved to shared module.
packages/ens-referrals/src/award-models/shared/api/zod-schemas.ts Centralises makeReferralProgramEditionSlugSchema (now backed by the canonical REFERRAL_PROGRAM_EDITION_SLUG_PATTERN) and makeBaseReferralProgramEditionConfigSchema; makeBaseReferralProgramEditionSummarySchema refactored to extend base.
packages/ens-referrals/src/award-models/shared/edition-summary.ts BaseReferralProgramEditionSummary now extends BaseReferralProgramEditionConfig, removing duplicated slug/displayName/rules fields while keeping the awardModel discriminant and status fields.
packages/ens-referrals/src/edition.test.ts New unit tests covering disjoint, interior-overlapping, abutting, and cross-subregistry cases for findOverlappingEditionPair, validateNonOverlappingEditionTimes, and buildReferralProgramEditionConfigSet.
packages/ens-referrals/src/api/zod-schemas.test.ts Extensive new Zod-level tests for the non-overlap invariant on both config-set and summaries schemas, including abutting boundaries, different-subregistry exemptions, and unrecognized-model editions.
packages/ens-referrals/src/internal.ts Adds re-exports for per-award-model (pie-split, rev-share-cap) and shared Zod schemas through the internal entrypoint.
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts Updates mock leaderboards to carry edition-specific rules so each edition summary has a distinct time window, preventing the new overlap invariant from rejecting the fixture data.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant buildReferralProgramEditionConfigSet
    participant validateNonOverlappingEditionTimes
    participant findOverlappingEditionPair
    participant ZodConfigSetArraySchema
    participant ZodSummariesDataSchema

    Caller->>buildReferralProgramEditionConfigSet: configs[]
    buildReferralProgramEditionConfigSet->>buildReferralProgramEditionConfigSet: check duplicate slugs
    buildReferralProgramEditionConfigSet->>validateNonOverlappingEditionTimes: configs[]
    validateNonOverlappingEditionTimes->>findOverlappingEditionPair: configs[]
    findOverlappingEditionPair->>findOverlappingEditionPair: group by subregistryId key
    findOverlappingEditionPair->>findOverlappingEditionPair: sort each group by startTime
    findOverlappingEditionPair->>findOverlappingEditionPair: adjacent-pair scan
    findOverlappingEditionPair-->>validateNonOverlappingEditionTimes: [a,b] or null
    validateNonOverlappingEditionTimes-->>buildReferralProgramEditionConfigSet: throws if overlap
    buildReferralProgramEditionConfigSet-->>Caller: ReferralProgramEditionConfigSet

    Note over ZodConfigSetArraySchema: Zod parse path
    ZodConfigSetArraySchema->>findOverlappingEditionPair: result[]
    findOverlappingEditionPair-->>ZodConfigSetArraySchema: [a,b] or null
    ZodConfigSetArraySchema->>ZodConfigSetArraySchema: ctx.addIssue if overlap

    Note over ZodSummariesDataSchema: Zod summary parse path
    ZodSummariesDataSchema->>findOverlappingEditionPair: data.editions[]
    findOverlappingEditionPair-->>ZodSummariesDataSchema: [a,b] or null
    ZodSummariesDataSchema->>ZodSummariesDataSchema: ctx.addIssue if overlap
Loading

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin' in..." | Re-trigger Greptile

Comment thread packages/ens-referrals/src/edition.ts
Copy link
Copy Markdown
Contributor

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

Prevents a single referral from matching multiple referral program editions by enforcing a per-subregistryId time-range non-overlap invariant (with inclusive bounds), and refactors shared edition config fields/types to be reused across configs and summaries.

Changes:

  • Introduces BaseReferralProgramEditionConfig and uses it as a shared parent for edition configs and base edition summaries.
  • Adds findOverlappingEditionPair / validateNonOverlappingEditionTimes and enforces the invariant in both config-set building and Zod parsing (including forward-compatible/unrecognized editions).
  • Adds/updates tests and fixtures to reflect inclusive-bound overlap behavior; exposes award-model Zod schemas via @namehash/ens-referrals/internal.

Reviewed changes

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

Show a summary per file
File Description
packages/ens-referrals/src/internal.ts Re-exports per-award-model and shared Zod schemas via the internal entrypoint.
packages/ens-referrals/src/edition.ts Adds shared base config type and overlap detection/validation; enforces invariant when building config sets.
packages/ens-referrals/src/edition.test.ts New unit tests for overlap detection/validation and config-set building.
packages/ens-referrals/src/award-models/shared/edition-summary.ts Refactors base summary to extend the shared base edition config type.
packages/ens-referrals/src/award-models/shared/api/zod-schemas.ts Adds shared Zod schemas for edition slug and base edition config; reuses them in base summary schema.
packages/ens-referrals/src/api/zod-schemas.ts Reuses shared schemas; enforces the non-overlap invariant in config-set array parsing and summaries response parsing.
packages/ens-referrals/src/api/zod-schemas.test.ts Updates fixtures and adds test coverage for the non-overlap invariant (configs and summaries).
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts Updates test setup to avoid summaries collapsing to overlapping windows by ensuring per-edition rules propagate into mock leaderboards.
.changeset/shiny-tigers-wander.md Changeset for rejecting overlapping editions invariant.
.changeset/quiet-mirrors-shine.md Changeset for exposing per-award-model Zod schemas via internal entrypoint.
.changeset/bright-rivers-flow.md Changeset for adding BaseReferralProgramEditionConfig as a shared parent type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Prevent overlapping referral program editions

2 participants