-
Notifications
You must be signed in to change notification settings - Fork 558
Shared Tree: Additional tests for schema compatibility cases #25883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TommyBrosman
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
TommyBrosman:additional-compat-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c20ae4a
Missing tests that should have been in #25861.
TommyBrosman e682d62
Update packages/dds/tree/src/test/simple-tree/api/snapshotCompatibili…
TommyBrosman 604e41c
Fixes/docs.
TommyBrosman 1c39544
Merge branch 'main' into additional-compat-tests
TommyBrosman f1136bd
Added backwards compatibility checks for staged and allowUnknownOptio…
TommyBrosman 197c1d8
Test cleanup.
TommyBrosman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ import { | |
| exportCompatibilitySchemaSnapshot, | ||
| TreeViewConfiguration, | ||
| type SchemaCompatibilityStatus, | ||
| SchemaFactoryBeta, | ||
| stringSchema, | ||
| numberSchema, | ||
| } from "../../../simple-tree/index.js"; | ||
| import { strict as assert } from "node:assert"; | ||
|
|
||
|
|
@@ -32,7 +35,7 @@ describe("snapshotCompatibilityChecker", () => { | |
| ); | ||
| }); | ||
|
|
||
| it("checkCompatibility detects incompatible schemas", () => { | ||
| it("checkCompatibility detects upgradeable schemas", () => { | ||
| const factory = new SchemaFactory("test"); | ||
| class Point2D extends factory.object("Point", { | ||
| x: factory.number, | ||
|
|
@@ -56,7 +59,7 @@ describe("snapshotCompatibilityChecker", () => { | |
| assert.deepEqual(compatibility, expected); | ||
| }); | ||
|
|
||
| it("checkCompatibility detects compatible schemas", () => { | ||
| it("checkCompatibility detects upgradeable schemas - snapshot test", () => { | ||
| const factory = new SchemaFactory("test"); | ||
|
|
||
| // The past view schema, for the purposes of illustration. This wouldn't normally appear as a concrete schema in the test | ||
|
|
@@ -99,4 +102,64 @@ describe("snapshotCompatibilityChecker", () => { | |
| // this means these two versions of the application cannot collaborate on content using these schema. | ||
| assert.equal(forwardsCompatibilityStatus.canView, false); | ||
| }); | ||
|
|
||
| it("checkCompatibility: allowUnknownOptionalFields", () => { | ||
| const factory = new SchemaFactoryBeta("test"); | ||
|
|
||
| // Point2D is constructed with allowUnknownOptionalFields, so it can read Point3D trees | ||
| // even though it does not know about the optional field `z`. | ||
| class Point2D extends factory.object( | ||
| "Point", | ||
| { | ||
| x: factory.number, | ||
| y: factory.number, | ||
| }, | ||
| { allowUnknownOptionalFields: true }, | ||
| ) {} | ||
| class Point3D extends factory.object("Point", { | ||
| x: factory.number, | ||
| y: factory.number, | ||
| z: factory.optional(factory.number), | ||
| }) {} | ||
|
|
||
| const oldViewSchema = new TreeViewConfiguration({ schema: Point2D }); | ||
| const currentViewSchema = new TreeViewConfiguration({ schema: Point3D }); | ||
|
|
||
| // Check to see if a document created with the current view schema can be opened with the historical view schema | ||
| const backwardsCompatibilityStatus = checkCompatibility(oldViewSchema, currentViewSchema); | ||
|
|
||
| // The current view schema has a superset of the fields on the old view schema, so the schema must be upgraded to add the new | ||
| // optional field `z`. | ||
| assert.equal(backwardsCompatibilityStatus.canView, false); | ||
| assert.equal(backwardsCompatibilityStatus.canUpgrade, true); | ||
|
|
||
| // Test what the old version of the application would do with a tree using the new schema: | ||
| const forwardsCompatibilityStatus = checkCompatibility(currentViewSchema, oldViewSchema); | ||
TommyBrosman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Content created with the current schema can be viewed by the old schema due to allowUnknownOptionalFields | ||
| assert.equal(forwardsCompatibilityStatus.canView, true); | ||
| }); | ||
|
|
||
| it("checkCompatibility: staged schema", () => { | ||
| const factory = new SchemaFactoryBeta("test"); | ||
| const oldSchema = factory.optional( | ||
| factory.types([numberSchema, factory.staged(stringSchema)]), | ||
| ); | ||
| const currentSchema = factory.optional([stringSchema, numberSchema]); | ||
|
|
||
| const oldViewSchema = new TreeViewConfiguration({ schema: oldSchema }); | ||
| const currentViewSchema = new TreeViewConfiguration({ schema: currentSchema }); | ||
|
|
||
| // Check to see if the document created by the historical view schema can be opened with the current view schema | ||
| const backwardsCompatibilityStatus = checkCompatibility(oldViewSchema, currentViewSchema); | ||
TommyBrosman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // The staged string schema in the old schema is supported in the current schema | ||
| assert.equal(backwardsCompatibilityStatus.canView, true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is true, we have a major issue. This should require an upgrade to add support for strings. If it does not, then new clients could add strings to a document whose stored schema does not support them, which is invalid. |
||
|
|
||
| // Check to see if a document created with the current view schema can be opened with the historical view schema | ||
| const forwardsCompatibilityStatus = checkCompatibility(currentViewSchema, oldViewSchema); | ||
|
|
||
| // The current schema's string schema is supported by the old schema's staged string schema | ||
| assert.equal(forwardsCompatibilityStatus.canView, true); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.