Repository navigation
Port test_requirements.py conformance tables and fix the divergences they reveal (Phase 1 exit gate) - #16
Merged
Conversation
…st-first order Go's regexp is leftmost-first, not leftmost-longest, so an alternative that is a prefix of a later one wins. init() built the alternation by ranging a Go map, randomizing the compiled pattern per process. Results are stable today only because the trailing PEP-440-shaped version group forces backtracking -- a constraint that relaxing the === operand pattern removes. Also adds the invariant that generalizes rstudio/package-manager#19369: a specifier string must never yield more specifiers than it has operators. Refs rstudio/package-manager#18640 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ost-releases
Two divergences from pypa/packaging 26.2, both reached through
requirement.Parse:
===arbitrarystring was rejected; PEP 440 arbitrary equality takes any
single token. 576 of the 5,184 gate cross-product
cases failed on this.
==1.2.3.post4.* was accepted; a .* prefix match may not combine with
a dev, post, OR local release. validate() checked
only dev and local.
Arbitrary equality takes ONE token, not any string: '=== lolwat' is valid
and normalizes to '===lolwat', while '===any string here' is rejected by
both implementations.
Also deletes two assertions that enshrined the wrong behavior
(specifier_test.go asserted ==2.0.post1.* is valid) and replaces the two
stale commented-out ===lolwat TODOs with live cases.
Refs rstudio/package-manager#18640
… quoted strings
Three divergences from pypa/packaging 26.2, 8 of the 11 error cases in
tests/test_requirements.py:
name() was rejected; an empty parenthesized group is
legal and means no constraint
(test_empty_specifier).
name>=1\n (and \r, \r\n, were accepted; upstream rejects a trailing line
and the same after a break. Whitespace consumption now covers
marker) horizontal whitespace only, so the existing
end-of-input check fires.
name; os_name == "C:\" was accepted; the closing quote is escaped, so
the string is unterminated. PEP 508 marker
strings have no escape sequences, so a
backslash is rejected outright.
A trailing space or tab remains legal (test_trailing_horizontal_whitespace).
Refs rstudio/package-manager#18640
…d ones
The prior fix rejected ALL backslashes in quoted strings, based on the
premise that "PEP 508 marker strings have no escape sequences." That
premise was wrong.
Upstream pypa/packaging (pinned SHA 4eb0753dba) tokenizes permissively
(QUOTED_STRING = '[^']*'|"[^"]*", no backslash exclusion) then calls
ast.literal_eval on the token, which decodes Python string-literal
escapes (\n, \\, \x41, etc.) and rejects only INVALID ones.
Measured boundary (verified at pinned SHA):
"C:\\U" (doubled backslash) -> ACCEPT, value = C:\U
"\n", "\t", "\r", "\x41" -> ACCEPT, decoded
"C:\" (trailing unpaired) -> REJECT "Invalid quoted string"
"\x" (truncated \x) -> REJECT "Invalid quoted string"
This fix:
1. Reverts tokenizer QuotedString pattern to upstream's exact form
(allowing backslashes to tokenize normally)
2. Adds targeted validation in marker.go parseMarkerVar (where the
Literal is produced) to reject the two specific malformed cases
upstream asserts: trailing unpaired backslash, and truncated \x
3. Updates test to accept "C:\\U" and "\n", while still rejecting
"C:\" and "\x"
4. Fixes wrong comment claiming packaging "takes token.text[1:-1]
directly" — it calls ast.literal_eval
We deliberately do NOT implement full escape decoding (out of scope).
The validation is surgical: only the two asserted cases.
All tests pass, including -race. Lint clean. Rejections verified to
fail without the validation logic (stash test).
Refs rstudio/package-manager#18640
…marker separator
Clears RFD 0001 Phase 1's exit criterion ("pypa/packaging req tests pass").
The separator: Requirement.String() emitted " ; " unconditionally, but
pypa/packaging renders "; " when there is no URL and " ; " when there is
(a bare ";" after a URL would be ambiguous, since a URL may contain ";").
1,512 of the 5,184 cross-product cases failed on this; the URL form was
already correct.
The table: upstream's 5-decorator cross-product is 5,184 cases. A curated
51-case subset was measured to give byte-identical statement coverage
(168/168 blocks, 38.6%); whitespace contributes zero blocks. The curation
rule is recorded in-file so it stays reproducible.
One case is deliberately skipped -- the operator-less specifier "2.0" --
with a pointer to rstudio/package-manager#18634, whose acceptance criteria
require re-enabling it.
Refs rstudio/package-manager#18640
The final whole-branch review caught a REGRESSION introduced earlier on this
branch: validateQuotedStringContents did two independent byte scans (trailing-
backslash parity, then a search for `\x`). The second scan had no way to know
which backslashes an earlier escape had already consumed, so an interior `\\`
pair followed by "x" read as a truncated \x escape.
Measured against packaging 26.2 -- all three were ACCEPTED at v0.1.2 and
rejected by the pre-fix branch:
"C:\\xyz" ACCEPT was: reject
"a\\x" ACCEPT was: reject
"\\x" ACCEPT was: reject
Fix: one left-to-right walk that consumes each escape as a unit. The two
malformed cases upstream asserts still reject ("C:\" trailing unpaired, "\x"
truncated). Verified 7/7 against the reference, and the new cases fail without
the fix.
Also, since the branch's own test could not catch this (its accept cases put no
"x" after a pair), it now includes bodies that do.
Two protective comment fixes: tokenizer.go and marker.go both still asserted
"PEP 508 quoted strings have no escape syntax" -- the premise 22379d8 disproved,
and the one a maintainer would cite when deleting this validation.
And the cross-product's marker assertion now compares CONTENT via a parsed
round-trip, as the file header already promised, instead of only IsEmpty().
Refs rstudio/package-manager#18640
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 3, 2026
jonyoder
added a commit
that referenced
this pull request
Aug 3, 2026
* docs: add CHANGELOG for the 0.2.0 conformance release (rstudio/package-manager#19403) This module is public and at v0.1.2 with no changelog of any kind, and the next release both narrows what parses and changes Requirement.String() output. A consumer had no way to learn any of that. Adds CHANGELOG.md in Keep-a-Changelog form with a 0.2.0 section listing the five narrowing changes and the one output-format change from rstudio/package-manager#18640 under an explicit Breaking heading, plus a Notes section recording the two deliberate scope limits and the upstream version skew (packaging 26.2 accepts a trailing newline; the pinned SHA does not). Backfills v0.1.0 through v0.1.2 from git history. Note that v0.1.1 is the license/ SPDX and GPL/LGPL classifier fix; issue #19403's body attributed "NewRSpecifiers honors its sanitizer" to it, but that is the OTHER module's (rstudio/go-pep440-version) v0.1.1 -- the two happen to share a version number. Records the versioning rule in CLAUDE.md so it survives: while major is 0, breaking changes take a MINOR bump, never a patch, because a consumer pinning ^0.1 would otherwise pick up a narrowing change silently. Also removes .superpowers/sdd/2026-08-01-18640-plan/task-3-report.md, 275 lines of internal working notes that landed in this public repo with #16, and gitignores the directory. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * docs: record the local-label and vertical-tab changes in 0.2.0 Two further divergences from pypa/packaging were found by the property tests added for rstudio/package-manager#19393 and are fixed in the same release, so they belong in the same section rather than a second breaking bump days later. The local-label separator change is the one that needs the Breaking heading: it alters String() output, equality, AND ordering. A dash- or underscore-separated label was compared as a single alphabetic segment, so 1.0+ubuntu-2 sorted above 1.0+ubuntu-10. Refs rstudio/package-manager#19403 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <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.
What
Ports
pypa/packaging'stests/test_requirements.pyand fixes the divergences it reveals, satisfying RFD 0001 Phase 1's exit criterion — verbatim, "pypa/packaging req tests pass".Tracked as rstudio/package-manager#18640.
Why it was needed
Phase 1's implementation issues were all closed, but nothing established the gate:
internal/pep508/{requirement,marker,tokenizer}_test.go(845 lines) were hand-written with zero upstream citation, and PEP 508 is the RFD's dominant risk gate. Two silent wrong answers had already escaped to production while that was the state (#19369, shipped; #19366, open).The measured gate failures
Against
packagingat the pinned SHA4eb0753, the 5,184-case cross-product had exactly two failure categories:===arbitrarystringrejected" ; "unconditionally; upstream uses"; "when there is no URLPlus 11 of 42 error cases wrong, split
version/3 /internal/pep5088.Commits
21f25f5regexpis leftmost-first, andinit()was ranging a Go map — randomizing the compiled pattern per process. Prerequisite, because the next commit removes the trailing version group that currently forces backtracking to the right operator. Adds the invariant that generalizes #19369: a specifier string must never yield more specifiers than it has operators.cc6b7c6version/:===accepts an arbitrary single token (=== lolwatvalid;===any string herecorrectly rejected, matching upstream). A.*prefix match on a post-release is now rejected —validate()checked only dev and local.374af55internal/pep508/:name()is valid (empty parens mean no constraint); trailing\n/\r/\r\nrejected; quoted-string handling changed.22379d8'[^']*'and validate contents at the marker-literal site instead — mirroring upstream's tokenize-then-validate structure.a1d3b09requirement/: the ported conformance tables + the conditional marker separator.9d9ae0e\\xis a pair, not a truncated\x.Two things worth a reviewer's attention
The line-break change matches upstream's current source, not the released 26.2. Installed
packaging26.2 accepts"name>=1\n"; the pinned SHA rejects it. Upstream fixed this between the two by changing_tokenizer.py'sENDrule fromre.compile(r"$")(Python's$matches before a trailing newline) tore.compile(r"\Z"). ItsWSrule is[ \t]+in both. OurWS: \A[ \t]+is byte-identical, and Go's$without(?m)already means end-of-text. So a reviewer comparing against apip install packagingwill see a discrepancy that is upstream's, not ours.9d9ae0efixes a regression this branch introduced. An earlier commit validated quoted strings with two independent byte scans, so an interior\\pair followed byxwas misread as a truncated\x."C:\\xyz","a\\x"and"\\x"were all accepted at v0.1.2 and wrongly rejected. Now a single left-to-right walk consumes each escape as a unit, and the regression cases put a\\pair immediately before anx— which the prior test could not do.Deliberate scope limits
ast.literal_eval; we validate only the two malformed cases its tests assert (trailing unpaired backslash, truncated\x) and do not decode escapes. Follow-up filed."2.0"is left accepted, with a commented-out conformance case pointing at rstudio/package-manager#18634 — tightening it is behavior-narrowing and blocked on a PPM-side refactor.==/!=are accepted, matching upstream, which rejects them only for>=,<=,>,<,~=.Testing
Parse. The whitespace dimension contributes zero coverage blocks. The curation rule is recorded in-file so it stays reproducible. (The rule's clauses overlap, so dedup yields 49 cases.){"2.0.post1", "==2.0.post1.*", true}), and two stale commented-out===lolwatTODOs.-raceclean;gofmt -l .silent;golangci-lint config verify+run ./...→ 0 issues at CI's pinned v2.11.2 from the module root.Compatibility
Behavior-narrowing changes:
===operand strictness, post-release wildcards, trailing line breaks, malformed quoted strings. Widening:name(). PPM currently consumes only this module'slicense/package, so the practical blast radius is small — but the module is public, so aCHANGELOGfor the next release is a filed follow-up.