Repository navigation
fix(project): read a usage's versionConstraint as a semver range - #1568
Merged
Merged
Conversation
Exact, =/v prefix, comparators, caret, tilde, x/* wildcards, hyphen ranges, space/comma as AND, || as OR, pre-release precedence per semver 2.0.0, in one place (constraint.go) used by pickInstalled, pickVersion and pickUnclaimed. The highest installed version in the range is taken; none, or a constraint the grammar does not read, is a project.load warning and the usage links nothing. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: jason.han <hanhuijun@gmail.com> # Conflicts: # docs/guide/03-command-line.md # docs/internals/design/package-management.md # internal/workspace/project/discovery.go
6 tasks done
…on-ranges Co-Authored-By: jason.han <hanhuijun@gmail.com> # Conflicts: # docs/internals/design/package-management.md # internal/workspace/project/interchange_test.go
…ase; ^*/~* admit any version; build metadata is read npm-style ranges let a pre-release in only through a comparator that is a pre-release of the same release, so ^1.2.3 no longer takes 1.3.0-rc.1 and * takes no pre-release; ^*, ^x and ~* lower to no bound; +build metadata is validated and discarded instead of being read as an empty pre-release. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
6 tasks done
…ranges Co-Authored-By: jason.han <hanhuijun@gmail.com> # Conflicts: # docs/project/spec-compliance.md
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What and why
Interchange.satisfiesunderstood only an exact version, so a usage whoseversionConstraintis a range (^1.0.0,>=1.0.0,~1.1.0,1.1.x,>=1.0.0 <2.0.0) never linked by elimination — every candidate was dropped, no warning — and on the publisher/name matchpickInstalledfell back to the latest installed version when nothing satisfied, so the range was ignored (an installed 2.0.0 picked for^1.0.0). Reproducer: one usage{"resource": "pkg:hg/hg.example.org/models/hg-widgets", "versionConstraint": "^1.0.0"},lib/acme-widgets_1.1.0/installed,private import Widgets::*;→unresolved reference: Widgets, while"1.1.0","=1.1.0"or no constraint loaded it.internal/workspace/project/constraint.go:parseVersionRangereads the npm-style semver range — exact (1.2.3,=1.2.3,v1.2.3), comparators<<=>>=, caret^, tilde~,x/X/*wildcards (1.x,*), hyphen ranges (1.0.0 - 2.0.0), space or comma as AND,||as OR, partial versions as their wildcard (1.2=1.2.x), build metadata validated and ignored (1.2.3+feature-oneis 1.2.3), pre-releases ordered as semver 2.0.0 orders them (newerVersion) and admitted only where an alternative names their release (>=1.0.0-rc.1 <1.0.0admits1.0.0-rc.9;^1.2.3,<2.0.0and*admit no pre-release), as npm ranges do;^*,^x,~*are unbounded.Usage.versionRange()parses the usage's constraint (versionConstraint, else the IRI's@version);Interchange.satisfies(versionRange)is the only test, used bypickInstalled,pickVersionandpickUnclaimed.pickInstalledis now "highest installed version in the range; else nothing", returning the versions it found named sousedcan say why. A constraint no installed version satisfies (usage … asks for version "^3.0.0" of acme/widgets, which none of the installed versions satisfies: 1.1.0 (…)) and a constraint outside the grammar (usage …: "latest": malformed version constraint: …) areproject.loadwarnings at the consumer's.project.json— the same routing as the ambiguity warning, so-warnings-as-errors,-baseline,-quiet, JSON/SARIF/JUnit treat them alike — and the usage links nothing; never silently "any", never silently the latest.Specification basis. KerML 1.1 §10.3 Table 12 makes
versionConstraintan optional string and defines no syntax for it. The npm-style range is the de-facto syntax package managers share; it is named as such indocs/project/spec-compliance.md(Table 12 row, status unchanged),docs/internals/design/package-management.md(§1 row and §3 "Versions") and the guide's "Working inside a package-manager project".Behaviour changes (adjudicated against the tests that relied on "exact, else latest"):
versionConstraintor@versionno installed version satisfies no longer takes the latest installed version: it is a warning and the usage selects nothing.TestPickInstalledPrefersTheConstrainedVersionThenTheLatestasserted the fallback (^3.0.0over 1.0.0/2.0.0/10.0.0 → 10.0.0;@3.0.0→ latest) and is replaced byTestPickInstalledTakesTheHighestVersionInTheRange; kept because a constraint the project author wrote is a statement about what the model was validated against, and loading something outside it silently is the failure this PR removes. No fixture undertests/orexamples/depended on the fallback; no update flag re-recorded anything.@1.0.0%2Bbuild(1.0.0+build) now selects 1.0.0 — build metadata is outside semver precedence — where it fell back to the latest.TestAroundReadsLibBesideTheProjectFileunchanged).This branch merges
fix/usage-elimination-named-forms(#1561), whoseused/pickUnclaimedlines it changes, thenorigin/developat12e4fc392, then #1561's head6320ce1c0again for its review fix (a deferred usage is revisited after every claim, even one that enqueues nothing) — one merge commit each, no rebase; it lands after #1561 (it applies clean on develop both alone and after #1561). The develop merge keeps #1563's elimination-link warning (Projects.Linking,eliminationUsage, theinstalledKeyexemption,pickUnclaimednever picking the consumer itself) beside thespellsLocationandversionRangerules: an elimination link is said once as a warning, the publisher/name match says nothing, and the unsatisfied/malformed warnings join the sameLinkinglist. The new tests assert that merged semantics (TestUsedHonoursARangeConstraintOnBothPathsexpects the link said once on thepkg:hg/path and nothing on thepkg:sysand/path; the exhaustion test expects its two links said).How it was verified
internal/workspace/project:TestVersionRangeMatches(every form above, 38 constraints, yes/no versions each, pre-release admission,^*/~x, hyphenated build metadata) andTestParseVersionRangeRefuses(=,^,1.2.3.4,abc,1.x.3,>*,latest,1.0.0 -,1.0.0-,1.2.3+,1.2.3+a..b, …);TestUsedHonoursARangeConstraintOnBothPaths(12 constraints × the slug pathpkg:sysand/acme/widgetsand the elimination pathpkg:hg/…/hg-widgets, over 1.0.0-rc.1/1.0.0/1.1.0/2.0.0 installed, each selecting the expected version alone);TestUsedReportsAnUnsatisfiedOrMalformedConstraint(^3.0.0,<1.0.0over 1.1.0,latest,1.x.3on both paths: nothing used, the warning at.project.jsonwith its text); the twopickInstalledtests reworked as above.tests/kpar/TestARangeConstraintLinksTheInstalledVersionItAdmits: the reproducer under^1.0.0,>=1.0.0,~1.1.0,1.1.x,>=1.0.0 <2.0.0,1.1.0,=1.1.0and none loadslib/acme-widgets_1.1.0/Widgets.sysmlthroughrepl.Sessionandsysml -validate; underlatest,-validate -warnings-as-errorsfails withmalformed version constraintandunresolved reference: Widgets.gofmt -l .empty;go vet ./...,go build ./...;go test -count=1 -timeout 40m ./...withOPENSYSML_REQUIRE_TRAINING_CORPUS,_PILOT_CORPORA,_SPEC_EXAMPLES,_PILOT_LIBRARY_XMI,_PSSM_SUITEset → all packages ok;make lint;make man-check;make docs-counts;python3 scripts/changelog.py check;tests/wasmbudgets.Checklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/020c7f4cdced4720a9afe70d9e4490ae
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/020c7f4cdced4720a9afe70d9e4490ae?variant=devin
Requested by: @HuiJun