Skip to content

Commit 9daa8f8

Browse files
Make tree's "currentVersion" actually current. (#26033)
## Description "currentVersion" Inside of shared tree is currently unused except for tests. It was set to 2.0.0, and this makes it actually stary current. As this is only used in tests, all the snapshot tests with update simply reflect a change to how their tests are configured, ensuring they test for the latest version and can detect changes in it.
1 parent cde81b5 commit 9daa8f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+142
-77
lines changed

packages/dds/tree/src/codec/codec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License.
44
*/
55

6+
import { cleanedPackageVersion as runtimeUtilsCleanedPackageVersion } from "@fluidframework/runtime-utils/internal";
67
import type { ErasedType } from "@fluidframework/core-interfaces/internal";
78
import { IsoBuffer, bufferToString } from "@fluid-internal/client-utils";
89
import { assert, fail } from "@fluidframework/core-utils/internal";
@@ -550,15 +551,22 @@ export const FluidClientVersion = {
550551
} as const satisfies Record<string, MinimumVersionForCollab>;
551552

552553
/**
553-
* An up to date version which includes all the important stable features.
554+
* An up to date version which includes all stable features.
554555
* @remarks
555-
* Use for cases when data is not persisted and thus would only ever be read by the current version of the framework.
556+
* Use for cases when data is not persisted and thus would only ever be read by the the same version of the code which read this value.
557+
*
558+
* The pkgVersion from this package (tree) can not be used here as it is not guaranteed to be a valid MinimumVersionForCollab
559+
* and would also unexpectedly disable features in prereleases and on CI if it didn't fail validation.
560+
* See {@link @fluidframework/runtime-utils/internal#cleanedPackageVersion} for more details on why cleanedPackageVersion is preferred over pkgVersion.
556561
*
557562
* @privateRemarks
558-
* Update as needed.
559-
* TODO: Consider using packageVersion.ts to keep this current.
563+
* It is safe to use CleanedPackageVersion from runtime-utils here since features are enabled in minor versions,
564+
* and this package (tree) depends on runtime-utils with a `~` semver range
565+
* ensuring that the version of runtime-utils this was imported from will match the version of this (tree) package at least up to the minor version.
566+
* Reusing this from runtime-utils avoids duplicating the cleanup logic here as well as the cost or recomputing it.
567+
* If in the future for some reason this becomes not okay, runtime-utils could instead export a function that performs that cleanup logic which could be reused here.
560568
*/
561-
export const currentVersion: MinimumVersionForCollab = FluidClientVersion.v2_0;
569+
export const currentVersion: MinimumVersionForCollab = runtimeUtilsCleanedPackageVersion;
562570

563571
export interface CodecTree {
564572
readonly name: string;

packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizerCodec.spec.ts

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
validateUsageError,
1111
} from "@fluidframework/test-runtime-utils/internal";
1212

