Skip to content

test(proptest): rapid property tests, and two divergences they found - #18

Merged
jonyoder merged 2 commits into
mainfrom
rapid-props-19393
Aug 3, 2026
Merged

jonyoder merged 2 commits into
mainfrom
rapid-props-19393

Conversation

@jonyoder

@jonyoder jonyoder commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

What

Adds internal/proptest/ — property-based tests adapted from pypa/packaging's Hypothesis suite (tests/property/) at pinned SHA 4eb0753dba8fcaaac8eb75463374e448f0931558, plus the four properties specific to this module's own API contracts. RFD 0001 §14 names rapid as 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 .. Parse only lowercased, so 1.0+abc-abc stayed verbatim and did not compare equal to 1.0+abc.abc.

This is not cosmetic. cmpkey splits the label on . to compare it segment by segment, with numeric segments ordering above alphabetic ones — so an un-normalized ubuntu-2 is one alphabetic segment and comparison falls back to lexicographic:

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 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's re \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 a pip 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-1 vs abc-2 passes either way, since lexicographic and numeric ordering agree there.

Structure: why every file here is a _test.go file

The issue proposed a non-test internal/pep440gen/gen.go to share generators, and correctly flagged that this puts MPL-2.0 rapid into a public dual-Apache-2.0-OR-MIT library's non-test import graph. A package containing only _test.go files shares generators just as well and keeps rapid test-only. Measured:

Structure rapid in non-test graph in a consumer's go.mod / vendor/
non-test gen.go yes no
all-_test.go (this PR) no no

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 tidy did not add rapid and go mod vendor did 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 in CLAUDE.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 @example decorators in the pinned tree are 15, all in test_ranges_to_specifier_set.py — an explicitly out-of-scope ranges file. The remaining "@example" string matches are @example.com addresses in metadata fixtures. Zero table cases are owed.

Scope, honestly

Upstream's suite is ~230 @given functions. 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_*.py are not ported: no packaging.ranges counterpart exists here, and they belong to go-pubgrub's versionset. Per the note on rstudio/package-manager#18653, test_ranges_pubgrub.py was not read at all.

Mutation tested, not assumed effective

Two findings, both recorded in the package doc:

  • A real gap in my port. 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. I had not ported upstream's test_zero_padding_matches/test_zero_padding_symmetric.
  • These properties do not subsume the conformance tables. Reverting 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". Only requirement/conformance_test.go catches it. Both layers are load-bearing; deleting either lets real regressions through.

Traps honored

Random seed kept (rapid.Check takes no seed option, and a fixed seed is just a slow table test); every Draw named; nothing filters hard enough to need assume() semantics, since rapid errors rather than skipping when too few examples are valid; versions built only through Parse, since Version{}.String() panics; Requirements built only through Parse, since a hand-built value with both URL and Specifiers silently drops the Specifiers; equivalence asserted via String() rather than reflect.DeepEqual, which always reports specifiers unequal because the operator is a func field — at version/specifier.go:100, not :67 as the issue states.

My generator initially emitted "; " after a URL and was rejected, which independently re-derived #16's asymmetric-separator rule.

Testing

  • 14/14 packages pass; -race clean.
  • 10,000 checks per property pass in 7s.
  • 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 an ineffassign violation and seeing it reported, since a path outside the module prints a reassuring 0 issues. having scanned nothing.
  • testdata/rapid/ gitignored (rapid writes failfiles into the package dir).
  • NOTICE records upstream attribution and rapid's MPL-2.0 test-only status.

Compatibility

The local-label fix changes String() output, equality, and ordering. CHANGELOG.md entries are on the changelog-19403 branch (#17) under the 0.2.0 Breaking heading, so both land before the tag rather than forcing consumers through two breaking bumps.

🤖 Generated with Claude Code

jonyoder and others added 2 commits August 3, 2026 12:14
…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
jonyoder force-pushed the rapid-props-19393 branch from 1b320a1 to 13c4556 Compare August 3, 2026 16:16
@jonyoder
jonyoder merged commit 3dfc5dc into main Aug 3, 2026
2 checks passed
@jonyoder
jonyoder deleted the rapid-props-19393 branch August 27, 2026 14:38
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