Repository navigation
Use RFC 8785 canonical state for cache keys, subscription ids, and stream comparison - #3
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
…ream comparison Asgard protocol §5.1 requires both client and server to compare and key states using RFC 8785 (JCS) canonical state. NativePHP/asgard already implemented CanonicalState, while Midgard still used ksort(..., SORT_STRING) with JSON_PRESERVE_ZERO_FRACTION in RegionCache and ServerRegion, and raw PHP array equality in RegionStreams::shape(). Add CanonicalState to Midgard, wire RegionCache::key(), ServerRegion::subscriptionId(), and RegionStreams::shape() through it, remove the duplicated canonical() helpers, and add RFC 8785 tests.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Aligns Midgard's client-side state keying and comparison with Asgard protocol §5.1 (RFC 8785 / JCS), matching
Native\Asgard\Support\CanonicalStateinNativePHP/asgard.Cause
RegionCache::key()andServerRegion::subscriptionId()each kept their owncanonical()helper usingksort(..., SORT_STRING)andJSON_PRESERVE_ZERO_FRACTION, whileRegionStreams::shape()compared subscription states using raw PHP===.That diverged from protocol §5.1 in three ways:
1vs1.0,-0.0vs0) produced different cache keys and subscription ids, and causedRegionStreams::watch()to reopen the SSE stream.SORT_STRING) instead of RFC 8785 UTF-16 code units.RegionStreams::watch()compared unequal under PHP===and reopened the stream unnecessarily.Changes
Native\Api\Client\Asgard\CanonicalStateimplementing RFC 8785 canonical state serialization.CanonicalState::encode((object) $state)inRegionCache::key(),ServerRegion::subscriptionId(), andRegionStreams::shape(), removing the duplicatedcanonical()helpers.nullfromRegionCache::key()when a state has no canonical form (for example non-finite floats or invalid UTF-8) instead of throwing.tests/Asgard/CanonicalStateTest.phpand §5.1 regression tests inFragmentSourceTest,RegionCacheTest, andRegionStreamsTest.Testing
./vendor/bin/pest(947 passed, 4,286 assertions).asgard-protocol/conformance/vectors/vectors.jsonagainstCanonicalState::encode()../vendor/bin/pint --test.