13-
import { currentVersion, type CodecWriteOptions } from "../../../codec/index.js";
13+
import {
14+
currentVersion,
15+
FluidClientVersion,
16+
type CodecWriteOptions,
17+
} from "../../../codec/index.js";
1418
import { rootFieldKey } from "../../../core/index.js";
1519
import { FormatValidatorBasic } from "../../../external-utilities/index.js";
1620
import {
@@ -39,18 +43,26 @@ import { brand } from "../../../util/index.js";
3943
import { EmptyObject } from "../../cursorTestSuite.js";
4044
import { testIdCompressor } from "../../utils.js";
4145

42-
const codecOptions: CodecWriteOptions = {
46+
const codecOptionsOld: CodecWriteOptions = {
47+
jsonValidator: FormatValidatorBasic,
48+
minVersionForCollab: FluidClientVersion.v2_0,
49+
};
50+
51+
const codecOptionsCurrent: CodecWriteOptions = {
4352
jsonValidator: FormatValidatorBasic,
4453
minVersionForCollab: currentVersion,
4554
};
46-
const fieldBatchCodec = makeFieldBatchCodec(codecOptions);
55+
56+
const fieldBatchCodecOld = makeFieldBatchCodec(codecOptionsOld);
57+
const fieldBatchCodecCurrent = makeFieldBatchCodec(codecOptionsCurrent);
4758
const context = {
4859
encodeType: TreeCompressionStrategy.Uncompressed,
4960
originatorId: testIdCompressor.localSessionId,
5061
idCompressor: testIdCompressor,
5162
};
5263

53-
const codec = makeForestSummarizerCodec(codecOptions, fieldBatchCodec);
64+
const codecOld = makeForestSummarizerCodec(codecOptionsOld, fieldBatchCodecOld);
65+
const codecCurrent = makeForestSummarizerCodec(codecOptionsCurrent, fieldBatchCodecCurrent);
5466

5567
const testFieldChunks: TreeChunk[] = chunkField(
5668
cursorForJsonableTreeField([{ type: brand(EmptyObject.identifier) }]),
@@ -66,14 +78,14 @@ const malformedData: [string, unknown][] = [
6678
],
6779
["incorrect data type", ["incorrect data type"]],
6880
];
69-
const validData: [string, FieldSet, FormatV1 | undefined][] = [
81+
const validDataOld: [string, FieldSet, FormatV1 | undefined][] = [
7082
[
7183
"no entry",
7284
new Map(),
7385
{
7486
version: brand(ForestFormatVersion.v1),
7587
keys: [],
76-
fields: fieldBatchCodec.encode([], context),
88+
fields: fieldBatchCodecOld.encode([], context),
7789
},
7890
],
7991
[
@@ -82,7 +94,36 @@ const validData: [string, FieldSet, FormatV1 | undefined][] = [
8294
{
8395
version: brand(ForestFormatVersion.v1),
8496
keys: [rootFieldKey],
85-
fields: fieldBatchCodec.encode([testFieldChunk.cursor()], context),
97+
fields: fieldBatchCodecOld.encode([testFieldChunk.cursor()], context),
98+
},
99+
],
100+
[
101+
"multiple entries",
102+
new Map([
103+
[rootFieldKey, testFieldChunk.cursor()],
104+
[brand("X"), testFieldChunk.cursor()],
105+
]),
106+
undefined,
107+
],
108+
];
109+
110+
const validDataCurrent: [string, FieldSet, FormatV1 | undefined][] = [
111+
[
112+
"no entry",
113+
new Map(),
114+
{
115+
version: brand(ForestFormatVersion.v2),
116+
keys: [],
117+
fields: fieldBatchCodecCurrent.encode([], context),
118+
},
119+
],
120+
[
121+
"single entry",
122+
new Map([[rootFieldKey, testFieldChunk.cursor()]]),
123+
{
124+
version: brand(ForestFormatVersion.v2),
125+
keys: [rootFieldKey],
126+
fields: fieldBatchCodecCurrent.encode([testFieldChunk.cursor()], context),
86127
},
87128
],
88129
[
@@ -96,15 +137,29 @@ const validData: [string, FieldSet, FormatV1 | undefined][] = [
96137
];
97138

98139
describe("ForestSummarizerCodec", () => {
99-
describe("encodes and decodes valid data.", () => {
100-
for (const [name, data, expected] of validData) {
140+
describe("encodes and decodes valid old data.", () => {
141+
for (const [name, data, expected] of validDataOld) {
142+
it(name, () => {
143+
const encodedData = codecOld.encode(data, context);
144+
if (expected !== undefined) {
145+
assert.deepEqual(encodedData, expected);
146+
}
147+
148+
const decodedData = codecOld.decode(encodedData, context);
149+
assert.deepEqual(decodedData, data);
150+
});
151+
}
152+
});
153+
154+
describe("encodes and decodes valid current data.", () => {
155+
for (const [name, data, expected] of validDataCurrent) {
101156
it(name, () => {
102-
const encodedData = codec.encode(data, context);
157+
const encodedData = codecCurrent.encode(data, context);
103158
if (expected !== undefined) {
104159
assert.deepEqual(encodedData, expected);
105160
}
106161

107-
const decodedData = codec.decode(encodedData, context);
162+
const decodedData = codecCurrent.decode(encodedData, context);
108163
assert.deepEqual(decodedData, data);
109164
});
110165
}
@@ -113,7 +168,7 @@ describe("ForestSummarizerCodec", () => {
113168
describe("throws on receiving malformed data during encode.", () => {
114169
for (const [name, data] of malformedData) {
115170
it(name, () => {
116-
assert.throws(() => codec.encode(data as FieldSet, context), "malformed data");
171+
assert.throws(() => codecCurrent.encode(data as FieldSet, context), "malformed data");
117172
});
118173
}
119174
});
@@ -122,7 +177,7 @@ describe("ForestSummarizerCodec", () => {
122177
it("invalid version", () => {
123178
assert.throws(
124179
() =>
125-
codec.decode(
180+
codecCurrent.decode(
126181
{
127182
version: 2.5 as ForestFormatVersion,
128183
fields: {
@@ -142,7 +197,7 @@ describe("ForestSummarizerCodec", () => {
142197
it("invalid nested version", () => {
143198
assert.throws(
144199
() =>
145-
codec.decode(
200+
codecCurrent.decode(
146201
{
147202
version: brand(ForestFormatVersion.v1),
148203
fields: {
@@ -162,7 +217,7 @@ describe("ForestSummarizerCodec", () => {
162217
it("missing fields", () => {
163218
assert.throws(
164219
() =>
165-
codec.decode(
220+
codecCurrent.decode(
166221
{
167222
version: brand<ForestFormatVersion>(ForestFormatVersion.v1),
168223
keys: [],
@@ -176,7 +231,7 @@ describe("ForestSummarizerCodec", () => {
176231
it("extra field", () => {
177232
assert.throws(
178233
() =>
179-
codec.decode(
234+
codecCurrent.decode(
180235
{
181236
version: brand<ForestFormatVersion>(ForestFormatVersion.v1),
182237
fields: { version: brand<FieldBatchFormatVersion>(FieldBatchFormatVersion.v1) },

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/allTheFields-full.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/allTheFields-minimal.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/empty.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/false boolean.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/handle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/hasAllMetadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/hasAllMetadataRootField.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

packages/dds/tree/src/test/snapshots/output/chunked-forest-schema-compressed/V1/hasAmbiguousField.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"identifiers": [],
44
"shapes": [
55
{

0 commit comments

Comments
 (0)