Commit 8d87e01
feat(storage): detect and report changed flags in update_state (#38)
## Description
Per the provider spec, `update_state` now detects and reports which
flags changed by comparing all flag fields between old and new
configurations.
**Changes:**
- **New `UpdateStateResponse` struct** - Returns `success`, `error`, and
`changedFlags` array
- **`FeatureFlag::is_different_from()`** - Uses derived `PartialEq` to
compare all flag fields (state, default variant, variants, targeting,
and metadata)
- **Change detection logic** - Identifies added, removed, and mutated
flags with sorted output
- **Updated API signature** - `update_flag_state()` returns
`Result<UpdateStateResponse, String>`
**Response format:**
```json
{
"success": true,
"error": null,
"changedFlags": ["flag1", "flag2"]
}
```
**Detection criteria:**
- Added: Flag exists in new config but not old
- Removed: Flag exists in old config but not new
- Mutated: Any flag field changed (state, default variant, variants,
targeting rules, or metadata)
## Related Issue
Closes #
## Type of Change
- [x] `feat`: New feature (minor version bump)
- [ ] `fix`: Bug fix (patch version bump)
- [ ] `docs`: Documentation only changes
- [ ] `chore`: Maintenance tasks, dependency updates
- [ ] `refactor`: Code refactoring without functional changes
- [ ] `test`: Adding or updating tests
- [ ] `ci`: CI/CD changes
- [ ] `perf`: Performance improvements
- [ ] `build`: Build system changes
- [ ] `style`: Code style/formatting changes
## PR Title Format
Title follows Conventional Commits format for automated changelog
generation.
## Testing
- [x] Unit tests added/updated
- [x] Integration tests added/updated
- [x] Manual testing performed
- [x] All tests pass (`cargo test`) - 338 tests passing
- [x] Code is formatted (`cargo fmt`)
- [x] Clippy checks pass (`cargo clippy -- -D warnings`)
- [x] WASM builds successfully (if applicable)
## Breaking Changes
- [x] This PR includes breaking changes
- [x] Documentation has been updated to reflect breaking changes
- [ ] Migration guide included (if needed)
**Breaking change:** `storage::update_flag_state()` return type changed
from `Result<(), String>` to `Result<UpdateStateResponse, String>`. WASM
API remains backward compatible with added `changedFlags` field.
## Additional Notes
Added 20 comprehensive tests covering all change scenarios including:
- First update, additions, removals
- Default variant, state, variants (value changes and additions),
targeting rules, and metadata mutations
- No changes scenario and mixed operations
Implementation simplified based on PR feedback to use derived
`PartialEq` for complete field comparison, making the code more
maintainable and robust. Changed flags are returned sorted
alphabetically for deterministic output.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Detect and report changed flags in
update_state</issue_title>
> <issue_description>Per the provider spec, when `update_state` is
called, the evaluator should compare newly parsed flags with the stored
flags to identify added, removed, or mutated flags (comparing at least
default variant, targeting rules, and metadata).
>
> Return the list of changed keys in the update response for use in
`PROVIDER_CONFIGURATION_CHANGED` events.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #37
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/open-feature-forking/flagd-evaluator/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>1 parent f2bb69d commit 8d87e01
5 files changed
Lines changed: 961 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
| 256 | + | |
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
263 | | - | |
| 264 | + | |
264 | 265 | | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
269 | | - | |
| 270 | + | |
| 271 | + | |
270 | 272 | | |
271 | 273 | | |
272 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
273 | 280 | | |
274 | 281 | | |
275 | 282 | | |
| |||
289 | 296 | | |
290 | 297 | | |
291 | 298 | | |
292 | | - | |
| 299 | + | |
| 300 | + | |
293 | 301 | | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
298 | 306 | | |
299 | 307 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
305 | 319 | | |
306 | 320 | | |
307 | | - | |
| 321 | + | |
| 322 | + | |
308 | 323 | | |
309 | 324 | | |
310 | 325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
89 | 123 | | |
90 | 124 | | |
91 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments