Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct Segment {
#[serde(default)]
pub unbounded: bool,
#[serde(default)]
unbounded_context_kind: Option<Kind>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New field is deserialized but never read

Low Severity

The unbounded_context_kind field is deserialized from JSON but never read in any production code. Unlike the similarly private generation field (which is consumed by unbounded_segment_id()), unbounded_context_kind has no accessor method and no internal usage. It's also not pub, so external crate consumers (e.g., big segment evaluation logic in the SDK layer) cannot access it either.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit eb06c29. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It will be used elsewhere.

#[serde(default)]
generation: Option<i64>,

/// An integer that is incremented by LaunchDarkly every time the configuration of the segment
Expand Down Expand Up @@ -302,6 +304,61 @@ mod tests {
assert!(segment.excluded_contexts.is_empty());
}

#[test]
fn handles_unbounded_context_kind() {
let json = r#"{
"key": "segment",
"included": [],
"excluded": [],
"rules": [],
"salt": "salty",
"unbounded": true,
"unboundedContextKind": "org",
"generation": 2,
"version": 1
}"#;

let segment: Segment = serde_json::from_str(json).expect("Failed to parse segment");
assert!(segment.unbounded);
assert_eq!(segment.unbounded_context_kind, Some(Kind::from("org")));
assert_eq!(segment.generation, Some(2));
}

#[test]
fn unbounded_context_kind_defaults_to_none() {
let json = r#"{
"key": "segment",
"included": [],
"excluded": [],
"rules": [],
"salt": "salty",
"unbounded": true,
"version": 1
}"#;

let segment: Segment = serde_json::from_str(json).expect("Failed to parse segment");
assert!(segment.unbounded);
assert_eq!(segment.unbounded_context_kind, None);
}

#[test]
fn unbounded_context_kind_user() {
let json = r#"{
"key": "segment",
"included": [],
"excluded": [],
"rules": [],
"salt": "salty",
"unbounded": true,
"unboundedContextKind": "user",
"generation": 1,
"version": 1
}"#;

let segment: Segment = serde_json::from_str(json).expect("Failed to parse segment");
assert_eq!(segment.unbounded_context_kind, Some(Kind::user()));
}

#[test]
fn handles_context_schema() {
let json = &r#"{
Expand Down Expand Up @@ -362,6 +419,7 @@ mod tests {
rules: vec![],
salt: "salty".to_string(),
unbounded: false,
unbounded_context_kind: None,
generation: Some(1),
version: 1,
}
Expand Down
Loading