Skip to content

feat(codereadiness): add hook for version-based flag validation - #1819

Open
marcin11858 wants to merge 4 commits into
open-feature:mainfrom
marcin11858:feature/codereadiness-hook
Open

feat(codereadiness): add hook for version-based flag validation#1819
marcin11858 wants to merge 4 commits into
open-feature:mainfrom
marcin11858:feature/codereadiness-hook

Conversation

@marcin11858

Copy link
Copy Markdown

Introduce the codereadiness hook to control feature flag evaluation by comparing the application's current version with a required minimum version specified in the flag's metadata. If the comparator returns false the hook returns an error to trigger fallback to the default flag value.

This PR

Introduces the codereadiness hook under hooks/codereadiness to control feature flag evaluation based on the application's running code version.

How it works

  • Compares the application's current version with the required minimum version specified in the flag's metadata (by default, in the minCodeVersion key).
  • If the comparison fails (by default, if the current version in SemVer format is lower than the minimum or invalid), the hook throws a GeneralError to trigger the SDK's fallback mechanism, returning the flag's default value.
  • The hook supports custom comparison logic (via .comparator(...)), custom metadata keys (via .metadataMinVerKey(...)), and optional strict validation (via .validationRequired(...)).

Notes

  • Includes comprehensive JUnit 5 unit tests in CodeReadinessHookTest.java and SemVerComparatorTest.java.
  • Includes a README.md with setup, configuration examples, and dependency setup.

Follow-up Tasks

None.

How to test

Run the module unit tests using Maven from the project root:

mvn test -pl hooks/codereadiness

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 531faef6-1b82-4411-abd7-56fba6472c5b

📥 Commits

Reviewing files that changed from the base of the PR and between e505a02 and 11f3788.

📒 Files selected for processing (1)
  • .release-please-manifest.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • .release-please-manifest.json

📝 Walkthrough

Walkthrough

Adds a new hooks/codereadiness Maven module implementing an OpenFeature hook that validates flag minimum-version metadata against a configured current version through pluggable comparators, with tests, documentation, and build/release configuration.

Changes

Codereadiness Hook

Layer / File(s) Summary
Version comparison contract and SemVer implementation
hooks/codereadiness/src/main/java/.../VersionComparator.java, SemVerComparator.java, hooks/codereadiness/src/test/java/.../SemVerComparatorTest.java
Defines the generic comparator contract and semver4j implementation, with valid and invalid version tests.
CodeReadinessHook evaluation flow
hooks/codereadiness/src/main/java/.../CodeReadinessHook.java
Implements builder configuration and after-phase metadata validation, comparison, strict validation, and GeneralError handling.
CodeReadinessHook validation tests
hooks/codereadiness/src/test/java/.../CodeReadinessHookTest.java
Covers readiness outcomes, strict validation, custom metadata keys, value validation, builder null checks, comparator customization, generic domains, and exception wrapping.
Module build, documentation, and release wiring
hooks/codereadiness/pom.xml, hooks/codereadiness/README.md, pom.xml, .release-please-manifest.json, release-please-config.json
Adds module metadata and documentation, registers the Maven module, and configures release-please.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HookContext
  participant CodeReadinessHook
  participant FlagEvaluationDetails
  participant VersionComparator

  HookContext->>CodeReadinessHook: after(ctx, details, hints)
  CodeReadinessHook->>FlagEvaluationDetails: read minCodeVersion
  CodeReadinessHook->>VersionComparator: parse and compare versions
  VersionComparator-->>CodeReadinessHook: true/false or exception
  CodeReadinessHook-->>HookContext: pass or GeneralError
Loading

Suggested reviewers: beeme1mr, thisthat, kavindu-dodan, toddbaert

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the new codereadiness hook and its version-based validation purpose.
Description check ✅ Passed The description matches the codereadiness hook, its behavior, tests, README, and testing steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from 59cde52 to c8244d9 Compare June 30, 2026 13:09
@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch 6 times, most recently from 3e3f136 to 07126e5 Compare July 2, 2026 13:38
@marcin11858
marcin11858 marked this pull request as ready for review July 6, 2026 09:04
@marcin11858
marcin11858 requested a review from a team as a code owner July 6, 2026 09:04
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Marcin Wlazły <marcinwlazly@google.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java (1)

17-17: 📐 Maintainability & Code Quality | 🔵 Trivial

Use the generic Hook<T> type instead of the raw type.

CodeReadinessHook implements raw Hook, and after(...) uses raw FlagEvaluationDetails and Map. The OpenFeature SDK Hook interface is generic (Hook<T>, with after(HookContext<T>, FlagEvaluationDetails<T>, Map<String, Object>)); using raw types here bypasses compiler type checking and produces unchecked-operation warnings.

