Skip to content

fix: the "--" terminator (F13), zero-value Version (F14), and document F11 - #17

Merged
jonyoder merged 1 commit into
mainfrom
findings-f9-f15
Aug 7, 2026
Merged

jonyoder merged 1 commit into
mainfrom
findings-f9-f15

Conversation

@jonyoder

@jonyoder jonyoder commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Three of the six remaining findings from rstudio/package-manager#19466. Two were mis-stated in the issue in ways that changed the fix.

F13 — -- never worked, in any position

Filed as "-- does not protect positional arguments." It's broader than that: reorderArgs consumed the terminator and never re-emitted it. Stopping our scan is half the job — flag.Parse does its own scan over whatever we return, and -- is the only token that stops it.

versions -- --json      ->  ["--json"]          --json parsed as a FLAG
versions pkg -- --json  ->  ["pkg", "--json"]   two positional args, not one

The first exits 1 with expected exactly one package name argument, got [] — blaming the caller for a package name the parser had silently eaten.

⚠️ The unit test asserted the broken output as want ([]string{"pkg", "--json"}), so it pinned the bug rather than the behavior, and there was no end-to-end test at all. That's how the two could coexist indefinitely. Fixed the expectation and added the missing end-to-end coverage, which asserts exit 2 (package not found) rather than exit 1.

Listed as Breaking in the changelog: arguments after -- are now taken literally. That's the documented behavior, but not the previous one.

F14 — reported against the wrong function

Filed as "a zero-value Version panics in Files." Measured:

Call Actual
Files(…, Version{}) No panic — fmt recovers panics raised inside a String method and substitutes %!s(PANIC=…), so it returned a garbled-but-plausible error
Metadata(…, Version{}) Panics — calls ver.String() directly as a map key

The root cause was upstream, where 8 of 13 exported methods panicked on a zero value, including every comparison method. Fixed in go-python-packaging v0.3.1 (posit-dev/go-python-packaging#24); this bumps to it and guards the boundary.

⚠️ The bump alone would have made things worse. With v0.3.1, String() returns "" instead of panicking, so an uninitialized Version stops crashing — and instead misses the map, falls through the equality scan, and returns ErrMetadataUnavailable: "the RSF has no metadata for that version." That blames the data for the caller's zero value, converting a loud crash into a quiet wrong answer and adding a fifth instance of the state-collapse class this repo has already fixed four times.

Verified by disabling the guard:

index "test-rsf": "flask" : metadata unavailable
                          ^ the empty version, sitting right there in the message

Deliberately not a new sentinel. The four sentinels describe states of the data; an uninitialized argument is a caller bug — nothing to branch on, only code to fix. The test asserts the error satisfies none of the four.

F11 — kept, not deleted

walk's ErrMetadataUnavailable branch is provably unreachable by mutation, which reads as dead code worth removing. It isn't:

  • It's unreachable only for *RSFIndex, the concrete type walkCmd holds, whose Versions/Metadata agreement is a tested invariant (TestVersionsAndMetadataAgreeOnEveryVersion).
  • The MetadataIndex contract permits that error for a known sdist-only release, and MockIndex already returns it.

So deleting it trades dead code for a latent gap that returns the moment walkCmd is generalized to the interface — and it would return as a silently wrong walk, not a compile error. Documented in place instead.

Verification

  • go test ./..., go vet ./... — pass. gofmt -l . — empty.
  • Each fix verified to fail without itself, individually reverted.
  • The F13 end-to-end test reports the precise diagnosis on failure (the terminator did not protect the argument, so "--json" was parsed as a flag).

Remaining

F9 (needs a new PackageMetadata field — rsfindex.go:390 discards the unparseable Requires-Python, so deps genuinely cannot tell "no constraint" from "unreadable constraint"), F10, and F15.

🤖 Generated with Claude Code

…, F11 documented

Three of the six remaining findings from rstudio/package-manager#19466.

F13 -- "--" NEVER WORKED, IN ANY POSITION, not merely "did not protect
positional arguments" as filed. reorderArgs consumed the terminator and never
re-emitted it. Stopping our own scan is half the job: flag.Parse does its own
scan over whatever we return, and "--" is the only token that stops it. So
dropping it un-protected exactly the arguments it exists to protect.

    versions -- --json      -> ["--json"]        --json parsed as a FLAG
    versions pkg -- --json  -> ["pkg","--json"]  two positional args, not one

The first exits 1, "expected exactly one package name argument, got []",
blaming the caller for a package name the parser had silently eaten. ⚠️ The unit
test asserted the BROKEN output as `want` -- []string{"pkg","--json"} -- so it
pinned the bug, and there was no end-to-end test at all, which is how both could
coexist. Fixed the expectation and added the missing end-to-end coverage.

F14 -- REPORTED AGAINST THE WRONG FUNCTION. Filed as "a zero-value Version
panics in Files". Measured: Files does NOT panic, because fmt RECOVERS a panic
raised inside a String method and substitutes "%!s(PANIC=...)", so it returned a
garbled-but-plausible error. Metadata calls ver.String() directly as a map key
and crashed. The root cause was upstream and is fixed in go-python-packaging
v0.3.1 (eight of thirteen exported methods panicked on a zero value); this bumps
to it and guards the boundary.

⚠️ THE BUMP ALONE WOULD HAVE MADE THINGS WORSE, which is why the guard is here
and not left implicit. With v0.3.1 String() returns "" instead of panicking, so
an uninitialized Version stops crashing and instead misses the map, falls through
the equality scan, and returns ErrMetadataUnavailable: "the RSF has no metadata
for that version." That blames the data for the caller passing a zero value --
converting a loud crash into a quiet wrong answer, and adding a FIFTH instance of
the state-collapse class this repo has already fixed four times. Verified by
disabling the guard: the error reads `index "test-rsf": "flask" : metadata
unavailable`, with an empty version sitting right there in the message.

Deliberately NOT a new sentinel. The four sentinels describe states of the data;
an uninitialized argument is a caller bug, with nothing to branch on and only
code to fix. The test asserts the error satisfies none of the four.

F11 -- KEPT, NOT DELETED. walk's ErrMetadataUnavailable branch is provably
unreachable, which reads as dead code. It is unreachable only for *RSFIndex, the
concrete type walkCmd holds, whose Versions/Metadata agreement is pinned by
TestVersionsAndMetadataAgreeOnEveryVersion. The MetadataIndex CONTRACT permits
that error for a known sdist-only release and MockIndex already returns it, so
deleting the branch trades dead code for a latent gap that returns the moment the
command is generalized to the interface -- as a silently wrong walk, not a
compile error. Documented in place.

Each fix verified to fail without itself. Remaining: F9 (needs a new
PackageMetadata field), F10, F15.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jonyoder
jonyoder merged commit 2ae96e1 into main Aug 7, 2026
2 checks passed
@jonyoder
jonyoder deleted the findings-f9-f15 branch August 7, 2026 18:54
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