From 0544458ec571e2812c289928e9c9406f98e4fdb6 Mon Sep 17 00:00:00 2001 From: Jonathan Yoder Date: Mon, 3 Aug 2026 11:12:20 -0400 Subject: [PATCH 1/2] 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 --- .gitignore | 3 + .../2026-08-01-18640-plan/task-3-report.md | 275 ------------------ CHANGELOG.md | 113 +++++++ CLAUDE.md | 15 + README.md | 5 + 5 files changed, 136 insertions(+), 275 deletions(-) delete mode 100644 .superpowers/sdd/2026-08-01-18640-plan/task-3-report.md create mode 100644 CHANGELOG.md diff --git a/.gitignore b/.gitignore index 1d54e1a..6d5e3f2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ coverage.html .vscode/ # roborev snapshots /.roborev/ + +# superpowers / SDD working notes (never committed) +/.superpowers/ diff --git a/.superpowers/sdd/2026-08-01-18640-plan/task-3-report.md b/.superpowers/sdd/2026-08-01-18640-plan/task-3-report.md deleted file mode 100644 index 6a8e467..0000000 --- a/.superpowers/sdd/2026-08-01-18640-plan/task-3-report.md +++ /dev/null @@ -1,275 +0,0 @@ -# Task 3 Report: Fix `internal/pep508/` — `name()`, trailing line breaks, malformed quoted strings - -## Status: DONE - -**Commit:** 374af55 - -## Summary - -Fixed three PEP 508 grammar divergences from pypa/packaging 26.2, covering 8 of the 11 measured error-case divergences. All tests pass, including with `-race`. The tokenizer changes affected `marker/` and `reqtxt/` packages as expected, but both passed all tests — no behavior was broken. One test in the `requirement/` package had the wrong expectation and was corrected. - -## Changes Made - -### 1. Allow empty parenthesised specifier (`name()`) - -**Files modified:** -- `internal/pep508/requirement.go` - -**Changes:** -- Deleted the error branch (lines 191-193) that rejected empty parentheses -- Updated the doc comment on `parseVersionSpec` to document that `name()` is valid - -**Rationale:** According to pypa/packaging's `test_empty_specifier`, an empty parenthesized group is legal and means "no constraint". The function already returns `""` (empty string) when `clauses` is empty, which is the correct behavior. - -**Test verification:** Without this fix, all 4 test cases in `TestParseRequirement_EmptyParenthesisedSpecifier` fail with "Expected version specifier inside parentheses". - -### 2. Reject trailing line breaks - -**Files modified:** -- `internal/pep508/tokenizer.go` -- `internal/pep508/requirement.go` - -**Changes in tokenizer.go:** -- Changed the `WS` token pattern from `\A\s+` to `\A[ \t]+` - - This restricts whitespace matching to horizontal whitespace only (space and tab) - - Line breaks (`\n`, `\r`) are no longer consumed as whitespace - -**Changes in requirement.go:** -- Modified the URL whitespace handling (lines 146-168) to explicitly accept and consume line breaks after a URL -- This preserves the existing behavior where `name @ url\n; marker` is valid (defensively multiline format) -- The final `consume(WS)` before `expect(End)` only consumes horizontal whitespace, so a trailing line break at the end causes the `expect(End)` check to fail with "Expected end of requirement string" - -**Rationale:** Upstream rejects trailing line breaks in all 6 variants tested (3 line breaks × 2 bases). By restricting `WS` to horizontal whitespace, a trailing line break stays unconsumed and triggers the existing end-of-input error. The URL case needed special handling because line breaks are valid separators there (common in Requires-Dist metadata). - -**Test verification:** Without the tokenizer change, all 6 test cases in `TestParseRequirement_RejectsTrailingLineBreak` fail with "An error is expected but got nil" (the line breaks were accepted). - -**Horizontal whitespace still valid:** `TestParseRequirement_AllowsTrailingHorizontalWhitespace` passes, confirming that trailing spaces and tabs remain valid. - -### 3. Reject malformed quoted strings - -**Files modified:** -- `internal/pep508/tokenizer.go` - -**Changes:** -- Changed the `QuotedString` token pattern from `\A(?:'[^']*'|"[^"]*")` to `\A(?:'[^'\\]*'|"[^"\\]*")` -- This rejects any string containing a backslash - -**Rationale:** PEP 508 marker strings have **no escape sequences**. A backslash before the closing quote leaves the string unterminated. The simplest correct fix is to reject backslashes entirely, which matches upstream behavior for both `"C:\"` and `"\x"`. - -**Test verification:** Without this fix, both test cases in `TestParseRequirement_RejectsMalformedQuotedString` fail with "An error is expected but got nil" (the malformed strings were accepted). - -## Impact on Other Packages - -### `marker/` package -- All tests passed (0.652s without race, 1.998s with race) -- No changes needed -- The tokenizer is shared, but the whitespace and quoted string changes are correct for markers too - -### `reqtxt/` package -- All tests passed (0.603s without race, 1.677s with race) -- No changes needed -- This package handles its own line splitting before tokenizing, so the WS change doesn't affect it - -### `requirement/` package -- One test updated: `TestParse_VersionSpec_EmptyParens_IsError` → `TestParse_VersionSpec_EmptyParens_IsValid` -- The old test expected `foo()` to be an error, but according to upstream it should be valid -- This is a correction of a wrong expectation, not a behavior regression - -## Commands Run - -### Test execution -```bash -# Initial test run to verify failures -cd /Users/jonyoder/Dev/gpp-worktrees/conformance-18640 -go test ./internal/pep508/ -run 'TestParseRequirement_' -v -# Result: 4 failures in EmptyParenthesisedSpecifier, 6 in RejectsTrailingLineBreak, -# 2 in RejectsMalformedQuotedString (as expected) - -# After fixes, run pep508 tests -go test ./internal/pep508/ -run 'TestParseRequirement_' -v -# Result: PASS, all 4 new test functions pass - -# Full module test -go test ./... -# Result: PASS all packages except requirement (test expectation bug) - -# After fixing requirement test -go test ./... -# Result: PASS all 14 packages - -# Race detector -go test -race ./... -# Result: PASS all 14 packages -``` - -### Individual fix verification (stash and test) -```bash -# Fix 1: Empty parenthesised specifier -git stash push internal/pep508/requirement.go requirement/requirement_test.go -go test ./internal/pep508/ -run TestParseRequirement_EmptyParenthesisedSpecifier -v -# Result: FAIL - all 4 cases fail with "Expected version specifier inside parentheses" -git stash pop - -# Fix 2: Trailing line breaks -git stash push internal/pep508/tokenizer.go -go test ./internal/pep508/ -run TestParseRequirement_RejectsTrailingLineBreak -v -# Result: FAIL - all 6 cases fail with "An error is expected but got nil" - -# Fix 3: Malformed quoted strings -go test ./internal/pep508/ -run TestParseRequirement_RejectsMalformedQuotedString -v -# Result: FAIL - both cases fail with "An error is expected but got nil" -git stash pop -``` - -### Formatting and linting -```bash -gofmt -l . -# Result: (empty output - all files correctly formatted) - -golangci-lint config verify -golangci-lint run ./... --timeout 10m -# Result: 0 issues -``` - -## Test Results Summary - -**New tests added:** 4 test functions in `internal/pep508/grammar_conformance_test.go` -- `TestParseRequirement_EmptyParenthesisedSpecifier` (4 subtests) -- `TestParseRequirement_RejectsTrailingLineBreak` (6 subtests) -- `TestParseRequirement_AllowsTrailingHorizontalWhitespace` (3 subtests) -- `TestParseRequirement_RejectsMalformedQuotedString` (2 subtests) - -**Tests modified:** 1 in `requirement/requirement_test.go` -- `TestParse_VersionSpec_EmptyParens_IsError` → `TestParse_VersionSpec_EmptyParens_IsValid` - -**All module tests:** 14 packages, all PASS -**Race detector:** All PASS -**Lint:** 0 issues - -## Notes - -1. **URL whitespace handling:** The most complex part of this task was handling the `name @ url\n; marker` case. A newline after a URL is valid as a separator (defensively multiline format), but a trailing newline at the end of the requirement should be rejected. The fix adds explicit line-break consumption after a URL while keeping the final `consume(WS)` horizontal-only. - -2. **No tokenizer breakage:** The tokenizer is shared with `marker/` and `reqtxt/`, but both packages passed all tests. The whitespace and quoted-string changes are correct for all consumers. - -3. **Upstream citation:** The test file includes the upstream commit pinned at `4eb0753dba8fcaaac8eb75463374e448f0931558` (pypa/packaging). - -4. **No provenance blocks added:** As instructed, I did not add per-file provenance blocks (separate issues #19394, #19395). - -## Fix round 1 - -### Status: DONE - -**What was wrong:** The brief's premise that "PEP 508 marker strings have no escape sequences" was incorrect. Upstream `pypa/packaging` at the pinned SHA (`4eb0753dba8fcaaac8eb75463374e448f0931558`) does NOT reject all backslashes. The tokenizer pattern is `('[^']*')|("[^"]*")` (no backslash exclusion), and the parser calls `ast.literal_eval(token.text)` to decode Python string-literal escapes. Only *invalid* escapes are rejected. - -The prior implementation's `QuotedString` pattern `\A(?:'[^'\\]*'|"[^"\\]*")` rejected all backslashes, which was over-strict. - -### Changes Made - -**Files modified:** -- `internal/pep508/tokenizer.go` -- `internal/pep508/marker.go` -- `internal/pep508/grammar_conformance_test.go` - -### 1. Reverted tokenizer pattern to upstream's form - -**File:** `internal/pep508/tokenizer.go:191` - -Changed `QuotedString` pattern from: -```go -QuotedString: regexp.MustCompile(`\A(?:'[^'\\]*'|"[^"\\]*")`), -``` - -To upstream's exact form: -```go -QuotedString: regexp.MustCompile(`\A(?:'[^']*'|"[^"]*")`), -``` - -This allows backslashes to tokenize normally, matching upstream behavior. - -### 2. Fixed wrong comment about escape handling - -**File:** `internal/pep508/tokenizer.go:140-146` - -The comment previously claimed packaging "takes `token.text[1:-1]` directly" — it does not. Updated to describe what upstream actually does (`ast.literal_eval`), and note that we deliberately do not implement full escape decoding (out of scope), but validate only the two specific malformed cases upstream asserts. - -### 3. Added targeted validation logic in marker.go - -**File:** `internal/pep508/marker.go:315-325, 352-394` - -Added validation where the marker literal is produced (`parseMarkerVar`), mirroring upstream's structure (tokenize permissively, then validate): - -- New function `validateQuotedStringContents(s string)` checks for: - 1. **Trailing unpaired backslash** — counts consecutive backslashes at end, rejects if odd - 2. **Truncated `\x` escape** — finds any `\x` not followed by two hex digits - -- Returns `&SyntaxError{Msg: "Invalid quoted string"}` — matching upstream's wording - -- New helper `isHexDigit(c byte)` checks if a character is 0-9, a-f, or A-F - -### 4. Updated test to accept valid escapes - -**File:** `internal/pep508/grammar_conformance_test.go:55-82` - -- Split `TestParseRequirement_RejectsMalformedQuotedString` into two sections: - - Still **REJECTS** `"C:\"` (trailing unpaired backslash) and `"\x"` (truncated escape) - - Newly **ACCEPTS** `"C:\\U"` (doubled backslash, paired) and `"\n"` (newline escape) - -- Added comments noting we accept the token but do not decode the escape - -### Verification - -All commands run from `/Users/jonyoder/Dev/gpp-worktrees/conformance-18640`: - -**1. Test the new logic:** -```bash -go test ./internal/pep508/ -v -run TestParseRequirement_RejectsMalformedQuotedString -# Result: PASS (4 subtests: 2 rejects, 2 accepts) -``` - -**2. All conformance tests:** -```bash -go test ./internal/pep508/ -v -run TestParseRequirement_ -# Result: PASS (all 4 test functions, 33 total subtests) -``` - -**3. Full module test:** -```bash -go test ./... -# Result: PASS all 14 packages -``` - -**4. Race detector:** -```bash -go test -race ./... -# Result: PASS all 14 packages -``` - -**5. Verify rejections fail without validation:** -```bash -git stash push internal/pep508/marker.go -go test ./internal/pep508/ -run "TestParseRequirement_RejectsMalformedQuotedString/reject" -v -# Result: FAIL - both rejection cases fail with "An error is expected but got nil" -git stash pop -``` - -This proves the validation logic is necessary. - -**6. Formatting and linting:** -```bash -gofmt -l . -# Result: (empty - all files correctly formatted after gofmt -w .) - -golangci-lint config verify -golangci-lint run ./... --timeout 10m -# Result: 0 issues -``` - -### Summary - -The fix correctly implements upstream's behavior: -- **Accepts** valid Python string escapes (`"C:\\U"`, `"\n"`) -- **Rejects** the two specific malformed cases upstream asserts (`"C:\"`, `"\x"`) -- **Does not decode** escapes (out of scope, left for future work) - -The tokenizer pattern now matches upstream exactly, and validation logic mirrors upstream's structure (permissive tokenization + targeted validation). diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..adebf1f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,113 @@ +# Changelog + +All notable changes to this module are documented here. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +While the major version is `0`, breaking changes ship in a **minor** bump rather +than a major one, and are always listed under a `Breaking` heading so they are not +mistaken for a safe patch upgrade. + +## [Unreleased] + +## [0.2.0] - 2026-08-03 + +A conformance release. `requirement/`, `version/`, and the PEP 508 grammar are now +tested against tables ported from `pypa/packaging`'s `tests/test_requirements.py` +(upstream SHA `4eb0753`), and the divergences those tables revealed are fixed. + +Several of those fixes **narrow what parses**, and one **changes rendered output**. +Read the Breaking section before upgrading — this is why the release is `0.2.0` +rather than `0.1.3`. + +### Breaking + +- `Requirement.String()` renders the marker separator as `"; "` when the requirement + has no URL. It previously always rendered `" ; "`. The `" ; "` form is kept when a + URL *is* present, because a bare `;` immediately after a URL is ambiguous — a URL + may itself contain `;`. Consumers that compare, hash, cache, or persist rendered + requirement strings will see different bytes for the same input. +- Arbitrary equality (`===`) accepts exactly one token. `=== lolwat` is valid and + normalizes to `===lolwat`; `===any string here` is now rejected. Previously the + whole operand was rejected regardless of shape. +- A `.*` prefix match is rejected on a post-release (for example `==1.2.3.post4.*`). + Validation previously covered only dev and local releases. +- A trailing line break (`\n`, `\r`, or `\r\n`) in a requirement string is rejected. + A trailing space or tab is still accepted. +- Malformed quoted strings in environment markers are rejected: a trailing unpaired + backslash (`os_name == "C:\"`) and a truncated `\x` escape (`"\x"`). Valid Python + escapes still parse, including a doubled backslash immediately before an `x` + (`"C:\\xyz"`). + +### Added + +- `name()` — an empty parenthesized specifier group — is valid, and means "no version + constraint". +- Conformance tables ported from `pypa/packaging` for PEP 508 requirements and grammar, + including an invariant that a specifier string can never yield more specifiers than + it contains operators. + +### Fixed + +- The PEP 440 operator alternation is built in a deterministic, longest-first order. + It was previously assembled by ranging a Go map, so the compiled pattern varied from + process to process. Because Go's `regexp` is leftmost-**first** rather than + leftmost-longest, an operator that is a prefix of another one could win the match. + +### Notes + +- The trailing-line-break rule matches upstream's current source, not the released + `packaging` 26.2. Upstream changed its end-of-input rule from `$` to `\Z` after 26.2; + Python's `$` matches *before* a trailing newline, so 26.2 still accepts `"name>=1\n"`. + Comparing this module against a `pip install packaging` will show a difference that + is upstream's version skew, not a divergence here. +- Full Python string-escape decoding is deliberately not implemented. Upstream gets it + from `ast.literal_eval`; this module validates only the two malformed forms upstream's + tests assert, and does not decode escapes. +- The operator-less specifier `"2.0"` is still accepted. Tightening it is behavior- + narrowing and is tracked in rstudio/package-manager#18634. + +## [0.1.2] - 2026-07-31 + +### Fixed + +- `version/`: PEP 440 pre-release spellings are ordered longest-first in the compiled + pattern, so a specifier like `==1.0alpha1` no longer silently matches nothing + (rstudio/package-manager#19369). + +## [0.1.1] - 2026-07-23 + +### Fixed + +- `license/`: the SPDX expression tokenizer decodes runes rather than bytes, so + multi-byte whitespace separators such as `NBSP` no longer prevent an expression from + being split. +- `license/`: `GNU Lesser General Public License v3 (LGPLv3)` maps to `LGPL-3.0-only` + rather than `LGPL-3.0-or-later` — a separate `LGPLv3+` classifier denotes or-later. +- `license/`: the versionless `GNU General Public License (GPL)` and + `GNU Library or Lesser General Public License (LGPL)` classifiers no longer fabricate + a version the metadata does not declare, and derive to `Unknown`. + + All three change license-derivation output (rstudio/package-manager#19135). + +## [0.1.0] - 2026-07-23 + +Initial release. One module, one package per PEP concern: + +- `version/` — PEP 440 versions and specifiers (migrated from `rstudio/go-pep440-version`). +- `requirement/` — PEP 508 dependency specifiers. +- `marker/` — PEP 508 environment markers and evaluation. +- `extras/` — PEP 685 extra-name normalization. +- `reqtxt/` — pip `requirements.txt` parsing, flattening, and round-trippable rendering. +- `distribution/` — METADATA and wheel parsing (migrated from + `rstudio/python-distribution-parser`). +- `wheelname/` — PEP 427 wheel filename to name/version/build/tags. +- `tags/` — PEP 425/600/656 compatibility tags, target-parameterized with no host + detection. +- `license/` — PyPI classifier standardization, SPDX expression parsing, and top-level + license derivation. + +[Unreleased]: https://github.com/posit-dev/go-python-packaging/compare/v0.2.0...HEAD +[0.2.0]: https://github.com/posit-dev/go-python-packaging/compare/v0.1.2...v0.2.0 +[0.1.2]: https://github.com/posit-dev/go-python-packaging/compare/v0.1.1...v0.1.2 +[0.1.1]: https://github.com/posit-dev/go-python-packaging/compare/v0.1.0...v0.1.1 +[0.1.0]: https://github.com/posit-dev/go-python-packaging/releases/tag/v0.1.0 diff --git a/CLAUDE.md b/CLAUDE.md index ce71b79..332cffe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -81,6 +81,21 @@ GitHub workflow — they run locally as you commit. - Treat RoboRev findings the way PPM treats its automated PR review: address Critical/Important findings before merge; record or dismiss Minor ones deliberately, not silently. +## Changelog + +`CHANGELOG.md` is the only signal a downstream consumer of this **public** module has. +Any change that alters what parses, what a `String()` method renders, or what a +derivation returns needs an entry under `## [Unreleased]` in the same PR — behavior +narrowing especially, because a consumer's previously-valid input starts erroring. + +- Sections: `Breaking`, `Added`, `Fixed`, `Notes`. Put narrowing changes under + `Breaking`, not `Fixed`, even when the old behavior was a bug. +- While the major version is `0`, breaking changes ship in a **minor** bump (`0.1.x` + → `0.2.0`), never a patch. A consumer pinning `^0.1` would otherwise pick up a + narrowing change silently. +- Internal refactors, test-only changes, and dependency bumps do not need entries. +- CI does not validate the changelog, so this is a review concern. + ## Committing Commit early and often. After each self-contained change that builds and passes tests, make a diff --git a/README.md b/README.md index 4ac3cdd..63939d9 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ Part of [RFD 0001 — Native Go PyPI Dependency Resolution](https://github.com/r | `wheelname/` | PEP 427 wheel filename → name/version/build/tags (implemented) | | `tags/` | PEP 425/600/656 compatibility tags (server-side, target-parameterized; no host detection) | +## Changelog + +See [`CHANGELOG.md`](CHANGELOG.md). Breaking changes ship in a minor bump while the +major version is `0`, so check the `Breaking` heading before upgrading. + ## License Dual-licensed under **Apache-2.0** OR **MIT** at your option. Every source From ce9508bfd113446bb9b80f3d6b5864f4de26bd8d Mon Sep 17 00:00:00 2001 From: Jonathan Yoder Date: Mon, 3 Aug 2026 11:44:00 -0400 Subject: [PATCH 2/2] 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 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index adebf1f..95f2fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,13 @@ rather than `0.1.3`. backslash (`os_name == "C:\"`) and a truncated `\x` escape (`"\x"`). Valid Python escapes still parse, including a doubled backslash immediately before an `x` (`"C:\\xyz"`). +- Local version labels now normalize their `-` and `_` separators to `.`, as PEP 440 + requires. `1.0+abc-abc` previously stayed verbatim; it now renders as `1.0+abc.abc` + and compares equal to it. **This also changes ordering**, and fixes a wrong answer: + a label was compared as a single alphabetic segment, so `1.0+ubuntu-2` sorted + *above* `1.0+ubuntu-10`. It now sorts below, matching upstream. Consumers that + persist or compare rendered versions, or that rely on the previous sort order of + dash- or underscore-separated local labels, will see a difference. ### Added @@ -45,6 +52,12 @@ rather than `0.1.3`. - Conformance tables ported from `pypa/packaging` for PEP 508 requirements and grammar, including an invariant that a specifier string can never yield more specifiers than it contains operators. +- A vertical tab is accepted as surrounding whitespace around a version, matching + upstream. Go's `\s` omits `\v` where Python's includes it, so `"1.0\v"` was + previously rejected. +- Property-based tests (`pgregory.net/rapid`) adapted from upstream's Hypothesis + suite. This is a test-only dependency and does not enter the module's non-test + import graph. ### Fixed