Skip to content

test: Pass private attribute raw paths to LDContext in contract tests#408

Merged
keelerm84 merged 1 commit into
mainfrom
mk/SDK-2738/fix-context-comparison-private-attributes
Jul 21, 2026
Merged

test: Pass private attribute raw paths to LDContext in contract tests#408
keelerm84 merged 1 commit into
mainfrom
mk/SDK-2738/fix-context-comparison-private-attributes

Conversation

@keelerm84

@keelerm84 keelerm84 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

The contextComparison handler in the contract test service built LaunchDarkly::Reference objects and placed them in _meta.privateAttributes. But LDContext.create re-parses each element of that array as a reference string via Reference.create, which rejects any non-String/Symbol input. Every private attribute was therefore silently dropped, and context comparisons involving private attributes were never exercised -- both contexts were always compared with empty private-attribute sets.

The SDK's own LDContext equality is correct (order-independent set of references; literal names compare equal to the equivalent reference). The defect was isolated to the contract test service.

This passes the reference raw_path (a string) to LDContext.create instead of the Reference object. For a literal attribute name this is the escaped single-component form (e.g. /address/street -> /~1address~1street), which LDContext.create re-parses into the correct reference.

Verified locally by running the context type/compare suite from a local sdk-test-harness build against this service: all 16 comparison tests pass, including two negative cases where private attributes are the sole differentiator.

Note on ordering

The failing behavior was previously masked by a bug in the released test harness (a malformed privateAttributes JSON tag) that meant private attributes were never sent for the contextComparison command. That harness bug is fixed in launchdarkly/sdk-test-harness#391 (v2) and #392 (v3), which also add the negative tests that catch this. Until the harness fix is released, this SDK's contract-test CI (which downloads the released v2 harness) will not yet exercise the new cases.


Note

Low Risk
Test-only change in the contract test service; no production SDK behavior is modified.

Overview
Fixes contract test contextComparison so _meta.privateAttributes is built the way LDContext.create expects.

The harness was putting LaunchDarkly::Reference instances into privateAttributes, but LDContext.create treats each entry as a reference string and re-parses it. Non-string values were dropped, so comparisons never exercised private attributes. The builder now passes each reference’s raw_path (including escaped literal paths from Reference.create_literal) so contexts are created with the intended private-attribute set.

Reviewed by Cursor Bugbot for commit e109beb. Bugbot is set up for automated code reviews on this repo. Configure here.

The contextComparison handler built LaunchDarkly::Reference objects and
placed them in _meta.privateAttributes, but LDContext.create re-parses
each element as a reference string via Reference.create, which rejects
non-strings. Every private attribute was therefore dropped, so context
comparisons involving private attributes were never exercised.

Pass the reference raw path (a string) instead. For a literal name this
is the escaped single-component form, which LDContext.create re-parses
into the correct reference.
@keelerm84 keelerm84 changed the title fix: Pass private attribute raw paths to LDContext in contract tests tests: Pass private attribute raw paths to LDContext in contract tests Jul 21, 2026
@keelerm84
keelerm84 marked this pull request as ready for review July 21, 2026 17:57
@keelerm84
keelerm84 requested a review from a team as a code owner July 21, 2026 17:57
@keelerm84 keelerm84 changed the title tests: Pass private attribute raw paths to LDContext in contract tests test: Pass private attribute raw paths to LDContext in contract tests Jul 21, 2026
@keelerm84
keelerm84 merged commit 5624901 into main Jul 21, 2026
16 of 19 checks passed
@keelerm84
keelerm84 deleted the mk/SDK-2738/fix-context-comparison-private-attributes branch July 21, 2026 19:38
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.

2 participants