Repository navigation
fix: the "--" terminator (F13), zero-value Version (F14), and document F11 - #17
Merged
Merged
Conversation
…, 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>
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.
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 positionFiled as "
--does not protect positional arguments." It's broader than that:reorderArgsconsumed the terminator and never re-emitted it. Stopping our scan is half the job —flag.Parsedoes its own scan over whatever we return, and--is the only token that stops it.The first exits 1 with
expected exactly one package name argument, got []— blaming the caller for a package name the parser had silently eaten.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
Versionpanics inFiles." Measured:Files(…, Version{})fmtrecovers panics raised inside aStringmethod and substitutes%!s(PANIC=…), so it returned a garbled-but-plausible errorMetadata(…, Version{})ver.String()directly as a map keyThe root cause was upstream, where 8 of 13 exported methods panicked on a zero value, including every comparison method. Fixed in
go-python-packagingv0.3.1 (posit-dev/go-python-packaging#24); this bumps to it and guards the boundary.String()returns""instead of panicking, so an uninitializedVersionstops crashing — and instead misses the map, falls through the equality scan, and returnsErrMetadataUnavailable: "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:
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'sErrMetadataUnavailablebranch is provably unreachable by mutation, which reads as dead code worth removing. It isn't:*RSFIndex, the concrete typewalkCmdholds, whoseVersions/Metadataagreement is a tested invariant (TestVersionsAndMetadataAgreeOnEveryVersion).MetadataIndexcontract permits that error for a known sdist-only release, andMockIndexalready returns it.So deleting it trades dead code for a latent gap that returns the moment
walkCmdis 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.the terminator did not protect the argument, so "--json" was parsed as a flag).Remaining
F9 (needs a new
PackageMetadatafield —rsfindex.go:390discards the unparseableRequires-Python, sodepsgenuinely cannot tell "no constraint" from "unreadable constraint"), F10, and F15.🤖 Generated with Claude Code