fix(versions): rank only published rows in the version_updates view (audit M2) - #435
Merged
Merged
Conversation
The view reduces each `(major, minor)` line to its single highest-patch row, with no status filter inside; the caller then filters `status = 'published'`. That is too late. If a line's newest patch is draft or yanked, that row is the only one the view exposes for the line, so the caller's filter drops the entire minor rather than falling back to the line's newest published patch. With 2.46.2 published and 2.46.3 draft, nothing in the 2.46 line was offered as an update at all — while the public `update_for` endpoint, which filters before it reduces, happily offers 2.46.2. MCP's `get_version` reads this view, so `available_updates` silently omitted whole release lines. The view now ranks published rows only. A line with nothing published in it still offers nothing, so an unpublished version can't leak out as an available update. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SGfH1cdFKPnKpM7ytRThft
…version-updates # Conflicts: # crates/database/tests/it/main.rs
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.
Fixes M2 (medium) from the audit in #370.
The bug
version_updatesreduces each(major, minor)line to its single highest-patch row (ROW_NUMBER() … WHERE rn = 1) with no status filter inside.get_updates_for_versionthen filtersstatus = 'published'— too late. If the newest patch in a line is draft or yanked, that row is the only one the view exposes for the line, so the caller's filter drops the entire minor rather than falling back to the line's newest published patch.MCP's
get_versionreads this, soavailable_updatessilently omitted whole release lines. The publicupdate_forendpoint does filter-then-reduce in Rust and offers the version fine, so the two disagree.The fix
A migration redefining the view to rank published rows only — filter before the reduction, matching what
update_foralready does. A line with nothing published in it still contributes nothing, so an unpublished version can't leak out as an available update. The caller keeps itsstatusfilter as belt-and-braces.Tests
New
crates/database/tests/it/version_updates_view.rs:a_line_offers_its_newest_published_patch_not_nothing— 2.46.{1,2} published + 2.46.3 draft, and 2.47.0 published + 2.47.1 yanked; updates from 2.45.0 are[2.46.2, 2.47.0].a_wholly_unpublished_line_offers_nothing.Confirmed against the unfixed view: updates from 2.45.0 come back empty — both lines vanish, not just the draft-topped one. Slightly worse than the audit described.
Generated by Claude Code