Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@angihe93
Copy link
Collaborator

@angihe93 angihe93 commented Dec 22, 2025

What Does this PR Do?

diff features & usage meters


Summary by cubic

Adds diffing for features and usage meters in pricing models using the existing slug-based diff utility. This identifies create, update, and remove operations and is covered by unit tests.

  • New Features
    • Added diffFeatures and diffUsageMeters powered by diffSluggedResources.
    • Introduced FeatureDiffInput and UsageMeterDiffInput derived from SetupPricingModelInput.
    • Added tests for create/update/remove and mixed scenarios; removal of usage meters is computed but will be blocked by validation later.

Written for commit 6370760. Summary will update automatically on new commits.

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for pricing model feature and usage meter comparison functionality, including removal, creation, update, and mixed change scenarios.
  • New Features

    • Introduced internal utilities to compare and diff features and usage meters within pricing models.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Walkthrough

This change introduces feature- and usage-meter-specific diff helper functions and corresponding type aliases. The new diffFeatures and diffUsageMeters functions derive from SetupPricingModelInput and compute differences through slug-based matching by delegating to the existing diffSluggedResources utility. Comprehensive test coverage is added for both functions.

Changes

Cohort / File(s) Summary
Implementation
platform/flowglad-next/src/utils/pricingModels/diffing.ts
Added two new type aliases (FeatureDiffInput, UsageMeterDiffInput) derived from SetupPricingModelInput, and two corresponding diff helper functions (diffFeatures, diffUsageMeters) that delegate to diffSluggedResources for computing toRemove, toCreate, and toUpdate based on slug matching.
Test Coverage
platform/flowglad-next/src/utils/pricingModels/diffing.test.ts
Added comprehensive test cases for diffFeatures and diffUsageMeters covering removal, creation, update, and mixed change scenarios, mirroring existing diffSluggedResources tests and including edge cases with empty existing or proposed sets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Type aliases are straightforward derivations from existing types
  • New functions are simple delegation wrappers with no complex logic
  • Test cases follow an established pattern with consistent structure

Possibly related PRs

Suggested reviewers

  • agreea
  • tembo

Poem

🐰 With slugs and features dancing free,
Two helpers hop to make diffs easy to see,
They delegate with grace and care,
To diff the resources everywhere!
Tests cover all, from create to remove,
A perfectly hoppy code groove! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main changes—adding diff functionality for features and usage meters in pricing models.
Description check ✅ Passed The description covers the main changes and includes a summary with new features and implementation details, though the initial custom description is minimal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pm-diffing-2

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e46c6f and 6370760.

📒 Files selected for processing (2)
  • platform/flowglad-next/src/utils/pricingModels/diffing.test.ts
  • platform/flowglad-next/src/utils/pricingModels/diffing.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use idiomatic TypeScript
Avoid type assertions
DO NOT use explicit any type

Files:

  • platform/flowglad-next/src/utils/pricingModels/diffing.ts
  • platform/flowglad-next/src/utils/pricingModels/diffing.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Avoid code duplication
Leave JSDoc comments for complex functions and APIs
DO NOT use IIFEs (Immediately Invoked Function Expressions)
DO NOT use nested ternaries

Files:

  • platform/flowglad-next/src/utils/pricingModels/diffing.ts
  • platform/flowglad-next/src/utils/pricingModels/diffing.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.{ts,tsx,js,jsx}: Avoid mocking unless absolutely necessary in tests
DO NOT use spy.on in tests
Never mock pure functions in tests
Never mock the database in tests - use real Postgres reads/writes

Files:

  • platform/flowglad-next/src/utils/pricingModels/diffing.test.ts
🧬 Code graph analysis (2)
platform/flowglad-next/src/utils/pricingModels/diffing.ts (1)
platform/flowglad-next/src/utils/pricingModels/setupSchemas.ts (1)
  • SetupPricingModelInput (170-172)
platform/flowglad-next/src/utils/pricingModels/diffing.test.ts (1)
platform/flowglad-next/src/utils/pricingModels/diffing.ts (4)
  • FeatureDiffInput (18-19)
  • diffFeatures (144-149)
  • UsageMeterDiffInput (24-25)
  • diffUsageMeters (171-176)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: flowglad-next-unit-tests / flowglad-next-sharded-tests (2, 4)
  • GitHub Check: flowglad-next-unit-tests / flowglad-next-sharded-tests (3, 4)
  • GitHub Check: flowglad-next-unit-tests / flowglad-next-sharded-tests (1, 4)
🔇 Additional comments (7)
platform/flowglad-next/src/utils/pricingModels/diffing.test.ts (3)

1-10: LGTM! Imports are properly organized.

The new imports for FeatureType, UsageMeterAggregationType, and the diffing functions/types are necessary for the comprehensive test coverage being added.


193-317: Excellent test coverage for diffFeatures!

The test suite comprehensively covers all scenarios:

  • Removal of features not in proposed
  • Updates to existing features
  • Creation of new features
  • Mixed operations (remove, update, create)

The TODO comment appropriately tracks future validation work.


319-429: Excellent test coverage for diffUsageMeters!

The test suite comprehensively covers all scenarios:

  • Removal of usage meters not in proposed
  • Updates to existing usage meters
  • Creation of new usage meters
  • Mixed operations (remove, update, create)

The TODO comment appropriately tracks future validation work.

platform/flowglad-next/src/utils/pricingModels/diffing.ts (4)

8-9: LGTM! Import is necessary and correct.

The SetupPricingModelInput import is required for deriving the feature and usage meter input types.


15-25: LGTM! Type aliases are well-defined.

The indexed access type pattern correctly extracts array element types from SetupPricingModelInput. This provides type safety for the diffing functions while maintaining a single source of truth for the input schema.


126-149: LGTM! Clean implementation with excellent documentation.

The diffFeatures function provides a type-safe wrapper around diffSluggedResources. The comprehensive JSDoc comment with usage example makes the API clear to consumers.


151-176: LGTM! Clean implementation with excellent documentation.

The diffUsageMeters function provides a type-safe wrapper around diffSluggedResources. The JSDoc appropriately notes that usage meter removal will cause validation errors in later stages, which provides helpful context for consumers.


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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.