Skip to content

fix: treat missing user attributes as non-matching - #37

Merged
deleteLater merged 2 commits into
mainfrom
fix/missing-user-attribute-matching
Sep 4, 2026
Merged

deleteLater merged 2 commits into
mainfrom
fix/missing-user-attribute-matching

Conversation

@deleteLater

@deleteLater deleteLater commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

according to the User Context Spec

Greptile Summary

This PR makes condition matching distinguish missing attributes from attributes containing an empty string while preserving the public ValueOf fallback.

  • Adds an internal presence-aware attribute lookup for condition evaluation.
  • Keeps event serialization aligned with the centralized built-in attribute names.
  • Adds coverage for missing, blank, built-in, and empty-valued attributes.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/FeatBit.ServerSdk/Evaluation/Evaluator.ConditionMatcher.cs Rejects blank or absent condition properties before invoking an operator.
src/FeatBit.ServerSdk/Model/FbUser.cs Preserves ValueOf compatibility while exposing presence-aware lookup internally.
src/FeatBit.ServerSdk/Events/DefaultEventSerializer.cs Reuses the centralized built-in attribute constants without changing serialized field names.
tests/FeatBit.ServerSdk.Tests/Evaluation/ConditionMatcherTests.cs Covers missing properties, empty values, invalid property names, and built-in precedence.
tests/FeatBit.ServerSdk.Tests/Model/FbUserTests.cs Verifies the established empty-string fallback for missing and empty-valued attributes.

Reviews (2): Last reviewed commit: "pr feedback" | Re-trigger Greptile

Summary by CodeRabbit

  • Bug Fixes

    • Conditions with missing, empty, or whitespace-only properties no longer match unexpectedly.
    • Missing user attributes now correctly fail condition matching, while empty values continue to be evaluated normally.
    • Built-in user attributes take precedence over custom attributes with the same name.
    • User attribute lookups consistently return an empty value when no matching attribute exists.
  • Tests

    • Added coverage for missing attributes, empty values, invalid properties, and built-in attribute precedence.

@deleteLater deleteLater self-assigned this Sep 4, 2026
@deleteLater deleteLater added the enhancement New feature or request label Sep 4, 2026
@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: aa7723a3-7fb0-4ced-9528-630e797cbfe8

📥 Commits

Reviewing files that changed from the base of the PR and between 6f9e665 and 108dfd4.

📒 Files selected for processing (5)
  • src/FeatBit.ServerSdk/Evaluation/Evaluator.ConditionMatcher.cs
  • src/FeatBit.ServerSdk/Events/DefaultEventSerializer.cs
  • src/FeatBit.ServerSdk/Model/FbUser.cs
  • tests/FeatBit.ServerSdk.Tests/Evaluation/ConditionMatcherTests.cs
  • tests/FeatBit.ServerSdk.Tests/Model/FbUserTests.cs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds explicit user-property lookup support, guards condition matching against invalid or missing properties, centralizes built-in attribute names, updates serialization, and adds regression tests for empty and built-in attributes.

Changes

User attribute matching

Layer / File(s) Summary
User lookup contract and serialization
src/FeatBit.ServerSdk/Model/FbUser.cs, src/FeatBit.ServerSdk/Events/DefaultEventSerializer.cs
FbUser adds shared built-in attribute constants and an internal TryGetValue method. ValueOf preserves its empty-string fallback. WriteUser uses the shared constants.
Condition matching guards
src/FeatBit.ServerSdk/Evaluation/Evaluator.ConditionMatcher.cs
IsMatchCondition returns false for null or whitespace properties and for properties missing from the user before operator evaluation.
Matching regression tests
tests/FeatBit.ServerSdk.Tests/Evaluation/ConditionMatcherTests.cs, tests/FeatBit.ServerSdk.Tests/Model/FbUserTests.cs
Tests cover missing properties, empty values, invalid property names, built-in attribute precedence, and ValueOf fallback behavior.

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

Merge Risk: ⚪ Minimal · up to 108df

Missing user attributes now do not satisfy attribute conditions, while present empty values continue to be evaluated normally. Existing ValueOf fallback behavior and event field names are preserved, with coverage for the changed matching cases.

Sequence Diagram(s)

sequenceDiagram
  participant Evaluator.IsMatchCondition
  participant FbUser.TryGetValue
  participant Operator evaluation
  Evaluator.IsMatchCondition->>FbUser.TryGetValue: request condition property
  FbUser.TryGetValue-->>Evaluator.IsMatchCondition: found flag and value
  Evaluator.IsMatchCondition->>Operator evaluation: evaluate operator when property exists
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: missing user attributes no longer match conditions.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/missing-user-attribute-matching

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.

Comment thread src/FeatBit.ServerSdk/Model/FbUser.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes consistently implement the spec’s “missing attribute is non-matching” rule and are backed by targeted tests for the new edge cases.

Pull request overview

This PR aligns user-attribute lookup and condition evaluation with the User Context Spec by distinguishing between missing attributes and present-but-empty attributes, and ensuring missing attributes never satisfy conditions (including negative operators).

Changes:

  • Updated FbUser attribute lookup to preserve attribute presence (missing → null/not found; present empty → "").
  • Updated condition matching to return false when the condition property is empty/whitespace or the user attribute is missing.
  • Added/extended unit tests to cover missing attributes, empty values, invalid properties, and built-in attribute precedence.
File summaries
File Description
tests/FeatBit.ServerSdk.Tests/Model/FbUserTests.cs Adds coverage for FbUser.ValueOf behavior with missing vs empty attributes.
tests/FeatBit.ServerSdk.Tests/Evaluation/ConditionMatcherTests.cs Adds coverage ensuring missing/invalid attributes do not match (including negative/unknown operators) and built-in precedence.
src/FeatBit.ServerSdk/Model/FbUser.cs Implements presence-aware attribute retrieval via TryGetValue and updates ValueOf semantics.
src/FeatBit.ServerSdk/Events/DefaultEventSerializer.cs Uses centralized attribute-name constants for built-in user fields.
src/FeatBit.ServerSdk/Evaluation/Evaluator.ConditionMatcher.cs Treats missing/invalid attributes as non-matching before applying operators.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deleteLater
deleteLater merged commit 08fa139 into main Sep 4, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in FeatBit Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants