Skip to content

Commit

Permalink
fix(test-version-utils): Fix version calculation to account for legac…
Browse files Browse the repository at this point in the history
…y breaking minor releases (#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)
  • Loading branch information
scottn12 authored Jan 24, 2025
1 parent 6076f48 commit bc91468
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
15 changes: 11 additions & 4 deletions packages/test/test-version-utils/src/test/versionUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ describe("versionUtils", () => {
const adjustPublicMajor = false;
createTest("1.0.0", -1, adjustPublicMajor, "^0.59.0");
createTest("1.0.0", -2, adjustPublicMajor, "^0.58.0");
createTest("2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0");
createTest("2.3.5", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0");
createTest("2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.5.0.0");
createTest("2.3.5", -1, adjustPublicMajor, "~2.0.0-rc.5.0.0");
createTest("2.10.0", -1, adjustPublicMajor, "~2.5.0");
createTest("2.10.0", -2, adjustPublicMajor, "^2.0.0-rc.5.0.0");
createTest("2.13.2", -1, adjustPublicMajor, "~2.5.0");
createTest("2.20.0", -1, adjustPublicMajor, "~2.13.0");
createTest("2.20.0", -2, adjustPublicMajor, "~2.5.0");
createTest("2.20.0", -3, adjustPublicMajor, "^2.0.0-rc.5.0.0");
});

describe("bumping public releases (adjustPublicMajor = true)", () => {
const adjustPublicMajor = true;
createTest("2.0.0", -1, adjustPublicMajor, "^1.0.0");
createTest("2.3.5", -1, adjustPublicMajor, "^1.0.0");
createTest("2.13.5", -1, adjustPublicMajor, "^1.0.0");
});

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

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

it("error cases for malformed versions", () => {
Expand Down
36 changes: 31 additions & 5 deletions packages/test/test-version-utils/src/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,39 @@ function calculateRequestedRange(
}

// If the base version is a public version and `adjustPublicMajor` is false, then we need to ensure that we
// calculate N-1 as he previous major release, regardless if it is public or internal.
// Currently, this case only applies to calculating N-X for 2.0.0.
// calculate N-1 as the previous major release, regardless if it is public or internal.
// Currently, this case only applies to calculating N-X for 2.x.y.
// TODO: This is a temporary solution and we need to entirely rewrite this function to handle the changes the version schemas. See ADO:8198.
if (adjustPublicMajor === false && version.major > 1) {
// In this case, we can pretend that 2.0 is RC6 and calculate the range as if it were an internal version.
const internalSchemeRange = internalSchema("2.0.0", "6.0.0", "rc", requested);
return internalSchemeRange;
if (version.minor < 10) {
// 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.
const internalSchemeRange = internalSchema("2.0.0", "6.0.0", "rc", requested);
return internalSchemeRange;
} else {
// 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.
const legacyMinorsToSkip = Math.abs(requested * 10);
if (legacyMinorsToSkip > version.minor) {
// 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.
// 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.
// 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.
// 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).
const remainingRequested =
(legacyMinorsToSkip - Math.floor(version.minor / 10) * 10) / 10;
const internalSchemeRange = internalSchema(
"2.0.0",
"6.0.0",
"rc",
remainingRequested * -1, // make sure the value is negative since we made it positive above
);
return internalSchemeRange;
}
// Here we know that the requested version will be >=2.0, so we can avoid all the RC releases.
// 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.
const lowerMinorRange = Math.floor((version.minor - legacyMinorsToSkip) / 10) * 10;
const upperMinorRange = lowerMinorRange + 10;
// Here we do a range that, when resolved, will result in the latest minor version that satisfies the request.
return `>=${version.major}.${lowerMinorRange}.0-0 <${version.major}.${upperMinorRange}.0-0`;
}
} else {
// calculate requested major version number
const requestedMajorVersion = version.major + requested;
Expand Down

0 comments on commit bc91468

Please sign in to comment.