-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add flag dependency test cases #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khvn26
wants to merge
8
commits into
main
Choose a base branch
from
test/flag-dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
00de9d3
feat: add flag dependency test cases
khvn26 e8e1f68
chore: point schemas at the in-flight dependent flags branches
khvn26 f9b1abc
feat: add flag dependency test cases for spellings, nesting and priority
khvn26 2db3b50
feat: add flag dependency cases for metadata, multiple overrides and …
khvn26 9d17cc5
feat: add a shared dependency segment test case
khvn26 30e30f2
feat: report a circular dependency as an error reason
khvn26 805b353
feat: add a cycle test case where a flag defaults to enabled
khvn26 3f10cd6
chore: point schemas back at main
khvn26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
test_cases/test_flag_dependency__absent_prerequisite__should_not_override.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| { | ||
| // Given: A segment conditioned on a feature that is not in the context | ||
| // When: The context is evaluated | ||
| // Then: The override is not applied, and evaluation does not fail | ||
| // | ||
| // NOTE: A dependency on an absent feature resolves to no value, as an | ||
| // unset property would. It is not an error. | ||
| "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", | ||
| "context": { | ||
| "environment": { | ||
| "key": "key", | ||
| "name": "Environment" | ||
| }, | ||
| "features": { | ||
| "dependent": { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": false, | ||
| "value": "off" | ||
| } | ||
| }, | ||
| "segments": { | ||
| "1": { | ||
| "key": "1", | ||
| "name": "dependency_on_absent", | ||
| "rules": [ | ||
| { | ||
| "type": "ALL", | ||
| "conditions": [ | ||
| { | ||
| "operator": "EQUAL", | ||
| "property": "$.flags.nonexistent.enabled", | ||
| "value": "true" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": true, | ||
| "value": "on" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "result": { | ||
| "flags": { | ||
| "dependent": { | ||
| "enabled": false, | ||
| "name": "dependent", | ||
| "reason": "DEFAULT", | ||
| "value": "off", | ||
| "variant": null | ||
| } | ||
| }, | ||
| "segments": [] | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
test_cases/test_flag_dependency__bracket_rooted_property__should_not_override.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| { | ||
| // Given: A segment overriding `dependent`, conditioned on a property that | ||
| // is a valid JSONPath query but is rooted with a bracket | ||
| // When: The context is evaluated with `prerequisite` enabled | ||
| // Then: No override is applied, and the segment does not match | ||
| // | ||
| // NOTE: Only a property prefixed `$.` is treated as a JSONPath query. A | ||
| // bracket-rooted query such as `$['flags']['prerequisite']` is a | ||
| // trait key, and as no such trait is set it resolves to no value. | ||
| // This is deliberate, and pinned here so that an implementation | ||
| // using a full JSONPath parser for the prefix test does not start | ||
| // honouring it and diverge. | ||
| "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", | ||
| "context": { | ||
| "environment": { | ||
| "key": "key", | ||
| "name": "Environment" | ||
| }, | ||
| "features": { | ||
| "prerequisite": { | ||
| "key": "1", | ||
| "name": "prerequisite", | ||
| "enabled": true, | ||
| "value": null | ||
| }, | ||
| "dependent": { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": false, | ||
| "value": "off" | ||
| } | ||
| }, | ||
| "segments": { | ||
| "1": { | ||
| "key": "1", | ||
| "name": "dependency_on_prerequisite", | ||
| "rules": [ | ||
| { | ||
| "type": "ALL", | ||
| "conditions": [ | ||
| { | ||
| "operator": "EQUAL", | ||
| "property": "$['flags']['prerequisite'].enabled", | ||
| "value": "true" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": true, | ||
| "value": "on" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "result": { | ||
| "flags": { | ||
| "prerequisite": { | ||
| "enabled": true, | ||
| "name": "prerequisite", | ||
| "reason": "DEFAULT", | ||
| "value": null, | ||
| "variant": null | ||
| }, | ||
| "dependent": { | ||
| "enabled": false, | ||
| "name": "dependent", | ||
| "reason": "DEFAULT", | ||
| "value": "off", | ||
| "variant": null | ||
| } | ||
| }, | ||
| "segments": [] | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
test_cases/test_flag_dependency__bracketed_field__should_override.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| // Given: A segment overriding `dependent`, conditioned on `prerequisite` | ||
| // with the *field* selected by a bracketed name rather than a dot | ||
| // When: The context is evaluated with `prerequisite` enabled | ||
| // Then: The dependency is satisfied, so `dependent` takes the override | ||
| // | ||
| // NOTE: `$.flags.prerequisite['enabled']` selects the same node as | ||
| // `$.flags.prerequisite.enabled`. An implementation that matches the | ||
| // property as text, rather than parsing it, is liable to miss this | ||
| // spelling and leave the dependency unresolved. | ||
| "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", | ||
| "context": { | ||
| "environment": { | ||
| "key": "key", | ||
| "name": "Environment" | ||
| }, | ||
| "features": { | ||
| "prerequisite": { | ||
| "key": "1", | ||
| "name": "prerequisite", | ||
| "enabled": true, | ||
| "value": null | ||
| }, | ||
| "dependent": { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": false, | ||
| "value": "off" | ||
| } | ||
| }, | ||
| "segments": { | ||
| "1": { | ||
| "key": "1", | ||
| "name": "dependency_on_prerequisite", | ||
| "rules": [ | ||
| { | ||
| "type": "ALL", | ||
| "conditions": [ | ||
| { | ||
| "operator": "EQUAL", | ||
| "property": "$.flags.prerequisite['enabled']", | ||
| "value": "true" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": true, | ||
| "value": "on" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "result": { | ||
| "flags": { | ||
| "prerequisite": { | ||
| "enabled": true, | ||
| "name": "prerequisite", | ||
| "reason": "DEFAULT", | ||
| "value": null, | ||
| "variant": null | ||
| }, | ||
| "dependent": { | ||
| "enabled": true, | ||
| "name": "dependent", | ||
| "reason": "TARGETING_MATCH; segment=dependency_on_prerequisite", | ||
| "value": "on", | ||
| "variant": null | ||
| } | ||
| }, | ||
| "segments": [ | ||
| { | ||
| "name": "dependency_on_prerequisite" | ||
| } | ||
| ] | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
test_cases/test_flag_dependency__competing_overrides__lowest_priority_wins.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| { | ||
| // Given: Two matching segments overriding `dependent`, both conditioned | ||
| // on `prerequisite`, with different override priorities | ||
| // When: The context is evaluated with the dependency satisfied | ||
| // Then: The lower priority number wins, as for any segment override | ||
| // | ||
| // NOTE: Resolving dependencies must not disturb override precedence, and | ||
| // in particular must not make it depend on resolution order. | ||
| "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", | ||
| "context": { | ||
| "environment": { | ||
| "key": "key", | ||
| "name": "Environment" | ||
| }, | ||
| "features": { | ||
| "prerequisite": { | ||
| "key": "1", | ||
| "name": "prerequisite", | ||
| "enabled": true, | ||
| "value": null | ||
| }, | ||
| "dependent": { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": false, | ||
| "value": "off" | ||
| } | ||
| }, | ||
| "segments": { | ||
| "weak": { | ||
| "key": "weak", | ||
| "name": "weaker_dependency", | ||
| "rules": [ | ||
| { | ||
| "type": "ALL", | ||
| "conditions": [ | ||
| { | ||
| "operator": "EQUAL", | ||
| "property": "$.flags.prerequisite.enabled", | ||
| "value": "true" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": true, | ||
| "value": "weaker", | ||
| "priority": 10 | ||
| } | ||
| ] | ||
| }, | ||
| "strong": { | ||
| "key": "strong", | ||
| "name": "stronger_dependency", | ||
| "rules": [ | ||
| { | ||
| "type": "ALL", | ||
| "conditions": [ | ||
| { | ||
| "operator": "EQUAL", | ||
| "property": "$.flags.prerequisite.enabled", | ||
| "value": "true" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "key": "2", | ||
| "name": "dependent", | ||
| "enabled": true, | ||
| "value": "stronger", | ||
| "priority": 1 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "result": { | ||
| "flags": { | ||
| "prerequisite": { | ||
| "enabled": true, | ||
| "name": "prerequisite", | ||
| "reason": "DEFAULT", | ||
| "value": null, | ||
| "variant": null | ||
| }, | ||
| "dependent": { | ||
| "enabled": true, | ||
| "name": "dependent", | ||
| "reason": "TARGETING_MATCH; segment=stronger_dependency", | ||
| "value": "stronger", | ||
| "variant": null | ||
| } | ||
| }, | ||
| "segments": [ | ||
| { | ||
| "name": "weaker_dependency" | ||
| }, | ||
| { | ||
| "name": "stronger_dependency" | ||
| } | ||
| ] | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a trait key could be, literally,
$['flags']['prerequisite']?