Skip to content

Port test_specifiers.py conformance tables and fix the six divergences they surface (rstudio/package-manager#19391) - #30

Closed
jonyoder wants to merge 10 commits into
feat/19383-conformance-apifrom
feat/19391-specifier-conformance
Closed

jonyoder wants to merge 10 commits into
feat/19383-conformance-apifrom
feat/19391-specifier-conformance

Conversation

@jonyoder

Copy link
Copy Markdown
Collaborator

Closes rstudio/package-manager#19391.

⚠️ Stacked on #28 (rstudio/package-manager#19383). Base is feat/19383-conformance-api, not main — the tables cannot be driven without that PR's API. Review #28 first; this diff is only what sits on top.

Headline

1,649 assertions ported from pypa/packaging's tests/test_specifiers.py @ 4eb0753. 358 of them failed against the library as it stood. All pass now.

The 358 is the real finding: #19391 predicted 7 wrongly-accepted invalid specifiers plus 3 named divergences. The tables found six distinct root causes, four of them in matching rather than parsing — a class the issue did not anticipate at all.

Both files cross-check every expectation against two independent sources: the literal in the pinned upstream file, and what the installed packaging 26.2 actually answers for the same input. A disagreement would mean a stale literal getting baked in; the generator fails loudly on one. All 1,649 agreed.

What was wrong

Parsing (3 causes, 305 of the 358 failures)

validConstraintRegexp lacked the (?i) flag specifierRegexp has ==1.0a1 parsed, ==1.0A1 was rejected before the parser saw it. 303 failures.
Go's \s excludes the vertical tab (0x0B), Python's includes it <= \r \f \v v1.0 was rejected. versionRegex had already been fixed for this; the two specifier patterns had not.
validate() guarded a wildcard against dev, post and local but never against a pre-release ==1.0a1.* and !=2.0rc1.* were wrongly accepted.

Matching (3 causes, 53 failures) — not anticipated by the issue

All four rules below were implemented as base-version comparisons standing in for what PEP 440 actually states. Base version discards pre/post/dev, so each guard fired far too broadly:

  • <V and a pre-release of V. For the spec 1.0.post1 it excluded 1.0.dev0 — which is a pre-release of 1.0, not of 1.0.post1. Now bounded by upstream's _earliest_prerelease.
  • >V and a post-release of V. The mirror error: for the spec 1.0a1 it excluded 1.0.post0. Now uses _post_base.
  • >V and a local version of V. "A local version of V" is one whose public part equals V, pre/post/dev included. Comparing base versions made >1.0a1 wrongly reject 1.0a2+local.
  • Prefix matching and ~=. versionSplit did not peel the epoch off as its own component, so ==0!2.* could not match 2. Padding ran between the two sides rather than up to the spec's numeric width, so 2 did not match ==2.0.0.*. And ~= derived its prefix by breaking only on post/dev, so a pre-release operand (~=1.0a1) produced the wrong prefix. Upstream's _version_split, _version_join, _is_not_suffix, _numeric_prefix_len and _left_pad are now ported directly, replacing padVersion.

Blast radius, measured

Extracted 25,457 distinct specifier tokens from the production PyPI snapshot (932,861 packages) and ran a real before/after differential — the pre-change tree is #28's HEAD, so this isolates this PR's changes.

Python path R path (NewRSpecifiers)
newly rejected (the risky direction) 0 0
newly accepted 874 874
match-result changes 12 —
rendered-form changes 0 0

Plus 59,139 constraint occurrences from a real CRAN PACKAGES file for the R path: 0 newly rejected.

The null results are instrumented, per the "prove the instrument works" rule:

  1. The extraction pattern was given a positive control and found exactly the four synthetic pre-release-wildcard shapes and none of the seven other lines.
  2. The differential harness was given a positive control: appending ==1.0a1.*, !=2.0rc1.*, ==1.0alpha3.* to the corpus makes it report three accept→reject flips, and appending >1.0a1, <1.0.post1, ~=1.0a1, ~=2022.01.01, ==0!2.* makes it report five match-result changes. So "0 newly rejected on real data" reflects the data, not an inert change.

The 12 match-result changes were checked for direction, not just presence. Each was evaluated against packaging 26.2 over a 19-version panel spanning final/pre/post/dev/local/epoch shapes:

agreed with the reference BEFORE: 0/17
agreed with the reference AFTER:  17/17

(12 real corpus tokens + 5 synthetic controls.) So these are conformance fixes, not behavior drift.

Wrong existing assertions

#19391 asks for these to be found and deleted. The two it named were already gone at 0.3.x, so I audited the whole hand-written table instead: all 163 rows of TestVersion_Check were checked against packaging 26.2.

No row disagrees with the reference where both implementations parse the input. The only 17 flagged rows are this package's four documented deliberate extensions — a bare version (rstudio/package-manager#18634), the = operator, * for "any", and || for the R path.

padVersion and its regression test are removed. The replacement test explains why: leftPad pads one side from one input with a single slice, so the "sliced left twice" bug the old test guarded is structurally impossible — what still has to hold, and is now asserted, is that the 0 padding lands after the numeric prefix and before the suffix.

Deliberate scope cuts

Recorded in each file's header so review does not have to guess:

  • is_subset / is_superset / is_disjoint / TestIsUnsatisfiable rest on packaging 26.2's interval subsystem (_to_ranges, _intersect_ranges, _LowerBound/_UpperBound). That is its own design exercise; out of scope for both issues.
  • test_pickle_* — Go has no pickle.
  • __match_args__, __hash__, TestSpecifierInternal.*, *_construction_is_lazy, TestSpecifierSetToRangeEquivalence.* — Python-implementation internals with no exported Go surface.
  • The bare-version case ("2.0" in test_specifiers_invalid) is commented out with a pointer, not silently dropped, and has its own test pinning the divergence in both directions.
  • Specifiers.String() still does not sort its members where upstream does; annotated at TestConformance_SetCombine, which asserts membership instead of rendering.

One thing I got wrong, and what it taught

My own extra cross-check ("a per-call policy must agree with a rebuilt set") failed on two rows. The code was right and my assertion was wrong: a per-call PreReleasesAuto is upstream's contains(item, prereleases=None) — "no opinion, defer to the set" — not upstream's spec.prereleases = None, which resets the set's own policy. Only the second can undo an explicit constructor policy. The assertion is now gated to explicit policies, with that distinction spelled out.

Verification

  • go build, go vet, go test -count=1 ./..., go test -race -count=1 ./... — all pass, from the module root, under GOTOOLCHAIN=go1.25.0 (CI's pinned version) and the local default 1.26.
  • gofmt -l . clean under both Go 1.25's gofmt (what the CI Format check runs) and the local default.
  • golangci-lint config verify + golangci-lint run ./... at CI's pinned v2.11.2, from the module root — 0 issues.
  • pgregory.net/rapid still absent from the non-test import graph.
  • No regressions: requirement/, reqtxt/, internal/pep508/, internal/proptest/, marker/ all pass unchanged.

Attribution for both the ported tables and the ported matching helpers is in NOTICE.

🤖 Generated with Claude Code

jonyoder and others added 2 commits August 10, 2026 11:42
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>
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>
@jonyoder

Copy link
Copy Markdown
Collaborator Author

Comma tolerance fixed, plus two undocumented changes recorded — cccc59a

1. The last listed #19391 divergence: blank comma items

Blank comma-separated items are now dropped rather than rejected, which is upstream's rule — SpecifierSet.__init__ does [s.strip() for s in specifiers.split(",") if s.strip()]. The newly-valid forms are in the valid table with the upstream citation and pinned SHA.

I checked where upstream actually lands rather than inferring it, because the widening is only safe if it lands in the same place. Measured against packaging 26.2:

input upstream now here
",>=1" / ",,>=1" accept, len 1 accept, len 1
">=1,,<2" / ">=1,,,<2" / ">=1 , , <2" accept, len 2 accept, len 2
">=1," accept, len 1 accept (already did)
"," / ",," / " , " / " , , " accept, len 0 — universal accept, universal
">=1<2" / ">=1 <2" InvalidSpecifier error

⚠️ The trap this contained

SpecifierSet(",") is the universal set upstream. Composed naively with the OR splitting, that reopens the HIGH finding from #28 through a different door: ">=1||," would have a comma-only segment → empty AND-group → matches everything → the >=1 is disabled.

So there is exactly one place this deliberately stops short of upstream: a specifier-less group is universal only when it is the entire input. NewSpecifiers(",") is universal; ">=1||," is an error. Upstream has no || and so has no opinion, and "a stray comma disables the constraint" is indefensible regardless.

The other safety property is preserved by construction: only blank items are dropped, and what survives is re-joined with commas and revalidated — so ">=1<2", ">=1 <2" and ",,>=1 <2,," all stay errors. The comma between two constraints is still required (0.4.0's fix).

The || control test is rewritten around this interaction rather than around the old rejected-comma behavior, so it still isolates the two concerns — it now asserts commas are tolerated within a group, comma-only input is universal, and comma-only segments are errors.

Blast radius

Corpus: 25,455 distinct PyPI specifier tokens + real CRAN constraints = 28,528 distinct inputs, run through both entry points before and after.

Python path R path
newly rejected 0 0
newly accepted 0 0
match-result changes 0 —
rendered-form changes 0 —

0 newly accepted on real data, because no real PyPI or CRAN constraint has a leading or doubled comma — a pure conformance fix with no observable effect on real input.

Instrument positive-controlled, so that double-null means something: the six synthetic comma shapes all flip reject -> accept on both paths, while ">=1<2" stays rejected and ">=1||," stays rejected.

input            python before->after   R before->after
,                reject -> accept       reject -> accept
,,               reject -> accept       reject -> accept
,,>=1            reject -> accept       reject -> accept
,>=1             reject -> accept       reject -> accept
>=1 , , <2       reject -> accept       reject -> accept
>=1,,<2          reject -> accept       reject -> accept
>=1<2            reject -> reject       reject -> reject
>=1||,           reject -> reject       reject -> reject

2. Two changes that shipped with no changelog entry

Both verified before recording — git tag --contains d097655 starts at v0.1.0, and CHANGELOG.md has never mentioned either. The commit message documents both; the changelog does not.

Recorded under ## [Unreleased] in a labelled "Previously undocumented, shipped in 0.1.0" subsection that names the release they actually shipped in and says they are recorded late. The tagged [0.1.0] section is untouched — backdating into a published, proxy-served section is the failure mode this project has already hit twice.

  • padVersion sliced the left-hand version for the right-hand remainder. Affects every ==X.*, !=X.* and ~= with differently-sized release segments, on both paths. 349 of 135,204 specifier sets flip; of 928 flipped pairs packaging 26.2 agrees with the new behavior 915 times vs the old 13 (those 13 being a separate pre-existing epoch divergence) — a real bug fix, shipped silently.
  • NewRSpecifiers discarded its sanitizer. 0 differences over real CRAN (2,814 constraints), 1,447 of 135,204 adversarially. ⚠️ Invisible in String(), which renders pre-sanitize text — so the natural way a consumer would check for it does not work.

Also added the requested note: this module has demonstrably shipped unrecorded semantic changes, so anyone assessing an upgrade should diff behavior on their own inputs rather than read this file — which is precisely how these two were found (rstudio/package-manager#18634 diffed the modules on identical input).

Verification

1,613 conformance assertions still pass, 0 failing. build/vet/test/test -race under GOTOOLCHAIN=go1.25.0 and local 1.26; gofmt -l . clean under both toolchains; golangci-lint v2.11.2 from the module root — 0 issues.

Per-job CI:

Not merged.

jonyoder and others added 7 commits August 10, 2026 13:20
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>
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>
@jonyoder
jonyoder deleted the branch feat/19383-conformance-api August 10, 2026 18:16
@jonyoder jonyoder closed this Aug 10, 2026
jonyoder added a commit that referenced this pull request Aug 10, 2026
#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant