Repository navigation
test(proptest): rapid property tests, and two divergences they found - #18
Merged
Merged
Conversation
…l tab
Two divergences from pypa/packaging, both found by the property tests added
in the following commit and both measured against the pinned upstream SHA
4eb0753dba8fcaaac8eb75463374e448f0931558 (26.3.dev0) read from source, not
against a pip-installed copy.
1. Local version labels did not normalize their separators.
PEP 440 requires "-" and "_" inside a local label to be rewritten as ".".
Parse only lowercased the label, so "1.0+abc-abc" stayed verbatim: String()
rendered the un-normalized form and it did not compare equal to
"1.0+abc.abc", which upstream reports as the same version.
This was not merely cosmetic. cmpkey splits the local label on "." to
compare it segment by segment, with numeric segments ordering above
alphabetic ones. An un-normalized "ubuntu-2" is therefore ONE alphabetic
segment, so comparison falls back to lexicographic ordering of the whole
label:
1.0+ubuntu.2 < 1.0+ubuntu.10 -> true (correct)
1.0+ubuntu-2 < 1.0+ubuntu-10 -> false (WRONG, upstream says true)
A silent wrong answer of the same kind as rstudio/package-manager#19369,
reachable through ordinary distro-patch labels like +ubuntu-1 and +deb-9.
2. The vertical tab was not accepted as surrounding whitespace.
The anchors used Go's \s, which is [\t\n\f\r ] and omits \v; Python's re \s
is [ \t\n\r\f\v] and includes it. Upstream accepts "1.0\v"; we rejected it.
Both fixes are proven by tests verified to fail without them INDIVIDUALLY:
reverting only the local fix fails the three local tests while the vertical
tab test still passes, and reverting only the whitespace fix fails only the
vertical tab test. The ordering cases are chosen to discriminate -- note
that "abc-1" vs "abc-2" passes either way, since lexicographic and numeric
ordering agree there.
Refs rstudio/package-manager#19393
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…-only
Adds internal/proptest/, adapting pypa/packaging's Hypothesis suite
(tests/property/) at pinned SHA 4eb0753dba8fcaaac8eb75463374e448f0931558 to
pgregory.net/rapid, plus the four properties specific to this module's own
API contracts. RFD 0001 names rapid as Layer 1 of the test strategy.
Structure: every file in internal/proptest is a _test.go file. The issue
proposed a non-test internal/pep440gen/gen.go to share generators, and
flagged that this puts MPL-2.0 rapid into a public library's non-test import
graph. A package of only _test.go files shares them just as well and keeps
rapid test-only, which is measurable and asserted in CLAUDE.md:
go list -deps ./... -> no rapid
go list -deps -test ./... -> rapid
Measured, contradicting the issue: the downstream half of that concern does
not exist. A consumer module importing only license/ neither records rapid
in go.mod after `go mod tidy` nor vendors it under `go mod vendor`, even
with a non-test file importing it, because of module graph pruning. So there
was no PPM vendoring or SBOM exposure either way; only this module's own
import graph was ever at stake.
Also measured, contradicting the issue: there is nothing to port for
@example. The issue budgeted "49 uses upstream", each becoming a table case.
The only Hypothesis @example decorators in the pinned tree are 15, all in
test_ranges_to_specifier_set.py -- an explicitly out-of-scope ranges file.
The rest of the "@example" string matches are @example.com addresses in
metadata fixtures. Zero table cases are owed.
Scope: upstream's suite is ~230 @given functions, most asserting the shape
of parsed fields (.epoch, .release, .pre, .major, hash()). This module
exports no such accessors, and in Go the field types make most of those
assertions statically true. The portable subset is the observable behavior --
ordering, normalization, round-tripping, specifier matching -- which is also
what a resolver depends on. tests/property/test_ranges_*.py are not ported;
they belong to go-pubgrub's versionset.
The suite was mutation tested rather than assumed effective, which produced
two findings recorded in the package doc:
- Dropping the trailing-zero Normalize() in cmpkey survived every property
until TestExactMatchIsZeroPaddingSymmetric was added. Version.Equal pads
independently, so only specifier matching observes that normalization.
A real gap in the port, now closed.
- Reverting Requirement.String()'s conditional marker separator survives
ALL of these properties, because a round-trip property is invariant to a
change of canonical form. Only requirement/conformance_test.go catches
it. The properties and the conformance tables are therefore both
load-bearing; deleting either lets real regressions through.
Traps honored: the random seed is kept (rapid.Check takes no seed option, and
a fixed seed is just a slow table test); every Draw is named; no property
filters hard enough to need assume() semantics, since rapid errors out rather
than skipping when too few examples are valid; versions are only ever built
through Parse, because Version{} has no exported constructor and Version{}
.String() panics; Requirements are only built through Parse, because a
hand-built value with both URL and Specifiers set silently drops the
Specifiers; and equivalence is asserted via String() rather than
reflect.DeepEqual, which always reports specifiers unequal because the
operator is a func field (version/specifier.go:100, not :67 as the issue
says).
Verified: 14/14 packages pass, -race clean, 10,000 checks per property pass
in 7s, gofmt silent, and golangci-lint v2.11.2 reports 0 issues from the
module root -- confirmed to be actually scanning by planting a violation,
since a path outside the module prints a reassuring "0 issues" having
scanned nothing.
testdata/rapid/ is gitignored; rapid writes failfiles into the package dir.
NOTICE records the upstream attribution and rapid's MPL-2.0 test-only status.
Refs rstudio/package-manager#19393
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jonyoder
force-pushed
the
rapid-props-19393
branch
from
August 3, 2026 16:16
1b320a1 to
13c4556
Compare
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
Adds
internal/proptest/— property-based tests adapted frompypa/packaging's Hypothesis suite (tests/property/) at pinned SHA4eb0753dba8fcaaac8eb75463374e448f0931558, plus the four properties specific to this module's own API contracts. RFD 0001 §14 namesrapidas Layer 1 of the test strategy.Tracked as rstudio/package-manager#19393.
The tests found two real defects, fixed in the first commit.
The defects
1. Local version labels did not normalize their separators. PEP 440 requires
-and_inside a local label to be rewritten as..Parseonly lowercased, so1.0+abc-abcstayed verbatim and did not compare equal to1.0+abc.abc.This is not cosmetic.
cmpkeysplits the label on.to compare it segment by segment, with numeric segments ordering above alphabetic ones — so an un-normalizedubuntu-2is one alphabetic segment and comparison falls back to lexicographic:A silent wrong answer of the same class as rstudio/package-manager#19369, reachable through ordinary distro-patch labels (
+ubuntu-1,+deb-9).2. The vertical tab was not accepted as surrounding whitespace. The anchors used Go's
\s=[\t\n\f\r ], which omits\v; Python'sre\s=[ \t\n\r\f\v]includes it. Upstream accepts"1.0\v".Both measured against the pinned SHA read from source (reporting
26.3.dev0), not apip install packaging— the released 26.2 differs from the pinned tree in unrelated ways.Both are proven by tests verified to fail without them individually: reverting only the local fix fails the three local tests while the vertical-tab test still passes, and vice versa. The ordering cases are chosen to discriminate —
abc-1vsabc-2passes either way, since lexicographic and numeric ordering agree there.Structure: why every file here is a
_test.gofileThe issue proposed a non-test
internal/pep440gen/gen.goto share generators, and correctly flagged that this puts MPL-2.0rapidinto a public dual-Apache-2.0-OR-MIT library's non-test import graph. A package containing only_test.gofiles shares generators just as well and keepsrapidtest-only. Measured:rapidin non-test graphgo.mod/vendor/gen.go_test.go(this PR)Correcting the issue: the downstream half of that concern does not exist. I built a consumer module importing only
license/with a non-test file importing rapid —go mod tidydid not add rapid andgo mod vendordid not vendor it, because of module graph pruning. There was never PPM vendoring or SBOM exposure either way; only this module's own import graph was at stake. The invariant is now asserted inCLAUDE.md.Also correcting the issue: there is nothing to port for
@example. The issue budgeted "49 uses upstream", each becoming a table case. The only Hypothesis@exampledecorators in the pinned tree are 15, all intest_ranges_to_specifier_set.py— an explicitly out-of-scope ranges file. The remaining"@example"string matches are@example.comaddresses in metadata fixtures. Zero table cases are owed.Scope, honestly
Upstream's suite is ~230
@givenfunctions. Most assert the shape of parsed fields (.epoch,.release,.pre,.major,hash()); this module exports no such accessors, and in Go the field types make most of those assertions statically true. The portable subset is observable behavior — ordering, normalization, round-tripping, specifier matching — which is also what a resolver depends on.tests/property/test_ranges_*.pyare not ported: nopackaging.rangescounterpart exists here, and they belong togo-pubgrub'sversionset. Per the note on rstudio/package-manager#18653,test_ranges_pubgrub.pywas not read at all.Mutation tested, not assumed effective
Two findings, both recorded in the package doc:
Normalize()incmpkeysurvived every property untilTestExactMatchIsZeroPaddingSymmetricwas added —Version.Equalpads independently, so only specifier matching observes that normalization. I had not ported upstream'stest_zero_padding_matches/test_zero_padding_symmetric.Requirement.String()'s conditional marker separator survives all of them, because a round-trip property is invariant to a change of canonical form — it detects non-idempotence, never "the canonical form moved". Onlyrequirement/conformance_test.gocatches it. Both layers are load-bearing; deleting either lets real regressions through.Traps honored
Random seed kept (
rapid.Checktakes no seed option, and a fixed seed is just a slow table test); everyDrawnamed; nothing filters hard enough to needassume()semantics, since rapid errors rather than skipping when too few examples are valid; versions built only throughParse, sinceVersion{}.String()panics;Requirements built only throughParse, since a hand-built value with bothURLandSpecifierssilently drops the Specifiers; equivalence asserted viaString()rather thanreflect.DeepEqual, which always reports specifiers unequal because the operator is a func field — atversion/specifier.go:100, not:67as the issue states.My generator initially emitted
"; "after a URL and was rejected, which independently re-derived #16's asymmetric-separator rule.Testing
-raceclean.gofmt -l .silent;golangci-lint run ./...at CI's pinned v2.11.2 → 0 issues from the module root — confirmed to be actually scanning by planting anineffassignviolation and seeing it reported, since a path outside the module prints a reassuring0 issues.having scanned nothing.testdata/rapid/gitignored (rapid writes failfiles into the package dir).NOTICErecords upstream attribution and rapid's MPL-2.0 test-only status.Compatibility
The local-label fix changes
String()output, equality, and ordering.CHANGELOG.mdentries are on thechangelog-19403branch (#17) under the0.2.0Breaking heading, so both land before the tag rather than forcing consumers through two breaking bumps.🤖 Generated with Claude Code