♻️ Suggested fix
-public class CodeReadinessHook implements Hook {
+public class CodeReadinessHook implements Hook<Object> {
...
-    public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
+    public void after(HookContext<Object> ctx, FlagEvaluationDetails<Object> details, Map<String, Object> hints) {

Also applies to: 47-47

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java`
at line 17, CodeReadinessHook is using the raw Hook type and raw after(...)
parameters, which bypasses generic type safety and triggers unchecked warnings.
Update CodeReadinessHook to use the generic Hook<T> signature and make its
after(...) method consistently generic with HookContext<T> and
FlagEvaluationDetails<T>, matching the OpenFeature SDK interface. Ensure any
related Map parameter remains properly typed so the class compiles cleanly
without raw-type usage.
hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java (1)

27-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use isGreaterThanOrEqualTo here The two comparisons can be collapsed to currentSemver.isGreaterThanOrEqualTo(minCodeVersionSemver).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java`
at line 27, The version comparison in SemVerComparator is doing two separate
checks for greater-than and equality that should be combined. Update the
comparison logic in the relevant semver check to use
currentSemver.isGreaterThanOrEqualTo(minCodeVersionSemver) instead of chaining
isGreaterThan and isEqualTo, keeping the behavior the same while simplifying the
expression.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java`:
- Line 17: CodeReadinessHook is using the raw Hook type and raw after(...)
parameters, which bypasses generic type safety and triggers unchecked warnings.
Update CodeReadinessHook to use the generic Hook<T> signature and make its
after(...) method consistently generic with HookContext<T> and
FlagEvaluationDetails<T>, matching the OpenFeature SDK interface. Ensure any
related Map parameter remains properly typed so the class compiles cleanly
without raw-type usage.

In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java`:
- Line 27: The version comparison in SemVerComparator is doing two separate
checks for greater-than and equality that should be combined. Update the
comparison logic in the relevant semver check to use
currentSemver.isGreaterThanOrEqualTo(minCodeVersionSemver) instead of chaining
isGreaterThan and isEqualTo, keeping the behavior the same while simplifying the
expression.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 85e7081b-8066-4050-85d0-fab3c0af2747

📥 Commits

Reviewing files that changed from the base of the PR and between c5efaff and 07126e5.

📒 Files selected for processing (10)
  • .release-please-manifest.json
  • hooks/codereadiness/README.md
  • hooks/codereadiness/pom.xml
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/VersionComparator.java
  • hooks/codereadiness/src/test/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHookTest.java
  • hooks/codereadiness/src/test/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparatorTest.java
  • pom.xml
  • release-please-config.json

@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from ef5127e to fb741fb Compare July 6, 2026 09:18
@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from 63dde37 to f48a669 Compare July 23, 2026 07:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java (1)

18-26: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Manual "v" prefix normalization is redundant and can misfire on "V" (capital).

org.semver4j's Semver.parse() already accepts and strips a leading "v" prefix itself, so this normalization step is unnecessary. Worse, startsWith("v") is case-sensitive: an input like "V1.2.0" won't match, so the code prepends another "v", producing "vV1.2.0", which will fail to parse instead of succeeding.

♻️ Proposed simplification
   public Semver parse(String versionString) {
     Objects.requireNonNull(versionString, "versionString cannot be null");
-    String formatted = versionString.startsWith("v") ? versionString : "v" + versionString;
-    Semver semver = Semver.parse(formatted);
+    Semver semver = Semver.parse(versionString);
     if (semver == null) {
       throw new IllegalArgumentException(String.format("invalid semver: \"%s\"", versionString));
     }
     return semver;
   }

Please confirm org.semver4j:semver4j:5.8.0's Semver.parse() behavior for "v"-prefixed strings to validate this simplification is safe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java`
around lines 18 - 26, Remove the manual prefix normalization in
SemVerComparator.parse and pass the original non-null versionString directly to
Semver.parse. Preserve the existing invalid-input IllegalArgumentException and
null validation, relying on org.semver4j’s parser to handle leading “v”
prefixes, including capital “V” inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java`:
- Around line 18-26: Remove the manual prefix normalization in
SemVerComparator.parse and pass the original non-null versionString directly to
Semver.parse. Preserve the existing invalid-input IllegalArgumentException and
null validation, relying on org.semver4j’s parser to handle leading “v”
prefixes, including capital “V” inputs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 49221b45-8abb-470c-bac1-88ae5fe77db0

📥 Commits

Reviewing files that changed from the base of the PR and between 2a3555d and f48a669.

📒 Files selected for processing (10)
  • .release-please-manifest.json
  • hooks/codereadiness/README.md
  • hooks/codereadiness/pom.xml
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparator.java
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/VersionComparator.java
  • hooks/codereadiness/src/test/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHookTest.java
  • hooks/codereadiness/src/test/java/dev/openfeature/contrib/hooks/codereadiness/SemVerComparatorTest.java
  • pom.xml
  • release-please-config.json
🚧 Files skipped from review as they are similar to previous changes (5)
  • hooks/codereadiness/pom.xml
  • pom.xml
  • hooks/codereadiness/README.md
  • hooks/codereadiness/src/main/java/dev/openfeature/contrib/hooks/codereadiness/CodeReadinessHook.java
  • release-please-config.json

@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from f48a669 to edb4fc7 Compare July 23, 2026 07:42
@marcin11858
marcin11858 requested a review from chrfwow July 23, 2026 07:53
@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from edb4fc7 to 51fbe31 Compare July 23, 2026 07:54

@chrfwow chrfwow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You will need to run the spotlessApply maven target to fix the formating issues

Introduce the codereadiness hook to control feature flag evaluation
by comparing the application's current version with a required minimum
version specified in the flag's metadata. If the comparator returns
false the hook returns an error to trigger fallback to
the default flag value.

Signed-off-by: Marcin Wlazły <marcinwlazly@google.com>
@marcin11858
marcin11858 force-pushed the feature/codereadiness-hook branch from cc0eac3 to e505a02 Compare July 23, 2026 11:15
@marcin11858
marcin11858 requested a review from chrfwow July 23, 2026 11:32

@chrfwow chrfwow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'll approve this because the code looks good. I have not followed the conversation about this hook in the spec repo. Please make sure you align with that outcome

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.

7 participants