Skip to content
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

fix(build-tools): mixed internal range detection #18828

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jason-ha
Copy link
Contributor

better inspect complex ranges with ||
handle cross prerelease rejection in single range set

refactor tests to see examples in table form

@github-actions github-actions bot added area: build Build related issues base: main PRs targeted against main branch labels Dec 14, 2023
@jason-ha jason-ha marked this pull request as ready for review January 4, 2024 08:10
@jason-ha jason-ha requested a review from a team as a code owner January 4, 2024 08:10
tylerbutler
tylerbutler previously approved these changes Jan 4, 2024
@@ -435,5 +470,6 @@ export function detectInternalVersionConstraintType(range: string): "minor" | "p
const minor = bumpInternalVersion(minVer, "minor");

const maxSatisfying = semver.maxSatisfying([patch, minor], range);
// maxSatisfying could return null in case of exact version. Should that return as "minor"?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably return "exact", which would change the function signature - which is also fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should bumpRange do when it encounters and exact constraint? throw?

// internalPrerelease only applies to versions, which won't have ~ or ^.
// internal ranges are restricted to uses of `>=` even though semver would permit more.
// For prerelease spec (internal range), ~ and ^ are interpreted as >= by semver.
// Why not just use the bump and checks all the time?
if (range.startsWith("~")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ and ^ are checked because there are/were cases where an internal version was naively prepended with one of those, even though it's not valid technically. What should this function do if passed a value like ^2.0.0-internal.1.0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases now? Why aren't they getting fixed?
The comment I added is not really correct. But I don't think such cases should be treated as internal because the semver meaning of them is treat ~ and ^ as >=(given spec) to ^(given spec less prerelease), at least as far as I can ascertain.
I would say they should just be rejected - throw as invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at the uses of this, I go back to my original comment as correct. This is not reachable except in test code. The one real use is bumpRange. But a range like ~2.0.0-internal.1.0.0 is detected as 'semver' and not internal.
To be explicit about my how does semver treat ~2.0.0-internal.1.0.0 in prior, that would become >=2.0.0-internal.1.0.0 <2.1.0.

Comment on lines +133 to +135
[true, ">=2.0.0-internal.1.0.0 <2.0.0-internal.1.1.0", undefined],
[true, ">=2.0.0-rc.1.0.0 <2.0.0-rc.1.1.0", undefined],
[false, ">=2.0.0-internal.1.0.0 <2.0.0-rc.1.1.0", undefined],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: FWIW, I find this format harder to read and understand. I think it's mostly that the test case "name" isn't easy to read. If I see "~2.0.0-internal.2.2.1 is not internal" I know what the test is checking without looking at the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are referring to the displayed test names shown in test output or test explorers. Such as:

      ✔ >=2.0.0-alpha.2.2.1 <2.0.0-alpha.3.0.0 is internal when allowAnyPrereleaseId is true
      ✔ >=2.0.0-dev.2.2.1.12345 <2.0.0-dev.3.0.0 is internal when allowAnyPrereleaseId is true
      ✔ >=1.0.0 <2.0.0 is not internal
      ✔ >=2.0.0-2.2.1 <2.0.0-3.0.0 is not internal
      ✔ ^2.0.0-internal.2.2.1 is not internal
      ✔ ~2.0.0-internal.2.2.1 is not internal

Those are preserved with this change. The above is from my local test run. Please let me know if you meant that or something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, saw that. I was referring to the source, though. It's probably just me - I can't look at that table and parse it easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree for the source. It isn't just you. I like the table because it addresses some issues with typos and making the file too long to see all of the cases which makes it hard to see what isn't there. There are two alternate patterns.

  1. Instead of array of arrays use array of records which has the parameters named and is a bit easier to follow a single line but adds verbosity to the table which makes it bigger again.
  2. Use a helper function and just call it a bunch of times in a row.

better inspect complex ranges with ||
handle cross prerelease rejection in single range set

refactor tests to see examples in table form
@jason-ha jason-ha force-pushed the build-versions-robust-internals branch from 9568eb3 to 44378a0 Compare January 6, 2024 00:17
@jason-ha jason-ha dismissed tylerbutler’s stale review January 8, 2024 17:50

Looking for formal re-review per comments and updates

@tylerbutler
Copy link
Member

My only concern is if test-version-utils in the client release group is expecting ^2.0.0-internal.1.0.0 to be identified as internal. Haven't had time to check myself. Everything else looks good.

@jason-ha
Copy link
Contributor Author

jason-ha commented Feb 7, 2024

My only concern is if test-version-utils in the client release group is expecting ^2.0.0-internal.1.0.0 to be identified as internal. Haven't had time to check myself. Everything else looks good.

@tylerbutler, that would be a problem in test-version-utils because ^2.0.0-interna.1.0.0 is not restricted to internal versions. And that is something that the current tests check. Test case is "^2.0.0-internal.2.2.1 is not internal".

There is a question for you about handling of exact constraint during bump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: build Build related issues base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants