Skip to content

Commit bc91468

Browse files
authored
fix(test-version-utils): Fix version calculation to account for legacy breaking minor releases (microsoft#23603)
This PR fixes N-X version calculation to take into account the new legacy breaking minor releases. For example, - For `2.0.0 <= N < 2.10.0`, N-1 is 2.0.0-rc.5.0.x. - For `2.10.0 <= N < 2.20.0`, N-1 is 2.5.x (latest minor between 2.0 and 2.10 is 2.5.x) - For `2.20.0 <= N < 2.30.0`, N-1 is 2.13.x (latest minor between 2.10 and 2.20 is 2.13.x) We should still consider a full rewrite of version calculation, since the code is extremely messy and hard to follow for developers not familiar with it already. However, this change is needed to ensure we continue testing properly in the meantime. See [AB#8198](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/8198) for more details. [AB#28437](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/28437)
1 parent 6076f48 commit bc91468

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

packages/test/test-version-utils/src/test/versionUtils.spec.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,21 @@ describe("versionUtils", () => {
5757
const adjustPublicMajor = false;
5858
createTest("1.0.0", -1, adjustPublicMajor, "^0.59.0");
5959
createTest("1.0.0", -2, adjustPublicMajor, "^0.58.0");
60-
createTest("2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0");
61-
createTest("2.3.5", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0");
60+
createTest("2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.5.0.0");
61+
createTest("2.3.5", -1, adjustPublicMajor, "~2.0.0-rc.5.0.0");
62+
createTest("2.10.0", -1, adjustPublicMajor, "~2.5.0");
63+
createTest("2.10.0", -2, adjustPublicMajor, "^2.0.0-rc.5.0.0");
64+
createTest("2.13.2", -1, adjustPublicMajor, "~2.5.0");
65+
createTest("2.20.0", -1, adjustPublicMajor, "~2.13.0");
66+
createTest("2.20.0", -2, adjustPublicMajor, "~2.5.0");
67+
createTest("2.20.0", -3, adjustPublicMajor, "^2.0.0-rc.5.0.0");
6268
});
6369

6470
describe("bumping public releases (adjustPublicMajor = true)", () => {
6571
const adjustPublicMajor = true;
6672
createTest("2.0.0", -1, adjustPublicMajor, "^1.0.0");
6773
createTest("2.3.5", -1, adjustPublicMajor, "^1.0.0");
74+
createTest("2.13.5", -1, adjustPublicMajor, "^1.0.0");
6875
});
6976

7077
describe("bumping internal releases to public releases (adjustPublicMajor = false)", () => {
@@ -127,8 +134,8 @@ describe("versionUtils", () => {
127134
createTest("2.0.0-rc.1.3.4", -2, adjustPublicMajor, "^2.0.0-internal.7.0.0");
128135

129136
// These tests should be enabled once 2.0.0-rc.1.0.0 is released (currently throws trying to fetch the unreleased packages)
130-
// createTest("2.0.0-rc.2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.1.0.0");
131-
// createTest("2.0.0-rc.2.0.0", -2, adjustPublicMajor, "^2.0.0-internal.8.0.0");
137+
createTest("2.0.0-rc.2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.1.0.0");
138+
createTest("2.0.0-rc.2.0.0", -2, adjustPublicMajor, "^2.0.0-internal.8.0.0");
132139
});
133140

134141
it("error cases for malformed versions", () => {

packages/test/test-version-utils/src/versionUtils.ts

+31-5
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,39 @@ function calculateRequestedRange(
438438
}
439439

440440
// If the base version is a public version and `adjustPublicMajor` is false, then we need to ensure that we
441-
// calculate N-1 as he previous major release, regardless if it is public or internal.
442-
// Currently, this case only applies to calculating N-X for 2.0.0.
441+
// calculate N-1 as the previous major release, regardless if it is public or internal.
442+
// Currently, this case only applies to calculating N-X for 2.x.y.
443443
// TODO: This is a temporary solution and we need to entirely rewrite this function to handle the changes the version schemas. See ADO:8198.
444444
if (adjustPublicMajor === false && version.major > 1) {
445-
// In this case, we can pretend that 2.0 is RC6 and calculate the range as if it were an internal version.
446-
const internalSchemeRange = internalSchema("2.0.0", "6.0.0", "rc", requested);
447-
return internalSchemeRange;
445+
if (version.minor < 10) {
446+
// If 2.0 <= N < 2.10, then we can pretend that N is RC6 (*which doesn't exist*) and calculate the range as if it were an internal version.
447+
const internalSchemeRange = internalSchema("2.0.0", "6.0.0", "rc", requested);
448+
return internalSchemeRange;
449+
} else {
450+
// For each requested version to go back, we go back 10 minor versions. If requested is -2, then we need to go back 20 minor versions.
451+
const legacyMinorsToSkip = Math.abs(requested * 10);
452+
if (legacyMinorsToSkip > version.minor) {
453+
// If the number of minors we need to go back is greater than the minor version, then that means we will be going back to RC releases.
454+
// Here we calculate how many more releases we need to go back **after** we take into account going from the current minor version to 2.0.
455+
// For example, if N is 2.20, then the range we need to return for N-1 starts at 2.10, for N-2 it starts at 2.0, N-3 is RC5, N-4 is RC4, etc.
456+
// So if N is 2.20 and requested is 4, then we still need to go back 2 more releases from 2.0 (treated as RC6).
457+
const remainingRequested =
458+
(legacyMinorsToSkip - Math.floor(version.minor / 10) * 10) / 10;
459+
const internalSchemeRange = internalSchema(
460+
"2.0.0",
461+
"6.0.0",
462+
"rc",
463+
remainingRequested * -1, // make sure the value is negative since we made it positive above
464+
);
465+
return internalSchemeRange;
466+
}
467+
// Here we know that the requested version will be >=2.0, so we can avoid all the RC releases.
468+
// If N >= 2.10, then the range we need to return for N-1 starts at legacy breaking minor before the one N belongs to.
469+
const lowerMinorRange = Math.floor((version.minor - legacyMinorsToSkip) / 10) * 10;
470+
const upperMinorRange = lowerMinorRange + 10;
471+
// Here we do a range that, when resolved, will result in the latest minor version that satisfies the request.
472+
return `>=${version.major}.${lowerMinorRange}.0-0 <${version.major}.${upperMinorRange}.0-0`;
473+
}
448474
} else {
449475
// calculate requested major version number
450476
const requestedMajorVersion = version.major + requested;

0 commit comments

Comments
 (0)