Repository navigation
Port test_specifiers.py conformance tables and fix the divergences they surface (rstudio/package-manager#19391) - #31
Merged
Conversation
Roughly 80% of pypa/packaging's test_specifiers.py cases could not be
written against this module's public surface -- not because they were
Python-specific, but because the corresponding Go API did not exist.
Only the *set* was public, exposing just Check and String.
Adds:
- Specifier, the exported singular specifier, with Operator/Version/
Original/String/Check/Contains/ContainsVersion/Filter/FilterVersions/
PreReleases/Equal.
- PreReleases, a three-state pre-release policy (Auto/Include/Exclude)
with WithPreReleases, usable at construction and per call.
- Filter and Contains on both types, implementing PEP 440 candidate
SELECTION. Contains is defined as "Filter of one item is non-empty",
exactly as upstream defines it, so the two cannot disagree.
- A string-operand query path, which finally makes ===lolwat
expressible: Check takes a Version and Parse("lolwat") fails.
- FilterBy, upstream's key= parameter, as a generic free function.
- Specifiers Len/List/Equal/And/ContainsInstalled, NewSpecifiersFrom.
- marker.Environment.With/Lookup and marker.VariableNames, the seam a
PARTIAL marker environment needs.
Two behavior changes worth reviewing carefully.
WithPreRelease(true) used to set a flag that made Version.IsPreRelease
report false for a version that plainly is a pre-release, disabling the
guards in specifierLessThan/specifierGreaterThan and making <2 match
2.0.dev1. That conflated candidate SELECTION with MATCHING. Measured
against pypa/packaging 26.2, Specifier("<2").contains("2.0.dev1") is
False under every pre-release policy -- the guard is part of what "<"
means, not a policy. The flag is removed, so IsPreRelease is now a
property of the version alone. One existing assertion pinned the old
behavior and is corrected.
Specifiers.String() now renders each member normalized rather than
echoing input text, so NewSpecifiers("< 2").String() is "<2".
Requirement.String() is unaffected: internal/pep508's
normalizeSpecifierClause already stripped that whitespace before
version.NewSpecifiers saw it, so the two levels previously disagreed.
Also fixes NewSpecifiers("") (now the universal set, the empty-input arm
that survived 0.3.0's zero-value fix) and the six MustParse calls on the
matching path, which no longer panic on an uninterpretable operand.
Every expected value was measured against pypa/packaging 26.2 rather
than derived from the PEP text.
Refs rstudio/package-manager#19383
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Ports 1,649 assertions from pypa/packaging's tests/test_specifiers.py
(classes TestSpecifier and TestSpecifierSet) at pinned commit
4eb0753dba8fcaaac8eb75463374e448f0931558. 358 of them failed against
the library as it stood. All pass now.
Every expectation was cross-checked against TWO independent sources --
the literal in the pinned upstream file, and what the installed
packaging 26.2 actually answers -- so a stale literal could not be
baked in silently. All of them agreed.
Six divergences fixed, in two groups.
PARSING:
- validConstraintRegexp lacked the (?i) flag specifierRegexp has, so
==1.0a1 parsed while ==1.0A1 was rejected before the parser saw it.
303 of the 358 failures. Pure widening: over the production PyPI
corpus (25,457 distinct specifier tokens) 874 are newly accepted and
0 newly rejected.
- A vertical tab (0x0B) was not accepted as surrounding whitespace,
because Go's \s excludes it and Python's includes it. versionRegex
had already been fixed; the specifier patterns had not.
- validate() guarded a wildcard against dev, post and local but never
against a PRE-release, so ==1.0a1.* was wrongly accepted. This is a
narrowing; measured at 0 newly rejected over the production PyPI
corpus and 0 over real CRAN data, with both the extraction pattern
and the differential harness proved to detect the shapes whose
absence is being claimed.
MATCHING (all four were base-version comparisons standing in for the
rule PEP 440 actually states):
- "<V must not allow a pre-release of V" compared base versions, so
for the spec 1.0.post1 it excluded 1.0.dev0 -- a pre-release of 1.0,
not of 1.0.post1. Now bounded by _earliest_prerelease.
- ">V must not allow a post-release of V" made the mirror error: for
the spec 1.0a1 it excluded 1.0.post0. Now uses _post_base.
- ">V must not match a local version of V" needs the PUBLIC version,
which keeps pre/post/dev; comparing base versions made >1.0a1
wrongly reject 1.0a2+local.
- Prefix matching and ~= both mis-split the operand. versionSplit did
not peel the epoch off, so ==0!2.* could not match 2; padding ran
between the two sides instead of up to the spec's numeric width, so
2 did not match ==2.0.0.*; and ~= broke its prefix only on
post/dev, so ~=1.0a1 derived the wrong prefix. Upstream's
_version_split, _version_join, _is_not_suffix, _numeric_prefix_len
and _left_pad are now ported directly, replacing padVersion.
Over the production corpus, 12 of 25,457 tokens change their match
results. All 12, plus 5 synthetic controls, were checked against
packaging 26.2 over a 19-version panel: 0 of 17 agreed with the
reference before, 17 of 17 agree after.
Also audited the 163 rows of the hand-written TestVersion_Check table
against packaging 26.2. No row disagrees with the reference where both
implementations parse the input; the only flagged rows are this
package's four documented deliberate extensions (a bare version, "=",
"*" for any, and "||").
Refs rstudio/package-manager#19391
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three review findings with one root cause: Specifiers is an OR of AND groups, and the new query API treated it as a flat bag of specifiers. HIGH -- an empty "||" segment silently disabled the whole constraint. Splitting on "||" produced a blank segment for a leading, trailing or doubled operator; parseGroup turned a blank segment into an empty AND-group; and an empty AND-group matches every version, so Check's OR swallowed every other group. ">=1||" parsed and then admitted 0.1, a version below its own floor, with nothing erroring and nothing logged. This was a regression introduced by this branch: at v0.4.0 the same input was an error. The R entry point shares the path and is what PPM uses for R version constraints. The universal set now has exactly one producer, universalSpecifiers, reached only when the ENTIRE input is blank. parseGroup can no longer return an empty group and says so; its doc comment previously read as justifying the behavior, which would have invited someone to restore it on purpose. MEDIUM -- And concatenated members instead of distributing, so (A||B) AND C became A AND B AND C. That is strictly narrower and usually unsatisfiable: (==1.0||==2.0) AND <3.0 matched NOTHING, rejecting both versions it should have admitted. Now distributes to (==1.0,<3.0) || (==2.0,<3.0). Chose distribution over erroring on multi-group operands because it is the correct semantics and And is new API, so there is no compatibility cost. The universal set is now the identity of And in both positions, which a cartesian product over zero groups would not have been. MEDIUM -- Equal compared a flattened member set, so ">=1||<2" (admits everything) compared equal to ">=1,<2" (admits the intersection). Now compares the set of canonicalized AND-groups: still blind to group order, within-group order, duplicates and pre-release policy, but no longer blind to which members share a group. For a single-group set -- everything a Python-style comma-separated string produces, and so everything the upstream conformance tables exercise -- this reduces exactly to the previous behavior. Audited every operation that consumes a flattened view. Check, String, Contains, Filter, matchAll and allArbitraryMatch already walk the groups. Len (a count), List (iteration) and Specifiers.PreReleases (a global policy hint, upstream's `any(s.prereleases for s in self._specs)`) are genuinely structure-independent, and there is now a test pinning that rather than leaving it as prose. List's doc comment warns against using it as a basis for semantics, naming both bugs it caused. Every test verified RED before the fix: 6 of 8 new test functions and 11 subtests failed on the parent commit, with ">=1||" reported as admitting 0.1 and the And result rejecting all three probe versions. The two that were already green are the preserved-behavior control (empty input stays universal, comma handling unchanged) and the Contains/Filter pin. Measured: "||" does not occur at all in real CRAN data (0 of 59,139 constraint occurrences), so the narrowing affects nothing real. The extraction pattern was proved to flag the three malformed shapes and not the well-formed ">=1||<2". Refs rstudio/package-manager#19383 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two things, both asked for in review.
1. COMMA TOLERANCE (the last listed #19391 divergence)
A blank comma-separated item is now dropped rather than rejected, which
is upstream's rule: SpecifierSet.__init__ does
`[s.strip() for s in specifiers.split(",") if s.strip()]`. So ",>=1",
",,>=1", ">=1,,<2" and ">=1 , , <2" now parse, and a comma-only input
(",", ",,", " , ") is the universal set -- exactly where packaging 26.2
lands, verified case by case rather than inferred.
Measured over the production PyPI corpus plus real CRAN constraints
(28,528 distinct inputs, both entry points): 0 newly rejected and 0
newly accepted. No real constraint in either corpus has a leading or
doubled comma, so this is a pure conformance fix with no observable
effect on real data. The harness was positive-controlled: all six
synthetic comma shapes flip reject->accept on both paths, while ">=1<2"
stays rejected.
⚠️ Two safety properties preserved, both tested:
- The comma BETWEEN two constraints is still required. Only blank
items are dropped, and what survives is re-joined with commas and
revalidated, so ">=1<2" and ",,>=1 <2,," stay errors.
- The tolerance stops at the "||" boundary, and this is the one place
the package deliberately stops short of upstream. SpecifierSet(",")
is universal upstream and NewSpecifiers(",") is universal here, but
">=1||," is an ERROR. Upstream has no "||" and so has no opinion;
composing "blank items are dropped" with "an empty group is
universal" per SEGMENT would let a stray comma disable the whole
constraint -- the same hole a stray "||" opened, reached by a
different typo. A specifier-less group is universal only when it is
the entire input.
The "||" control test is rewritten around that interaction rather than
around the old rejected-comma behavior, so it still isolates the two
concerns. The newly-valid forms are in the valid table with the upstream
citation and the pinned SHA.
2. TWO CHANGES THAT SHIPPED WITH NO CHANGELOG ENTRY
Both landed in v0.1.0 (commit d097655) and appear nowhere in
CHANGELOG.md. Verified: `git tag --contains d097655` starts at v0.1.0,
and the file has never mentioned either.
- padVersion derived the right-hand version's remainder by slicing the
LEFT-hand version, so every ==X.*, !=X.* and ~= comparison with
differently-sized release segments could answer wrongly. 349 of
135,204 specifier sets flip over the production PyPI corpus; of 928
flipped pairs, packaging 26.2 agrees with the new behavior 915 times
and the old 13 (those 13 are a separate pre-existing epoch
divergence).
- NewRSpecifiers discarded its sanitizer argument. 0 differences over
real CRAN (2,814 constraints), 1,447 of 135,204 adversarially, and
⚠️ invisible in String(), which renders pre-sanitize text.
Recorded under [Unreleased] in a labelled subsection naming the version
they actually shipped in, NOT backdated into the tagged [0.1.0] section.
Also states what the omission implies: this module has shipped
unrecorded semantic changes, so an upgrade should be assessed by
diffing behavior on real input, which is how these two were found.
Refs rstudio/package-manager#19391, rstudio/package-manager#18634
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Six review findings. Four are behavioral, two are claims that were wrong.
FINDING 1 -- ~= panicked on a suffix-only operand.
specifierCompatible derives its prefix by taking release components up to
the first post/dev suffix and dropping the last one. An operand that IS a
suffix from its first segment ("dev1", "post1", "dev", "post") leaves
prefixElements empty, and [:len-1] of empty is [:-1]: "slice bounds out
of range". Guarded.
⚠️ The hardening test could not have caught this. Its operand list
("lolwat", "", "not a version", "1.2.3.4.5-garbage") contains no member
that reaches the break-on-first-iteration path, so it exercised every
operator EXCEPT the one that could crash, while its name and header
claimed the whole shape class. The suffix-only shapes are now in the
list, plus a dedicated test naming this as the one panic in the table
that is a slice bound rather than a MustParse.
FINDINGS 6 and 7 -- container state was overwriting member state.
newSpecifier stamped the SET's policy onto every member, so a member read
off a set reported the set's policy rather than its own: upstream's
list(SpecifierSet(">=1.0.dev1", prereleases=False))[0].prereleases is
True while the set's is False. And re-stamped members with the combined
policy, which could ERASE an explicit member policy and let autodetection
reach the opposite answer -- a member built with Exclude on ">=1.0.dev1"
became Auto, autodetected Include off the .dev1, and flipped the set's
resolved policy, so the combined set offered a pre-release the original
held back. NewSpecifiersFrom stamped too, discarding exactly the
per-member policy that constructor exists to carry through.
parseGroup now takes no conf at all; newSpecifier is reached with a real
conf only from NewSpecifier, where the conf IS that specifier's own.
This is the same defect shape as the flat-bag bug in e93e425: state that
belongs to the member, taken over by the container. Audited every other
site and recorded the clean ones in member_policy_test.go -- cmpkey's
k.pre, normalizeLocal, filterGeneric's strs[i], every keep[i] mask write,
dedupeSpecifiers, orGroups, String/Len/List/Equal/PreReleases, and
marker.Environment.With. After this change exactly one line in non-test
code sets a member's policy from a conf.
FINDING 8 -- the zero-value Specifier was inconsistent. Contains("1.0")
was true via Check's nil guard while Contains("lolwat") was false, even
though NewSpecifiers("").Contains("lolwat") is true. Three spellings of
"no constraint" now agree. The guard is on the nil operator function, not
the empty operator string: a parsed bare version has an empty operator
and must keep constraining.
FINDING 2 -- And now deduplicates, and a false parity claim is removed.
The claim that len(SpecifierSet(">=1.0") & SpecifierSet(">=1.0")) == 2 is
deliberate upstream parity was wrong. It holds only on a fresh object:
len is 2, then str() is ">=1.0", then len is 1, because
_canonical_specs() dedupes lazily. So the 2 was a transient artifact of
upstream's caching -- the one thing this port declares non-portable --
and it made the count depend on call order. Dedupe is canonical, so
">=1.0.0" and ">=1" collapse while "~=1.18.0" and "~=1.18" do not.
Matching is unaffected; a conjunction is idempotent.
FINDING 5 -- TestContainsAgreesWithFilterOfOne was tautological.
Contains IS len(Filter([]{item})) > 0, so the test asserted an expression
against itself and could not fail for any input; its own comment conceded
they "can never disagree". Replaced with a 300-row table whose expected
values were measured against packaging 26.2 -- an oracle that is not the
implementation.
FINDING 3 -- three doc comments asserted ==1.0A1 behavior this package
cannot produce, because validConstraintRegexp lacks the (?i) flag and
rejects it at parse time. They described upstream in Go method doc
comments, where a reader takes them as this API's contract. All three
qualified, with the divergence and its issue named.
Every behavioral fix verified red-then-green: 10 test functions and 22
subtests fail on e93e425, including the real "slice bounds out of range
[:-1]" panic.
Refs rstudio/package-manager#19383
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Both figures in the previous entry were wrong, and both were the kind that get quoted into an RFD and into status reporting as fact. The denominator: tests/test_specifiers.py at 4eb0753 collects 2,031 test cases from 116 functions -- 1,985 from the 70 parametrized ones and 46 from the rest. Reconciled: 1,939 with VERSIONS unresolved, plus the 92 entries of VERSIONS imported from tests/test_version.py, is 2,031.⚠️ The previous "1,735 parametrized cases" is withdrawn. It came from a counter that only evaluated MODULE-level assignments, so every parametrize referring to TestIsUnsatisfiable's UNSATISFIABLE and SATISFIABLE ClassVars -- declared inside the class -- failed to evaluate and was silently counted as one case each. It also happened to equal the sum of three approximate buckets quoted beside it, which is exactly why an unreconciled number should not have been stated as exact.⚠️ The scope cut was understated ~10x. The four set-relation and unsatisfiability APIs are 259 cases, not "~25": TestIsUnsatisfiable alone is 222. TestSpecifierInternal is a further 18 and TestSpecifierSetToRangeEquivalence 290. The cut stands on its merits -- those APIs rest on packaging 26.2's interval machinery, which has no counterpart here -- but it is a large cut, not a rounding error. What was accurate is now stated as measured rather than as a total: 1,613 Go leaf subtests (1,649 with table parents), 358 of which failed against the pre-fix library. Refs rstudio/package-manager#19391 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…onformance Conflicts in version/specifier.go, both from parseGroup changing on both branches, resolved to keep BOTH intents: - parseGroup(vv, sanitizer, allowEmpty): #30's allowEmpty parameter AND #28's removal of the conf parameter. A member's pre-release policy is not the set's to stamp, and a comma-only group may only be universal when it is the entire input. - specifierCompatible keeps #30's versionJoin-based algorithm. #28's slice-bound guard is already present here and its comment is updated with what #28 established: the panic was reachable before versionSplit prepended the epoch, and the operand shapes that trigger it are the ones a hardening test stocked with "lolwat" never reaches. One conformance assertion updated: TestConformance_SetCombine expected And to keep duplicates. It now expects them to collapse, with the reason recorded -- upstream's len() of 2 is a pre-canonicalization artifact of a lazy cache, and str() is ">=1.0" under every ordering. The generator in the scratchpad was patched to match so a regeneration cannot reintroduce the old expectation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
My fix for finding 8 introduced a worse bug than the one it fixed, and it was the selection-versus-matching conflation for the third time in this change's history. The fix short-circuited Specifier.filterKeep on a nil operator function by filling the result with true and returning BEFORE the pre-release logic. Measured on 015553d: zero Specifier Filter(["1.0","1.1a1"]) Auto = [1.0 1.1a1] NewSpecifiers("") same = [1.0] zero Specifier same, WithPreReleases(Exclude) = [1.0 1.1a1] NewSpecifiers("") same = [1.0] So a zero-value Specifier offered a pre-release even though a final release was available -- the rule its own doc comment describes -- and an explicit PreReleasesExclude could no longer exclude anything. "Constrains nothing" is a statement about MATCHING: the operator admits every version. It is not a statement about SELECTION, which is a separate axis that still has to run. The nil operator function is now a flag consumed by the existing loop (via admitsUnparseable, and via Check's existing nil guard on the parseable path) rather than an early return that skips everything downstream. Fixed a fourth spelling in the same family while re-checking the others: allArbitraryMatch re-tested `op == "==="` inline instead of sharing the predicate, so NewSpecifiersFrom([]Specifier{{}}).Contains("lolwat") was false while Specifier{}.Contains("lolwat") was true. Two copies of one predicate is how they drifted; there is now a single admitsUnparseable used by both call sites. Added the companion test whose absence let this through: all four spellings of "constrains nothing" -- zero Specifier, zero Specifiers, NewSpecifiers(""), and a set holding a zero member -- are asserted to agree on Filter output with a pre-release present, with a lone pre-release, and under each explicit policy, as well as on Contains across eight input classes including three unparseable ones.⚠️ Note for the record: a parsed bare version (NewSpecifier("2.0")) is NOT a spelling of "constrains nothing". It is a real constraint equivalent to ==2.0, and TestZeroValueShortcutDoesNotSwallowRealSpecifiers pins that separately -- the zero-value shortcut keys on the nil operator FUNCTION, not the empty operator string, precisely so a bare version does not become a no-op. Red-then-green: 4 subtests fail on 015553d, reporting "zero Specifier must hold back the pre-release when a final release is available", "zero Specifier must honor PreReleasesExclude", and three "set with zero member must agree on Contains(...)" failures. The lone-pre-release subtest passes both ways and is a guard. Refs rstudio/package-manager#19383 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
NewSpecifier validated with validConstraintRegexp -- the SET grammar --
which tolerates a trailing comma deliberately. That leniency leaked into
the singular constructor: NewSpecifier(">=1,") was accepted and silently
yielded the single specifier ">=1", contradicting the function's own doc
comment ("A comma-separated set is not a single specifier") and the
inline rationale two lines below it.
Measured against packaging 26.2, which draws the line sharply:
Specifier(">=1,") -> InvalidSpecifier SpecifierSet(">=1,") -> len 1
Specifier(",>=1") -> InvalidSpecifier SpecifierSet(",>=1") -> len 1
Specifier(",") -> InvalidSpecifier SpecifierSet(",") -> len 0
So the doc comment was right and the code was wrong. NewSpecifier now
validates against a dedicated anchored single-constraint grammar, so the
strictness it promises is delivered on purpose rather than as a side
effect of which comma positions the set grammar happens to reject. Same
"one rule, one copy" lesson as admitsUnparseable, applied to grammars.
⚠️ Two corrections to the finding as reported.
First, only ">=1," was affected, not ",>=1". The set grammar's trailing
`,?` admits one trailing comma; a LEADING comma was never in that
pattern, so ",>=1" was already rejected by NewSpecifier.
Second, and more importantly, this is NOT a side effect of the comma
widening in #19391. Verified by running the same probe on this branch,
which does not contain that work: NewSpecifier(">=1,") was accepted here
too, identically. The defect originates where NewSpecifier was written --
borrowing the plural grammar -- so it belongs in this PR rather than the
one that widened the set. The diagnosis of the root cause was exactly
right; only the attribution and the affected-input set were narrower.
Blast radius: nothing real narrows. TestNewSpecifier_StillAcceptsEveryWell
FormedSingle pins 24 well-formed shapes including whitespace forms
(">= 1.0", ">= v1.0 ", leading/trailing tabs and newlines), bare
versions, epochs, locals, wildcards, arbitrary equality and pre/post/dev
operands. A trailing comma on a SINGLE specifier is not a real-world
shape -- it only arises from splitting a set, which goes through
NewSpecifiers.
Red-then-green: TestNewSpecifier_RejectsAnyComma fails on bcf0481 for
">=1," and ">=1 , ", and the set-contrast test fails there too because
the two constructors had not yet diverged.
Refs rstudio/package-manager#19383
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
🔴 Release-blocking. v0.4.0 answers ==X.*, !=X.* and ~= wrongly, and a repository server built on it SERVES versions pip EXCLUDES. F1 -- padVersion's two zero-padding loops were written `for i := 0; i < len(a)-len(b); i++` while appending to b INSIDE the loop, so the bound was re-evaluated each iteration and shrank as the slice grew. They appended ceil(d/2) zeros for a gap of d segments. ==2.0.0.* did not match 2; !=7.0.0.* DID match 7. F2 -- versionSplit did not prepend the epoch the way upstream's _version_split does, so "1!1.0" split to ["1!1","0"], the digit filter dropped "1!1" entirely, and the under-padding made the two sides coincidentally equal: ==0.0.0.* MATCHED 1!1.0. The retired go-pep440-version said false and packaging 26.2 says False, so this one was introduced by the earlier padVersion change rather than inherited. WHICH FIX IS LOAD-BEARING, measured rather than assumed: fixing the loop bound ALONE takes the 82-row oracle from 30 divergences to 7, and it removes every epoch false-positive -- so the under-padding, not the missing epoch prepend, was the proximate cause of the ==0.0.0.* match. The remaining 7 need the epoch prepend plus suffix-aware padding. Fixed by porting upstream's _version_split / _version_join / _is_not_suffix / _numeric_prefix_len / _left_pad directly, replacing padVersion and isDigist, and rewriting specifierEqual's wildcard branch and specifierCompatible's prefix derivation on top of them. That code already existed on the #19391 branch and is transplanted here verbatim so this PR is correct standalone -- whichever of the two merges first, main is right -- and so the forward-merge is trivial.⚠️ WHY THIS SURVIVED A REWRITE, A RELEASE AND A CHANGELOG CLAIM: ceil(1/2) == 1, so a gap of ONE segment is padded correctly by accident, and every pre-existing regression case here was a 1-segment gap. v0.4.0's changelog asserted the padding worked "as PEP 440 requires"; that held only for a 1-segment gap. The new table sweeps gaps of 1-4 in both directions, with zero and non-zero tails, pre-release segments and epochs, and every expected value comes from packaging 26.2. Measured on the RELEASED module rather than just the parent commit: v0.4.0 diverges on 30 of the 82 rows, identically to this branch before the fix. 0 after. Blast radius vs v0.4.0 over 28,529 distinct specifier tokens (production PyPI + real CRAN), 24-version panel: parse acceptance ... 0 newly accepted, 0 newly rejected match results ...... 2 tokens change, ==2.0.* and !=2.0.*, both on the version 2rc1, and both move TO packaging's answer (True / False); v0.4.0 had them backwards. Instrument validated: 7 of 8 synthetic multi-segment controls appended to the corpus flip. The 8th needs a panel version the panel lacks and is covered by the oracle instead. The small real count reflects that multi-segment wildcards barely occur in real data, NOT that the bug was harmless -- it is reachable from arbitrary client input. Also corrects a claim this changelog made: the "13 pairs where the old answer agreed with packaging" were described as a separate, pre-existing epoch divergence. They are neither. The old module was correct, the new one was wrong, and the cause was padVersion itself. Red-then-green: 30 of the 82 subtests fail on 244fc46.⚠️ Do NOT tag from this commit without an explicit decision: v0.4.0 is immutable and already consumed, so shipping this is a Breaking release. Refs rstudio/package-manager#19383, rstudio/package-manager#18634 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
They were described as a separate, pre-existing epoch divergence that the padVersion change neither caused nor fixed. Both halves were wrong: the retired module answered correctly on them, the change made them wrong, and the cause was padVersion itself. Corrected in place, pointing at the fix under [Unreleased]. Refs rstudio/package-manager#19391 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…onformance Brings in the v0.4.0 padding under-count and epoch regression fix. The specifier.go merge was clean: #28 now carries the same upstream _version_split / _left_pad port this branch already had, transplanted verbatim precisely so the two sides would be identical here. One CHANGELOG conflict, both branches having added to ### Breaking. Resolved by keeping BOTH entries with the padding one first, since a released module that serves versions pip excludes outranks a parse narrowing that measured 0 newly-rejected on real data. Conformance now 1,695 leaf subtests (1,613 + the 82-row padding/epoch oracle), 0 failing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reported as a bug: isNotSuffix omits "c", so ~=1.0c1 derives a narrower prefix than ~=1.0rc1 and the two spellings of one constraint disagree.⚠️ I did NOT fix it, because measuring says there is nothing to fix. packaging 26.2 gives the same asymmetry: SpecifierSet("~=1.0c1").contains("1.1") -> False SpecifierSet("~=1.0rc1").contains("1.1") -> True gpp's isNotSuffix is a byte-faithful port of upstream's _is_not_suffix, which also checks only ("dev","a","b","rc","post"). The asymmetry comes from a mismatch between two UPSTREAM tables: _prefix_regex includes "c" (so 0c1 splits into 0 + c1) while _is_not_suffix does not (so the resulting c1 counts as release, not suffix). "c" is the only alias in that gap -- alpha and beta are caught incidentally because the check is a PREFIX match and they begin with "a"/"b", while pre, preview, r and rev never match _prefix_regex and stay whole. Both proposed fixes were measured and both make conformance WORSE: - adding "c" to the suffix list moves ~=1.0c1 away from the reference; - normalizing the operand through the parser before deriving the prefix -- the structural fix, which specifierEqual legitimately uses -- turns 0 divergences into 6, additionally breaking ~=1.0.pre1, ~=1.0.preview1, ~=1.0.r1, ~=1.0.rev1 and ~=1.0.c1, because upstream derives the prefix from the RAW operand text and those forms do not match _prefix_regex un-normalized. I applied the structural fix experimentally and counted before reverting, rather than arguing from the code. So the deliverable is evidence and a guard rather than a behavior change: a 410-row sweep covering every PEP 440 pre/post alias (a, alpha, b, beta, c, rc, pre, preview, post, r, rev, dev) against every permitted separator ("", ".", "-", "_") for both ~= and wildcard equality, measured against packaging 26.2. 0 divergences on both heads.⚠️ Upstream's own test suite does not exercise "c" under ~=, so the ported conformance tables stay GREEN under the broken variant -- verified. That is why this sweep is separate from them: it is the only thing holding this behavior, and without it the next person to read PEP 440 will "fix" isNotSuffix and silently break six alias forms. isNotSuffix now carries a "DO NOT ADD C" note with the measurements, and a companion test pins both alias tables so the coupling is visible rather than discovered. Refs rstudio/package-manager#19383 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
#28 was merged to main as a SQUASH while this branch had already merged #28's branch, so the same work reached main by two routes and git had no common ancestor linking them. Five conflicts, all of that shape. Resolution: took THIS branch's side for all five, because this branch's content is main's content plus #30's own changes. Verified rather than assumed, three ways: - CHANGELOG.md diffs 198 insertions / 0 DELETIONS against main, which proves it contains every line main has; both sets of [Unreleased] entries survive, and the #28 landmarks (the DO-NOT-ADD-C note, the anchored single-constraint grammar, the 410-row sweep) are all still quoted in it. - `git diff origin/main -- version/specifier.go` shows ONLY #30's own changes: the [\s\v] whitespace class, the (?i) flags on validConstraintRegexp and singleConstraintRegexp, parseGroup's allowEmpty plus blank-comma-item dropping, and the >V post-release / local-version guards. No #28 content is re-added or reverted; the deletions are all lines #30 legitimately rewrites. - Every #28-derived file that #30 does not touch is byte-identical to main: alias_conformance_test.go, padding_conformance_test.go, member_policy_test.go, operand_hardening_test.go, prerelease_policy_test.go, specifier_query.go, prerelease.go, specifier_option.go, marker/environment.go and marker/partial_environment_test.go. And padVersion/isDigist -- the v0.4.0 bug -- are confirmed gone. Conformance is unchanged at 2,105 leaf subtests, 0 failing, which is the check that would have caught a bad resolution. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Closes rstudio/package-manager#19391.
What this is
The Phase 1.6 conformance port:
pypa/packaging'stests/test_specifiers.pyat4eb0753(release 26.2), plus the divergences it surfaced.2,105 leaf conformance subtests, 0 failing. Of the originally ported set, 358 failed against the pre-fix library.
The merge (please read this first)
#28 reached
mainas a squash, while this branch had already merged #28's branch. Same work, two routes, no common ancestor — so five files conflicted:CHANGELOG.md,version/specifier.go,version/version.go, and add/add onversion/or_group_structure_test.goandversion/specifier_api_test.go.I resolved all five to this branch's side, because this branch's content is
main's content plus this PR's own changes. That claim is verified three ways rather than assumed:CHANGELOG.mddiffs 198 insertions / 0 deletions againstmain— it therefore contains every linemainhas. Both sets of[Unreleased]entries survive, and Add the public specifier and marker API that PEP 440/508 conformance assertions need (rstudio/package-manager#19383) #28's landmarks are still quoted in it (the "DO NOT ADD C" note, the anchored single-constraint grammar, the 410-row sweep).git diff origin/main -- version/specifier.goshows only this PR's changes — the[\s\v]whitespace class, the(?i)flags onvalidConstraintRegexpandsingleConstraintRegexp,parseGroup'sallowEmptyplus blank-comma-item dropping, and the>Vpost-release / local-version guards. Nothing from Add the public specifier and marker API that PEP 440/508 conformance assertions need (rstudio/package-manager#19383) #28 is re-added or reverted; every deletion is a line this PR legitimately rewrites.main:alias_conformance_test.go,padding_conformance_test.go,member_policy_test.go,operand_hardening_test.go,prerelease_policy_test.go,specifier_query.go,prerelease.go,specifier_option.go,marker/environment.go,marker/partial_environment_test.go. AndpadVersion/isDigist— thev0.4.0bug — are confirmed gone.The conformance count is unchanged at 2,105 / 0 failing, which is the check a bad resolution would have broken.
What this PR changes on top of
mainSix divergences fixed, each measured against
packaging26.2:validConstraintRegexplacked(?i)==1.0A1rejected while==1.0a1parsed. 303 of the 358 failures.\sexcludes the vertical tab<= \r \f \v v1.0rejected;versionRegexhad been fixed, the specifier patterns had notvalidate()never guarded a wildcard against a pre-release==1.0a1.*wrongly accepted<Vand a pre-release of V1.0.dev0was excluded for the spec1.0.post1. Now bounded by_earliest_prerelease>Vand a post-release / local version of V_post_baseand the public version~=versionSplitdid not peel the epoch, so==0!2.*could not match2; padding ran between the two sides instead of up to the spec's width, so2did not match==2.0.0.*Plus blank comma items are now dropped rather than rejected (
",>=1",">=1,,<2", and","as the universal set), matching upstream's[s.strip() for s in specifiers.split(",") if s.strip()].||boundary, deliberately.SpecifierSet(",")is universal upstream andNewSpecifiers(",")is universal here, but">=1||,"is an error. Upstream has no||and so has no opinion; letting a comma-only segment become an empty AND-group would let a stray comma disable an entire constraint — the same failure mode a stray||opened.Blast radius
Everything measured on real corpora, with every null result positive-controlled:
>/<against a pre-release or post-release operand. Each was checked againstpackaging26.2 over a 19-version panel: 0 of 17 agreed with the reference before, 17 of 17 after.Counts, stated with a denominator
tests/test_specifiers.pyat4eb0753collects 2,031 test cases from 116 functions — 1,985 from the 70 parametrized ones, 46 from the rest. (Reconciliation: 1,939 withVERSIONSunresolved, plus its 92 entries fromtests/test_version.py.)parametrizereferring toTestIsUnsatisfiable'sUNSATISFIABLE/SATISFIABLEClassVars silently counted as 1 — exactly the missing 222. The real scope cut is 259 cases.Deliberately not ported
is_subset/is_superset/is_disjoint/TestIsUnsatisfiable(259 cases) rest on packaging 26.2's interval subsystem (_to_ranges,_intersect_ranges,_LowerBound/_UpperBound), which has no counterpart in this module. Also skipped: pickling,__match_args__,__hash__, the one-element caches, construction laziness, andto_rangeequivalence. Each reason is recorded in the relevant file header.Verification
build,vet,test -count=1,test -race -count=1from the module root underGOTOOLCHAIN=go1.25.0(CI's pinned version) and the local default 1.26 —-raceexit code 0, 12 packages ok.gofmt -l .clean under both toolchains.golangci-lintv2.11.2 from the module root with the exit code read:config verify0,run ./...0.Attribution for the ported tables and the ported matching helpers is in
NOTICE.🤖 Generated with Claude Code